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 "videosettings.h"
|
||||||
#include "imagesettings.h"
|
#include "imagesettings.h"
|
||||||
|
|
||||||
#include <qmediaservice.h>
|
#include <QMediaService>
|
||||||
#include <qmediarecorder.h>
|
#include <QMediaRecorder>
|
||||||
#include <qcamera.h>
|
#include <QCameraViewfinder>
|
||||||
#include <qcameraviewfinder.h>
|
|
||||||
|
|
||||||
#include <qmessagebox.h>
|
#include <QMessageBox>
|
||||||
#include <qpalette.h>
|
#include <QPalette>
|
||||||
|
|
||||||
#include <QtWidgets>
|
#include <QtWidgets>
|
||||||
|
|
||||||
@@ -85,7 +84,7 @@ Camera::Camera(QWidget *parent) :
|
|||||||
ui->menuDevices->addAction(videoDeviceAction);
|
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()));
|
connect(ui->captureWidget, SIGNAL(currentChanged(int)), SLOT(updateCaptureMode()));
|
||||||
|
|
||||||
#ifdef HAVE_CAMERA_BUTTONS
|
#ifdef HAVE_CAMERA_BUTTONS
|
||||||
@@ -154,7 +153,6 @@ void Camera::keyPressEvent(QKeyEvent * event)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
switch (event->key()) {
|
switch (event->key()) {
|
||||||
#if QT_VERSION >= 0x040700
|
|
||||||
case Qt::Key_CameraFocus:
|
case Qt::Key_CameraFocus:
|
||||||
displayViewfinder();
|
displayViewfinder();
|
||||||
camera->searchAndLock();
|
camera->searchAndLock();
|
||||||
@@ -171,7 +169,6 @@ void Camera::keyPressEvent(QKeyEvent * event)
|
|||||||
}
|
}
|
||||||
event->accept();
|
event->accept();
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
default:
|
default:
|
||||||
QMainWindow::keyPressEvent(event);
|
QMainWindow::keyPressEvent(event);
|
||||||
}
|
}
|
||||||
@@ -183,11 +180,9 @@ void Camera::keyReleaseEvent(QKeyEvent * event)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
switch (event->key()) {
|
switch (event->key()) {
|
||||||
#if QT_VERSION >= 0x040700
|
|
||||||
case Qt::Key_CameraFocus:
|
case Qt::Key_CameraFocus:
|
||||||
camera->unlock();
|
camera->unlock();
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
default:
|
default:
|
||||||
QMainWindow::keyReleaseEvent(event);
|
QMainWindow::keyReleaseEvent(event);
|
||||||
}
|
}
|
||||||
@@ -207,7 +202,8 @@ void Camera::processCapturedImage(int requestId, const QImage& img)
|
|||||||
Qt::SmoothTransformation);
|
Qt::SmoothTransformation);
|
||||||
|
|
||||||
ui->lastImagePreviewLabel->setPixmap(QPixmap::fromImage(scaledImage));
|
ui->lastImagePreviewLabel->setPixmap(QPixmap::fromImage(scaledImage));
|
||||||
//display captured image for 4 seconds
|
|
||||||
|
// Display captured image for 4 seconds.
|
||||||
displayCapturedImage();
|
displayCapturedImage();
|
||||||
QTimer::singleShot(4000, this, SLOT(displayViewfinder()));
|
QTimer::singleShot(4000, this, SLOT(displayViewfinder()));
|
||||||
}
|
}
|
||||||
@@ -319,7 +315,6 @@ void Camera::updateLockStatus(QCamera::LockStatus status, QCamera::LockChangeRea
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Camera::takeImage()
|
void Camera::takeImage()
|
||||||
|
|
||||||
{
|
{
|
||||||
isCapturingImage = true;
|
isCapturingImage = true;
|
||||||
imageCapture->capture();
|
imageCapture->capture();
|
||||||
|
|||||||
@@ -41,25 +41,20 @@
|
|||||||
#ifndef CAMERA_H
|
#ifndef CAMERA_H
|
||||||
#define CAMERA_H
|
#define CAMERA_H
|
||||||
|
|
||||||
#include <qcamera.h>
|
#include <QCamera>
|
||||||
#include <qmediarecorder.h>
|
#include <QCameraImageCapture>
|
||||||
#include <qcameraimagecapture.h>
|
#include <QMediaRecorder>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
namespace Ui {
|
|
||||||
class Camera;
|
|
||||||
}
|
|
||||||
class QCameraViewfinder;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QDir>
|
|
||||||
|
|
||||||
QT_USE_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
namespace Ui { class Camera; }
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
class Camera : public QMainWindow
|
class Camera : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Camera(QWidget *parent = 0);
|
Camera(QWidget *parent = 0);
|
||||||
~Camera();
|
~Camera();
|
||||||
@@ -85,7 +80,7 @@ private slots:
|
|||||||
void displayRecorderError();
|
void displayRecorderError();
|
||||||
void displayCameraError();
|
void displayCameraError();
|
||||||
|
|
||||||
void updateCameraDevice(QAction*);
|
void updateCameraDevice(QAction *action);
|
||||||
|
|
||||||
void updateCameraState(QCamera::State);
|
void updateCameraState(QCamera::State);
|
||||||
void updateCaptureMode();
|
void updateCaptureMode();
|
||||||
@@ -100,8 +95,8 @@ private slots:
|
|||||||
void displayViewfinder();
|
void displayViewfinder();
|
||||||
void displayCapturedImage();
|
void displayCapturedImage();
|
||||||
|
|
||||||
void readyForCapture(bool);
|
void readyForCapture(bool ready);
|
||||||
void imageSaved(int, const QString&);
|
void imageSaved(int id, const QString &fileName);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *event);
|
void keyPressEvent(QKeyEvent *event);
|
||||||
|
|||||||
@@ -41,11 +41,10 @@
|
|||||||
#include "imagesettings.h"
|
#include "imagesettings.h"
|
||||||
#include "ui_imagesettings.h"
|
#include "ui_imagesettings.h"
|
||||||
|
|
||||||
#include <QtWidgets/qcombobox.h>
|
#include <QComboBox>
|
||||||
#include <QtCore/qdebug.h>
|
#include <QDebug>
|
||||||
#include <qcameraimagecapture.h>
|
#include <QCameraImageCapture>
|
||||||
#include <qmediaservice.h>
|
#include <QMediaService>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ImageSettings::ImageSettings(QCameraImageCapture *imageCapture, QWidget *parent) :
|
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)
|
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) {
|
if (box->itemData(i) == value) {
|
||||||
box->setCurrentIndex(i);
|
box->setCurrentIndex(i);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -41,31 +41,29 @@
|
|||||||
#ifndef IMAGESETTINGS_H
|
#ifndef IMAGESETTINGS_H
|
||||||
#define IMAGESETTINGS_H
|
#define IMAGESETTINGS_H
|
||||||
|
|
||||||
#include <QtWidgets/QDialog>
|
#include <QDialog>
|
||||||
#include <qmediaencodersettings.h>
|
#include <QAudioEncoderSettings>
|
||||||
|
#include <QVideoEncoderSettings>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
namespace Ui {
|
|
||||||
class ImageSettingsUi;
|
|
||||||
}
|
|
||||||
|
|
||||||
class QCameraImageCapture;
|
class QCameraImageCapture;
|
||||||
|
namespace Ui { class ImageSettingsUi; }
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
QT_USE_NAMESPACE
|
class ImageSettings : public QDialog
|
||||||
|
{
|
||||||
class ImageSettings : public QDialog {
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ImageSettings(QCameraImageCapture *imageCapture, QWidget *parent = 0);
|
ImageSettings(QCameraImageCapture *imageCapture, QWidget *parent = 0);
|
||||||
~ImageSettings();
|
~ImageSettings();
|
||||||
|
|
||||||
QAudioEncoderSettings audioSettings() const;
|
QAudioEncoderSettings audioSettings() const;
|
||||||
void setAudioSettings(const QAudioEncoderSettings&);
|
void setAudioSettings(const QAudioEncoderSettings &settings);
|
||||||
|
|
||||||
QImageEncoderSettings imageSettings() const;
|
QImageEncoderSettings imageSettings() const;
|
||||||
void setImageSettings(const QImageEncoderSettings&);
|
void setImageSettings(const QImageEncoderSettings &settings);
|
||||||
|
|
||||||
QString format() const;
|
QString format() const;
|
||||||
void setFormat(const QString &format);
|
void setFormat(const QString &format);
|
||||||
@@ -74,7 +72,7 @@ protected:
|
|||||||
void changeEvent(QEvent *e);
|
void changeEvent(QEvent *e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVariant boxValue(const QComboBox*) const;
|
QVariant boxValue(const QComboBox *box) const;
|
||||||
void selectComboBoxItem(QComboBox *box, const QVariant &value);
|
void selectComboBoxItem(QComboBox *box, const QVariant &value);
|
||||||
|
|
||||||
Ui::ImageSettingsUi *ui;
|
Ui::ImageSettingsUi *ui;
|
||||||
|
|||||||
@@ -41,10 +41,10 @@
|
|||||||
#include "videosettings.h"
|
#include "videosettings.h"
|
||||||
#include "ui_videosettings.h"
|
#include "ui_videosettings.h"
|
||||||
|
|
||||||
#include <QtWidgets/qcombobox.h>
|
#include <QComboBox>
|
||||||
#include <QtCore/qdebug.h>
|
#include <QDebug>
|
||||||
#include <qmediarecorder.h>
|
#include <QMediaRecorder>
|
||||||
#include <qmediaservice.h>
|
#include <QMediaService>
|
||||||
|
|
||||||
|
|
||||||
VideoSettings::VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent) :
|
VideoSettings::VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent) :
|
||||||
@@ -152,7 +152,7 @@ void VideoSettings::setVideoSettings(const QVideoEncoderSettings &videoSettings)
|
|||||||
ui->videoQualitySlider->setValue(videoSettings.quality());
|
ui->videoQualitySlider->setValue(videoSettings.quality());
|
||||||
|
|
||||||
//special case for frame rate
|
//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>();
|
qreal itemRate = ui->videoFramerateBox->itemData(i).value<qreal>();
|
||||||
if (qFuzzyCompare(itemRate, videoSettings.frameRate())) {
|
if (qFuzzyCompare(itemRate, videoSettings.frameRate())) {
|
||||||
ui->videoFramerateBox->setCurrentIndex(i);
|
ui->videoFramerateBox->setCurrentIndex(i);
|
||||||
@@ -182,7 +182,7 @@ QVariant VideoSettings::boxValue(const QComboBox *box) const
|
|||||||
|
|
||||||
void VideoSettings::selectComboBoxItem(QComboBox *box, const QVariant &value)
|
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) {
|
if (box->itemData(i) == value) {
|
||||||
box->setCurrentIndex(i);
|
box->setCurrentIndex(i);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -41,22 +41,20 @@
|
|||||||
#ifndef VIDEOSETTINGS_H
|
#ifndef VIDEOSETTINGS_H
|
||||||
#define VIDEOSETTINGS_H
|
#define VIDEOSETTINGS_H
|
||||||
|
|
||||||
#include <QtWidgets/QDialog>
|
#include <QDialog>
|
||||||
#include <qmediaencodersettings.h>
|
#include <QAudioEncoderSettings>
|
||||||
|
#include <QVideoEncoderSettings>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
namespace Ui {
|
|
||||||
class VideoSettingsUi;
|
|
||||||
}
|
|
||||||
|
|
||||||
class QMediaRecorder;
|
class QMediaRecorder;
|
||||||
|
namespace Ui { class VideoSettingsUi; }
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
QT_USE_NAMESPACE
|
class VideoSettings : public QDialog
|
||||||
|
{
|
||||||
class VideoSettings : public QDialog {
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent = 0);
|
VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent = 0);
|
||||||
~VideoSettings();
|
~VideoSettings();
|
||||||
|
|||||||
Reference in New Issue
Block a user