#include <QtGui>
#include <QDateTime>
#include <QTextCursor>
#include "windowmanager.h"
#include "mainwindow.h"
#include "finddialog.h"
#include "replacedialog.h"
#include "gotodialog.h"
extern windowManager *wmanager;
MainWindow::MainWindow(QString fileName, windowListNode *_myNode, QWidget *parent)
: QMainWindow(parent)
{
myNode = _myNode;
setAttribute(Qt::WA_DeleteOnClose);
setAcceptDrops(true);
textEdit = new QTextEdit(this);
setCentralWidget(textEdit);
textEdit->setAcceptRichText(false);
textEdit->setFocus();
textCodecName = QTextCodec::codecForLocale()->name();
createActions();
createMenus();
createStatusBar();
if (!fileName.isEmpty()){
loadFile(fileName);
} else {
setCurrentFile("");
}
readSettings();
setFormat(true);
connect(textEdit, SIGNAL(textChanged ()),
this, SLOT(textModified()));
findDialog = 0;
replaceDialog = 0;
gotoDialog = 0;
printer = 0;
utf8HaveBom = true;
setWindowIcon(QIcon(":/nipad_icon.ico"));
}
MainWindow::~MainWindow() //删除没有父对象的指针,防止内存泄露
{
delete CurrentTextCursor;
if (printer)
delete printer;
wmanager->deleteClosed(myNode);
}
void MainWindow::createActions()
{
newAction = new QAction(tr("新建(&N)"), this);
newAction->setShortcut(QKeySequence::New);
connect(newAction, SIGNAL(triggered()), this, SLOT(newFile()));
openAction = new QAction(tr("打开(&O)..."), this);
openAction->setShortcut(QKeySequence::Open);
connect(openAction, SIGNAL(triggered()), this, SLOT(open()));
saveAction = new QAction(tr("保存(&S)"), this);
saveAction->setShortcut(QKeySequence::Save);
connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
saveAsAction = new QAction(tr("另存为(&A)..."), this);
connect(saveAsAction, SIGNAL(triggered()), this, SLOT(saveAs()));
pageSetupAction = new QAction(tr("页面设置(&U)..."), this);
connect(pageSetupAction, SIGNAL(triggered()), this, SLOT(pageSetup()));
printAction = new QAction(tr("打印(&P)..."), this);
printAction->setShortcut(QKeySequence::Print);
connect(printAction, SIGNAL(triggered()), this, SLOT(print()));
exitAction = new QAction(tr("退出(&X)"), this);
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
undoAction = new QAction(tr("撤销(&U)"), this);
undoAction->setShortcut(QKeySequence::Undo);
connect(undoAction, SIGNAL(triggered()), this, SLOT(undo()));
undoAction->setEnabled(false);
connect(textEdit->document(), SIGNAL(undoAvailable(bool)),
undoAction, SLOT(setEnabled(bool)));
redoAction = new QAction(tr("重做(&R)"), this);
redoAction->setShortcut(QKeySequence::Redo);
connect(redoAction, SIGNAL(triggered()), this, SLOT(redo()));
redoAction->setEnabled(false);
connect(textEdit->document(), SIGNAL(redoAvailable(bool)),
redoAction, SLOT(setEnabled(bool)));
cutAction = new QAction(tr("剪切(&T)"), this);
cutAction->setShortcut(QKeySequence::Cut);
connect(cutAction, SIGNAL(triggered()), this, SLOT(cut()));
cutAction->setEnabled(false);
connect(textEdit, SIGNAL(copyAvailable(bool)), cutAction, SLOT(setEnabled(bool)));
copyAction = new QAction(tr("复制(&C)"), this);
copyAction->setShortcut(QKeySequence::Copy);
connect(copyAction, SIGNAL(triggered()), this, SLOT(copy()));
copyAction->setEnabled(false);
connect(textEdit, SIGNAL(copyAvailable(bool)), copyAction, SLOT(setEnabled(bool)));
pasteAction = new QAction(tr("粘贴(&P)"), this);
pasteAction->setShortcut(QKeySequence::Paste);
connect(pasteAction, SIGNAL(triggered()), this, SLOT(paste()));
pasteAction->setEnabled(false);
#ifndef QT_NO_CLIPBOARD
pasteAction->setEnabled(!QApplication::clipboard()->text().isEmpty());
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
#endif
deleteAction = new QAction(tr("删除(&D)"), this);
deleteAction->setShortcut(QKeySequence::Delete);
connect(deleteAction, SIGNAL(triggered()), this, SLOT(del()));
deleteAction->setEnabled(false);
connect(textEdit, SIGNAL(copyAvailable(bool)), deleteAction, SLOT(setEnabled(bool)));
findAction = new QAction(tr("查找(&F)..."), this);
findAction->setShortcut(QKeySequence::Find);
connect(findAction, SIGNAL(triggered()), this, SLOT(find()));
findAction->setEnabled(false);
findNextAction = new QAction(tr("查找下一个(&N)"), this);
findNextAction->setShortcut(QKeySequence::FindNext);
findNextAction->setEnabled(false);
connect(findNextAction, SIGNAL(triggered()), this, SLOT(findNext()));
replaceAction = new QAction(tr("替换(&R)..."), this);
replaceAction->setShortcut(QKeySequence::Replace);
connect(replaceAction, SIGNAL(triggered()), this, SLOT(replace()));
gotoAction = new QAction(tr("转到(&G)..."), this);
gotoAction->setShortcut(tr("Ctrl+G"));
connect(gotoAction, SIGNAL(triggered()), this, SLOT(gotoSlot()));
selectAllAction = new QAction(tr("全选(&A)"), this);
selectAllAction->setShortcut(QKeySequence::SelectAll);
connect(selectAllAction, SIGNAL(triggered()), this, SLOT(selectAll()));
timeDateAction = new QAction(tr("时间/日期(&D)"), this);
timeDateAction->setShortcut(tr("F5"));
connect(timeDateAction, SIGNAL(triggered()), this, SLOT(timeDate()));
wordWrapAction = new QAction(tr("自动换行(&W)"), this);
wordWrapAction->setCheckable(true);
connect(wordWrapAction, SIGNAL(triggered(bool)), this, SLOT(setFormat(bool)));
fontAction = new QAction(tr("字体(&F)..."), this);
connect(fontAction, SIGNAL(triggered()), this, SLOT(setFont()));
statusBarAction = new QAction(tr("状态栏(&S)"), this);
statusBarAction->setCheckable(true);
connect(statusBarAction, SIGNAL(triggered(bool)), this, SLOT(setFormat(bool)));
aboutAction = new QAction(tr("关于(&A)"), this);
connect(aboutAction, SIGNAL(triggered()), this, SLOT(aboutNipad()));
aboutQtAction = new QAction(tr("关于&Qt"), this);
connect(aboutQtAction, SIGNAL(triggered()), this, SLOT(aboutQt()));
}
void MainWindow::createMenus()
{
fileMenu = menuBar()->addMenu(tr("文件(&F)"));
fileMenu->addAction(newAction);
fileMenu->addAction(openAction);
fileMenu->addAction(saveAction);
fileMenu->addAction(saveAsAction);
fileMenu->addSeparator();
fileMenu->addAction(pageSetupAction);
fileMenu->addAction(printAction);
fileMenu->addSeparator();
fileMenu->addAction(exitAction);
editMenu = menuBar()->addMenu(tr("编辑(&E)"));
editMenu->addAction(undoAction);
editMenu->addAction(redoAction);
editMenu->addSeparator();
editMenu->addAction(cutAction);
editMenu->addAction(copyAction);
editMenu->addAction(pasteAction);
editMenu->addAction(deleteAction);
editMenu->addSeparator();
editMenu->addAction(findAction);
editMenu->addAction(findNextAction);
editMenu->addAction(replaceAction);
editMenu->addAction(gotoAction);
editMenu->addSeparator();
editMenu->addAction(selectAllAction);
editMenu->addAction(timeDateAction);
formatMenu = menuBar()->addMenu(tr("格式(&O)"));
formatMenu->addAction(wordWrapAction);
formatMenu->addAction(fontAction);
viewMenu = menuBar()->addMenu(tr("查看(&V)"));
viewMenu->addAction(statusBarAction);
menuBar()->addSeparator();
helpMenu = menuBar()->addMenu(tr("帮助(&H)"));
helpMenu->addAction(aboutAction);
helpMenu->addSeparator();
helpMenu->addAction(aboutQtAction);
}
void MainWindow::dragEnterEvent(QDragEnterEvent *event)
{
【源代码】用C++、Qt实现的记事本,模拟Windows自带的
4星 · 超过85%的资源 需积分: 14 142 浏览量
2012-10-17
20:52:19
上传
评论 3
收藏 3.96MB 7Z 举报
wc_111191
- 粉丝: 0
- 资源: 6
最新资源
- week6.1.7z
- 移动机器人自主路径规划之RRTStar算法MATLAB实现代码
- 基于Python+OpenCV+FFmpeg实现自动识别电影剪辑+分析剪辑主题颜色+源码+文档(毕业设计&课程设计&项目开发)
- 基于python的二手商品交易平台 python+django开发的供需平台
- 微信小程序源码 侧滑布局小程序 (源码下载 +内附使用说明)
- heima-JUC-资料
- coreg_FSL.sh
- ROS+YOLOV8+SLAM智能小车导航实战(四、激光雷达+SLAM建图)
- 什么是决策树,有哪些适用场景?
- 基于python开发的口红色号识别程序+源码+开发文档+源码解析(毕业设计&课程设计&项目开发)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页