From patchwork Mon Mar 23 14:21:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3249 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8684862C48 for ; Mon, 23 Mar 2020 15:22:20 +0100 (CET) Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 08505308 for ; Mon, 23 Mar 2020 15:22:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1584973340; bh=eW09ti/wOhxVQFXKOBaWJE47HHMZe5xlSLIBrHdwJ54=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bk2E/Pt2chfQhtaqlLvos5gXMF9U77P2wW+ijU3Fjghs5yGVqmSvAX7FbgD3IV3VP fozMLV0wAYlbsULOj9JC60Z3XLLj/Sv0qvg3mYIx1Jnv5uyzNU5aFSLEBbFAFLFCjv Y4IQBCRBzxTcx6K9HHDD7pJso1Aess+PFi+PnJ2k= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Mon, 23 Mar 2020 16:21:50 +0200 Message-Id: <20200323142205.28342-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200323142205.28342-1-laurent.pinchart@ideasonboard.com> References: <20200323142205.28342-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 06/21] qcam: main_window: Replace start and stop actions with a toggle action X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Mar 2020 14:22:24 -0000 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 | 30 ++++++++++++++++++++---------- src/qcam/main_window.h | 9 ++++++--- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp index afd8b9c413f5..86f92360a1a9 100644 --- a/src/qcam/main_window.cpp +++ b/src/qcam/main_window.cpp @@ -63,11 +63,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 +112,10 @@ int MainWindow::createToolbars() toolbar_->addSeparator(); - action = toolbar_->addAction(QIcon(":play-circle.svg"), "start"); - connect(action, &QAction::triggered, this, &MainWindow::startCapture); - - action = toolbar_->addAction(QIcon(":stop-circle.svg"), "stop"); - connect(action, &QAction::triggered, this, &MainWindow::stopCapture); + action = toolbar_->addAction(QIcon(":play-circle.svg"), "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 +157,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 +215,17 @@ int MainWindow::openCamera() return 0; } +void MainWindow::toggleCapture(bool start) +{ + if (start) { + startCapture(); + startStopAction_->setText("Stop Capture"); + } else { + stopCapture(); + startStopAction_->setText("Start Capture"); + } +} + int MainWindow::startCapture() { int ret; @@ -322,6 +331,7 @@ int MainWindow::startCapture() } isCapturing_ = true; + return 0; error_disconnect: diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index c623120d5894..3d8d02b44696 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -26,6 +26,7 @@ using namespace libcamera; +class QAction; class ViewFinder; enum { @@ -49,9 +50,7 @@ private Q_SLOTS: void updateTitle(); void switchCamera(int index); - - int startCapture(); - void stopCapture(); + void toggleCapture(bool start); void saveImageAs(); @@ -60,6 +59,9 @@ private: std::string chooseCamera(); int openCamera(); + int startCapture(); + void stopCapture(); + void requestComplete(Request *request); void processCapture(); int display(FrameBuffer *buffer); @@ -87,6 +89,7 @@ private: QQueue doneQueue_; QToolBar *toolbar_; + QAction *startStopAction_; ViewFinder *viewfinder_; std::map> mappedBuffers_; };