QtMultimedia: examples/camera coding style
Also unconditionally include code for Qt >= 4.7 Change-Id: Ic8b9d009a54f9e0fe7e9477c75c125ad09a485ee Reviewed-by: David Schulz <david.schulz@digia.com>
This commit is contained in:
@@ -43,13 +43,12 @@
|
||||
#include "videosettings.h"
|
||||
#include "imagesettings.h"
|
||||
|
||||
#include <qmediaservice.h>
|
||||
#include <qmediarecorder.h>
|
||||
#include <qcamera.h>
|
||||
#include <qcameraviewfinder.h>
|
||||
#include <QMediaService>
|
||||
#include <QMediaRecorder>
|
||||
#include <QCameraViewfinder>
|
||||
|
||||
#include <qmessagebox.h>
|
||||
#include <qpalette.h>
|
||||
#include <QMessageBox>
|
||||
#include <QPalette>
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
@@ -85,7 +84,7 @@ Camera::Camera(QWidget *parent) :
|
||||
ui->menuDevices->addAction(videoDeviceAction);
|
||||
}
|
||||
|
||||
connect(videoDevicesGroup, SIGNAL(triggered(QAction*)), this, SLOT(updateCameraDevice(QAction*)));
|
||||
connect(videoDevicesGroup, SIGNAL(triggered(QAction*)), SLOT(updateCameraDevice(QAction*)));
|
||||
connect(ui->captureWidget, SIGNAL(currentChanged(int)), SLOT(updateCaptureMode()));
|
||||
|
||||
#ifdef HAVE_CAMERA_BUTTONS
|
||||
@@ -154,7 +153,6 @@ void Camera::keyPressEvent(QKeyEvent * event)
|
||||
return;
|
||||
|
||||
switch (event->key()) {
|
||||
#if QT_VERSION >= 0x040700
|
||||
case Qt::Key_CameraFocus:
|
||||
displayViewfinder();
|
||||
camera->searchAndLock();
|
||||
@@ -171,23 +169,20 @@ void Camera::keyPressEvent(QKeyEvent * event)
|
||||
}
|
||||
event->accept();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
QMainWindow::keyPressEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Camera::keyReleaseEvent(QKeyEvent * event)
|
||||
void Camera::keyReleaseEvent(QKeyEvent *event)
|
||||
{
|
||||
if (event->isAutoRepeat())
|
||||
return;
|
||||
|
||||
switch (event->key()) {
|
||||
#if QT_VERSION >= 0x040700
|
||||
case Qt::Key_CameraFocus:
|
||||
camera->unlock();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
QMainWindow::keyReleaseEvent(event);
|
||||
}
|
||||
@@ -207,7 +202,8 @@ void Camera::processCapturedImage(int requestId, const QImage& img)
|
||||
Qt::SmoothTransformation);
|
||||
|
||||
ui->lastImagePreviewLabel->setPixmap(QPixmap::fromImage(scaledImage));
|
||||
//display captured image for 4 seconds
|
||||
|
||||
// Display captured image for 4 seconds.
|
||||
displayCapturedImage();
|
||||
QTimer::singleShot(4000, this, SLOT(displayViewfinder()));
|
||||
}
|
||||
@@ -319,7 +315,6 @@ void Camera::updateLockStatus(QCamera::LockStatus status, QCamera::LockChangeRea
|
||||
}
|
||||
|
||||
void Camera::takeImage()
|
||||
|
||||
{
|
||||
isCapturingImage = true;
|
||||
imageCapture->capture();
|
||||
|
||||
@@ -41,25 +41,20 @@
|
||||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
|
||||
#include <qcamera.h>
|
||||
#include <qmediarecorder.h>
|
||||
#include <qcameraimagecapture.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class Camera;
|
||||
}
|
||||
class QCameraViewfinder;
|
||||
QT_END_NAMESPACE
|
||||
#include <QCamera>
|
||||
#include <QCameraImageCapture>
|
||||
#include <QMediaRecorder>
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QDir>
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class Camera; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class Camera : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Camera(QWidget *parent = 0);
|
||||
~Camera();
|
||||
@@ -85,7 +80,7 @@ private slots:
|
||||
void displayRecorderError();
|
||||
void displayCameraError();
|
||||
|
||||
void updateCameraDevice(QAction*);
|
||||
void updateCameraDevice(QAction *action);
|
||||
|
||||
void updateCameraState(QCamera::State);
|
||||
void updateCaptureMode();
|
||||
@@ -94,19 +89,19 @@ private slots:
|
||||
|
||||
void updateRecordTime();
|
||||
|
||||
void processCapturedImage(int requestId, const QImage& img);
|
||||
void processCapturedImage(int requestId, const QImage &img);
|
||||
void updateLockStatus(QCamera::LockStatus, QCamera::LockChangeReason);
|
||||
|
||||
void displayViewfinder();
|
||||
void displayCapturedImage();
|
||||
|
||||
void readyForCapture(bool);
|
||||
void imageSaved(int, const QString&);
|
||||
void readyForCapture(bool ready);
|
||||
void imageSaved(int id, const QString &fileName);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent * event);
|
||||
void keyReleaseEvent(QKeyEvent * event);
|
||||
void closeEvent(QCloseEvent *event );
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void keyReleaseEvent(QKeyEvent *event);
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
||||
private:
|
||||
Ui::Camera *ui;
|
||||
|
||||
@@ -41,11 +41,10 @@
|
||||
#include "imagesettings.h"
|
||||
#include "ui_imagesettings.h"
|
||||
|
||||
#include <QtWidgets/qcombobox.h>
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <qcameraimagecapture.h>
|
||||
#include <qmediaservice.h>
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDebug>
|
||||
#include <QCameraImageCapture>
|
||||
#include <QMediaService>
|
||||
|
||||
|
||||
ImageSettings::ImageSettings(QCameraImageCapture *imageCapture, QWidget *parent) :
|
||||
@@ -117,7 +116,7 @@ QVariant ImageSettings::boxValue(const QComboBox *box) const
|
||||
|
||||
void ImageSettings::selectComboBoxItem(QComboBox *box, const QVariant &value)
|
||||
{
|
||||
for (int i=0; i<box->count(); i++) {
|
||||
for (int i = 0; i < box->count(); ++i) {
|
||||
if (box->itemData(i) == value) {
|
||||
box->setCurrentIndex(i);
|
||||
break;
|
||||
|
||||
@@ -41,31 +41,29 @@
|
||||
#ifndef IMAGESETTINGS_H
|
||||
#define IMAGESETTINGS_H
|
||||
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <qmediaencodersettings.h>
|
||||
#include <QDialog>
|
||||
#include <QAudioEncoderSettings>
|
||||
#include <QVideoEncoderSettings>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QComboBox;
|
||||
namespace Ui {
|
||||
class ImageSettingsUi;
|
||||
}
|
||||
|
||||
class QCameraImageCapture;
|
||||
namespace Ui { class ImageSettingsUi; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
class ImageSettings : public QDialog {
|
||||
class ImageSettings : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ImageSettings(QCameraImageCapture *imageCapture, QWidget *parent = 0);
|
||||
~ImageSettings();
|
||||
|
||||
QAudioEncoderSettings audioSettings() const;
|
||||
void setAudioSettings(const QAudioEncoderSettings&);
|
||||
void setAudioSettings(const QAudioEncoderSettings &settings);
|
||||
|
||||
QImageEncoderSettings imageSettings() const;
|
||||
void setImageSettings(const QImageEncoderSettings&);
|
||||
void setImageSettings(const QImageEncoderSettings &settings);
|
||||
|
||||
QString format() const;
|
||||
void setFormat(const QString &format);
|
||||
@@ -74,7 +72,7 @@ protected:
|
||||
void changeEvent(QEvent *e);
|
||||
|
||||
private:
|
||||
QVariant boxValue(const QComboBox*) const;
|
||||
QVariant boxValue(const QComboBox *box) const;
|
||||
void selectComboBoxItem(QComboBox *box, const QVariant &value);
|
||||
|
||||
Ui::ImageSettingsUi *ui;
|
||||
|
||||
@@ -41,10 +41,10 @@
|
||||
#include "videosettings.h"
|
||||
#include "ui_videosettings.h"
|
||||
|
||||
#include <QtWidgets/qcombobox.h>
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <qmediarecorder.h>
|
||||
#include <qmediaservice.h>
|
||||
#include <QComboBox>
|
||||
#include <QDebug>
|
||||
#include <QMediaRecorder>
|
||||
#include <QMediaService>
|
||||
|
||||
|
||||
VideoSettings::VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent) :
|
||||
@@ -56,13 +56,13 @@ VideoSettings::VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent) :
|
||||
|
||||
//audio codecs
|
||||
ui->audioCodecBox->addItem(tr("Default audio codec"), QVariant(QString()));
|
||||
foreach(const QString &codecName, mediaRecorder->supportedAudioCodecs()) {
|
||||
foreach (const QString &codecName, mediaRecorder->supportedAudioCodecs()) {
|
||||
QString description = mediaRecorder->audioCodecDescription(codecName);
|
||||
ui->audioCodecBox->addItem(codecName+": "+description, QVariant(codecName));
|
||||
}
|
||||
|
||||
//sample rate:
|
||||
foreach(int sampleRate, mediaRecorder->supportedAudioSampleRates()) {
|
||||
foreach (int sampleRate, mediaRecorder->supportedAudioSampleRates()) {
|
||||
ui->audioSampleRateBox->addItem(QString::number(sampleRate), QVariant(sampleRate));
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ VideoSettings::VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent) :
|
||||
|
||||
//video codecs
|
||||
ui->videoCodecBox->addItem(tr("Default video codec"), QVariant(QString()));
|
||||
foreach(const QString &codecName, mediaRecorder->supportedVideoCodecs()) {
|
||||
foreach (const QString &codecName, mediaRecorder->supportedVideoCodecs()) {
|
||||
QString description = mediaRecorder->videoCodecDescription(codecName);
|
||||
ui->videoCodecBox->addItem(codecName+": "+description, QVariant(codecName));
|
||||
}
|
||||
@@ -80,7 +80,7 @@ VideoSettings::VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent) :
|
||||
|
||||
ui->videoResolutionBox->addItem(tr("Default"));
|
||||
QList<QSize> supportedResolutions = mediaRecorder->supportedResolutions();
|
||||
foreach(const QSize &resolution, supportedResolutions) {
|
||||
foreach (const QSize &resolution, supportedResolutions) {
|
||||
ui->videoResolutionBox->addItem(QString("%1x%2").arg(resolution.width()).arg(resolution.height()),
|
||||
QVariant(resolution));
|
||||
}
|
||||
@@ -88,14 +88,14 @@ VideoSettings::VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent) :
|
||||
ui->videoFramerateBox->addItem(tr("Default"));
|
||||
QList<qreal> supportedFrameRates = mediaRecorder->supportedFrameRates();
|
||||
qreal rate;
|
||||
foreach(rate, supportedFrameRates) {
|
||||
foreach (rate, supportedFrameRates) {
|
||||
QString rateString = QString("%1").arg(rate, 0, 'f', 2);
|
||||
ui->videoFramerateBox->addItem(rateString, QVariant(rate));
|
||||
}
|
||||
|
||||
//containers
|
||||
ui->containerFormatBox->addItem(tr("Default container"), QVariant(QString()));
|
||||
foreach(const QString &format, mediaRecorder->supportedContainers()) {
|
||||
foreach (const QString &format, mediaRecorder->supportedContainers()) {
|
||||
ui->containerFormatBox->addItem(format+":"+mediaRecorder->containerDescription(format),
|
||||
QVariant(format));
|
||||
}
|
||||
@@ -152,7 +152,7 @@ void VideoSettings::setVideoSettings(const QVideoEncoderSettings &videoSettings)
|
||||
ui->videoQualitySlider->setValue(videoSettings.quality());
|
||||
|
||||
//special case for frame rate
|
||||
for (int i=0; i<ui->videoFramerateBox->count(); i++) {
|
||||
for (int i = 0; i < ui->videoFramerateBox->count(); ++i) {
|
||||
qreal itemRate = ui->videoFramerateBox->itemData(i).value<qreal>();
|
||||
if (qFuzzyCompare(itemRate, videoSettings.frameRate())) {
|
||||
ui->videoFramerateBox->setCurrentIndex(i);
|
||||
@@ -182,7 +182,7 @@ QVariant VideoSettings::boxValue(const QComboBox *box) const
|
||||
|
||||
void VideoSettings::selectComboBoxItem(QComboBox *box, const QVariant &value)
|
||||
{
|
||||
for (int i=0; i<box->count(); i++) {
|
||||
for (int i = 0; i < box->count(); ++i) {
|
||||
if (box->itemData(i) == value) {
|
||||
box->setCurrentIndex(i);
|
||||
break;
|
||||
|
||||
@@ -41,22 +41,20 @@
|
||||
#ifndef VIDEOSETTINGS_H
|
||||
#define VIDEOSETTINGS_H
|
||||
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <qmediaencodersettings.h>
|
||||
#include <QDialog>
|
||||
#include <QAudioEncoderSettings>
|
||||
#include <QVideoEncoderSettings>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QComboBox;
|
||||
namespace Ui {
|
||||
class VideoSettingsUi;
|
||||
}
|
||||
|
||||
class QMediaRecorder;
|
||||
namespace Ui { class VideoSettingsUi; }
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
class VideoSettings : public QDialog {
|
||||
class VideoSettings : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent = 0);
|
||||
~VideoSettings();
|
||||
|
||||
Reference in New Issue
Block a user