forked from fzyz999/Lucky_OIer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
101 lines (87 loc) · 3.21 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* This file is part of Lucky OIer
*
* Copyright (C) 2012 by Wang Luming <wlm199558@126.com>
*
* Lucky OIer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Lucky OIer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Lucky OIer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
read_settings();
p_tabmgr=new TabManager(this);
setCentralWidget(p_tabmgr);
create_menu();
}
MainWindow::~MainWindow()
{
write_settings();
}
void MainWindow::about_dialog()
{
aboutDialog aboutdlg(this);
aboutdlg.exec();
}
void MainWindow::create_menu()
{
QMenuBar *menubar=new QMenuBar(this);
QMenu *menu=new QMenu(tr("file"),menubar);
menu->addAction(tr("new"),p_tabmgr,SLOT(new_file()),QKeySequence(QKeySequence::New));
menu->addAction(tr("open"),p_tabmgr,SLOT(open_file()),QKeySequence(QKeySequence::Open));
menu->addSeparator();
menu->addAction(tr("save"),p_tabmgr,SLOT(save()),QKeySequence(QKeySequence::Save));
menu->addAction(tr("save all"),p_tabmgr,SLOT(save_all()));
menu->addSeparator();
menu->addAction(tr("quit"),this,SLOT(close()),QKeySequence(QKeySequence::Quit));
menubar->addMenu(menu);
menu=new QMenu(tr("edit"),menubar);
menu->addAction(tr("redo"),p_tabmgr,SLOT(redo()),QKeySequence(QKeySequence::Redo));
menu->addAction(tr("undo"),p_tabmgr,SLOT(undo()),QKeySequence(QKeySequence::Undo));
menu->addSeparator();
menu->addAction(tr("cut"),p_tabmgr,SLOT(cut()),QKeySequence(QKeySequence::Cut));
menu->addAction(tr("copy"),p_tabmgr,SLOT(copy()),QKeySequence(QKeySequence::Copy));
menu->addAction(tr("paste"),p_tabmgr,SLOT(paste()),QKeySequence(QKeySequence::Paste));
menu->addAction(tr("select all"),p_tabmgr,SLOT(paste()),QKeySequence(QKeySequence::SelectAll));
/* TODO: options menu
menu->addAction(tr("options"));*/
menubar->addMenu(menu);
menu=new QMenu(tr("help"),menubar);
menu->addAction(tr("about"),this,SLOT(about_dialog()));
menu->addAction(tr("about Qt"),this,SLOT(about_qt()));
menubar->addMenu(menu);
setMenuBar(menubar);
}
void MainWindow::read_settings()
{
QSettings settings;
settings.beginGroup("mainwindow");
resize(settings.value("windowSize",QSize(600,500)).toSize());
restoreGeometry(settings.value("geometry").toByteArray());
restoreState(settings.value("windowState").toByteArray());
settings.endGroup();
}
void MainWindow::write_settings()
{
QSettings settings;
settings.beginGroup("mainwindow");
settings.setValue("windowSize",size());
settings.setValue("geometry", saveGeometry());
settings.setValue("windowState", saveState());
settings.endGroup();
}
void MainWindow::about_qt()
{
QMessageBox::aboutQt(this);
}