[libcamera-devel,v6,3/4] qcam: CamSelectDialog: Display Capture script path
diff mbox series

Message ID 20220807203204.152358-4-utkarsh02t@gmail.com
State Superseded
Headers show
Series
  • Introduce capture scripts to qcam
Related show

Commit Message

Utkarsh Tiwari Aug. 7, 2022, 8:32 p.m. UTC
Display the path of the selected capture script in a thinner font.

Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com>
---
Difference from V5:
	came to existance.
 src/qcam/cam_select_dialog.h | 41 +++++++++++++++++++++++++++++++-----
 src/qcam/main_window.cpp     |  3 ++-
 2 files changed, 38 insertions(+), 6 deletions(-)

Patch
diff mbox series

diff --git a/src/qcam/cam_select_dialog.h b/src/qcam/cam_select_dialog.h
index fc29b46a..7dc44794 100644
--- a/src/qcam/cam_select_dialog.h
+++ b/src/qcam/cam_select_dialog.h
@@ -19,18 +19,22 @@ 
 #include <QDialog>
 #include <QDialogButtonBox>
 #include <QFileDialog>
+#include <QFont>
 #include <QFormLayout>
 #include <QLabel>
 #include <QPushButton>
 #include <QString>
+#include <QVBoxLayout>
+#include <QWidget>
 
 class CamSelectDialog : public QDialog
 {
 	Q_OBJECT
 public:
 	CamSelectDialog(libcamera::CameraManager *cameraManager,
-			bool isScriptRunning, QWidget *parent)
-		: QDialog(parent), cm_(cameraManager), isScriptRunning_(isScriptRunning)
+			bool isScriptRunning, std::string scriptPath, QWidget *parent)
+		: QDialog(parent), cm_(cameraManager),
+		  isScriptRunning_(isScriptRunning), scriptPath_(scriptPath)
 	{
 		/* Use a QFormLayout for the dialog. */
 		QFormLayout *camSelectDialogLayout = new QFormLayout(this);
@@ -51,14 +55,31 @@  public:
 					cameraIdComboBox_->currentText().toStdString()));
 			});
 
+		/* Setup widget for capture script button. */
+		QWidget *captureWidget = new QWidget;
+		captureWidgetLayout_ = new QVBoxLayout(captureWidget);
+		captureWidgetLayout_->setMargin(0);
+
 		captureScriptButton_ = new QPushButton;
 		connect(captureScriptButton_, &QPushButton::clicked,
 			this, &CamSelectDialog::handleCaptureScriptButton);
+		captureWidgetLayout_->addWidget(captureScriptButton_);
+
+		/* Use a thinner font to indicate script info. */
+		QFont smallFont;
+		smallFont.setWeight(QFont::Thin);
+
+		scriptPathLabel_ = new QLabel;
+		scriptPathLabel_->setFont(smallFont);
+		scriptPathLabel_->setWordWrap(true);
 
 		/* Display the action that would be performed when button is clicked. */
-		if (isScriptRunning_)
+		if (isScriptRunning_) {
 			captureScriptButton_->setText("Stop");
-		else
+
+			scriptPathLabel_->setText(QString::fromStdString(scriptPath_));
+			captureWidgetLayout_->addWidget(scriptPathLabel_);
+		} else
 			captureScriptButton_->setText("Open");
 
 		/* Setup the QDialogButton Box */
@@ -75,7 +96,7 @@  public:
 		camSelectDialogLayout->addRow("Camera: ", cameraIdComboBox_);
 		camSelectDialogLayout->addRow("Location: ", cameraLocation_);
 		camSelectDialogLayout->addRow("Model: ", cameraModel_);
-		camSelectDialogLayout->addRow("Capture Script: ", captureScriptButton_);
+		camSelectDialogLayout->addRow("Capture Script: ", captureWidget);
 		camSelectDialogLayout->addWidget(dialogButtonBox);
 	}
 
@@ -148,6 +169,8 @@  public:
 			Q_EMIT stopCaptureScript();
 			isScriptRunning_ = false;
 			captureScriptButton_->setText("Open");
+
+			captureWidgetLayout_->removeWidget(scriptPathLabel_);
 		} else {
 			scriptPath_ = QFileDialog::getOpenFileName(this, "Run Capture Script",
 								   QDir::currentPath(), "Capture Script (*.yaml)")
@@ -155,6 +178,11 @@  public:
 
 			if (!scriptPath_.empty())
 				captureScriptButton_->setText("Loaded");
+			else
+				return;
+
+			scriptPathLabel_->setText(QString::fromStdString(scriptPath_));
+			captureWidgetLayout_->addWidget(scriptPathLabel_);
 		}
 	}
 
@@ -171,5 +199,8 @@  private:
 	QComboBox *cameraIdComboBox_;
 	QLabel *cameraLocation_;
 	QLabel *cameraModel_;
+
+	QVBoxLayout *captureWidgetLayout_;
 	QPushButton *captureScriptButton_;
+	QLabel *scriptPathLabel_ = new QLabel;
 };
diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index e0219e5e..e354ba10 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -332,7 +332,8 @@  void MainWindow::loadCaptureScript()
 std::string MainWindow::chooseCamera()
 {
 	bool scriptRunning = script_ != nullptr;
-	camSelectDialog_ = new CamSelectDialog(cm_, scriptRunning, this);
+	camSelectDialog_ = new CamSelectDialog(cm_, scriptRunning,
+					       scriptPath_, this);
 
 	connect(camSelectDialog_, &CamSelectDialog::stopCaptureScript,
 		this, &MainWindow::stopCaptureScript);