Skip to content

Commit 4b94ec8

Browse files
QTCaptureTest: Add support for disabling autofocus
1 parent 70df873 commit 4b94ec8

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

QtCaptureTest/mainwindow.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ MainWindow::MainWindow(QWidget *parent) :
8787
connect(ui->exposureSlider, SIGNAL(valueChanged(int)),this, SLOT(onExposureSlider(int)));
8888
connect(ui->whitebalanceSlider, SIGNAL(valueChanged(int)),this, SLOT(onWhiteBalanceSlider(int)));
8989
connect(ui->autoGain, SIGNAL(toggled(bool)), this, SLOT(onAutoGain(bool)));
90+
connect(ui->autoFocus, SIGNAL(toggled(bool)), this, SLOT(onAutoFocus(bool)));
9091
connect(ui->gainSlider, SIGNAL(valueChanged(int)), this, SLOT(onGainSlider(int)));
9192
connect(ui->contrastSlider, SIGNAL(valueChanged(int)), this, SLOT(onContrastSlider(int)));
9293
connect(ui->brightnessSlider, SIGNAL(valueChanged(int)), this, SLOT(onBrightnessSlider(int)));
@@ -226,6 +227,13 @@ void MainWindow::onAutoGain(bool state)
226227
ui->gainSlider->setEnabled((!state) & m_hasGain);
227228
}
228229

230+
void MainWindow::onAutoFocus(bool state)
231+
{
232+
qDebug() << "Auto focus set to " << state;
233+
Cap_setAutoProperty(m_ctx, m_streamID, CAPPROPID_FOCUS, state ? 1 : 0);
234+
ui->gainSlider->setEnabled((!state) & m_hasGain);
235+
}
236+
229237
void MainWindow::readCameraSettings()
230238
{
231239
qDebug() << "readCameraSettings -> Context = " << m_ctx;
@@ -248,6 +256,7 @@ void MainWindow::readCameraSettings()
248256
ui->exposureSlider->setEnabled(false);
249257
ui->gainSlider->setEnabled(false);
250258
ui->whitebalanceSlider->setEnabled(false);
259+
ui->focusSlider->setEnabled(false);
251260

252261
// ********************************************************************************
253262
// AUTO EXPOSURE
@@ -295,6 +304,23 @@ void MainWindow::readCameraSettings()
295304
ui->autoWhiteBalance->setCheckState((bValue==0) ? Qt::Unchecked : Qt::Checked);
296305
}
297306

307+
// ********************************************************************************
308+
// AUTO FOCUS
309+
// ********************************************************************************
310+
311+
if (Cap_getAutoProperty(m_ctx, m_streamID, CAPPROPID_FOCUS, &bValue) != CAPRESULT_OK)
312+
{
313+
qDebug() << "Autofocus unsupported";
314+
ui->autoFocus->setEnabled(false);
315+
ui->autoFocus->setCheckState(Qt::Unchecked);
316+
}
317+
else
318+
{
319+
qDebug() << "Autofocus supported";
320+
ui->autoFocus->setEnabled(true);
321+
ui->autoFocus->setCheckState((bValue==0) ? Qt::Unchecked : Qt::Checked);
322+
}
323+
298324
// ********************************************************************************
299325
// EXPOSURE
300326
// ********************************************************************************

QtCaptureTest/mainwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public slots:
4141
void onAutoExposure(bool state);
4242
void onAutoWhiteBalance(bool state);
4343
void onAutoGain(bool state);
44+
void onAutoFocus(bool state);
4445
void onExposureSlider(int value);
4546
void onWhiteBalanceSlider(int value);
4647
void onGainSlider(int value);

QtCaptureTest/mainwindow.ui

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@
6161
<string>Camera Settings</string>
6262
</property>
6363
<layout class="QGridLayout" name="gridLayout">
64-
<item row="13" column="1">
64+
<item row="14" column="1">
6565
<widget class="QSlider" name="sharpnessSlider">
6666
<property name="orientation">
6767
<enum>Qt::Horizontal</enum>
6868
</property>
6969
</widget>
7070
</item>
71-
<item row="15" column="1">
71+
<item row="16" column="1">
7272
<widget class="QSlider" name="powerlineFreqSlider">
7373
<property name="orientation">
7474
<enum>Qt::Horizontal</enum>
7575
</property>
7676
</widget>
7777
</item>
78-
<item row="15" column="0">
78+
<item row="16" column="0">
7979
<widget class="QLabel" name="label_13">
8080
<property name="text">
8181
<string>Power line freq</string>
@@ -159,7 +159,7 @@
159159
</property>
160160
</widget>
161161
</item>
162-
<item row="14" column="0">
162+
<item row="15" column="0">
163163
<widget class="QLabel" name="label_8">
164164
<property name="text">
165165
<string>Zoom</string>
@@ -180,7 +180,7 @@
180180
</property>
181181
</widget>
182182
</item>
183-
<item row="14" column="1">
183+
<item row="15" column="1">
184184
<widget class="QSlider" name="zoomSlider">
185185
<property name="orientation">
186186
<enum>Qt::Horizontal</enum>
@@ -215,6 +215,13 @@
215215
</property>
216216
</widget>
217217
</item>
218+
<item row="13" column="1">
219+
<widget class="QCheckBox" name="autoFocus">
220+
<property name="text">
221+
<string>Auto Focus</string>
222+
</property>
223+
</widget>
224+
</item>
218225
<item row="7" column="1">
219226
<widget class="QSlider" name="saturationSlider">
220227
<property name="orientation">
@@ -257,7 +264,7 @@
257264
</property>
258265
</widget>
259266
</item>
260-
<item row="13" column="0">
267+
<item row="14" column="0">
261268
<widget class="QLabel" name="label_12">
262269
<property name="text">
263270
<string>Sharpness</string>

0 commit comments

Comments
 (0)