From afe7629a1308f51b2fbcca40af8e4d16cea6c9cc Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 29 Mar 2020 15:35:26 +0200 Subject: video/ps3eye: implement dialog --- video-ps3eye/dialog.ui | 133 +++++++++++++++++++++++++++++++++++++++++++++ video-ps3eye/lang/nl_NL.ts | 19 +++++++ video-ps3eye/lang/ru_RU.ts | 19 +++++++ video-ps3eye/lang/stub.ts | 19 +++++++ video-ps3eye/lang/zh_CN.ts | 19 +++++++ video-ps3eye/module.cpp | 58 ++++++++++++++++++-- video-ps3eye/module.hpp | 34 ++++++++++-- 7 files changed, 291 insertions(+), 10 deletions(-) create mode 100644 video-ps3eye/dialog.ui (limited to 'video-ps3eye') diff --git a/video-ps3eye/dialog.ui b/video-ps3eye/dialog.ui new file mode 100644 index 00000000..1e94ce74 --- /dev/null +++ b/video-ps3eye/dialog.ui @@ -0,0 +1,133 @@ + + + Dialog + + + Qt::ApplicationModal + + + + 0 + 0 + 439 + 211 + + + + + 439 + 0 + + + + PS3 Eye + + + + + + Camera settings + + + + + + true + + + QAbstractSpinBox::NoButtons + + + 255 + + + + + + + + 0 + 0 + + + + true + + + QAbstractSpinBox::NoButtons + + + 63 + + + + + + + + 1 + 0 + + + + 255 + + + Qt::Horizontal + + + + + + + Exposure + + + + + + + + 0 + 0 + + + + 63 + + + Qt::Horizontal + + + + + + + Gain + + + + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + diff --git a/video-ps3eye/lang/nl_NL.ts b/video-ps3eye/lang/nl_NL.ts index 6401616d..c98370ec 100644 --- a/video-ps3eye/lang/nl_NL.ts +++ b/video-ps3eye/lang/nl_NL.ts @@ -1,4 +1,23 @@ + + Dialog + + PS3 Eye + + + + Camera settings + + + + Exposure + + + + Gain + + + diff --git a/video-ps3eye/lang/ru_RU.ts b/video-ps3eye/lang/ru_RU.ts index 6401616d..c98370ec 100644 --- a/video-ps3eye/lang/ru_RU.ts +++ b/video-ps3eye/lang/ru_RU.ts @@ -1,4 +1,23 @@ + + Dialog + + PS3 Eye + + + + Camera settings + + + + Exposure + + + + Gain + + + diff --git a/video-ps3eye/lang/stub.ts b/video-ps3eye/lang/stub.ts index 6401616d..c98370ec 100644 --- a/video-ps3eye/lang/stub.ts +++ b/video-ps3eye/lang/stub.ts @@ -1,4 +1,23 @@ + + Dialog + + PS3 Eye + + + + Camera settings + + + + Exposure + + + + Gain + + + diff --git a/video-ps3eye/lang/zh_CN.ts b/video-ps3eye/lang/zh_CN.ts index 6401616d..c98370ec 100644 --- a/video-ps3eye/lang/zh_CN.ts +++ b/video-ps3eye/lang/zh_CN.ts @@ -1,4 +1,23 @@ + + Dialog + + PS3 Eye + + + + Camera settings + + + + Exposure + + + + Gain + + + diff --git a/video-ps3eye/module.cpp b/video-ps3eye/module.cpp index 3ee43ec1..7dbdd8fb 100644 --- a/video-ps3eye/module.cpp +++ b/video-ps3eye/module.cpp @@ -4,12 +4,15 @@ #include "compat/run-in-thread.hpp" #include +#include #include #include #include +using namespace options; + #ifdef __GNUG__ # pragma clang diagnostic ignored "-Wcast-qual" #endif @@ -76,14 +79,21 @@ std::unique_ptr ps3eye_camera_::make_camera(const QString& name) else return {}; } + +static bool show_dialog_() +{ + (new dialog)->show(); + return true; +} + bool ps3eye_camera_::show_dialog(const QString&) { - // TODO - return false; + return show_dialog_(); } -bool ps3eye_camera_::can_show_dialog(const QString&) + +bool ps3eye_camera_::can_show_dialog(const QString& name) { - return false; + return name == camera_name && check_device_exists(); } ps3eye_camera::ps3eye_camera() @@ -210,7 +220,45 @@ ok: bool ps3eye_camera::show_dialog() { - return false; + return show_dialog_(); } OTR_REGISTER_CAMERA(ps3eye_camera_) + +dialog::dialog(QWidget* parent) : QWidget(parent) +{ + ui.setupUi(this); + tie_setting(s.exposure, ui.exposure_slider); + tie_setting(s.gain, ui.gain_slider); + ui.exposure_label->setValue((int)*s.exposure); + ui.gain_label->setValue((int)*s.gain); + connect(&s.exposure, value_::value_changed(), this, [this](const slider_value&) { s.set_exposure(); }); + connect(&s.gain, value_::value_changed(), this, [this](const slider_value&) { s.set_gain(); }); + connect(ui.exposure_slider, &QSlider::valueChanged, ui.exposure_label, &QSpinBox::setValue); + connect(ui.gain_slider, &QSlider::valueChanged, ui.gain_label, &QSpinBox::setValue); + connect(ui.buttonBox, &QDialogButtonBox::accepted, this, &dialog::do_ok); + connect(ui.buttonBox, &QDialogButtonBox::rejected, this, &dialog::do_cancel); +} + +// XXX copypasta -sh 20200329 +void settings::set_gain() +{ + if (!shm.success()) + return; + + auto& ptr = *(ps3eye::shm volatile*)shm.ptr(); + ptr.in.gain = (unsigned char)*gain; + ++ptr.in.settings_updated; + std::atomic_thread_fence(std::memory_order_seq_cst); +} + +void settings::set_exposure() +{ + if (!shm.success()) + return; + + auto& ptr = *(ps3eye::shm volatile*)shm.ptr(); + ptr.in.exposure = (unsigned char)*exposure; + ++ptr.in.settings_updated; + std::atomic_thread_fence(std::memory_order_seq_cst); +} diff --git a/video-ps3eye/module.hpp b/video-ps3eye/module.hpp index 957e221e..9f7aaec1 100644 --- a/video-ps3eye/module.hpp +++ b/video-ps3eye/module.hpp @@ -5,21 +5,45 @@ #include "compat/shm.h" #include "options/options.hpp" #include "compat/macros1.h" +#include "ui_dialog.h" -using namespace options; - +#include #include +using namespace options; + using video::impl::camera; using video::impl::camera_; using video::frame; -struct settings : opts +struct settings final { - settings() : opts{"video-ps3eye"} {} + bundle b = make_bundle("video-ps3eye"); + shm_wrapper shm { "ps3eye-driver-shm", nullptr, sizeof(ps3eye::shm) }; - value exposure{b, "exposure", {63, 0, 63}}; + value exposure{b, "exposure", {255, 0, 255}}; value gain{b, "gain", {30, 0, 63}}; + + void set_exposure(); + void set_gain(); +}; + +class dialog final : public QWidget +{ + Q_OBJECT + Ui_Dialog ui; + settings s; + + shm_wrapper shm { "ps3eye-driver-shm", nullptr, sizeof(ps3eye::shm) }; + + void do_ok() { s.b->save(); close(); deleteLater(); } + void do_cancel() { s.b->reload(); close(); deleteLater(); } + +protected: + void closeEvent(QCloseEvent*) override { do_cancel(); } + +public: + explicit dialog(QWidget* parent = nullptr); }; struct ps3eye_camera final : video::impl::camera -- cgit v1.2.3