diff options
-rw-r--r-- | src/qcam/main_window.cpp | 34 | ||||
-rw-r--r-- | src/qcam/main_window.h | 13 |
2 files changed, 34 insertions, 13 deletions
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 <QComboBox> #include <QCoreApplication> #include <QFileDialog> -#include <QIcon> #include <QImage> #include <QImageWriter> #include <QInputDialog> @@ -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: diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h index c623120d..34a090cc 100644 --- a/src/qcam/main_window.h +++ b/src/qcam/main_window.h @@ -10,6 +10,7 @@ #include <memory> #include <QElapsedTimer> +#include <QIcon> #include <QMainWindow> #include <QMutex> #include <QObject> @@ -26,6 +27,7 @@ using namespace libcamera; +class QAction; class ViewFinder; enum { @@ -49,9 +51,7 @@ private Q_SLOTS: void updateTitle(); void switchCamera(int index); - - int startCapture(); - void stopCapture(); + void toggleCapture(bool start); void saveImageAs(); @@ -60,11 +60,17 @@ private: std::string chooseCamera(); int openCamera(); + int startCapture(); + void stopCapture(); + void requestComplete(Request *request); void processCapture(); int display(FrameBuffer *buffer); void queueRequest(FrameBuffer *buffer); + QIcon iconPlay_; + QIcon iconStop_; + QString title_; QTimer titleTimer_; @@ -87,6 +93,7 @@ private: QQueue<FrameBuffer *> doneQueue_; QToolBar *toolbar_; + QAction *startStopAction_; ViewFinder *viewfinder_; std::map<int, std::pair<void *, unsigned int>> mappedBuffers_; }; |