mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-23 00:25:07 +03:00
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
77ea51820a
commit
15273b38df
2 changed files with 34 additions and 13 deletions
|
@ -15,7 +15,6 @@
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QIcon>
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QImageWriter>
|
#include <QImageWriter>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
@ -63,11 +62,10 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)
|
||||||
adjustSize();
|
adjustSize();
|
||||||
|
|
||||||
ret = openCamera();
|
ret = openCamera();
|
||||||
if (!ret)
|
|
||||||
ret = startCapture();
|
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
quit();
|
quit();
|
||||||
|
|
||||||
|
startStopAction_->setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -113,11 +111,13 @@ int MainWindow::createToolbars()
|
||||||
|
|
||||||
toolbar_->addSeparator();
|
toolbar_->addSeparator();
|
||||||
|
|
||||||
action = toolbar_->addAction(QIcon(":play-circle.svg"), "start");
|
iconPlay_ = QIcon(":play-circle.svg");
|
||||||
connect(action, &QAction::triggered, this, &MainWindow::startCapture);
|
iconStop_ = QIcon(":stop-circle.svg");
|
||||||
|
|
||||||
action = toolbar_->addAction(QIcon(":stop-circle.svg"), "stop");
|
action = toolbar_->addAction(iconPlay_, "Start Capture");
|
||||||
connect(action, &QAction::triggered, this, &MainWindow::stopCapture);
|
action->setCheckable(true);
|
||||||
|
connect(action, &QAction::toggled, this, &MainWindow::toggleCapture);
|
||||||
|
startStopAction_ = action;
|
||||||
|
|
||||||
action = toolbar_->addAction(QIcon(":save.svg"), "saveAs");
|
action = toolbar_->addAction(QIcon(":save.svg"), "saveAs");
|
||||||
connect(action, &QAction::triggered, this, &MainWindow::saveImageAs);
|
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;
|
std::cout << "Switching to camera " << cam->name() << std::endl;
|
||||||
|
|
||||||
stopCapture();
|
startStopAction_->setChecked(false);
|
||||||
|
|
||||||
camera_->release();
|
camera_->release();
|
||||||
camera_ = cam;
|
camera_ = cam;
|
||||||
|
|
||||||
startCapture();
|
startStopAction_->setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MainWindow::chooseCamera()
|
std::string MainWindow::chooseCamera()
|
||||||
|
@ -217,6 +217,19 @@ int MainWindow::openCamera()
|
||||||
return 0;
|
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 MainWindow::startCapture()
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -322,6 +335,7 @@ int MainWindow::startCapture()
|
||||||
}
|
}
|
||||||
|
|
||||||
isCapturing_ = true;
|
isCapturing_ = true;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_disconnect:
|
error_disconnect:
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
|
#include <QIcon>
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
@ -26,6 +27,7 @@
|
||||||
|
|
||||||
using namespace libcamera;
|
using namespace libcamera;
|
||||||
|
|
||||||
|
class QAction;
|
||||||
class ViewFinder;
|
class ViewFinder;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -49,9 +51,7 @@ private Q_SLOTS:
|
||||||
void updateTitle();
|
void updateTitle();
|
||||||
|
|
||||||
void switchCamera(int index);
|
void switchCamera(int index);
|
||||||
|
void toggleCapture(bool start);
|
||||||
int startCapture();
|
|
||||||
void stopCapture();
|
|
||||||
|
|
||||||
void saveImageAs();
|
void saveImageAs();
|
||||||
|
|
||||||
|
@ -60,11 +60,17 @@ private:
|
||||||
std::string chooseCamera();
|
std::string chooseCamera();
|
||||||
int openCamera();
|
int openCamera();
|
||||||
|
|
||||||
|
int startCapture();
|
||||||
|
void stopCapture();
|
||||||
|
|
||||||
void requestComplete(Request *request);
|
void requestComplete(Request *request);
|
||||||
void processCapture();
|
void processCapture();
|
||||||
int display(FrameBuffer *buffer);
|
int display(FrameBuffer *buffer);
|
||||||
void queueRequest(FrameBuffer *buffer);
|
void queueRequest(FrameBuffer *buffer);
|
||||||
|
|
||||||
|
QIcon iconPlay_;
|
||||||
|
QIcon iconStop_;
|
||||||
|
|
||||||
QString title_;
|
QString title_;
|
||||||
QTimer titleTimer_;
|
QTimer titleTimer_;
|
||||||
|
|
||||||
|
@ -87,6 +93,7 @@ private:
|
||||||
QQueue<FrameBuffer *> doneQueue_;
|
QQueue<FrameBuffer *> doneQueue_;
|
||||||
|
|
||||||
QToolBar *toolbar_;
|
QToolBar *toolbar_;
|
||||||
|
QAction *startStopAction_;
|
||||||
ViewFinder *viewfinder_;
|
ViewFinder *viewfinder_;
|
||||||
std::map<int, std::pair<void *, unsigned int>> mappedBuffers_;
|
std::map<int, std::pair<void *, unsigned int>> mappedBuffers_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue