-
Notifications
You must be signed in to change notification settings - Fork 25
/
controlWindow.cpp
243 lines (182 loc) · 6.66 KB
/
controlWindow.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "controlWindow.h"
#include "controlClassify.h"
#include "controlDetection.h"
// constructor
ControlWindow::ControlWindow( commandLine& commandLine, CaptureWindow* capture )
{
captureWindow = capture;
cmdLine = &commandLine;
datasetTypes[0] = "Classification";
datasetTypes[1] = "Detection";
memset(datasetWidgets, 0, sizeof(datasetWidgets));
/*
* create layout
*/
QVBoxLayout* layout = new QVBoxLayout();
layout->setAlignment(Qt::AlignTop);
/*
* dataset type drop-down
*/
QHBoxLayout* datasetLayout = new QHBoxLayout();
QComboBox* datasetDropdown = new QComboBox();
for( int n=0; n < numDatasetTypes; n++ )
datasetDropdown->addItem(tr(datasetTypes[n]));
datasetDropdown->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
datasetLayout->addWidget(new QLabel(tr(" Dataset Type ")));
datasetLayout->addWidget(datasetDropdown);
connect(datasetDropdown, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(onDatasetType(const QString&)));
layout->addItem(datasetLayout);
/*
* dataset control widgets
*/
datasetWidgets[0] = new ControlClassifyWidget(cmdLine, captureWindow);
datasetWidgets[1] = new ControlDetectionWidget(cmdLine, captureWindow);
layout->addWidget(datasetWidgets[0]);
layout->addWidget(datasetWidgets[1]);
datasetWidgets[1]->hide();
/*
* configure options
*/
setMinimumWidth(200);
setMaximumWidth(750);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::MinimumExpanding);
setLayout(layout);
setWindowTitle(tr("Data Capture Control"));
// move the window away from the camera feed
move(capture->GetWindowWidth() + 75, 25 /*pos().y()*/);
}
void ControlWindow::onDatasetType(const QString& text)
{
printf("camera-capture: switching dataset type to '%s'\n", text.toUtf8().constData());
for( int n=0; n < numDatasetTypes; n++ )
{
if( text != datasetTypes[n] )
datasetWidgets[n]->hide();
}
for( int n=0; n < numDatasetTypes; n++ )
{
if( text == datasetTypes[n] )
datasetWidgets[n]->show();
}
}
// sizeHint
QSize ControlWindow::sizeHint() const
{
return QSize(475,15);
}
// destructor
ControlWindow::~ControlWindow()
{
}
// ProcessEvents
void ControlWindow::ProcessEvents()
{
QCoreApplication::processEvents();
}
// IsOpen
bool ControlWindow::IsOpen() const
{
return isVisible();
}
// IsClosed
bool ControlWindow::IsClosed() const
{
return !isVisible();
}
// https://github.com/Jorgen-VikingGod/Qt-Frameless-Window-DarkStyle
class DarkStyle : public QProxyStyle {
public:
DarkStyle();
explicit DarkStyle(QStyle *style);
QStyle *baseStyle() const;
void polish(QPalette &palette) override;
void polish(QApplication *app) override;
private:
QStyle *styleBase(QStyle *style = Q_NULLPTR) const;
};
// Create
ControlWindow* ControlWindow::Create( commandLine& cmdLine, CaptureWindow* capture )
{
// create QApplication
QApplication* app = new QApplication(cmdLine.argc, cmdLine.argv);
app->setStyle(new DarkStyle());
// create ControlWindow
ControlWindow* window = new ControlWindow(cmdLine, capture);
if( !window )
return NULL;
window->show();
return window;
}
//-----------------------------------------------------------------------------------------
DarkStyle::DarkStyle() : DarkStyle(styleBase()) {}
DarkStyle::DarkStyle(QStyle *style) : QProxyStyle(style) {}
QStyle *DarkStyle::styleBase(QStyle *style) const {
static QStyle *base =
!style ? QStyleFactory::create(QStringLiteral("Fusion")) : style;
return base;
}
QStyle *DarkStyle::baseStyle() const { return styleBase(); }
void DarkStyle::polish(QPalette &palette) {
// modify palette to dark
palette.setColor(QPalette::Window, QColor(53, 53, 53));
palette.setColor(QPalette::WindowText, Qt::white);
palette.setColor(QPalette::Disabled, QPalette::WindowText,
QColor(127, 127, 127));
palette.setColor(QPalette::Base, QColor(42, 42, 42));
palette.setColor(QPalette::AlternateBase, QColor(66, 66, 66));
palette.setColor(QPalette::ToolTipBase, Qt::white);
palette.setColor(QPalette::ToolTipText, QColor(53, 53, 53));
palette.setColor(QPalette::Text, Qt::white);
palette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));
palette.setColor(QPalette::Dark, QColor(35, 35, 35));
palette.setColor(QPalette::Shadow, QColor(20, 20, 20));
palette.setColor(QPalette::Button, QColor(53, 53, 53));
palette.setColor(QPalette::ButtonText, Qt::white);
palette.setColor(QPalette::Disabled, QPalette::ButtonText,
QColor(127, 127, 127));
palette.setColor(QPalette::BrightText, Qt::red);
palette.setColor(QPalette::Link, QColor(42, 130, 218));
palette.setColor(QPalette::Highlight, QColor(42, 130, 218));
palette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(80, 80, 80));
palette.setColor(QPalette::HighlightedText, Qt::white);
palette.setColor(QPalette::Disabled, QPalette::HighlightedText,
QColor(127, 127, 127));
}
void DarkStyle::polish(QApplication *app) {
if (!app) return;
// increase font size for better reading,
// setPointSize was reduced from +2 because when applied this way in Qt5, the
// font is larger than intended for some reason
QFont defaultFont = QApplication::font();
defaultFont.setPointSize(defaultFont.pointSize() + 1);
app->setFont(defaultFont);
// loadstylesheet
QFile qfDarkstyle(QStringLiteral(":/darkstyle/darkstyle.qss"));
if (qfDarkstyle.open(QIODevice::ReadOnly | QIODevice::Text)) {
// set stylesheet
QString qsStylesheet = QString::fromLatin1(qfDarkstyle.readAll());
app->setStyleSheet(qsStylesheet);
qfDarkstyle.close();
}
}