[libcamera-devel,v2,07/11] qcam: Slider: Add SliderLayout to display value
diff mbox series

Message ID 20220812124651.27496-8-utkarsh02t@gmail.com
State New
Headers show
Series
  • Introduce control interaction to qcam
Related show

Commit Message

Utkarsh Tiwari Aug. 12, 2022, 12:46 p.m. UTC
Implement SliderLayout which displays minimum Value, maximum Value,
currentValue of the slider. The currentValue may not reflect the
immediate current value of the control.

The SliderLayout is inherits the Slider type so it can support both
floatSlider and integer sliders.

Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
---
 src/qcam/settings/slider.h | 81 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 78 insertions(+), 3 deletions(-)

Patch
diff mbox series

diff --git a/src/qcam/settings/slider.h b/src/qcam/settings/slider.h
index f4a4825c..008c746c 100644
--- a/src/qcam/settings/slider.h
+++ b/src/qcam/settings/slider.h
@@ -7,18 +7,46 @@ 
 
 #pragma once
 
+#include <QHBoxLayout>
+#include <QLabel>
 #include <QSlider>
+#include <QVBoxLayout>
 #include <QWidget>
 
-class FloatSlider : public QSlider
+class Slider : public QSlider
+{
+	Q_OBJECT
+
+public:
+	Slider(QWidget *parent = nullptr)
+		: QSlider(parent){};
+	~Slider() = default;
+
+	virtual QString maximumValueStr()
+	{
+		return QString::number(maximum());
+	}
+
+	virtual QString minimumValueStr()
+	{
+		return QString::number(minimum());
+	}
+
+	virtual QString currValueStr()
+	{
+		return QString::number(value());
+	}
+};
+
+class FloatSlider : public Slider
 {
 	Q_OBJECT
 
 	const float INT_TO_FLOAT = 100.0;
 
 public:
-	FloatSlider(QWidget *parent)
-		: QSlider(parent)
+	FloatSlider(QWidget *parent = nullptr)
+		: Slider(parent)
 	{
 		connect(this, &QSlider::valueChanged,
 			this, &FloatSlider::notifyValueChanged);
@@ -51,6 +79,21 @@  public:
 		return QSlider::value() / INT_TO_FLOAT;
 	}
 
+	QString maximumValueStr() override
+	{
+		return QString::number(maximum());
+	}
+
+	QString minimumValueStr() override
+	{
+		return QString::number(minimum());
+	}
+
+	QString currValueStr() override
+	{
+		return QString::number(value());
+	}
+
 Q_SIGNALS:
 	void valueChanged(float value);
 
@@ -61,3 +104,35 @@  public Q_SLOTS:
 		Q_EMIT valueChanged(floatVal);
 	}
 };
+
+class SliderLayout : public QWidget
+{
+	Q_OBJECT
+
+public:
+	SliderLayout(Slider *slider, QWidget *parent = nullptr)
+		: QWidget(parent)
+	{
+		QVBoxLayout *mainVLayout = new QVBoxLayout(this);
+
+		QHBoxLayout *labelHLayout = new QHBoxLayout;
+
+		QLabel *minLabel = new QLabel(slider->minimumValueStr());
+		QLabel *currValueLabel = new QLabel(slider->currValueStr());
+		QLabel *maxLabel = new QLabel(slider->maximumValueStr());
+
+		connect(slider, &Slider::valueChanged,
+			this, [currValueLabel, slider]() {
+				currValueLabel->setText(slider->currValueStr());
+			});
+
+		labelHLayout->addWidget(minLabel);
+		labelHLayout->addStretch();
+		labelHLayout->addWidget(currValueLabel);
+		labelHLayout->addStretch();
+		labelHLayout->addWidget(maxLabel);
+
+		mainVLayout->addLayout(labelHLayout);
+		mainVLayout->addWidget(slider);
+	}
+};