1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Add Test Video feature in settings form

Tested on Windows.
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-06-28 22:11:42 +02:00
parent 2a42b1c922
commit 036827086b
4 changed files with 135 additions and 0 deletions

View File

@ -17,6 +17,9 @@ SettingsForm::SettingsForm()
id.setFont(small);
id.setTextInteractionFlags(Qt::TextSelectableByMouse);
camview = new SelfCamView();
videoTest.setText("Test video");
main->setLayout(&layout);
layout.addWidget(&nameLabel);
layout.addWidget(&name);
@ -24,14 +27,18 @@ SettingsForm::SettingsForm()
layout.addWidget(&statusText);
layout.addWidget(&idLabel);
layout.addWidget(&id);
layout.addWidget(&videoTest);
layout.addStretch();
head->setLayout(&headLayout);
headLayout.addWidget(&headLabel);
connect(&videoTest, SIGNAL(clicked()), this, SLOT(onTestVideoClicked()));
}
SettingsForm::~SettingsForm()
{
delete camview;
}
void SettingsForm::setFriendAddress(const QString& friendAddress)
@ -48,3 +55,8 @@ void SettingsForm::show(Ui::Widget &ui)
main->show();
head->show();
}
void SettingsForm::onTestVideoClicked()
{
camview->show();
}

View File

@ -8,6 +8,7 @@
#include <QObject>
#include <QSpacerItem>
#include "ui_widget.h"
#include "widget/selfcamview.h"
class SettingsForm : public QObject
{
@ -21,10 +22,15 @@ public:
public slots:
void setFriendAddress(const QString& friendAddress);
private slots:
void onTestVideoClicked();
private:
QLabel headLabel, nameLabel, statusTextLabel, idLabel, id;
QPushButton videoTest;
QVBoxLayout layout, headLayout;
QWidget *main, *head;
SelfCamView* camview;
public:
QLineEdit name, statusText;

80
widget/selfcamview.cpp Normal file
View File

@ -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();
}

37
widget/selfcamview.h Normal file
View File

@ -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