forked from QNnovation/ZBC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zbc_mainwindow.cpp
199 lines (170 loc) · 6.13 KB
/
zbc_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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//#include <QDebug>
#include "zbc_styles.h"
#include "zbc_mainwindow.h"
#include "zbc_centralwidget.h"
#include <QApplication>
#include <QDir>
#include <QMenuBar>
#include <QPalette>
#include <QProcess>
#include <QToolBar>
#include <QSettings>
#include <QStyleFactory>
//C-tor
ZBC_MainWindow::ZBC_MainWindow(QWidget* pwgt) : QMainWindow(pwgt)
{
this->setWindowIcon(QIcon(":/mainwindow/icons/resource/app.ico"));
//Actions
QAction* pactQuit = new QAction(QIcon(":/mainwindow/icons/resource/close.ico"), "Quit", this);
QAction* pactBack = new QAction(QIcon(":/buttons/toolbar/resource/left32.ico"), tr("Back"), this);
QAction* pactForward = new QAction(QIcon(":/buttons/toolbar/resource/right32.ico"), tr("Forward"), this);
QAction* pactCMD = new QAction(QIcon(":/buttons/toolbar/resource/cmd.ico"), tr("Run cmd.exe"), this);
QAction* pactNotepad = new QAction(QIcon(":/buttons/toolbar/resource/notepad.ico"), tr("Run notepad.exe"), this);
QAction* pactPaint = new QAction(QIcon(":/buttons/toolbar/resource/paint.ico"), tr("Run mspaint.exe"), this);
QAction* pactCalc = new QAction(QIcon(":/buttons/toolbar/resource/calc.ico"), tr("Run calc.exe"), this);
QAction* pactTaskmgr = new QAction(QIcon(":/buttons/toolbar/resource/taskmgr.ico"), tr("Run taskmgr.exe"), this);
// QAction* pactRegedit = new QAction(QIcon(":/buttons/toolbar/resource/regedit.ico"), tr("Run regedit.exe"), this);
//Menu Bar
QMenu* pmnuFile = menuBar()->addMenu("File");
pmnuFile->addAction(pactQuit);
QMenu* pmnuView = menuBar()->addMenu("View");
QMenu* pmnuSetStyle = new QMenu("Set Style", this);
pmnuView->addMenu(pmnuSetStyle);
for( QString styleName : QStyleFactory::keys() )
{
if (styleName == "Fusion"){
QMenu* pmnuFusion = new QMenu("Fusion");
pmnuSetStyle->addMenu(pmnuFusion);
QAction* pactFusionDefault = new QAction("Default", this);
QAction* pactFusionDark = new QAction("Dark", this);
pmnuFusion->addAction(pactFusionDefault);
pmnuFusion->addAction(pactFusionDark);
connect(pactFusionDefault,
&QAction::triggered,
[=](){
QApplication::setStyle(QStyleFactory::create("Fusion"));
});
connect(pactFusionDark,
&QAction::triggered,
[=](){
QApplication::setStyle(new ZBC_SimpleStyle);
});
}
else{
QAction* pactStyle = new QAction(styleName, this);
pmnuSetStyle->addAction(pactStyle);
connect(pactStyle,
&QAction::triggered,
[=](){
QApplication::setStyle(QStyleFactory::create(styleName));
});
}
}
//Tool Bar
/*
QToolBar* ptbrFile = addToolBar("File");
ptbrFile->setMovable(false);
ptbrFile->addAction(pactQuit);
*/
QToolBar* ptbrGo = addToolBar("Go");
ptbrGo->setMovable(false);
ptbrGo->addAction(pactBack);
ptbrGo->addAction(pactForward);
QToolBar* ptbrTools = addToolBar(tr("Tools"));
ptbrTools->setMovable(false);
ptbrTools->addAction(pactCMD);
ptbrTools->addAction(pactNotepad);
ptbrTools->addAction(pactPaint);
ptbrTools->addAction(pactCalc);
ptbrTools->addAction(pactTaskmgr);
// ptbrTools->addAction(pactRegedit);
//Central Widget
ZBC_CentralWidget* pzbcCwgt = new ZBC_CentralWidget(this);
this->setCentralWidget(pzbcCwgt);
//Connections
//Quit
connect(pactQuit,
&QAction::triggered,
this,
&QMainWindow::close);
//Go Back
connect(pactBack,
&QAction::triggered,
pzbcCwgt,
&ZBC_CentralWidget::goBack
);
//Go Forward
connect(pactForward,
&QAction::triggered,
pzbcCwgt,
&ZBC_CentralWidget::goForward);
//Run cmd.exe
connect(pactCMD,
&QAction::triggered,
[=](){
QProcess* pprcCmd = new QProcess(this);
pprcCmd->startDetached("cmd.exe");
});
//Run notepad.exe
connect(pactNotepad,
&QAction::triggered,
[=](){
QProcess* pprcCmd = new QProcess(this);
pprcCmd->startDetached("notepad.exe");
});
//Run mspaint.exe
connect(pactPaint,
&QAction::triggered,
[=](){
QProcess* pprcCmd = new QProcess(this);
pprcCmd->startDetached("mspaint.exe");
});
//Run calc.exe
connect(pactCalc,
&QAction::triggered,
[=](){
QProcess* pprcCmd = new QProcess(this);
pprcCmd->startDetached("calc.exe");
});
//Run taskmgr.exe
connect(pactTaskmgr,
&QAction::triggered,
[=](){
QProcess* pprcCmd = new QProcess(this);
pprcCmd->startDetached("taskmgr.exe");
});
//Run regedit.exe !!! Doesn't work!!!
/*
connect(pactRegedit,
&QAction::triggered,
[=](){
QProcess* pprcCmd = new QProcess(this);
pprcCmd->startDetached("regedit.exe");
qDebug() << "regedit.exe";
});
*/
connect(this,
&ZBC_MainWindow::mainWindowClose,
pzbcCwgt,
&ZBC_CentralWidget::mainWindowClose);
//Settings
QSettings Settings;
Settings.beginGroup("/Settings");
Settings.beginGroup("/MainWindow");
if (Settings.contains("/Geometry"))
this->restoreGeometry(Settings.value("/Geometry").toByteArray());
Settings.endGroup();
Settings.endGroup();
}
//Override closeEvent
void ZBC_MainWindow::closeEvent(QCloseEvent *pe)
{
QSettings Settings;
Settings.beginGroup("/Settings");
Settings.beginGroup("/MainWindow");
Settings.setValue("Geometry", saveGeometry());
Settings.endGroup();
Settings.endGroup();
emit mainWindowClose();
QMainWindow::closeEvent(pe);
}