-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.cpp
159 lines (126 loc) · 3.76 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
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
#include "MainWindow.h"
#include "ui_MainForm.h"
MainWindow::MainWindow():QMainWindow(0)
{
info = new Details(this);
settings = new Settings(this);
fullscreen = false;
gui.setupUi(this);
QDeclarativeContext* context = gui.menu->rootContext();
context->setContextProperty("fullscreen",fullscreen);
context->setContextProperty("windowWidth",this->width());
gui.menu->setSource(QUrl("qrc:/menu.qml"));
QPalette pal = this->palette();
pal.setColor(this->backgroundRole(), Qt::black);
this->setPalette(pal);
gui.menu->setResizeMode(QDeclarativeView::SizeRootObjectToView);
setMouseTracking(true);
QObject *item = gui.menu->rootObject();
connect(item, SIGNAL(switchToFullscreen()), this, SLOT(toggleFullscreen()));
connect(item, SIGNAL(switchToWindow()), this, SLOT(disableFullscreen()));
connect(item, SIGNAL(showSettings()), this, SLOT(showSettings()));
connect(item, SIGNAL(showInfo()), this, SLOT(showInfo()));
connect(item, SIGNAL(closeApp()), this, SLOT(closeApp()));
settings->loadSettings();
this->resize(settings->getWidth(), settings->getHeight());
}
MainWindow::~MainWindow()
{
delete info;
delete settings;
}
void MainWindow::resizeEvent(QResizeEvent *)
{
settings->setWidth(this->width());
settings->setHeight(this->height());
settings->saveSettings();
QDeclarativeContext* context = gui.menu->rootContext();
context->setContextProperty("windowWidth",this->width());
float width = this->width();
float height = this->height();
int dy = 0;
if(!fullscreen)
{
height -= gui.menu->height();
dy = gui.menu->height();
}
resizeVideoFrame(0, dy, width, height);
gui.menu->setGeometry(0,0,this->width(), 60);
}
void MainWindow::resizeVideoFrame(int dx, int dy, int width, int height)
{
int capture_width = gui.glWidget->getCaptureWidth();
int capture_height = gui.glWidget->getCaptureHeight();
int new_width = width;
int new_height = capture_height * width / capture_width;
if(new_height > height)
{
new_height = height;
new_width = capture_width * height / capture_height;
}
gui.glWidget->setGeometry((width - new_width)/2+dx,(height - new_height)/2+dy,new_width,new_height);
}
void MainWindow::toggleFullscreen()
{
if(fullscreen) return;
gui.menu->setVisible(false);
this->setWindowState(Qt::WindowFullScreen);
fullscreen = true;
QDeclarativeContext* context = gui.menu->rootContext();
context->setContextProperty("fullscreen",fullscreen);
}
void MainWindow::disableFullscreen()
{
if(!fullscreen) return;
gui.menu->setVisible(true);
this->setWindowState(Qt::WindowNoState);
fullscreen = false;
QDeclarativeContext* context = gui.menu->rootContext();
context->setContextProperty("fullscreen",fullscreen);
}
void MainWindow::keyPressEvent(QKeyEvent *ke)
{
switch (ke->key())
{
case Qt::Key_Escape:
if(fullscreen)
disableFullscreen();
else
exit(EXIT_SUCCESS);
break;
}
}
void MainWindow::mouseMoveEvent(QMouseEvent *me)
{
me->accept();
if(fullscreen)
{
if(me->y() == 0)
gui.menu->setVisible(true);
else if(me->y() > gui.menu->height())
gui.menu->setVisible(false);
}
}
void MainWindow::mouseDoubleClickEvent(QMouseEvent *)
{
if(fullscreen)
disableFullscreen();
else
toggleFullscreen();
}
void MainWindow::showSettings()
{
if(settings->exec() == 1)
{
settings->saveSettings();
this->setGeometry(this->x(), this->y(), settings->getWidth(), settings->getHeight());
}
}
void MainWindow::showInfo()
{
info->show();
}
void MainWindow::closeApp()
{
exit(EXIT_SUCCESS);
}