diff --git a/src/cameraclient.cpp b/src/cameraclient.cpp index 83b728b..2673b60 100644 --- a/src/cameraclient.cpp +++ b/src/cameraclient.cpp @@ -20,11 +20,21 @@ CameraClient::CameraClient(QObject *parent): QObject(parent) { connect(m_pollingNam, &QNetworkAccessManager::finished, this, &CameraClient::handlePollResponse); } +void CameraClient::setPresetVC(int preset, VideoConfig const&vc) { + if (preset > 0 && preset < MaxCameraPresets) { + get(QString("/cgi-bin/ptzctrl.cgi?ptzcmd&poscall&%1").arg(preset)); + setBrightness(vc.brightness); + setSaturation(vc.saturation); + setContrast(vc.contrast); + setSharpness(vc.sharpness); + setHue(vc.hue); + } +} + void CameraClient::setPreset(int preset) { if (preset > 0 && preset < MaxCameraPresets) { get(QString("/cgi-bin/ptzctrl.cgi?ptzcmd&poscall&%1").arg(preset)); - --preset; - auto const vc = getVideoConfig()[preset]; + auto const vc = getVideoConfig()[preset - 1]; setBrightness(vc.brightness); setSaturation(vc.saturation); setContrast(vc.contrast); diff --git a/src/cameraclient.hpp b/src/cameraclient.hpp index f81d592..58c76b2 100644 --- a/src/cameraclient.hpp +++ b/src/cameraclient.hpp @@ -25,6 +25,8 @@ class CameraClient: public QObject { public: explicit CameraClient(QObject *parent = nullptr); + void setPresetVC(int preset, struct VideoConfig const&vc); + void setPreset(int preset); void setBrightness(int val); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b794d18..dd2d1b7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -198,6 +198,7 @@ void MainWindow::setupViewControls(QVBoxLayout *rootLyt) { void MainWindow::openSettings() { SettingsDialog d(this); + connect(&d, &SettingsDialog::previewPreset, &m_cameraClient, &CameraClient::setPreset); auto const result = d.exec(); if (result == QDialog::Accepted) { m_cameraClient.setBaseUrl(); diff --git a/src/settingsdata.hpp b/src/settingsdata.hpp index 3ea1c1b..093e79d 100644 --- a/src/settingsdata.hpp +++ b/src/settingsdata.hpp @@ -8,7 +8,7 @@ #pragma once -#include +#include #include #include @@ -24,7 +24,7 @@ void setVideoConfig(class QSettings &settings, QVector const&vc); void setVideoConfig(QVector const&vc); -QVector getVideoConfig(QSettings &settings); +QVector getVideoConfig(class QSettings &settings); QVector getVideoConfig(); diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index ca9bda9..f193cc6 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -87,37 +86,56 @@ QWidget *SettingsDialog::setupNetworkInputs(QWidget *parent) { QWidget *SettingsDialog::setupImageConfig(QWidget *parent) { auto const root = new QWidget(parent); - auto const lyt = new QFormLayout(root); - m_videoConfig = getVideoConfig(); - auto const mkSb = [parent, lyt](QString lbl) { - auto const s = new QSpinBox(parent); - s->setAlignment(Qt::AlignRight); - s->setRange(0, 14); - lyt->addRow(lbl, s); - return s; - }; - auto const presetNo = new QComboBox(parent); - connect(presetNo, &QComboBox::currentIndexChanged, this, &SettingsDialog::updateVidConfigPreset); - for (auto i = 0; i < MaxCameraPresets; ++i) { - presetNo->addItem(tr("Camera Preset %1").arg(i + 1)); + auto const lyt = new QVBoxLayout(root); + { + auto const formRoot = new QWidget(parent); + auto const formLyt = new QFormLayout(formRoot); + lyt->addWidget(formRoot); + m_videoConfig = getVideoConfig(); + auto const mkSb = [parent, formLyt](QString const&lbl) { + auto const s = new QSpinBox(parent); + s->setAlignment(Qt::AlignRight); + s->setRange(0, 14); + formLyt->addRow(lbl, s); + return s; + }; + auto const presetNo = new QComboBox(parent); + connect(presetNo, &QComboBox::currentIndexChanged, this, &SettingsDialog::updateVidConfigPreset); + for (auto i = 0; i < MaxCameraPresets; ++i) { + presetNo->addItem(tr("Camera Preset %1").arg(i + 1)); + } + formLyt->addRow(presetNo); + m_vidBrightness = mkSb(tr("&Brightness:")); + m_vidSaturation = mkSb(tr("&Saturation:")); + m_vidContrast = mkSb(tr("Con&trast:")); + m_vidSharpness = mkSb(tr("Sh&arpness:")); + m_vidHue = mkSb(tr("&Hue:")); + updateVidConfigPreset(0); + } + { + auto const btnRoot = new QWidget(parent); + auto const btnLyt = new QHBoxLayout(btnRoot); + lyt->addWidget(btnRoot); + btnLyt->setAlignment(Qt::AlignRight); + auto const previewBtn = new QPushButton(tr("&Preview"), btnRoot); + btnLyt->addWidget(previewBtn); + connect(previewBtn, &QPushButton::clicked, this, [this] { + this->collectVideoConfig(); + auto const &vc = m_videoConfig[m_vidCurrentPreset]; + emit previewPreset(m_vidCurrentPreset + 1, vc); + }); } - lyt->addRow(presetNo); - m_vidBrightness = mkSb(tr("&Brightness:")); - m_vidSaturation = mkSb(tr("&Saturation:")); - m_vidContrast = mkSb(tr("Con&trast:")); - m_vidSharpness = mkSb(tr("Sh&arpness:")); - m_vidHue = mkSb(tr("&Hue:")); - updateVidConfigPreset(0); return root; } QWidget *SettingsDialog::setupViewConfig(QWidget *parent) { auto const root = new QWidget(parent); auto const lyt = new QVBoxLayout(root); - // table - m_viewTable = new QTableWidget(parent); - { - lyt->addWidget(m_viewTable); + auto const btnsRoot = new QWidget(root); + m_viewTable = new QTableWidget(root); + lyt->addWidget(btnsRoot); + lyt->addWidget(m_viewTable); + { // table QStringList columns; columns.resize(ViewColumn::Count); columns[ViewColumn::Name] = tr("Name"); @@ -134,19 +152,16 @@ QWidget *SettingsDialog::setupViewConfig(QWidget *parent) { m_viewTable->setColumnWidth(3, 70); hdr->setStretchLastSection(true); } - // add/removes buttons - { - auto const btnsRoot = new QWidget(root); + { // add/removes buttons auto const btnsLyt = new QHBoxLayout(btnsRoot); - auto const addBtn = new QPushButton("+", btnsRoot); - auto const rmBtn = new QPushButton("-", btnsRoot); - addBtn->setFixedWidth(20); - rmBtn->setFixedWidth(20); + auto const addBtn = new QPushButton("&Add", btnsRoot); + auto const rmBtn = new QPushButton("&Remove", btnsRoot); + addBtn->setFixedWidth(70); + rmBtn->setFixedWidth(70); rmBtn->setDisabled(true); - lyt->addWidget(btnsRoot); btnsLyt->addWidget(addBtn); btnsLyt->addWidget(rmBtn); - btnsLyt->addSpacerItem(new QSpacerItem(1000, 0, QSizePolicy::Expanding, QSizePolicy::Ignored)); + btnsLyt->setAlignment(Qt::AlignLeft); connect(addBtn, &QPushButton::clicked, this, [this, addBtn] { auto const row = m_viewTable->rowCount(); m_viewTable->setRowCount(row + 1); diff --git a/src/settingsdialog.hpp b/src/settingsdialog.hpp index fd6dcdd..9674197 100644 --- a/src/settingsdialog.hpp +++ b/src/settingsdialog.hpp @@ -49,4 +49,6 @@ class SettingsDialog: public QDialog { void collectVideoConfig(); void updateVidConfigPreset(int preset); void updateVidConfigPresetCollect(int preset); + signals: + void previewPreset(int, VideoConfig const&); };