diff --git a/src/cameraclient.cpp b/src/cameraclient.cpp index 242ab6f..dcca931 100644 --- a/src/cameraclient.cpp +++ b/src/cameraclient.cpp @@ -8,6 +8,7 @@ #include #include +#include #include "settingsdata.hpp" #include "cameraclient.hpp" @@ -20,16 +21,93 @@ CameraClient::CameraClient(QObject *parent): QObject(parent) { } void CameraClient::setPreset(int preset) { - if (preset > -1) { + if (preset > 0 && preset < MaxCameraPresets) { get(QString("/cgi-bin/ptzctrl.cgi?ptzcmd&poscall&%1").arg(preset)); + --preset; + auto const vc = getVideoConfig()[preset]; + qDebug() << preset << vc.brightness; + setBrightness(vc.brightness); + setSaturation(vc.saturation); + setContrast(vc.contrast); + setSharpness(vc.sharpness); + setHue(vc.hue); } } +void CameraClient::setBrightness(int val) { + if (val > -1) { + get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&bright&%1").arg(val)); + } +} + +void CameraClient::setSaturation(int val) { + if (val > -1) { + get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&saturation&%1").arg(val)); + } +} + +void CameraClient::setContrast(int val) { + if (val > -1) { + get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&contrast&%1").arg(val)); + } +} + +void CameraClient::setSharpness(int val) { + if (val > -1) { + get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&sharpness&%1").arg(val)); + } +} + +void CameraClient::setHue(int val) { + if (val > -1) { + get(QString("/cgi-bin/ptzctrl.cgi?post_image_value&hue&%1").arg(val)); + } +} + +/* +void CameraClient::getVideoConfig() { + QUrl url(QString(m_baseUrl) + "/cgi-bin/param.cgi?get_image_conf"); + QNetworkRequest rqst(url); + auto const reply = m_nam->get(rqst); + connect(reply, &QIODevice::readyRead, this, [this, reply] {processVideoConfig(reply);}); +} +*/ + void CameraClient::setBaseUrl() { auto const [host, port] = getCameraConnectionData(); m_baseUrl = QString("http://%1:%2").arg(host, QString::number(port)); } +/* +void CameraClient::processVideoConfig(QNetworkReply *reply) { + auto constexpr brightStart = std::string_view("bright = "); + auto constexpr saturationStart = std::string_view("saturation = "); + auto constexpr contrastStart = std::string_view("contrast = "); + auto constexpr sharpnessStart = std::string_view("sharpness = "); + auto constexpr hueStart = std::string_view("hue = "); + while (!reply->atEnd()) { + auto const line = reply->readLine(); + if (line.startsWith(brightStart)) { + m_videoConfig.brightness = QString(line.mid(brightStart.size())).toInt(); + } else if (line.startsWith(saturationStart)) { + m_videoConfig.saturation = QString(line.mid(saturationStart.size())).toInt(); + } else if (line.startsWith(contrastStart)) { + m_videoConfig.contrast = QString(line.mid(contrastStart.size())).toInt(); + } else if (line.startsWith(sharpnessStart)) { + m_videoConfig.sharpness = QString(line.mid(sharpnessStart.size())).toInt(); + } else if (line.startsWith(hueStart)) { + m_videoConfig.hue = QString(line.mid(hueStart.size())).toInt(); + } + } + qDebug() << + "brightness:" << m_videoConfig.brightness << + "saturation:" << m_videoConfig.brightness << + "contrast:" << m_videoConfig.brightness << + "sharpness:" << m_videoConfig.brightness << + "hue:" << m_videoConfig.hue; +} +*/ + void CameraClient::get(QString const&urlExt) { QUrl url(QString(m_baseUrl) + urlExt); QNetworkRequest rqst(url); diff --git a/src/cameraclient.hpp b/src/cameraclient.hpp index 9f90d09..202dfed 100644 --- a/src/cameraclient.hpp +++ b/src/cameraclient.hpp @@ -27,10 +27,22 @@ class CameraClient: public QObject { void setPreset(int preset); + void setBrightness(int val); + + void setSaturation(int val); + + void setContrast(int val); + + void setSharpness(int val); + + void setHue(int val); + public slots: void setBaseUrl(); private: + void processVideoConfig(QNetworkReply*); + void get(QString const&url); void poll(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 952d783..5649bfb 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -113,7 +113,7 @@ void MainWindow::setupMenu() { // camera preset menu { auto const menu = menuBar()->addMenu(tr("&Camera Preset")); - for (auto i = 0; i < MaxCameraPresets; ++i) { + for (auto i = 0; i < std::min(9, MaxCameraPresets); ++i) { auto const cameraPresetAct = new QAction(tr("Camera Preset &%1").arg(i + 1), this); cameraPresetAct->setShortcut(Qt::ALT | static_cast(Qt::Key_1 + i)); connect(cameraPresetAct, &QAction::triggered, &m_cameraClient, [this, i] { @@ -141,27 +141,7 @@ Built on Qt library under LGPL 2.0)").arg(__DATE__)); } } -void MainWindow::setupDefaultViewControls(QGridLayout *viewCtlLyt) { - auto const mainWidget = viewCtlLyt->parentWidget(); - auto const btnHideSlides = new QPushButton(tr("1. Hide"), mainWidget); - auto const btnOpenLpShowSlides = new QPushButton(tr("2. Show in OpenLP Only"), mainWidget); - auto const btnShowSlides = new QPushButton(tr("3. Show"), mainWidget); - viewCtlLyt->addWidget(btnHideSlides, 0, 0); - viewCtlLyt->addWidget(btnOpenLpShowSlides, 0, 1); - viewCtlLyt->addWidget(btnShowSlides, 0, 2); - btnHideSlides->setShortcut(Qt::Key_1); - btnOpenLpShowSlides->setShortcut(Qt::Key_2); - btnHideSlides->setToolTip(tr("Also hides slides in OBS")); - btnShowSlides->setShortcut(Qt::Key_3); - connect(btnHideSlides, &QPushButton::clicked, &m_openlpClient, &OpenLPClient::blankScreen); - connect(btnHideSlides, &QPushButton::clicked, &m_obsClient, &OBSClient::hideSlides); - connect(btnOpenLpShowSlides, &QPushButton::clicked, &m_openlpClient, &OpenLPClient::showSlides); - connect(btnOpenLpShowSlides, &QPushButton::clicked, &m_obsClient, &OBSClient::hideSlides); - connect(btnShowSlides, &QPushButton::clicked, &m_obsClient, &OBSClient::showSlides); - connect(btnShowSlides, &QPushButton::clicked, &m_openlpClient, &OpenLPClient::showSlides); -} - -void MainWindow::setupCustomViewControls(QVector const&views, QGridLayout *viewCtlLyt) { +void MainWindow::setupViewControlButtons(QVector const&views, QGridLayout *viewCtlLyt) { constexpr auto columns = 3; auto const parent = viewCtlLyt->parentWidget(); for (auto i = 0; auto const&view : views) { @@ -203,8 +183,8 @@ void MainWindow::setupViewControls(QVBoxLayout *rootLyt) { .obsSlides = false, }); views.emplace_back(View{ - .name = tr("Hide in OBS"), - .slides = false, + .name = tr("Show in OpenLP Only"), + .slides = true, .obsSlides = false, }); views.emplace_back(View{ @@ -213,11 +193,7 @@ void MainWindow::setupViewControls(QVBoxLayout *rootLyt) { .obsSlides = false, }); } - if (views.empty()) { - setupDefaultViewControls(viewCtlLyt); - } else { - setupCustomViewControls(views, viewCtlLyt); - } + setupViewControlButtons(views, viewCtlLyt); } void MainWindow::openSettings() { diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index 27b13a0..6b5d371 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -40,9 +40,7 @@ class MainWindow: public QMainWindow { private: void setupMenu(); - void setupDefaultViewControls(class QGridLayout *rootLyt); - - void setupCustomViewControls(QVector const&views, class QGridLayout *rootLyt); + void setupViewControlButtons(QVector const&views, class QGridLayout *rootLyt); void setupViewControls(class QVBoxLayout *rootLyt); diff --git a/src/settingsdata.cpp b/src/settingsdata.cpp index a807447..fa37df7 100644 --- a/src/settingsdata.cpp +++ b/src/settingsdata.cpp @@ -8,8 +8,54 @@ #include +#include "consts.hpp" #include "settingsdata.hpp" +void setVideoConfig(QSettings &settings, QVector const&vcList) { + settings.beginGroup("Camera"); + settings.beginWriteArray("VideoImageConfig"); + for (auto i = 0; auto const&vc : vcList) { + settings.setArrayIndex(i); + settings.setValue("brightness", vc.brightness); + settings.setValue("saturation", vc.saturation); + settings.setValue("contrast", vc.contrast); + settings.setValue("sharpness", vc.sharpness); + settings.setValue("hue", vc.hue); + ++i; + } + settings.endArray(); + settings.endGroup(); +} + +void setVideoConfig(QVector const&vcList) { + QSettings s; + setVideoConfig(s, vcList); +} + +QVector getVideoConfig(QSettings &settings) { + QVector vc(MaxCameraPresets); + settings.beginGroup("Camera"); + auto const size = std::min(settings.beginReadArray("VideoImageConfig"), MaxCameraPresets); + for (auto i = 0; i < size; ++i) { + settings.setArrayIndex(i); + vc[i] = { + .brightness = settings.value("brightness").toInt(), + .saturation = settings.value("saturation").toInt(), + .contrast = settings.value("contrast").toInt(), + .sharpness = settings.value("sharpness").toInt(), + .hue = settings.value("hue").toInt(), + }; + } + settings.endArray(); + settings.endGroup(); + return vc; +} + +QVector getVideoConfig() { + QSettings s; + return getVideoConfig(s); +} + void setCameraConnectionData(QSettings &settings, ConnectionData const&cd) { settings.beginGroup("CameraClient"); settings.setValue("Host", cd.host); diff --git a/src/settingsdata.hpp b/src/settingsdata.hpp index 4a39622..3ea1c1b 100644 --- a/src/settingsdata.hpp +++ b/src/settingsdata.hpp @@ -8,9 +8,26 @@ #pragma once +#include #include #include +struct VideoConfig { + int brightness = 6; + int saturation = 4; + int contrast = 8; + int sharpness = 3; + int hue = 7; +}; + +void setVideoConfig(class QSettings &settings, QVector const&vc); + +void setVideoConfig(QVector const&vc); + +QVector getVideoConfig(QSettings &settings); + +QVector getVideoConfig(); + struct ConnectionData { QString host; uint16_t port = 0; @@ -56,4 +73,4 @@ void setViews(QVector const&views); QVector getViews(class QSettings &settings); [[nodiscard]] -QVector getViews(); \ No newline at end of file +QVector getViews(); diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 408c3bb..b51c525 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -14,7 +15,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -34,6 +37,7 @@ SettingsDialog::SettingsDialog(QWidget *parent): QDialog(parent) { auto const lyt = new QVBoxLayout(this); auto const tabs = new QTabWidget(this); lyt->addWidget(tabs); + tabs->addTab(setupImageConfig(tabs), tr("&Image")); tabs->addTab(setupViewConfig(tabs), tr("&Views")); tabs->addTab(setupNetworkInputs(tabs), tr("&Network")); lyt->addWidget(setupButtons(this)); @@ -81,6 +85,32 @@ QWidget *SettingsDialog::setupNetworkInputs(QWidget *parent) { return root; } +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)); + } + lyt->addRow(presetNo); + m_vidBrightness = mkSb(tr("&Brightness:")); + m_vidSaturation = mkSb(tr("&Saturation:")); + m_vidContrast = mkSb(tr("C&ontrast:")); + 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); @@ -177,6 +207,8 @@ void SettingsDialog::handleOK() { .host = m_obsHostLe->text(), .port = m_obsPortLe->text().toUShort(), }); + collectVideoConfig(); + setVideoConfig(settings, m_videoConfig); accept(); } @@ -220,3 +252,38 @@ int SettingsDialog::collectViews(QVector &views) const { } return 0; } + +void SettingsDialog::collectVideoConfig() { + auto &vc = m_videoConfig[m_vidCurrentPreset]; + auto constexpr getVal = [](int &val, QSpinBox *src) { + if (src) { + val = src->value(); + } + }; + getVal(vc.brightness, m_vidBrightness); + getVal(vc.saturation, m_vidSaturation); + getVal(vc.contrast, m_vidContrast); + getVal(vc.sharpness, m_vidSharpness); + getVal(vc.hue, m_vidHue); +} + +void SettingsDialog::updateVidConfigPreset(int preset) { + // update to new value + auto constexpr setVal = [](int val, QSpinBox *dst) { + if (dst) { + dst->setValue(val); + } + }; + auto const&vc = m_videoConfig[preset]; + setVal(vc.brightness, m_vidBrightness); + setVal(vc.saturation, m_vidSaturation); + setVal(vc.contrast, m_vidContrast); + setVal(vc.sharpness, m_vidSharpness); + setVal(vc.hue, m_vidHue); + m_vidCurrentPreset = preset; +} + +void SettingsDialog::updateVidConfigPresetCollect(int preset) { + collectVideoConfig(); + updateVidConfigPreset(preset); +} diff --git a/src/settingsdialog.hpp b/src/settingsdialog.hpp index 37916b3..fd6dcdd 100644 --- a/src/settingsdialog.hpp +++ b/src/settingsdialog.hpp @@ -10,11 +10,13 @@ #include +#include "consts.hpp" #include "settingsdata.hpp" class SettingsDialog: public QDialog { Q_OBJECT private: + QVector m_videoConfig = QVector(MaxCameraPresets); class QLabel *m_errLbl = nullptr; class QLineEdit *m_cameraHostLe = nullptr; class QLineEdit *m_cameraPortLe = nullptr; @@ -22,12 +24,19 @@ class SettingsDialog: public QDialog { class QLineEdit *m_openLpPortLe = nullptr; class QLineEdit *m_obsHostLe = nullptr; class QLineEdit *m_obsPortLe = nullptr; + class QSpinBox *m_vidBrightness = nullptr; + class QSpinBox *m_vidSaturation = nullptr; + class QSpinBox *m_vidContrast = nullptr; + class QSpinBox *m_vidSharpness = nullptr; + class QSpinBox *m_vidHue = nullptr; + int m_vidCurrentPreset = 0; class QTableWidget *m_viewTable = nullptr; public: explicit SettingsDialog(QWidget *parent); private: QWidget *setupNetworkInputs(QWidget *parent); QWidget *setupViewConfig(QWidget *parent); + QWidget *setupImageConfig(QWidget *parent); QWidget *setupButtons(QWidget *parent); void handleOK(); void setupViewRow(int row, View const&view = {}); @@ -37,4 +46,7 @@ class SettingsDialog: public QDialog { */ [[nodiscard("Must check error code")]] int collectViews(QVector &views) const; + void collectVideoConfig(); + void updateVidConfigPreset(int preset); + void updateVidConfigPresetCollect(int preset); };