mirror of https://github.com/qTox/qTox.git
4 changed files with 135 additions and 0 deletions
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
#include "selfcamview.h" |
||||
#include <QActionGroup> |
||||
#include <QMessageBox> |
||||
#include <QCloseEvent> |
||||
#include <QShowEvent> |
||||
|
||||
SelfCamView::SelfCamView(QWidget* parent) |
||||
: QWidget(parent), camera(nullptr), mainLayout{new QHBoxLayout()} |
||||
{ |
||||
setLayout(mainLayout); |
||||
setWindowTitle("Tox video test"); |
||||
setMinimumSize(320,240); |
||||
|
||||
QByteArray cameraDevice; |
||||
|
||||
/*
|
||||
QActionGroup *videoDevicesGroup = new QActionGroup(this); |
||||
videoDevicesGroup->setExclusive(true); |
||||
foreach(const QByteArray &deviceName, QCamera::availableDevices()) { |
||||
QString description = camera->deviceDescription(deviceName); |
||||
QAction *videoDeviceAction = new QAction(description, videoDevicesGroup); |
||||
videoDeviceAction->setCheckable(true); |
||||
videoDeviceAction->setData(QVariant(deviceName)); |
||||
if (cameraDevice.isEmpty()) { |
||||
cameraDevice = deviceName; |
||||
videoDeviceAction->setChecked(true); |
||||
} |
||||
ui->menuDevices->addAction(videoDeviceAction); |
||||
} |
||||
|
||||
connect(videoDevicesGroup, SIGNAL(triggered(QAction*)), SLOT(updateCameraDevice(QAction*))); |
||||
*/ |
||||
|
||||
viewfinder = new QCameraViewfinder(this); |
||||
mainLayout->addWidget(viewfinder); |
||||
viewfinder->show(); |
||||
|
||||
setCamera(cameraDevice); |
||||
} |
||||
|
||||
SelfCamView::~SelfCamView() |
||||
{ |
||||
delete camera; |
||||
} |
||||
|
||||
void SelfCamView::setCamera(const QByteArray &cameraDevice) |
||||
{ |
||||
delete camera; |
||||
|
||||
if (cameraDevice.isEmpty()) |
||||
camera = new QCamera; |
||||
else |
||||
camera = new QCamera(cameraDevice); |
||||
|
||||
//connect(camera, SIGNAL(stateChanged(QCamera::State)), this, SLOT(updateCameraState(QCamera::State)));
|
||||
connect(camera, SIGNAL(error(QCamera::Error)), this, SLOT(displayCameraError())); |
||||
|
||||
camera->setViewfinder(viewfinder); |
||||
|
||||
//updateCameraState(camera->state());
|
||||
|
||||
camera->setCaptureMode(QCamera::CaptureVideo); |
||||
} |
||||
|
||||
void SelfCamView::displayCameraError() |
||||
{ |
||||
QMessageBox::warning(this, tr("Camera error"), camera->errorString()); |
||||
} |
||||
|
||||
void SelfCamView::closeEvent(QCloseEvent* event) |
||||
{ |
||||
camera->stop(); |
||||
event->accept(); |
||||
} |
||||
|
||||
void SelfCamView::showEvent(QShowEvent* event) |
||||
{ |
||||
camera->start(); |
||||
event->accept(); |
||||
} |
||||
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
#ifndef SELFCAMVIEW_H |
||||
#define SELFCAMVIEW_H |
||||
|
||||
#include <QCamera> |
||||
#include <QCameraImageCapture> |
||||
#include <QMediaRecorder> |
||||
#include <QWidget> |
||||
#include <QVideoWidget> |
||||
#include <QCameraViewfinder> |
||||
#include <QHBoxLayout> |
||||
|
||||
class QCloseEvent; |
||||
class QShowEvent; |
||||
|
||||
class SelfCamView : public QWidget |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
SelfCamView(QWidget *parent=0); |
||||
~SelfCamView(); |
||||
|
||||
private: |
||||
void closeEvent(QCloseEvent*); |
||||
void showEvent(QShowEvent*); |
||||
|
||||
private slots: |
||||
void setCamera(const QByteArray &cameraDevice); |
||||
void displayCameraError(); |
||||
|
||||
private: |
||||
QCamera *camera; |
||||
QCameraViewfinder* viewfinder; |
||||
QHBoxLayout* mainLayout; |
||||
}; |
||||
|
||||
#endif // SELFCAMVIEW_H
|
||||
Loading…
Reference in new issue