From 15273b38dff309af52eb0b9454ade5f5cbb18ac0 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 22 Mar 2020 19:47:40 +0200 Subject: qcam: main_window: Replace start and stop actions with a toggle action The main window toolbar contains a start button and a stop button. This allows starting an already started camera (which is currently not handled and results in an error) or stopping an already stopped camera. Replace the two actions with a single start/stop toggle action, preventing UI misuse and reducing confusion. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/qcam/main_window.cpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'src/qcam/main_window.cpp') diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index 805690d5..74b8748c 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -63,11 +62,10 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options) adjustSize(); ret = openCamera(); - if (!ret) - ret = startCapture(); - if (ret < 0) quit(); + + startStopAction_->setChecked(true); } MainWindow::~MainWindow() @@ -113,11 +111,13 @@ int MainWindow::createToolbars() toolbar_->addSeparator(); - action = toolbar_->addAction(QIcon(":play-circle.svg"), "start"); - connect(action, &QAction::triggered, this, &MainWindow::startCapture); + iconPlay_ = QIcon(":play-circle.svg"); + iconStop_ = QIcon(":stop-circle.svg"); - action = toolbar_->addAction(QIcon(":stop-circle.svg"), "stop"); - connect(action, &QAction::triggered, this, &MainWindow::stopCapture); + action = toolbar_->addAction(iconPlay_, "Start Capture"); + action->setCheckable(true); + connect(action, &QAction::toggled, this, &MainWindow::toggleCapture); + startStopAction_ = action; action = toolbar_->addAction(QIcon(":save.svg"), "saveAs"); connect(action, &QAction::triggered, this, &MainWindow::saveImageAs); @@ -159,12 +159,12 @@ void MainWindow::switchCamera(int index) std::cout << "Switching to camera " << cam->name() << std::endl; - stopCapture(); + startStopAction_->setChecked(false); camera_->release(); camera_ = cam; - startCapture(); + startStopAction_->setChecked(true); } std::string MainWindow::chooseCamera() @@ -217,6 +217,19 @@ int MainWindow::openCamera() return 0; } +void MainWindow::toggleCapture(bool start) +{ + if (start) { + startCapture(); + startStopAction_->setIcon(iconStop_); + startStopAction_->setText("Stop Capture"); + } else { + stopCapture(); + startStopAction_->setIcon(iconPlay_); + startStopAction_->setText("Start Capture"); + } +} + int MainWindow::startCapture() { int ret; @@ -322,6 +335,7 @@ int MainWindow::startCapture() } isCapturing_ = true; + return 0; error_disconnect: -- cgit v1.2.1