-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
152 lines (116 loc) · 3.83 KB
/
Copy pathmainwindow.cpp
File metadata and controls
152 lines (116 loc) · 3.83 KB
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
// ===========================================================================
/// <summary>
/// mainwindow.cpp
/// QtIntroduction
/// created by Mehrdad Soleimanimajd on 10.09.2019
/// </summary>
/// <created>ʆϒʅ, 10.09.2019</created>
/// <changed>ʆϒʅ, 27.06.2023</changed>
// ===========================================================================
#include "mainwindow.h"
#include "./ui_mainwindow.h"
MainWindow::MainWindow ()
: appStyle ( nullptr ), windowScreenShot ( nullptr )
{
try
{
QWidget* widget = new QWidget;
setCentralWidget ( widget );
QWidget* menuBar = new QWidget;
menuBar->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
QWidget* statusBar = new QWidget;
statusBar->setSizePolicy ( QSizePolicy::Expanding, QSizePolicy::Expanding );
QVBoxLayout* layout = new QVBoxLayout;
layout->setContentsMargins ( 2, 2, 2, 2 );
layout->addWidget ( menuBar );
layout->addWidget ( statusBar );
widget->setLayout ( layout );
createActions ();
createMenus ();
//QString message { "Menus can be chosen! :)" };
//QString message = tr ( "Menus can be chosen! :)" );
//statusBar ()->showMessage ( message );
setWindowTitle ( tr ( "Qt GUI" ) );
setMinimumSize ( 240, 160 );
resize ( 480, 320 );
appStyle = new AppStyle;
this->centralWidget ()->setStyleSheet ( appStyle->theme.form );
this->menuBar ()->setStyleSheet ( appStyle->theme.menu );
this->statusBar ()->setStyleSheet ( appStyle->theme.status );
}
catch (const std::exception& ex)
{
}
}
MainWindow::~MainWindow ()
{
if (windowScreenShot)
delete windowScreenShot;
if (appStyle)
delete appStyle;
}
void MainWindow::themeOne ( void )
{
if (!actionTheme->isChecked ())
{
actionTheme->toggled ( false );
setStyle ( 0 );
} else
{
actionTheme->toggled ( true );
setStyle ( 1 );
}
};
void MainWindow::screenShot ( void )
{
if (!windowScreenShot)
{
windowScreenShot = new ScreenShot ( this->centralWidget (), appStyle );
windowScreenShot->move ( QApplication::primaryScreen ()->availableGeometry ().topLeft () + QPoint ( 50, 50 ) );
windowScreenShot->show ();
} else
if (windowScreenShot->getInitialized ())
{
windowScreenShot->show ();
}
};
void MainWindow::createActions ( void )
{
actionScreenShot = new QAction ( tr ( "ScreenShot" ), this );
connect ( actionScreenShot, &QAction::triggered, this, &MainWindow::screenShot );
actionTheme = new QAction ( tr ( "Theme" ), this );
actionTheme->setShortcut ( QKeySequence::AddTab ); // Ctrl+T
actionTheme->setCheckable ( true );
actionTheme->setStatusTip ( tr ( "Set the application theme" ) );
connect ( actionTheme, &QAction::triggered, this, &MainWindow::themeOne );
};
void MainWindow::createMenus ( void )
{
menuFile = menuBar ()->addMenu ( tr ( "&File" ) );
menuFile->addAction ( actionScreenShot );
menuView = menuBar ()->addMenu ( tr ( "&View" ) );
menuView->addAction ( actionTheme );
};
//#ifndef QT_NO_CONTEXTMENU
//void MainWindow::contextMenuEvent ( QContextMenuEvent* event )
//{
// QMenu menu ( this );
// menu.addAction ( actionTheme );
// menu.exec ( event->globalPos () );
//};
//#endif // QT_NO_CONTEXTMENU
void MainWindow::setStyle ( unsigned char index )
{
appStyle->set ( index );
if (appStyle->getLoaded ())
{
this->centralWidget ()->setStyleSheet ( appStyle->theme.form );
this->menuBar ()->setStyleSheet ( appStyle->theme.menu );
this->statusBar ()->setStyleSheet ( appStyle->theme.status );
if (windowScreenShot)
{
windowScreenShot->updateStyle ();
}
}
};