mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-24 00:55:07 +03:00
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>
This commit is contained in:
parent
871879eb73
commit
fb497899e2
2 changed files with 67 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue