From 6b4994c265889db2058b7d5850b51ddfc5478754 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 5 Dec 2012 13:03:09 +0100 Subject: centralize and fixup example sources install targets This follows suit with aeb036e in qtbase. Change-Id: Ie8580d0a1f38ab9858b0e44c9f99bdc552a1752a Reviewed-by: Oswald Buddenhagen Reviewed-by: hjk --- examples/multimediawidgets/camera/camera.cpp | 435 ++++++++++++++++++ examples/multimediawidgets/camera/camera.h | 121 +++++ examples/multimediawidgets/camera/camera.pro | 25 ++ examples/multimediawidgets/camera/camera.ui | 492 +++++++++++++++++++++ .../camera/doc/images/camera-example.png | Bin 0 -> 13647 bytes .../multimediawidgets/camera/doc/src/camera.qdoc | 80 ++++ .../multimediawidgets/camera/imagesettings.cpp | 125 ++++++ examples/multimediawidgets/camera/imagesettings.h | 82 ++++ examples/multimediawidgets/camera/imagesettings.ui | 123 ++++++ examples/multimediawidgets/camera/main.cpp | 53 +++ .../multimediawidgets/camera/videosettings.cpp | 191 ++++++++ examples/multimediawidgets/camera/videosettings.h | 82 ++++ examples/multimediawidgets/camera/videosettings.ui | 211 +++++++++ 13 files changed, 2020 insertions(+) create mode 100644 examples/multimediawidgets/camera/camera.cpp create mode 100644 examples/multimediawidgets/camera/camera.h create mode 100644 examples/multimediawidgets/camera/camera.pro create mode 100644 examples/multimediawidgets/camera/camera.ui create mode 100644 examples/multimediawidgets/camera/doc/images/camera-example.png create mode 100644 examples/multimediawidgets/camera/doc/src/camera.qdoc create mode 100644 examples/multimediawidgets/camera/imagesettings.cpp create mode 100644 examples/multimediawidgets/camera/imagesettings.h create mode 100644 examples/multimediawidgets/camera/imagesettings.ui create mode 100644 examples/multimediawidgets/camera/main.cpp create mode 100644 examples/multimediawidgets/camera/videosettings.cpp create mode 100644 examples/multimediawidgets/camera/videosettings.h create mode 100644 examples/multimediawidgets/camera/videosettings.ui (limited to 'examples/multimediawidgets/camera') diff --git a/examples/multimediawidgets/camera/camera.cpp b/examples/multimediawidgets/camera/camera.cpp new file mode 100644 index 000000000..c270d5585 --- /dev/null +++ b/examples/multimediawidgets/camera/camera.cpp @@ -0,0 +1,435 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "camera.h" +#include "ui_camera.h" +#include "videosettings.h" +#include "imagesettings.h" + +#include +#include +#include + +#include +#include + +#include + +#if (defined(Q_WS_MAEMO_6)) && QT_VERSION >= 0x040700 +#define HAVE_CAMERA_BUTTONS +#endif + +Camera::Camera(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::Camera), + camera(0), + imageCapture(0), + mediaRecorder(0), + isCapturingImage(false), + applicationExiting(false) +{ + ui->setupUi(this); + + //Camera devices: + 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*))); + connect(ui->captureWidget, SIGNAL(currentChanged(int)), SLOT(updateCaptureMode())); + +#ifdef HAVE_CAMERA_BUTTONS + ui->lockButton->hide(); +#endif + + setCamera(cameraDevice); +} + +Camera::~Camera() +{ + delete mediaRecorder; + delete imageCapture; + delete camera; +} + +void Camera::setCamera(const QByteArray &cameraDevice) +{ + delete imageCapture; + delete mediaRecorder; + 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())); + + mediaRecorder = new QMediaRecorder(camera); + connect(mediaRecorder, SIGNAL(stateChanged(QMediaRecorder::State)), this, SLOT(updateRecorderState(QMediaRecorder::State))); + + imageCapture = new QCameraImageCapture(camera); + + connect(mediaRecorder, SIGNAL(durationChanged(qint64)), this, SLOT(updateRecordTime())); + connect(mediaRecorder, SIGNAL(error(QMediaRecorder::Error)), this, SLOT(displayRecorderError())); + + mediaRecorder->setMetaData(QMediaMetaData::Title, QVariant(QLatin1String("Test Title"))); + + connect(ui->exposureCompensation, SIGNAL(valueChanged(int)), SLOT(setExposureCompensation(int))); + + camera->setViewfinder(ui->viewfinder); + + updateCameraState(camera->state()); + updateLockStatus(camera->lockStatus(), QCamera::UserRequest); + updateRecorderState(mediaRecorder->state()); + + connect(imageCapture, SIGNAL(readyForCaptureChanged(bool)), this, SLOT(readyForCapture(bool))); + connect(imageCapture, SIGNAL(imageCaptured(int,QImage)), this, SLOT(processCapturedImage(int,QImage))); + connect(imageCapture, SIGNAL(imageSaved(int,QString)), this, SLOT(imageSaved(int,QString))); + + connect(camera, SIGNAL(lockStatusChanged(QCamera::LockStatus, QCamera::LockChangeReason)), + this, SLOT(updateLockStatus(QCamera::LockStatus, QCamera::LockChangeReason))); + + ui->captureWidget->setTabEnabled(0, (camera->isCaptureModeSupported(QCamera::CaptureStillImage))); + ui->captureWidget->setTabEnabled(1, (camera->isCaptureModeSupported(QCamera::CaptureVideo))); + + updateCaptureMode(); + camera->start(); +} + +void Camera::keyPressEvent(QKeyEvent * event) +{ + if (event->isAutoRepeat()) + return; + + switch (event->key()) { + case Qt::Key_CameraFocus: + displayViewfinder(); + camera->searchAndLock(); + event->accept(); + break; + case Qt::Key_Camera: + if (camera->captureMode() == QCamera::CaptureStillImage) { + takeImage(); + } else { + if (mediaRecorder->state() == QMediaRecorder::RecordingState) + stop(); + else + record(); + } + event->accept(); + break; + default: + QMainWindow::keyPressEvent(event); + } +} + +void Camera::keyReleaseEvent(QKeyEvent *event) +{ + if (event->isAutoRepeat()) + return; + + switch (event->key()) { + case Qt::Key_CameraFocus: + camera->unlock(); + break; + default: + QMainWindow::keyReleaseEvent(event); + } +} + +void Camera::updateRecordTime() +{ + QString str = QString("Recorded %1 sec").arg(mediaRecorder->duration()/1000); + ui->statusbar->showMessage(str); +} + +void Camera::processCapturedImage(int requestId, const QImage& img) +{ + Q_UNUSED(requestId); + QImage scaledImage = img.scaled(ui->viewfinder->size(), + Qt::KeepAspectRatio, + Qt::SmoothTransformation); + + ui->lastImagePreviewLabel->setPixmap(QPixmap::fromImage(scaledImage)); + + // Display captured image for 4 seconds. + displayCapturedImage(); + QTimer::singleShot(4000, this, SLOT(displayViewfinder())); +} + +void Camera::configureCaptureSettings() +{ + switch (camera->captureMode()) { + case QCamera::CaptureStillImage: + configureImageSettings(); + break; + case QCamera::CaptureVideo: + configureVideoSettings(); + break; + default: + break; + } +} + +void Camera::configureVideoSettings() +{ + VideoSettings settingsDialog(mediaRecorder); + + settingsDialog.setAudioSettings(audioSettings); + settingsDialog.setVideoSettings(videoSettings); + settingsDialog.setFormat(videoContainerFormat); + + if (settingsDialog.exec()) { + audioSettings = settingsDialog.audioSettings(); + videoSettings = settingsDialog.videoSettings(); + videoContainerFormat = settingsDialog.format(); + + mediaRecorder->setEncodingSettings( + audioSettings, + videoSettings, + videoContainerFormat); + } +} + +void Camera::configureImageSettings() +{ + ImageSettings settingsDialog(imageCapture); + + settingsDialog.setImageSettings(imageSettings); + + if (settingsDialog.exec()) { + imageSettings = settingsDialog.imageSettings(); + imageCapture->setEncodingSettings(imageSettings); + } +} + +void Camera::record() +{ + mediaRecorder->record(); + updateRecordTime(); +} + +void Camera::pause() +{ + mediaRecorder->pause(); +} + +void Camera::stop() +{ + mediaRecorder->stop(); +} + +void Camera::setMuted(bool muted) +{ + mediaRecorder->setMuted(muted); +} + +void Camera::toggleLock() +{ + switch (camera->lockStatus()) { + case QCamera::Searching: + case QCamera::Locked: + camera->unlock(); + break; + case QCamera::Unlocked: + camera->searchAndLock(); + } +} + +void Camera::updateLockStatus(QCamera::LockStatus status, QCamera::LockChangeReason reason) +{ + QColor indicationColor = Qt::black; + + switch (status) { + case QCamera::Searching: + indicationColor = Qt::yellow; + ui->statusbar->showMessage(tr("Focusing...")); + ui->lockButton->setText(tr("Focusing...")); + break; + case QCamera::Locked: + indicationColor = Qt::darkGreen; + ui->lockButton->setText(tr("Unlock")); + ui->statusbar->showMessage(tr("Focused"), 2000); + break; + case QCamera::Unlocked: + indicationColor = reason == QCamera::LockFailed ? Qt::red : Qt::black; + ui->lockButton->setText(tr("Focus")); + if (reason == QCamera::LockFailed) + ui->statusbar->showMessage(tr("Focus Failed"), 2000); + } + + QPalette palette = ui->lockButton->palette(); + palette.setColor(QPalette::ButtonText, indicationColor); + ui->lockButton->setPalette(palette); +} + +void Camera::takeImage() +{ + isCapturingImage = true; + imageCapture->capture(); +} + +void Camera::startCamera() +{ + camera->start(); +} + +void Camera::stopCamera() +{ + camera->stop(); +} + +void Camera::updateCaptureMode() +{ + int tabIndex = ui->captureWidget->currentIndex(); + QCamera::CaptureModes captureMode = tabIndex == 0 ? QCamera::CaptureStillImage : QCamera::CaptureVideo; + + if (camera->isCaptureModeSupported(captureMode)) + camera->setCaptureMode(captureMode); +} + +void Camera::updateCameraState(QCamera::State state) +{ + switch (state) { + case QCamera::ActiveState: + ui->actionStartCamera->setEnabled(false); + ui->actionStopCamera->setEnabled(true); + ui->captureWidget->setEnabled(true); + ui->actionSettings->setEnabled(true); + break; + case QCamera::UnloadedState: + case QCamera::LoadedState: + ui->actionStartCamera->setEnabled(true); + ui->actionStopCamera->setEnabled(false); + ui->captureWidget->setEnabled(false); + ui->actionSettings->setEnabled(false); + } +} + +void Camera::updateRecorderState(QMediaRecorder::State state) +{ + switch (state) { + case QMediaRecorder::StoppedState: + ui->recordButton->setEnabled(true); + ui->pauseButton->setEnabled(true); + ui->stopButton->setEnabled(false); + break; + case QMediaRecorder::PausedState: + ui->recordButton->setEnabled(true); + ui->pauseButton->setEnabled(false); + ui->stopButton->setEnabled(true); + break; + case QMediaRecorder::RecordingState: + ui->recordButton->setEnabled(false); + ui->pauseButton->setEnabled(true); + ui->stopButton->setEnabled(true); + break; + } +} + +void Camera::setExposureCompensation(int index) +{ + camera->exposure()->setExposureCompensation(index*0.5); +} + +void Camera::displayRecorderError() +{ + QMessageBox::warning(this, tr("Capture error"), mediaRecorder->errorString()); +} + +void Camera::displayCameraError() +{ + QMessageBox::warning(this, tr("Camera error"), camera->errorString()); +} + +void Camera::updateCameraDevice(QAction *action) +{ + setCamera(action->data().toByteArray()); +} + +void Camera::displayViewfinder() +{ + ui->stackedWidget->setCurrentIndex(0); +} + +void Camera::displayCapturedImage() +{ + ui->stackedWidget->setCurrentIndex(1); +} + +void Camera::readyForCapture(bool ready) +{ + ui->takeImageButton->setEnabled(ready); +} + +void Camera::imageSaved(int id, const QString &fileName) +{ + Q_UNUSED(id); + Q_UNUSED(fileName); + + isCapturingImage = false; + if (applicationExiting) + close(); +} + +void Camera::closeEvent(QCloseEvent *event) +{ + if (isCapturingImage) { + setEnabled(false); + applicationExiting = true; + event->ignore(); + } else { + event->accept(); + } +} diff --git a/examples/multimediawidgets/camera/camera.h b/examples/multimediawidgets/camera/camera.h new file mode 100644 index 000000000..299483f67 --- /dev/null +++ b/examples/multimediawidgets/camera/camera.h @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef CAMERA_H +#define CAMERA_H + +#include +#include +#include + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class Camera; } +QT_END_NAMESPACE + +class Camera : public QMainWindow +{ + Q_OBJECT + +public: + Camera(QWidget *parent = 0); + ~Camera(); + +private slots: + void setCamera(const QByteArray &cameraDevice); + + void startCamera(); + void stopCamera(); + + void record(); + void pause(); + void stop(); + void setMuted(bool); + + void toggleLock(); + void takeImage(); + + void configureCaptureSettings(); + void configureVideoSettings(); + void configureImageSettings(); + + void displayRecorderError(); + void displayCameraError(); + + void updateCameraDevice(QAction *action); + + void updateCameraState(QCamera::State); + void updateCaptureMode(); + void updateRecorderState(QMediaRecorder::State state); + void setExposureCompensation(int index); + + void updateRecordTime(); + + void processCapturedImage(int requestId, const QImage &img); + void updateLockStatus(QCamera::LockStatus, QCamera::LockChangeReason); + + void displayViewfinder(); + void displayCapturedImage(); + + void readyForCapture(bool ready); + void imageSaved(int id, const QString &fileName); + +protected: + void keyPressEvent(QKeyEvent *event); + void keyReleaseEvent(QKeyEvent *event); + void closeEvent(QCloseEvent *event); + +private: + Ui::Camera *ui; + + QCamera *camera; + QCameraImageCapture *imageCapture; + QMediaRecorder* mediaRecorder; + + QImageEncoderSettings imageSettings; + QAudioEncoderSettings audioSettings; + QVideoEncoderSettings videoSettings; + QString videoContainerFormat; + bool isCapturingImage; + bool applicationExiting; +}; + +#endif diff --git a/examples/multimediawidgets/camera/camera.pro b/examples/multimediawidgets/camera/camera.pro new file mode 100644 index 000000000..fe8f39385 --- /dev/null +++ b/examples/multimediawidgets/camera/camera.pro @@ -0,0 +1,25 @@ +TEMPLATE = app +TARGET = camera + +QT += multimedia multimediawidgets + +HEADERS = \ + camera.h \ + imagesettings.h \ + videosettings.h + +SOURCES = \ + main.cpp \ + camera.cpp \ + imagesettings.cpp \ + videosettings.cpp + +FORMS += \ + camera.ui \ + videosettings.ui \ + imagesettings.ui + +target.path = $$[QT_INSTALL_EXAMPLES]/multimediawidgets/camera +INSTALLS += target + +QT+=widgets diff --git a/examples/multimediawidgets/camera/camera.ui b/examples/multimediawidgets/camera/camera.ui new file mode 100644 index 000000000..ea790fab0 --- /dev/null +++ b/examples/multimediawidgets/camera/camera.ui @@ -0,0 +1,492 @@ + + + Camera + + + + 0 + 0 + 668 + 422 + + + + Camera + + + + + + + + 1 + 0 + + + + + + + + + 255 + 255 + 255 + + + + + + + 145 + 145 + 145 + + + + + + + + + 255 + 255 + 255 + + + + + + + 145 + 145 + 145 + + + + + + + + + 145 + 145 + 145 + + + + + + + 145 + 145 + 145 + + + + + + + + 0 + + + + + + + + + + + + + + + 0 + 0 + + + + QFrame::Box + + + + + + + + + + + + + + Focus + + + + + + + 0 + + + + Image + + + + + + Capture Photo + + + + + + + Qt::Vertical + + + + 20 + 161 + + + + + + + + Exposure Compensation: + + + + + + + -4 + + + 4 + + + 2 + + + Qt::Horizontal + + + QSlider::TicksAbove + + + + + + + + Video + + + + + + Record + + + + + + + Pause + + + + + + + Stop + + + + + + + Qt::Vertical + + + + 20 + 76 + + + + + + + + Mute + + + true + + + + + + + + + + + + + 0 + 0 + 668 + 29 + + + + + File + + + + + + + + + + + Devices + + + + + + + + + Exit + + + + + Start Camera + + + + + Stop Camera + + + + + Settings + + + + + + QCameraViewfinder + QWidget +
qcameraviewfinder.h
+ 1 +
+
+ + + + recordButton + clicked() + Camera + record() + + + 647 + 149 + + + 61 + 238 + + + + + stopButton + clicked() + Camera + stop() + + + 647 + 225 + + + 140 + 236 + + + + + pauseButton + clicked() + Camera + pause() + + + 647 + 187 + + + 234 + 237 + + + + + actionExit + triggered() + Camera + close() + + + -1 + -1 + + + 154 + 130 + + + + + takeImageButton + clicked() + Camera + takeImage() + + + 625 + 132 + + + 603 + 169 + + + + + lockButton + clicked() + Camera + toggleLock() + + + 658 + 75 + + + 453 + 119 + + + + + muteButton + toggled(bool) + Camera + setMuted(bool) + + + 647 + 377 + + + 5 + 280 + + + + + exposureCompensation + valueChanged(int) + Camera + setExposureCompensation(int) + + + 559 + 367 + + + 665 + 365 + + + + + actionSettings + triggered() + Camera + configureCaptureSettings() + + + -1 + -1 + + + 333 + 210 + + + + + actionStartCamera + triggered() + Camera + startCamera() + + + -1 + -1 + + + 333 + 210 + + + + + actionStopCamera + triggered() + Camera + stopCamera() + + + -1 + -1 + + + 333 + 210 + + + + + + record() + pause() + stop() + enablePreview(bool) + configureCaptureSettings() + takeImage() + startCamera() + toggleLock() + setMuted(bool) + stopCamera() + setExposureCompensation(int) + +
diff --git a/examples/multimediawidgets/camera/doc/images/camera-example.png b/examples/multimediawidgets/camera/doc/images/camera-example.png new file mode 100644 index 000000000..12e1b5728 Binary files /dev/null and b/examples/multimediawidgets/camera/doc/images/camera-example.png differ diff --git a/examples/multimediawidgets/camera/doc/src/camera.qdoc b/examples/multimediawidgets/camera/doc/src/camera.qdoc new file mode 100644 index 000000000..c40c25135 --- /dev/null +++ b/examples/multimediawidgets/camera/doc/src/camera.qdoc @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + + + +/*! + +\example camera +\title Camera Example +\ingroup camera_examples +\brief The Camera Example shows how to use the API to capture a still image +or video. + + + +The Camera Example demonstrates how you can use QtMultimedia to implement +some basic Camera functionality to take still images and record video clips +with audio. + +A Camera class is created that will act as our Camera. It has a user interface, +control functions, setting values and a means of defining the location where +the image or video clip is to be saved. It will also store the image and video +settings. + +The Camera class contains an instance of \l {QCamera}, the API class interface to +the hardware. It also has an instance of \l {QCameraImageCapture} to take still images +and an instance of \l {QMediaRecorder} to record video. It also contains the user +interface object. + +The Camera constructor does some basic initialization. The camera object is +set to '0', the user interface is initialized and UI signal are connected to +slots that react to the triggering event. However, most of the work is done when +the \e{setCamera()} function is called, passing in a \l {QByteArray}. + +\e{setCamera()} sets up various connections between the user interface and the functionality +of the Camera class using signals and slots. It also instantiates and initializes the \l {QCamera}, +\l {QCameraImageCapture} and \l {QMediaRecorder} objects mentioned above. The still +and video recording visual tabs are enabled and finally the +\l {QCamera::start()}{start()} function of the \l{QCamera} object is called. + +Now that the camera is ready for user commands it waits for a suitable event. +Such an event will be the key press of either the \l {Qt::Key_CameraFocus} or +\l {Qt::Key_Camera} buttons on the application window. Camera focus will +simply display the viewfinder and lock the camera settings. Key_Camera will +either call \e{takeImage()} if the \l {QCamera::captureMode()}{captureMode()} +is QCamera::CaptureStillImage, or if the capture mode is for video then one +of two actions will occur. If the recording state shows that we are currently +recording then the \e{stop()} function is called resulting in a call to +\l {QCamera::stop()}, whereas if we are not recording then a video recording +is started with a call to \l {QMediaRecorder::record()}. + +\image camera-example.png + +*/ + + diff --git a/examples/multimediawidgets/camera/imagesettings.cpp b/examples/multimediawidgets/camera/imagesettings.cpp new file mode 100644 index 000000000..566a1260b --- /dev/null +++ b/examples/multimediawidgets/camera/imagesettings.cpp @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "imagesettings.h" +#include "ui_imagesettings.h" + +#include +#include +#include +#include + + +ImageSettings::ImageSettings(QCameraImageCapture *imageCapture, QWidget *parent) : + QDialog(parent), + ui(new Ui::ImageSettingsUi), + imagecapture(imageCapture) +{ + ui->setupUi(this); + + //image codecs + ui->imageCodecBox->addItem(tr("Default image format"), QVariant(QString())); + foreach(const QString &codecName, imagecapture->supportedImageCodecs()) { + QString description = imagecapture->imageCodecDescription(codecName); + ui->imageCodecBox->addItem(codecName+": "+description, QVariant(codecName)); + } + + ui->imageQualitySlider->setRange(0, int(QMultimedia::VeryHighQuality)); + + ui->imageResolutionBox->addItem(tr("Default Resolution")); + QList supportedResolutions = imagecapture->supportedResolutions(); + foreach(const QSize &resolution, supportedResolutions) { + ui->imageResolutionBox->addItem(QString("%1x%2").arg(resolution.width()).arg(resolution.height()), + QVariant(resolution)); + } +} + +ImageSettings::~ImageSettings() +{ + delete ui; +} + +void ImageSettings::changeEvent(QEvent *e) +{ + QDialog::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +QImageEncoderSettings ImageSettings::imageSettings() const +{ + QImageEncoderSettings settings = imagecapture->encodingSettings(); + settings.setCodec(boxValue(ui->imageCodecBox).toString()); + settings.setQuality(QMultimedia::EncodingQuality(ui->imageQualitySlider->value())); + settings.setResolution(boxValue(ui->imageResolutionBox).toSize()); + + return settings; +} + +void ImageSettings::setImageSettings(const QImageEncoderSettings &imageSettings) +{ + selectComboBoxItem(ui->imageCodecBox, QVariant(imageSettings.codec())); + selectComboBoxItem(ui->imageResolutionBox, QVariant(imageSettings.resolution())); + ui->imageQualitySlider->setValue(imageSettings.quality()); +} + +QVariant ImageSettings::boxValue(const QComboBox *box) const +{ + int idx = box->currentIndex(); + if (idx == -1) + return QVariant(); + + return box->itemData(idx); +} + +void ImageSettings::selectComboBoxItem(QComboBox *box, const QVariant &value) +{ + for (int i = 0; i < box->count(); ++i) { + if (box->itemData(i) == value) { + box->setCurrentIndex(i); + break; + } + } +} diff --git a/examples/multimediawidgets/camera/imagesettings.h b/examples/multimediawidgets/camera/imagesettings.h new file mode 100644 index 000000000..5c3e69461 --- /dev/null +++ b/examples/multimediawidgets/camera/imagesettings.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef IMAGESETTINGS_H +#define IMAGESETTINGS_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QComboBox; +class QCameraImageCapture; +namespace Ui { class ImageSettingsUi; } +QT_END_NAMESPACE + +class ImageSettings : public QDialog +{ + Q_OBJECT + +public: + ImageSettings(QCameraImageCapture *imageCapture, QWidget *parent = 0); + ~ImageSettings(); + + QAudioEncoderSettings audioSettings() const; + void setAudioSettings(const QAudioEncoderSettings &settings); + + QImageEncoderSettings imageSettings() const; + void setImageSettings(const QImageEncoderSettings &settings); + + QString format() const; + void setFormat(const QString &format); + +protected: + void changeEvent(QEvent *e); + +private: + QVariant boxValue(const QComboBox *box) const; + void selectComboBoxItem(QComboBox *box, const QVariant &value); + + Ui::ImageSettingsUi *ui; + QCameraImageCapture *imagecapture; +}; + +#endif // IMAGESETTINGS_H diff --git a/examples/multimediawidgets/camera/imagesettings.ui b/examples/multimediawidgets/camera/imagesettings.ui new file mode 100644 index 000000000..f790c770d --- /dev/null +++ b/examples/multimediawidgets/camera/imagesettings.ui @@ -0,0 +1,123 @@ + + + ImageSettingsUi + + + + 0 + 0 + 332 + 270 + + + + Dialog + + + + + + Image + + + + + + Resolution: + + + + + + + + + + Image Format: + + + + + + + + + + Quality: + + + + + + + 4 + + + Qt::Horizontal + + + + + + + + + + Qt::Vertical + + + + 20 + 14 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + ImageSettingsUi + accept() + + + 322 + 272 + + + 44 + 230 + + + + + buttonBox + rejected() + ImageSettingsUi + reject() + + + 405 + 262 + + + 364 + 227 + + + + + diff --git a/examples/multimediawidgets/camera/main.cpp b/examples/multimediawidgets/camera/main.cpp new file mode 100644 index 000000000..aa5fbdb84 --- /dev/null +++ b/examples/multimediawidgets/camera/main.cpp @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "camera.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + Camera camera; + camera.show(); + + return app.exec(); +}; diff --git a/examples/multimediawidgets/camera/videosettings.cpp b/examples/multimediawidgets/camera/videosettings.cpp new file mode 100644 index 000000000..2ec880801 --- /dev/null +++ b/examples/multimediawidgets/camera/videosettings.cpp @@ -0,0 +1,191 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "videosettings.h" +#include "ui_videosettings.h" + +#include +#include +#include +#include + + +VideoSettings::VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent) : + QDialog(parent), + ui(new Ui::VideoSettingsUi), + mediaRecorder(mediaRecorder) +{ + ui->setupUi(this); + + //audio codecs + ui->audioCodecBox->addItem(tr("Default audio codec"), QVariant(QString())); + 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()) { + ui->audioSampleRateBox->addItem(QString::number(sampleRate), QVariant(sampleRate)); + } + + ui->audioQualitySlider->setRange(0, int(QMultimedia::VeryHighQuality)); + + //video codecs + ui->videoCodecBox->addItem(tr("Default video codec"), QVariant(QString())); + foreach (const QString &codecName, mediaRecorder->supportedVideoCodecs()) { + QString description = mediaRecorder->videoCodecDescription(codecName); + ui->videoCodecBox->addItem(codecName+": "+description, QVariant(codecName)); + } + + ui->videoQualitySlider->setRange(0, int(QMultimedia::VeryHighQuality)); + + + ui->videoResolutionBox->addItem(tr("Default")); + QList supportedResolutions = mediaRecorder->supportedResolutions(); + foreach (const QSize &resolution, supportedResolutions) { + ui->videoResolutionBox->addItem(QString("%1x%2").arg(resolution.width()).arg(resolution.height()), + QVariant(resolution)); + } + + ui->videoFramerateBox->addItem(tr("Default")); + QList supportedFrameRates = mediaRecorder->supportedFrameRates(); + qreal rate; + 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()) { + ui->containerFormatBox->addItem(format+":"+mediaRecorder->containerDescription(format), + QVariant(format)); + } +} + +VideoSettings::~VideoSettings() +{ + delete ui; +} + +void VideoSettings::changeEvent(QEvent *e) +{ + QDialog::changeEvent(e); + switch (e->type()) { + case QEvent::LanguageChange: + ui->retranslateUi(this); + break; + default: + break; + } +} + +QAudioEncoderSettings VideoSettings::audioSettings() const +{ + QAudioEncoderSettings settings = mediaRecorder->audioSettings(); + settings.setCodec(boxValue(ui->audioCodecBox).toString()); + settings.setQuality(QMultimedia::EncodingQuality(ui->audioQualitySlider->value())); + settings.setSampleRate(boxValue(ui->audioSampleRateBox).toInt()); + return settings; +} + +void VideoSettings::setAudioSettings(const QAudioEncoderSettings &audioSettings) +{ + selectComboBoxItem(ui->audioCodecBox, QVariant(audioSettings.codec())); + selectComboBoxItem(ui->audioSampleRateBox, QVariant(audioSettings.sampleRate())); + ui->audioQualitySlider->setValue(audioSettings.quality()); +} + +QVideoEncoderSettings VideoSettings::videoSettings() const +{ + QVideoEncoderSettings settings = mediaRecorder->videoSettings(); + settings.setCodec(boxValue(ui->videoCodecBox).toString()); + settings.setQuality(QMultimedia::EncodingQuality(ui->videoQualitySlider->value())); + settings.setResolution(boxValue(ui->videoResolutionBox).toSize()); + settings.setFrameRate(boxValue(ui->videoFramerateBox).value()); + + return settings; +} + +void VideoSettings::setVideoSettings(const QVideoEncoderSettings &videoSettings) +{ + selectComboBoxItem(ui->videoCodecBox, QVariant(videoSettings.codec())); + selectComboBoxItem(ui->videoResolutionBox, QVariant(videoSettings.resolution())); + ui->videoQualitySlider->setValue(videoSettings.quality()); + + //special case for frame rate + for (int i = 0; i < ui->videoFramerateBox->count(); ++i) { + qreal itemRate = ui->videoFramerateBox->itemData(i).value(); + if (qFuzzyCompare(itemRate, videoSettings.frameRate())) { + ui->videoFramerateBox->setCurrentIndex(i); + break; + } + } +} + +QString VideoSettings::format() const +{ + return boxValue(ui->containerFormatBox).toString(); +} + +void VideoSettings::setFormat(const QString &format) +{ + selectComboBoxItem(ui->containerFormatBox, QVariant(format)); +} + +QVariant VideoSettings::boxValue(const QComboBox *box) const +{ + int idx = box->currentIndex(); + if (idx == -1) + return QVariant(); + + return box->itemData(idx); +} + +void VideoSettings::selectComboBoxItem(QComboBox *box, const QVariant &value) +{ + for (int i = 0; i < box->count(); ++i) { + if (box->itemData(i) == value) { + box->setCurrentIndex(i); + break; + } + } +} diff --git a/examples/multimediawidgets/camera/videosettings.h b/examples/multimediawidgets/camera/videosettings.h new file mode 100644 index 000000000..32b519064 --- /dev/null +++ b/examples/multimediawidgets/camera/videosettings.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef VIDEOSETTINGS_H +#define VIDEOSETTINGS_H + +#include +#include +#include + +QT_BEGIN_NAMESPACE +class QComboBox; +class QMediaRecorder; +namespace Ui { class VideoSettingsUi; } +QT_END_NAMESPACE + +class VideoSettings : public QDialog +{ + Q_OBJECT + +public: + VideoSettings(QMediaRecorder *mediaRecorder, QWidget *parent = 0); + ~VideoSettings(); + + QAudioEncoderSettings audioSettings() const; + void setAudioSettings(const QAudioEncoderSettings&); + + QVideoEncoderSettings videoSettings() const; + void setVideoSettings(const QVideoEncoderSettings&); + + QString format() const; + void setFormat(const QString &format); + +protected: + void changeEvent(QEvent *e); + +private: + QVariant boxValue(const QComboBox*) const; + void selectComboBoxItem(QComboBox *box, const QVariant &value); + + Ui::VideoSettingsUi *ui; + QMediaRecorder *mediaRecorder; +}; + +#endif // VIDEOSETTINGS_H diff --git a/examples/multimediawidgets/camera/videosettings.ui b/examples/multimediawidgets/camera/videosettings.ui new file mode 100644 index 000000000..f6aa004c5 --- /dev/null +++ b/examples/multimediawidgets/camera/videosettings.ui @@ -0,0 +1,211 @@ + + + VideoSettingsUi + + + + 0 + 0 + 561 + 369 + + + + Dialog + + + + + + QFrame::NoFrame + + + true + + + + + 0 + 0 + 543 + 250 + + + + + + + Audio + + + + + + Audio Codec: + + + + + + + + + + Sample Rate: + + + + + + + + + + Quality: + + + + + + + 4 + + + Qt::Horizontal + + + + + + + + + + Video + + + + + + Resolution: + + + + + + + + + + Framerate: + + + + + + + + + + Video Codec: + + + + + + + + + + Quality: + + + + + + + 4 + + + Qt::Horizontal + + + + + + + + + + Container Format: + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 14 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + VideoSettingsUi + accept() + + + 322 + 272 + + + 44 + 230 + + + + + buttonBox + rejected() + VideoSettingsUi + reject() + + + 405 + 262 + + + 364 + 227 + + + + + -- cgit v1.2.3