summaryrefslogtreecommitdiff
path: root/src/qcam/main_window.cpp
diff options
context:
space:
mode:
authorKieran Bingham <kieran.bingham@ideasonboard.com>2020-02-05 15:12:06 +0000
committerKieran Bingham <kieran.bingham@ideasonboard.com>2020-02-14 12:34:27 +0000
commitfb497899e2c9651022356a2339349d3e7c518687 (patch)
treeb3084c5f80be0e6f87686703e9ce397a8c128854 /src/qcam/main_window.cpp
parent871879eb7356d532c4ed7791ec22cf5ae9f005e8 (diff)
qcam: Introduce a toolbar and camera switching
Implement a quit button, and a list of cameras. Selecting a different camera from the Toolbar will stop the current stream, and start streaming the chosen camera device if it can be acquired. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/qcam/main_window.cpp')
-rw-r--r--src/qcam/main_window.cpp64
1 files changed, 62 insertions, 2 deletions
diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index 2ed84cac..f55628c7 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -10,9 +10,12 @@
#include <string>
#include <sys/mman.h>
+#include <QComboBox>
#include <QCoreApplication>
#include <QInputDialog>
#include <QTimer>
+#include <QToolBar>
+#include <QToolButton>
#include <libcamera/camera_manager.h>
#include <libcamera/version.h>
@@ -27,6 +30,8 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)
{
int ret;
+ createToolbars();
+
title_ = "QCam " + QString::fromStdString(CameraManager::version());
setWindowTitle(title_);
connect(&titleTimer_, SIGNAL(timeout()), this, SLOT(updateTitle()));
@@ -40,8 +45,7 @@ MainWindow::MainWindow(CameraManager *cm, const OptionsParser::Options &options)
ret = startCapture();
if (ret < 0)
- QTimer::singleShot(0, QCoreApplication::instance(),
- &QCoreApplication::quit);
+ quit();
}
MainWindow::~MainWindow()
@@ -53,6 +57,39 @@ MainWindow::~MainWindow()
}
}
+int MainWindow::createToolbars()
+{
+ QAction *action;
+
+ toolbar_ = addToolBar("Main");
+
+ /* Disable right click context menu. */
+ toolbar_->setContextMenuPolicy(Qt::PreventContextMenu);
+
+ action = toolbar_->addAction("Quit");
+ connect(action, &QAction::triggered, this, &MainWindow::quit);
+
+ /* Camera selection. */
+ QComboBox *cameraCombo = new QComboBox();
+ connect(cameraCombo, QOverload<int>::of(&QComboBox::activated),
+ this, &MainWindow::switchCamera);
+
+ for (const std::shared_ptr<Camera> &cam : cm_->cameras())
+ cameraCombo->addItem(QString::fromStdString(cam->name()));
+
+ toolbar_->addWidget(cameraCombo);
+
+ toolbar_->addSeparator();
+
+ return 0;
+}
+
+void MainWindow::quit()
+{
+ QTimer::singleShot(0, QCoreApplication::instance(),
+ &QCoreApplication::quit);
+}
+
void MainWindow::updateTitle()
{
unsigned int duration = frameRateInterval_.elapsed();
@@ -66,6 +103,29 @@ void MainWindow::updateTitle()
setWindowTitle(title_ + " : " + QString::number(fps, 'f', 2) + " fps");
}
+void MainWindow::switchCamera(int index)
+{
+ const auto &cameras = cm_->cameras();
+ if (static_cast<unsigned int>(index) >= cameras.size())
+ return;
+
+ const std::shared_ptr<Camera> &cam = cameras[index];
+
+ if (cam->acquire()) {
+ std::cout << "Failed to acquire camera " << cam->name() << std::endl;
+ return;
+ }
+
+ std::cout << "Switching to camera " << cam->name() << std::endl;
+
+ stopCapture();
+
+ camera_->release();
+ camera_ = cam;
+
+ startCapture();
+}
+
std::string MainWindow::chooseCamera()
{
QStringList cameras;