@@ -161,8 +161,7 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)
}
/* Show stopping availability. */
- scriptExecAction_->setIcon(QIcon(":x-square.svg"));
- scriptExecAction_->setText("Stop Script execution");
+ toggleScriptAction(false);
}
startStopAction_->setChecked(true);
@@ -252,6 +251,8 @@ int MainWindow::createToolbars()
QIcon(":file.svg")),
"Open Capture Script");
connect(action, &QAction::triggered, this, &MainWindow::chooseScript);
+
+ /* Do not operate directly call toggleScriptAction */
scriptExecAction_ = action;
return 0;
@@ -289,10 +290,7 @@ void MainWindow::chooseScript()
* This is the second valid press of load script button,
* It indicates stopping, Stop and set button for new script.
*/
- script_.reset();
- scriptExecAction_->setIcon(QIcon::fromTheme("document-open",
- QIcon(":file.svg")));
- scriptExecAction_->setText("Open Capture Script");
+ toggleScriptAction(true);
return;
}
@@ -323,14 +321,26 @@ void MainWindow::chooseScript()
* Valid script verified
* Set the button to indicate stopping availibility.
*/
- scriptExecAction_->setIcon(QIcon(":x-square.svg"));
- scriptExecAction_->setText("Stop Script execution");
+ toggleScriptAction(false);
/* Start capture again if we were capturing before. */
if (wasCapturing)
toggleCapture(true);
}
+void MainWindow::toggleScriptAction(bool showAvailable)
+{
+ if (showAvailable) {
+ script_.reset();
+ scriptExecAction_->setIcon(QIcon::fromTheme("document-open",
+ QIcon(":file.svg")));
+ scriptExecAction_->setText("Open Capture Script");
+ } else {
+ scriptExecAction_->setIcon(QIcon(":x-square.svg"));
+ scriptExecAction_->setText("Stop Script execution");
+ }
+}
+
/* -----------------------------------------------------------------------------
* Camera Selection
*/
@@ -90,6 +90,8 @@ private:
void chooseScript();
+ void toggleScriptAction(bool showAvailable);
+
/* UI elements */
QToolBar *toolbar_;
QAction *startStopAction_;
Centralize the use of scriptExecAction_ in a single function toggleScriptAction(). Call toggleScriptAction() with a true value to reset script_ and set the icon to show availability to load script to the user. Call with a false value to set the icon to show the stopping icon. Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com> --- This patch applies on top of series https://lists.libcamera.org/pipermail/libcamera-devel/2022-June/031151.html src/qcam/main_window.cpp | 26 ++++++++++++++++++-------- src/qcam/main_window.h | 2 ++ 2 files changed, 20 insertions(+), 8 deletions(-)