-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCameraConnectDialog.cpp
More file actions
226 lines (209 loc) · 9.22 KB
/
Copy pathCameraConnectDialog.cpp
File metadata and controls
226 lines (209 loc) · 9.22 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
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
/************************************************************************/
/* qt-opencv-multithreaded: */
/* A multithreaded OpenCV application using the Qt framework. */
/* */
/* CameraConnectDialog.cpp */
/* */
/* Nick D'Ademo <nickdademo@gmail.com> */
/* */
/* Copyright (c) 2012-2013 Nick D'Ademo */
/* */
/* 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 "CameraConnectDialog.h"
#include "ui_CameraConnectDialog.h"
// Qt
#include <QtCore/QThread>
#include <QMessageBox>
#include <QFileDialog>
#include <QStandardPaths>
#include <QDebug>
#include <QDesktopServices>
#include <QDir>
CameraConnectDialog::CameraConnectDialog(QWidget *parent, bool isStreamSyncEnabled) :
QDialog(parent),
ui(new Ui::CameraConnectDialog)
{
// Setup dialog
ui->setupUi(this);
// deviceNumberEdit (device number) input validation
QRegExp rx1("^[0-9]{1,3}$"); // Integers 0 to 999
QRegExpValidator *validator1 = new QRegExpValidator(rx1, 0);
ui->deviceNumberEdit->setValidator(validator1);
// imageBufferSizeEdit (image buffer size) input validation
QRegExp rx2("^[0-9]{1,3}$"); // Integers 0 to 999
QRegExpValidator *validator2 = new QRegExpValidator(rx2, 0);
ui->imageBufferSizeEdit->setValidator(validator2);
// resWEdit (resolution: width) input validation
QRegExp rx3("^[0-9]{1,4}$"); // Integers 0 to 9999
QRegExpValidator *validator3 = new QRegExpValidator(rx3, 0);
ui->resWEdit->setValidator(validator3);
// resHEdit (resolution: height) input validation
QRegExp rx4("^[0-9]{1,4}$"); // Integers 0 to 9999
QRegExpValidator *validator4 = new QRegExpValidator(rx4, 0);
ui->resHEdit->setValidator(validator4);
// Setup combo boxes
QStringList threadPriorities;
threadPriorities<<"Idle"<<"Lowest"<<"Low"<<"Normal"<<"High"<<"Highest"<<"Time Critical"<<"Inherit";
ui->capturePrioComboBox->addItems(threadPriorities);
ui->processingPrioComboBox->addItems(threadPriorities);
// Set dialog to defaults
resetToDefaults();
// Enable/disable checkbox
ui->enableFrameProcessingCheckBox->setEnabled(isStreamSyncEnabled);
// Connect button to slot
connect(ui->resetToDefaultsPushButton,SIGNAL(released()),SLOT(resetToDefaults()));
// added by quqinglei@icloud.com for my own use
ui->deviceNumberEdit->setText("0");
ui->resWEdit->setText("1920");
ui->resHEdit->setText("1080");
QString desktopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
ui->lineEditLocalFilePath->setText(desktopPath);
}
CameraConnectDialog::~CameraConnectDialog()
{
delete ui;
}
int CameraConnectDialog::getDeviceNumber()
{
// Set device number to default (any available camera) if field is blank
if(ui->deviceNumberEdit->text().isEmpty())
{
QMessageBox::warning(this->parentWidget(), "WARNING:","Device Number field blank.\nAutomatically set to 0.");
return 0;
}
else
return ui->deviceNumberEdit->text().toInt();
}
int CameraConnectDialog::getResolutionWidth()
{
// Return -1 if field is blank
if(ui->resWEdit->text().isEmpty())
return -1;
else
return ui->resWEdit->text().toInt();
}
int CameraConnectDialog::getResolutionHeight()
{
// Return -1 if field is blank
if(ui->resHEdit->text().isEmpty())
return -1;
else
return ui->resHEdit->text().toInt();
}
int CameraConnectDialog::getImageBufferSize()
{
// Set image buffer size to default if field is blank
if(ui->imageBufferSizeEdit->text().isEmpty())
{
QMessageBox::warning(this->parentWidget(), "WARNING:","Image Buffer Size field blank.\nAutomatically set to default value.");
return DEFAULT_IMAGE_BUFFER_SIZE;
}
// Set image buffer size to default if field is zero
else if(ui->imageBufferSizeEdit->text().toInt()==0)
{
QMessageBox::warning(this->parentWidget(), "WARNING:","Image Buffer Size cannot be zero.\nAutomatically set to default value.");
return DEFAULT_IMAGE_BUFFER_SIZE;;
}
// Use image buffer size specified by user
else
return ui->imageBufferSizeEdit->text().toInt();
}
bool CameraConnectDialog::getDropFrameCheckBoxState()
{
return ui->dropFrameCheckBox->isChecked();
}
int CameraConnectDialog::getCaptureThreadPrio()
{
return ui->capturePrioComboBox->currentIndex();
}
int CameraConnectDialog::getProcessingThreadPrio()
{
return ui->processingPrioComboBox->currentIndex();
}
QString CameraConnectDialog::getTabLabel()
{
return ui->tabLabelEdit->text();
}
bool CameraConnectDialog::getEnableFrameProcessingCheckBoxState()
{
return ui->enableFrameProcessingCheckBox->isChecked();
}
void CameraConnectDialog::resetToDefaults()
{
// Default camera
ui->deviceNumberEdit->clear();
// Resolution
ui->resWEdit->clear();
ui->resHEdit->clear();
// Image buffer size
ui->imageBufferSizeEdit->setText(QString::number(DEFAULT_IMAGE_BUFFER_SIZE));
// Drop frames
ui->dropFrameCheckBox->setChecked(DEFAULT_DROP_FRAMES);
// Capture thread
if(DEFAULT_CAP_THREAD_PRIO==QThread::IdlePriority)
ui->capturePrioComboBox->setCurrentIndex(0);
else if(DEFAULT_CAP_THREAD_PRIO==QThread::LowestPriority)
ui->capturePrioComboBox->setCurrentIndex(1);
else if(DEFAULT_CAP_THREAD_PRIO==QThread::LowPriority)
ui->capturePrioComboBox->setCurrentIndex(2);
else if(DEFAULT_CAP_THREAD_PRIO==QThread::NormalPriority)
ui->capturePrioComboBox->setCurrentIndex(3);
else if(DEFAULT_CAP_THREAD_PRIO==QThread::HighPriority)
ui->capturePrioComboBox->setCurrentIndex(4);
else if(DEFAULT_CAP_THREAD_PRIO==QThread::HighestPriority)
ui->capturePrioComboBox->setCurrentIndex(5);
else if(DEFAULT_CAP_THREAD_PRIO==QThread::TimeCriticalPriority)
ui->capturePrioComboBox->setCurrentIndex(6);
else if(DEFAULT_CAP_THREAD_PRIO==QThread::InheritPriority)
ui->capturePrioComboBox->setCurrentIndex(7);
// Processing thread
if(DEFAULT_PROC_THREAD_PRIO==QThread::IdlePriority)
ui->processingPrioComboBox->setCurrentIndex(0);
else if(DEFAULT_PROC_THREAD_PRIO==QThread::LowestPriority)
ui->processingPrioComboBox->setCurrentIndex(1);
else if(DEFAULT_PROC_THREAD_PRIO==QThread::LowPriority)
ui->processingPrioComboBox->setCurrentIndex(2);
else if(DEFAULT_PROC_THREAD_PRIO==QThread::NormalPriority)
ui->processingPrioComboBox->setCurrentIndex(3);
else if(DEFAULT_PROC_THREAD_PRIO==QThread::HighPriority)
ui->processingPrioComboBox->setCurrentIndex(4);
else if(DEFAULT_PROC_THREAD_PRIO==QThread::HighestPriority)
ui->processingPrioComboBox->setCurrentIndex(5);
else if(DEFAULT_PROC_THREAD_PRIO==QThread::TimeCriticalPriority)
ui->processingPrioComboBox->setCurrentIndex(6);
else if(DEFAULT_PROC_THREAD_PRIO==QThread::InheritPriority)
ui->processingPrioComboBox->setCurrentIndex(7);
// Tab label
ui->tabLabelEdit->setText("");
// Enable Frame Processing checkbox
ui->enableFrameProcessingCheckBox->setChecked(true);
}
QString CameraConnectDialog::getLocalSavePath()
{
return ui->lineEditLocalFilePath->text();
}
void CameraConnectDialog::on_pushButtonLocalPath_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this, tr("打开路径"), "", QFileDialog::ShowDirsOnly| QFileDialog::DontResolveSymlinks);
ui->lineEditLocalFilePath->setText(dir);
}