-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
304 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#include "cameramanager.h" | ||
#include "console.h" | ||
|
||
CameraManager::CameraManager(QObject *parent) | ||
:QObject(parent) | ||
{ | ||
|
||
} | ||
|
||
QList<QCameraInfo> CameraManager::listCameras() | ||
{ | ||
return QCameraInfo::availableCameras(); | ||
|
||
//// if (cameraInfo.deviceName() == "mycamera") | ||
// camera = new QCamera(QCameraInfo::defaultCamera()); | ||
|
||
// camera->setViewfinder(ui->cameraViewFinder); | ||
// camera->start(); | ||
|
||
// ui->statusBar->showMessage("Aaaaa"); | ||
} | ||
|
||
QSharedPointer<QCamera> CameraManager::getCameraByDeviceName(const QString &deviceName) | ||
{ | ||
QList<QCameraInfo> cameras = listCameras(); | ||
|
||
foreach (const QCameraInfo &cameraInfo, cameras) { | ||
if (cameraInfo.deviceName() == deviceName) { | ||
return QSharedPointer<QCamera>(new QCamera(cameraInfo)); | ||
} | ||
} | ||
|
||
return QSharedPointer<QCamera>(nullptr); | ||
} | ||
|
||
void CameraManager::changeSelectedCamera(const QVariant &variant) | ||
{ | ||
changeSelectedCamera(variant.toString()); | ||
} | ||
|
||
void CameraManager::changeSelectedCamera(const QString &deviceName) | ||
{ | ||
QSharedPointer<QCamera> cameraPtr = getCameraByDeviceName(deviceName); | ||
|
||
if (cameraPtr.isNull()) { | ||
Console::error(QString("Couln't change selected camera to %1 (): null pointer returned").arg(deviceName)); | ||
} | ||
|
||
selectedCamera = cameraPtr; | ||
selectedCameraInfo = QCameraInfo(*cameraPtr.data()); | ||
|
||
emit changedSelectedCamera(cameraPtr); | ||
|
||
Console::log(QString("Changed selected camera to %1").arg(selectedCameraInfo.description())); | ||
} | ||
|
||
QSharedPointer<QCamera> CameraManager::getSelectedCamera() | ||
{ | ||
return selectedCamera; | ||
} | ||
|
||
QCameraInfo &CameraManager::getSelectedCameraInfo() | ||
{ | ||
return selectedCameraInfo; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef CAMERAMANAGER_H | ||
#define CAMERAMANAGER_H | ||
|
||
#include <QObject> | ||
#include <QList> | ||
#include <QCameraInfo> | ||
#include <QSharedPointer> | ||
|
||
class CameraManager: public QObject | ||
{ | ||
Q_OBJECT | ||
private: | ||
QSharedPointer<QCamera> selectedCamera; | ||
QCameraInfo selectedCameraInfo; | ||
|
||
public: | ||
CameraManager(QObject *parent = 0); | ||
QList<QCameraInfo> listCameras(); | ||
QSharedPointer<QCamera> getCameraByDeviceName(const QString &deviceName); | ||
QSharedPointer<QCamera> getSelectedCamera(); | ||
QCameraInfo &getSelectedCameraInfo(); | ||
|
||
public slots: | ||
void changeSelectedCamera(const QVariant &variant); | ||
void changeSelectedCamera(const QString &deviceName); | ||
|
||
signals: | ||
void changedSelectedCamera(const QSharedPointer<QCamera> &); | ||
}; | ||
|
||
#endif // CAMERAMANAGER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "console.h" | ||
|
||
QTextEdit *Console::outputControl; | ||
QTextEdit *Console::output; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "dataawarecombobox.h" | ||
|
||
DataAwareComboBox::DataAwareComboBox(QWidget *parent) | ||
:QComboBox(parent) | ||
{ | ||
connect(this, SIGNAL(activated(int)), this, SLOT(triggerVariantActivated(int))); | ||
} | ||
|
||
void DataAwareComboBox::triggerVariantActivated(int index) | ||
{ | ||
emit activated(itemData(index)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef CAMERACOMBOBOX_H | ||
#define CAMERACOMBOBOX_H | ||
|
||
#include <QComboBox> | ||
|
||
class DataAwareComboBox : public QComboBox | ||
{ | ||
Q_OBJECT | ||
|
||
private slots: | ||
void triggerVariantActivated(int index); | ||
|
||
public: | ||
DataAwareComboBox(QWidget *parent = 0); | ||
|
||
signals: | ||
void activated(const QVariant &); | ||
}; | ||
|
||
#endif // CAMERACOMBOBOX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "mainwindow.h" | ||
#include "ui_mainwindow.h" | ||
#include "console.h" | ||
|
||
MainWindow::MainWindow(QWidget *parent) : | ||
QMainWindow(parent), | ||
ui(new Ui::MainWindow), | ||
cameraManager(new CameraManager) | ||
{ | ||
ui->setupUi(this); | ||
Console::setOutputControl(ui->consoleOutput); | ||
|
||
QWidget *horizontalSpacer = new QWidget(ui->mainToolBar); | ||
horizontalSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | ||
ui->mainToolBar->addWidget(horizontalSpacer); | ||
|
||
cameraComboBox = new DataAwareComboBox(ui->mainToolBar); | ||
cameraComboBoxAction = ui->mainToolBar->addWidget(cameraComboBox); | ||
|
||
connect(cameraComboBox, SIGNAL(activated(QVariant)), cameraManager, SLOT(changeSelectedCamera(QVariant))); | ||
connect(cameraManager, SIGNAL(changedSelectedCamera(QSharedPointer<QCamera>)), this, SLOT(onCameraChanged(QSharedPointer<QCamera>))); | ||
|
||
//ui->consoleDockWidget->setVisible(false); | ||
|
||
detectCameras(); | ||
} | ||
|
||
MainWindow::~MainWindow() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void MainWindow::detectCameras() | ||
{ | ||
QList<QCameraInfo> cameras = cameraManager->listCameras(); | ||
|
||
if (cameras.empty()) { | ||
Console::error("No available cameras detected!"); | ||
cameraComboBoxAction->setVisible(false); | ||
ui->consoleDockWidget->setVisible(true); | ||
return; | ||
} | ||
|
||
Console::log(QString("Detected %1 cameras:").arg(cameras.size())); | ||
|
||
foreach (const QCameraInfo &cameraInfo, cameras) { | ||
Console::log(cameraInfo.description()); | ||
cameraComboBox->addItem(cameraInfo.description(), cameraInfo.deviceName()); | ||
} | ||
|
||
cameraManager->changeSelectedCamera(cameras.first().deviceName()); | ||
} | ||
|
||
void MainWindow::onCameraChanged(const QSharedPointer<QCamera> &cameraPtr) | ||
{ | ||
ui->actionToggleCamera->setChecked(false); | ||
|
||
QCamera *camera = cameraPtr.data(); | ||
camera->setViewfinder(ui->cameraViewFinder); | ||
} | ||
|
||
void MainWindow::toggleCamera(bool enable) | ||
{ | ||
QCamera *camera = cameraManager->getSelectedCamera().data(); | ||
QCameraInfo cameraInfo = cameraManager->getSelectedCameraInfo(); | ||
|
||
qDebug() << "MainWindow::toggleCamera" << camera; | ||
|
||
if (enable) { | ||
Console::log(QString("Starting camera %1").arg(cameraInfo.description())); | ||
camera->start(); | ||
} else { | ||
Console::log(QString("Stopping camera %1").arg(cameraInfo.description())); | ||
camera->stop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.