1 #include "mainwindow.h"
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18 #include
19 #include
20
21 MainWindow::MainWindow(QWidget *parent)22 : QMainWindow(parent)23 {24 //查找文本框
25 find_dialog = new FindDialog(this);26 //替换文本框
27 replace_dialog = new replacedialog(this);28 //剪贴板
29 clipboard =QApplication::clipboard();30
31 this->resize(900, 700);32 CreateMenu();33 Creatslots();34 }35
36 voidMainWindow::CreateMenu()37 {38 /*添加核心控件*/
39 textEdit = new QTextEdit(this);40 this->setCentralWidget(textEdit);41 cur_file_name = "";42 sbar =statusBar();43 label = new QLabel(this);44
45 /*添加菜单栏*/
46 qBar =menuBar();47 //添加菜单--文件
48 menu_file = qBar->addMenu("文件(F)");49 menu_file_new = menu_file->addAction("新建(N)");50 menu_file_new->setShortcut(QKeySequence::New);51 menu_file_new_win = menu_file->addAction("新窗口(W)");52 menu_file_open = menu_file->addAction("打开(O)");53 menu_file_open->setShortcut(QKeySequence::Open);54 menu_file_save = menu_file->addAction("保存(S)");55 menu_file_save->setShortcut(QKeySequence::Save);56 menu_file_save_as = menu_file->addAction("另存为(S)");57 menu_file_save_as->setShortcut(QKeySequence::SaveAs);58 menu_file->addSeparator();59 menu_file_print = menu_file->addAction("打印(P)");60 menu_file_print->setShortcut(QKeySequence::Print);61 menu_file->addSeparator();62 menu_file_quit = menu_file->addAction("退出(X)");63 menu_file_quit->setShortcut(QKeySequence::Quit);64
65 //添加菜单项--编辑
66 menu_edit = qBar->addMenu("编辑(E)");67 menu_edit_undo = menu_edit->addAction("撤销(U)");68 menu_edit_undo->setShortcut(QKeySequence::Undo);69 menu_edit_undo->setEnabled(false);70 menu_edit->addSeparator();71 menu_edit_cut = menu_edit->addAction("剪切(T)");72 menu_edit_cut->setShortcut(QKeySequence::Cut);73 menu_edit_cut->setEnabled(false);74 menu_edit_copy = menu_edit->addAction("复制(C)");75 menu_edit_copy->setShortcut(QKeySequence::Copy);76 menu_edit_copy->setEnabled(false);77 menu_edit_paste = menu_edit->addAction("粘贴(P)");78 menu_edit_paste->setShortcut(QKeySequence::Paste);79 menu_edit_delete = menu_edit->addAction("删除(D)");80 menu_edit_delete->setShortcut(QKeySequence::Delete);81 menu_edit_delete->setEnabled(false);82 menu_edit_delete->setShortcut(QKeySequence::Delete);83 menu_edit->addSeparator();84 menu_edit_find = menu_edit->addAction("查找(F)");85 menu_edit_find->setShortcut(QKeySequence::Find);86 menu_edit_replace = menu_edit->addAction("替换(R)");87 menu_edit_replace->setShortcut(QKeySequence::Replace);88 menu_edit->addSeparator();89 menu_edit_all = menu_edit->addAction("全选(A)");90 menu_edit_all->setShortcut(QKeySequence::SelectAll);91
92 //添加菜单项--格式
93 menu_format = qBar->addMenu("格式(O)");94 menu_format_warp = menu_format->addAction("自动换行(W)");95 menu_format_font = menu_form