summaryrefslogtreecommitdiff
path: root/src/qcam/main_window.cpp
diff options
context:
space:
mode:
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;