[libcamera-devel] [PATCH v2 06/11] qcam: Add Float Slider
Utkarsh Tiwari
utkarsh02t at gmail.com
Fri Aug 12 14:46:46 CEST 2022
Qt doesn't support float value sliders.
Implement a float slider to help implementing intereactive controls
GUI for ControlTypeFloat
Signed-off-by: Utkarsh Tiwari <utkarsh02t at gmail.com>
---
src/qcam/meson.build | 1 +
src/qcam/settings/slider.h | 63 ++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+)
create mode 100644 src/qcam/settings/slider.h
diff --git a/src/qcam/meson.build b/src/qcam/meson.build
index 7a785fd0..b6a09c87 100644
--- a/src/qcam/meson.build
+++ b/src/qcam/meson.build
@@ -35,6 +35,7 @@ qcam_moc_headers = files([
'settings/control_frame.h',
'settings/controls_tab.h',
'settings/settings_dialog.h',
+ 'settings/slider.h',
'viewfinder_qt.h',
])
diff --git a/src/qcam/settings/slider.h b/src/qcam/settings/slider.h
new file mode 100644
index 00000000..f4a4825c
--- /dev/null
+++ b/src/qcam/settings/slider.h
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2022, Utkarsh Tiwari <utkarsh02t at gmail.com>
+ *
+ * slider.h - qcam - Slider
+ */
+
+#pragma once
+
+#include <QSlider>
+#include <QWidget>
+
+class FloatSlider : public QSlider
+{
+ Q_OBJECT
+
+ const float INT_TO_FLOAT = 100.0;
+
+public:
+ FloatSlider(QWidget *parent)
+ : QSlider(parent)
+ {
+ connect(this, &QSlider::valueChanged,
+ this, &FloatSlider::notifyValueChanged);
+ }
+
+ ~FloatSlider() = default;
+
+ void setValue(float value)
+ {
+ QSlider::setValue(value * INT_TO_FLOAT);
+ }
+
+ void setRange(float min, float max)
+ {
+ QSlider::setRange(min * INT_TO_FLOAT, max * INT_TO_FLOAT);
+ }
+
+ float minimum()
+ {
+ return QSlider::minimum() / INT_TO_FLOAT;
+ }
+
+ float maximum()
+ {
+ return QSlider::maximum() / INT_TO_FLOAT;
+ }
+
+ float value()
+ {
+ return QSlider::value() / INT_TO_FLOAT;
+ }
+
+Q_SIGNALS:
+ void valueChanged(float value);
+
+public Q_SLOTS:
+ void notifyValueChanged(int value)
+ {
+ float floatVal = value / INT_TO_FLOAT;
+ Q_EMIT valueChanged(floatVal);
+ }
+};
--
2.25.1
More information about the libcamera-devel
mailing list