[libcamera-devel,02/11] qcam: ControlFrame: Display defualt value of controls
diff mbox series

Message ID 20220715191400.890976-3-utkarsh02t@gmail.com
State Superseded
Headers show
Series
  • Introduce control interaction to qcam
Related show

Commit Message

Utkarsh Tiwari July 15, 2022, 7:13 p.m. UTC
Display a QLabel below the Control Name showing the default value for
the controls.

This adds support to Display defualt value for the
control types :
    ControlTypeBool
    ControlTypeInteger32
    ControlTypeInteger64
    ControlTypeFloat

Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
---
 src/qcam/settings/control_frame.cpp | 52 +++++++++++++++++++++++++++--
 src/qcam/settings/control_frame.h   |  9 +++++
 src/qcam/settings/controls_tab.cpp  |  2 +-
 3 files changed, 60 insertions(+), 3 deletions(-)

Patch
diff mbox series

diff --git a/src/qcam/settings/control_frame.cpp b/src/qcam/settings/control_frame.cpp
index 6f5cba6d..785e4040 100644
--- a/src/qcam/settings/control_frame.cpp
+++ b/src/qcam/settings/control_frame.cpp
@@ -14,13 +14,61 @@ 
 #include <QString>
 #include <QVBoxLayout>
 
-ControlFrame::ControlFrame(const libcamera::ControlId *control, QWidget *parent)
-	: QFrame(parent), control_(control)
+using namespace libcamera;
+
+ControlFrame::ControlFrame(const libcamera::ControlId *control,
+			   const libcamera::ControlInfo &controlInfo,
+			   QWidget *parent)
+	: QFrame(parent), control_(control), controlInfo_(controlInfo)
 {
 	/* Main layout for the frame */
 	QVBoxLayout *frameVLayout = new QVBoxLayout(this);
 
 	frameVLayout->addWidget(new QLabel(QString::fromStdString(control_->name())));
 
+	/*
+	 * No need to pass parents to widgets,
+	 * as QVBoxLayout transfers ownership to
+	 * its parent widget.
+	 */
+	frameVLayout->addWidget(defaultValueLabel());
+
 	setFrameStyle(QFrame::StyledPanel);
 }
+
+/* -----------------------------------------------------------------------------
+ * Widgets
+ */
+
+QLabel *ControlFrame::defaultValueLabel(QWidget *parent)
+{
+	QLabel *defaultValLabel = new QLabel(parent);
+
+	defaultValLabel->setText("Default Value: " + getDefaultValueQStr());
+
+	return defaultValLabel;
+}
+
+/* -----------------------------------------------------------------------------
+ * Helpers
+ */
+
+QString ControlFrame::getDefaultValueQStr()
+{
+	switch (control_->type()) {
+	case ControlTypeBool:
+		if (controlInfo_.def().get<bool>()) {
+			return QString("True");
+		} else {
+			return QString("False");
+		}
+	case ControlTypeInteger32:
+		return QString::number(controlInfo_.def().get<int32_t>());
+	case ControlTypeInteger64:
+		return QString::number(controlInfo_.def().get<int64_t>());
+	case ControlTypeFloat:
+		return QString::number(controlInfo_.def().get<float>());
+	default:
+		return QString("Unavailable");
+	}
+}
diff --git a/src/qcam/settings/control_frame.h b/src/qcam/settings/control_frame.h
index 10690674..884feb6b 100644
--- a/src/qcam/settings/control_frame.h
+++ b/src/qcam/settings/control_frame.h
@@ -9,6 +9,7 @@ 
 
 #include <libcamera/controls.h>
 
+#include <QLabel>
 #include <QFrame>
 #include <QWidget>
 
@@ -18,9 +19,17 @@  class ControlFrame : public QFrame
 
 public:
 	ControlFrame(const libcamera::ControlId *control,
+		     const libcamera::ControlInfo &controlInfo,
 		     QWidget *parent);
 	~ControlFrame() = default;
 
 private:
 	const libcamera::ControlId *control_;
+	const libcamera::ControlInfo &controlInfo_;
+
+	/* Widgets */
+	QLabel *defaultValueLabel(QWidget *parent = nullptr);
+
+	/* Helper Hunctions */
+	QString getDefaultValueQStr();
 };
diff --git a/src/qcam/settings/controls_tab.cpp b/src/qcam/settings/controls_tab.cpp
index 33ed9332..adc24326 100644
--- a/src/qcam/settings/controls_tab.cpp
+++ b/src/qcam/settings/controls_tab.cpp
@@ -26,7 +26,7 @@  ControlsTab::ControlsTab(std::shared_ptr<libcamera::Camera> camera_,
 
 	int controlCount = 0;
 	for (auto &[control, info] : camera_->controls()) {
-		ControlFrame *controlFrame = new ControlFrame(control, this);
+		ControlFrame *controlFrame = new ControlFrame(control, info, this);
 
 		controlGLayout->addWidget(controlFrame, controlCount / 2,
 					  controlCount % 2);