summaryrefslogtreecommitdiff
path: root/src/qcam
diff options
context:
space:
mode:
authorUtkarsh Tiwari <utkarsh02t@gmail.com>2022-08-08 23:55:54 +0530
committerUtkarsh Tiwari <utkarsh02t@gmail.com>2022-09-05 12:14:14 +0530
commitb63519d201628bd662b4d616b90db88d3fcce163 (patch)
treec2f4274b11590057e51591e8329513d7513e0d15 /src/qcam
parent923927ae45dd10be5c3c854d568dae6751ccb87e (diff)
qcam: MainWindow: Replace cameraCombo_ with CameraSelectorDialog
Replace the cameraCombo_ on the toolbar with a QPushButton which displays the CameraSelectorDialog. This would allow the user to view information about the camera when switching. The QPushButton text is set to the camera Id currently in use. Signed-off-by: Utkarsh Tiwari <utkarsh02t@gmail.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/qcam')
-rw-r--r--src/qcam/main_window.cpp33
-rw-r--r--src/qcam/main_window.h6
2 files changed, 19 insertions, 20 deletions
diff --git a/src/qcam/main_window.cpp b/src/qcam/main_window.cpp
index 385b0059..675b4cb0 100644
--- a/src/qcam/main_window.cpp
+++ b/src/qcam/main_window.cpp
@@ -14,7 +14,6 @@
#include <libcamera/camera_manager.h>
#include <libcamera/version.h>
-#include <QComboBox>
#include <QCoreApplication>
#include <QFileDialog>
#include <QImage>
@@ -195,14 +194,11 @@ int MainWindow::createToolbars()
connect(action, &QAction::triggered, this, &MainWindow::quit);
/* Camera selector. */
- cameraCombo_ = new QComboBox();
- connect(cameraCombo_, QOverload<int>::of(&QComboBox::activated),
+ cameraSelectButton_ = new QPushButton;
+ connect(cameraSelectButton_, &QPushButton::clicked,
this, &MainWindow::switchCamera);
- for (const std::shared_ptr<Camera> &cam : cm_->cameras())
- cameraCombo_->addItem(QString::fromStdString(cam->id()));
-
- toolbar_->addWidget(cameraCombo_);
+ toolbar_->addWidget(cameraSelectButton_);
toolbar_->addSeparator();
@@ -262,14 +258,18 @@ void MainWindow::updateTitle()
* Camera Selection
*/
-void MainWindow::switchCamera(int index)
+void MainWindow::switchCamera()
{
/* Get and acquire the new camera. */
- const auto &cameras = cm_->cameras();
- if (static_cast<unsigned int>(index) >= cameras.size())
+ std::string newCameraId = chooseCamera();
+
+ if (newCameraId.empty())
return;
- const std::shared_ptr<Camera> &cam = cameras[index];
+ if (camera_ && newCameraId == camera_->id())
+ return;
+
+ const std::shared_ptr<Camera> &cam = cm_->get(newCameraId);
if (cam->acquire()) {
qInfo() << "Failed to acquire camera" << cam->id().c_str();
@@ -288,6 +288,9 @@ void MainWindow::switchCamera(int index)
camera_ = cam;
startStopAction_->setChecked(true);
+
+ /* Display the current cameraId in the toolbar .*/
+ cameraSelectButton_->setText(QString::fromStdString(newCameraId));
}
std::string MainWindow::chooseCamera()
@@ -327,8 +330,8 @@ int MainWindow::openCamera()
return -EBUSY;
}
- /* Set the combo-box entry with the currently selected Camera. */
- cameraCombo_->setCurrentText(QString::fromStdString(cameraName));
+ /* Set the camera switch button with the currently selected Camera id. */
+ cameraSelectButton_->setText(QString::fromStdString(cameraName));
return 0;
}
@@ -598,7 +601,6 @@ void MainWindow::processHotplug(HotplugEvent *e)
HotplugEvent::PlugEvent event = e->hotplugEvent();
if (event == HotplugEvent::HotPlug) {
- cameraCombo_->addItem(cameraId);
cameraSelectorDialog_->addCamera(cameraId);
} else if (event == HotplugEvent::HotUnplug) {
/* Check if the currently-streaming camera is removed. */
@@ -606,11 +608,8 @@ void MainWindow::processHotplug(HotplugEvent *e)
toggleCapture(false);
camera_->release();
camera_.reset();
- cameraCombo_->setCurrentIndex(0);
}
- int camIndex = cameraCombo_->findText(cameraId);
- cameraCombo_->removeItem(camIndex);
cameraSelectorDialog_->removeCamera(cameraId);
}
}
diff --git a/src/qcam/main_window.h b/src/qcam/main_window.h
index e17c8010..3fa98b05 100644
--- a/src/qcam/main_window.h
+++ b/src/qcam/main_window.h
@@ -23,6 +23,7 @@
#include <QMainWindow>
#include <QMutex>
#include <QObject>
+#include <QPushButton>
#include <QQueue>
#include <QTimer>
@@ -31,7 +32,6 @@
#include "viewfinder.h"
class QAction;
-class QComboBox;
class CameraSelectorDialog;
class Image;
@@ -60,7 +60,7 @@ private Q_SLOTS:
void quit();
void updateTitle();
- void switchCamera(int index);
+ void switchCamera();
void toggleCapture(bool start);
void saveImageAs();
@@ -90,7 +90,7 @@ private:
/* UI elements */
QToolBar *toolbar_;
QAction *startStopAction_;
- QComboBox *cameraCombo_;
+ QPushButton *cameraSelectButton_;
QAction *saveRaw_;
ViewFinder *viewfinder_;