[libcamera-devel,05/11] qcam: ControlFrame: Add Current Value label
diff mbox series

Message ID 20220715191400.890976-6-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
Add a QLabel which displays the Current value of the control.
Currently this only supports ControlTypeBool.

At start do not display any Current value as we cannot be sure of the
starting conditions and the controls that have been applied.

When a request completes succesfully completes, we use its ControlList
to update the currentValue.

The current model for sending the controlValue is :

MainWindow -> Settings -> Control Tab -> Control Frame

Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
---
 src/qcam/main_window.cpp            | 10 +++++++++
 src/qcam/main_window.h              |  4 ++++
 src/qcam/settings/control_frame.cpp | 32 +++++++++++++++++++++++++++++
 src/qcam/settings/control_frame.h   |  4 ++++
 src/qcam/settings/controls_tab.cpp  |  7 +++++++
 src/qcam/settings/controls_tab.h    |  5 +++++
 src/qcam/settings/settings_dialog.h |  3 +++
 7 files changed, 65 insertions(+)

Patch
diff mbox series

diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index 5d11ef98..0dc72f3c 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -355,6 +355,8 @@  void MainWindow::openSettingsDialog()
 	settingsDialog_ = std::make_unique<SettingsDialog>(camera_, this);
 	connect(settingsDialog_.get(), &SettingsDialog::controlListChanged,
 		this, &MainWindow::controlListLatch);
+	connect(this, &MainWindow::processControls,
+		settingsDialog_.get(), &SettingsDialog::processControls);
 	settingsDialog_->show();
 }
 
@@ -823,6 +825,14 @@  void MainWindow::processCapture()
 		request = doneQueue_.dequeue();
 	}
 
+	/* Process controlList for current values. */
+	if (settingsDialog_) {
+		if (settingsDialog_->isVisible()) {
+			controlListShared_ = std::make_shared<const libcamera::ControlList>(request->controls());
+			Q_EMIT processControls(controlListShared_);
+		}
+	}
+
 	/* Process buffers. */
 	if (request->buffers().count(vfStream_))
 		processViewfinder(request->buffers().at(vfStream_));
diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h
index 05207023..97234d2e 100644
--- a/src/qcam/main_window.h
+++ b/src/qcam/main_window.h
@@ -57,6 +57,9 @@  public:
 
 	bool event(QEvent *e) override;
 
+Q_SIGNALS:
+	void processControls(std::shared_ptr<const libcamera::ControlList>);
+
 private Q_SLOTS:
 	void quit();
 	void updateTitle();
@@ -143,4 +146,5 @@  private:
 	std::unique_ptr<CaptureScript> script_;
 
 	libcamera::ControlList controlList_;
+	std::shared_ptr<const libcamera::ControlList> controlListShared_;
 };
diff --git a/src/qcam/settings/control_frame.cpp b/src/qcam/settings/control_frame.cpp
index e335d373..3ab9fdb4 100644
--- a/src/qcam/settings/control_frame.cpp
+++ b/src/qcam/settings/control_frame.cpp
@@ -33,6 +33,7 @@  ControlFrame::ControlFrame(const libcamera::ControlId *control,
 	 * ownership to its parent widget.
 	 */
 	frameVLayout->addWidget(defaultValueLabel());
+	frameVLayout->addWidget(currentValueLabel());
 	frameVLayout->addWidget(controlInteraction());
 
 	setFrameStyle(QFrame::StyledPanel);
@@ -83,10 +84,41 @@  QWidget *ControlFrame::controlInteraction(QWidget *parent)
 	}
 }
 
+QWidget *ControlFrame::currentValueLabel(QWidget *parent)
+{
+	QWidget *containerWidget = new QWidget(parent);
+
+	QHBoxLayout *HCurrentValueLayout = new QHBoxLayout(containerWidget);
+
+	currentValue_ = new QLabel;
+
+	HCurrentValueLayout->addWidget(new QLabel("Current Value: "));
+	HCurrentValueLayout->addWidget(currentValue_);
+
+	/* Align with ControlName. */
+	HCurrentValueLayout->setAlignment(Qt::AlignLeft);
+	HCurrentValueLayout->setMargin(0);
+
+	return containerWidget;
+}
 /* -----------------------------------------------------------------------------
  * Qt Slots
  */
 
+void ControlFrame::setCurrentValue(const libcamera::ControlValue controlValue)
+{
+	switch (control_->type()) {
+	case ControlTypeBool:
+		if (controlValue.get<bool>())
+			currentValue_->setText("True");
+		else
+			currentValue_->setText("False");
+		break;
+	default:
+		break;
+	}
+}
+
 void ControlFrame::notifyControlChange()
 {
 	ControlValue controlValue = ControlValue();
diff --git a/src/qcam/settings/control_frame.h b/src/qcam/settings/control_frame.h
index 61005ea5..9c3b059b 100644
--- a/src/qcam/settings/control_frame.h
+++ b/src/qcam/settings/control_frame.h
@@ -12,6 +12,7 @@ 
 #include <QCheckBox>
 #include <QFrame>
 #include <QLabel>
+#include <QString>
 #include <QWidget>
 
 class ControlFrame : public QFrame
@@ -24,6 +25,7 @@  public:
 		     QWidget *parent);
 	~ControlFrame() = default;
 
+	void setCurrentValue(const libcamera::ControlValue controlValue);
 Q_SIGNALS:
 	void controlChanged(const libcamera::ControlId *controlId,
 			    const libcamera::ControlValue);
@@ -37,9 +39,11 @@  private:
 
 	/* Widgets */
 	QWidget *controlInteraction(QWidget *parent = nullptr);
+	QWidget *currentValueLabel(QWidget *parent = nullptr);
 	QLabel *defaultValueLabel(QWidget *parent = nullptr);
 
 	QCheckBox *controlCheckBox_;
+	QLabel *currentValue_;
 
 	/* Helper Hunctions */
 	QString getDefaultValueQStr();
diff --git a/src/qcam/settings/controls_tab.cpp b/src/qcam/settings/controls_tab.cpp
index 30899783..496b5d3b 100644
--- a/src/qcam/settings/controls_tab.cpp
+++ b/src/qcam/settings/controls_tab.cpp
@@ -31,6 +31,7 @@  ControlsTab::ControlsTab(std::shared_ptr<libcamera::Camera> camera_,
 	int controlCount = 0;
 	for (auto &[control, info] : camera_->controls()) {
 		ControlFrame *controlFrame = new ControlFrame(control, info, this);
+		controlFrameMap_[control->id()] = controlFrame;
 		connect(controlFrame, &ControlFrame::controlChanged,
 			this, &ControlsTab::controlChanged);
 
@@ -50,6 +51,12 @@  ControlsTab::ControlsTab(std::shared_ptr<libcamera::Camera> camera_,
  * Qt Slots
  */
 
+void ControlsTab::notifyControlFrame(std::shared_ptr<const libcamera::ControlList> controlList)
+{
+	for (auto &[id, controlValue] : *(controlList))
+		controlFrameMap_[id]->setCurrentValue(controlValue);
+}
+
 void ControlsTab::controlChanged(const libcamera::ControlId *controlId,
 				 const libcamera::ControlValue controlValue)
 {
diff --git a/src/qcam/settings/controls_tab.h b/src/qcam/settings/controls_tab.h
index 28efd35e..215c41fd 100644
--- a/src/qcam/settings/controls_tab.h
+++ b/src/qcam/settings/controls_tab.h
@@ -7,6 +7,7 @@ 
 
 #pragma once
 
+#include <map>
 #include <memory>
 
 #include <libcamera/camera.h>
@@ -15,6 +16,8 @@ 
 #include <QVBoxLayout>
 #include <QWidget>
 
+#include "control_frame.h"
+
 class ControlsTab : public QScrollArea
 {
 	Q_OBJECT
@@ -29,7 +32,9 @@  Q_SIGNALS:
 public Q_SLOTS:
 	void controlChanged(const libcamera::ControlId *controlId,
 			    const libcamera::ControlValue controlValue);
+	void notifyControlFrame(std::shared_ptr<const libcamera::ControlList> controlList);
 
 private:
 	std::shared_ptr<libcamera::ControlList> controlList_;
+	std::map<const unsigned int, ControlFrame *> controlFrameMap_;
 };
diff --git a/src/qcam/settings/settings_dialog.h b/src/qcam/settings/settings_dialog.h
index e6efd876..f0462d89 100644
--- a/src/qcam/settings/settings_dialog.h
+++ b/src/qcam/settings/settings_dialog.h
@@ -34,6 +34,8 @@  public:
 		settingTabWidget->addTab(controlsTab, "Controls");
 		connect(controlsTab, &ControlsTab::controlListChanged,
 			this, &SettingsDialog::controlListChanged);
+		connect(this, &SettingsDialog::processControls,
+			controlsTab, &ControlsTab::notifyControlFrame);
 
 		setWindowTitle("Settings");
 	}
@@ -41,4 +43,5 @@  public:
 
 Q_SIGNALS:
 	void controlListChanged(std::shared_ptr<const libcamera::ControlList>);
+	void processControls(std::shared_ptr<const libcamera::ControlList>);
 };