diff options
Diffstat (limited to 'examples/multimediawidgets/camera')
-rw-r--r-- | examples/multimediawidgets/camera/camera.cpp | 435 | ||||
-rw-r--r-- | examples/multimediawidgets/camera/camera.h | 121 | ||||
-rw-r--r-- | examples/multimediawidgets/camera/camera.pro | 25 | ||||
-rw-r--r-- | examples/multimediawidgets/camera/camera.ui | 492 | ||||
-rw-r--r-- | examples/multimediawidgets/camera/doc/images/camera-example.png | bin | 0 -> 13647 bytes | |||
-rw-r--r-- | examples/multimediawidgets/camera/doc/src/camera.qdoc | 80 | ||||
-rw-r--r-- | examples/multimediawidgets/camera/imagesettings.cpp | 125 | ||||
-rw-r--r-- | examples/multimediawidgets/camera/imagesettings.h | 82 | ||||
-rw-r--r-- | examples/multimediawidgets/camera/imagesettings.ui | 123 | ||||
-rw-r--r-- | examples/multimediawidgets/camera/main.cpp | 53 | ||||
-rw-r--r-- | examples/multimediawidgets/camera/videosettings.cpp | 191 | ||||
-rw-r--r-- | examples/multimediawidgets/camera/videosettings.h | 82 | ||||
-rw-r--r-- | examples/multimediawidgets/camera/videosettings.ui | 211 |
13 files changed, 2020 insertions, 0 deletions
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 <QMediaService> +#include <QMediaRecorder> +#include <QCameraViewfinder> + +#include <QMessageBox> +#include <QPalette> + +#include <QtWidgets> + +#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 <QCamera> +#include <QCameraImageCapture> +#include <QMediaRecorder> + +#include <QMainWindow> + +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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>Camera</class> + <widget class="QMainWindow" name="Camera"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>668</width> + <height>422</height> + </rect> + </property> + <property name="windowTitle"> + <string>Camera</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QGridLayout" name="gridLayout_3"> + <item row="0" column="0" rowspan="3"> + <widget class="QStackedWidget" name="stackedWidget"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="palette"> + <palette> + <active> + <colorrole role="Base"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + <colorrole role="Window"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>145</red> + <green>145</green> + <blue>145</blue> + </color> + </brush> + </colorrole> + </active> + <inactive> + <colorrole role="Base"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </brush> + </colorrole> + <colorrole role="Window"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>145</red> + <green>145</green> + <blue>145</blue> + </color> + </brush> + </colorrole> + </inactive> + <disabled> + <colorrole role="Base"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>145</red> + <green>145</green> + <blue>145</blue> + </color> + </brush> + </colorrole> + <colorrole role="Window"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>145</red> + <green>145</green> + <blue>145</blue> + </color> + </brush> + </colorrole> + </disabled> + </palette> + </property> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="viewfinderPage"> + <layout class="QGridLayout" name="gridLayout_5"> + <item row="0" column="0"> + <widget class="QCameraViewfinder" name="viewfinder" native="true"/> + </item> + </layout> + </widget> + <widget class="QWidget" name="previewPage"> + <layout class="QGridLayout" name="gridLayout_4"> + <item row="0" column="0"> + <widget class="QLabel" name="lastImagePreviewLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="frameShape"> + <enum>QFrame::Box</enum> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + </item> + <item row="1" column="1" colspan="2"> + <widget class="QPushButton" name="lockButton"> + <property name="text"> + <string>Focus</string> + </property> + </widget> + </item> + <item row="2" column="1" colspan="2"> + <widget class="QTabWidget" name="captureWidget"> + <property name="currentIndex"> + <number>0</number> + </property> + <widget class="QWidget" name="tab_2"> + <attribute name="title"> + <string>Image</string> + </attribute> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QPushButton" name="takeImageButton"> + <property name="text"> + <string>Capture Photo</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <spacer name="verticalSpacer_2"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>161</height> + </size> + </property> + </spacer> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Exposure Compensation:</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QSlider" name="exposureCompensation"> + <property name="minimum"> + <number>-4</number> + </property> + <property name="maximum"> + <number>4</number> + </property> + <property name="pageStep"> + <number>2</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="tickPosition"> + <enum>QSlider::TicksAbove</enum> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="tab"> + <attribute name="title"> + <string>Video</string> + </attribute> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0"> + <widget class="QPushButton" name="recordButton"> + <property name="text"> + <string>Record</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QPushButton" name="pauseButton"> + <property name="text"> + <string>Pause</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QPushButton" name="stopButton"> + <property name="text"> + <string>Stop</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>76</height> + </size> + </property> + </spacer> + </item> + <item row="4" column="0"> + <widget class="QPushButton" name="muteButton"> + <property name="text"> + <string>Mute</string> + </property> + <property name="checkable"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>668</width> + <height>29</height> + </rect> + </property> + <widget class="QMenu" name="menuFile"> + <property name="title"> + <string>File</string> + </property> + <addaction name="actionStartCamera"/> + <addaction name="actionStopCamera"/> + <addaction name="separator"/> + <addaction name="actionSettings"/> + <addaction name="separator"/> + <addaction name="actionExit"/> + </widget> + <widget class="QMenu" name="menuDevices"> + <property name="title"> + <string>Devices</string> + </property> + </widget> + <addaction name="menuFile"/> + <addaction name="menuDevices"/> + </widget> + <widget class="QStatusBar" name="statusbar"/> + <action name="actionExit"> + <property name="text"> + <string>Exit</string> + </property> + </action> + <action name="actionStartCamera"> + <property name="text"> + <string>Start Camera</string> + </property> + </action> + <action name="actionStopCamera"> + <property name="text"> + <string>Stop Camera</string> + </property> + </action> + <action name="actionSettings"> + <property name="text"> + <string>Settings</string> + </property> + </action> + </widget> + <customwidgets> + <customwidget> + <class>QCameraViewfinder</class> + <extends>QWidget</extends> + <header>qcameraviewfinder.h</header> + <container>1</container> + </customwidget> + </customwidgets> + <resources/> + <connections> + <connection> + <sender>recordButton</sender> + <signal>clicked()</signal> + <receiver>Camera</receiver> + <slot>record()</slot> + <hints> + <hint type="sourcelabel"> + <x>647</x> + <y>149</y> + </hint> + <hint type="destinationlabel"> + <x>61</x> + <y>238</y> + </hint> + </hints> + </connection> + <connection> + <sender>stopButton</sender> + <signal>clicked()</signal> + <receiver>Camera</receiver> + <slot>stop()</slot> + <hints> + <hint type="sourcelabel"> + <x>647</x> + <y>225</y> + </hint> + <hint type="destinationlabel"> + <x>140</x> + <y>236</y> + </hint> + </hints> + </connection> + <connection> + <sender>pauseButton</sender> + <signal>clicked()</signal> + <receiver>Camera</receiver> + <slot>pause()</slot> + <hints> + <hint type="sourcelabel"> + <x>647</x> + <y>187</y> + </hint> + <hint type="destinationlabel"> + <x>234</x> + <y>237</y> + </hint> + </hints> + </connection> + <connection> + <sender>actionExit</sender> + <signal>triggered()</signal> + <receiver>Camera</receiver> + <slot>close()</slot> + <hints> + <hint type="sourcelabel"> + <x>-1</x> + <y>-1</y> + </hint> + <hint type="destinationlabel"> + <x>154</x> + <y>130</y> + </hint> + </hints> + </connection> + <connection> + <sender>takeImageButton</sender> + <signal>clicked()</signal> + <receiver>Camera</receiver> + <slot>takeImage()</slot> + <hints> + <hint type="sourcelabel"> + <x>625</x> + <y>132</y> + </hint> + <hint type="destinationlabel"> + <x>603</x> + <y>169</y> + </hint> + </hints> + </connection> + <connection> + <sender>lockButton</sender> + <signal>clicked()</signal> + <receiver>Camera</receiver> + <slot>toggleLock()</slot> + <hints> + <hint type="sourcelabel"> + <x>658</x> + <y>75</y> + </hint> + <hint type="destinationlabel"> + <x>453</x> + <y>119</y> + </hint> + </hints> + </connection> + <connection> + <sender>muteButton</sender> + <signal>toggled(bool)</signal> + <receiver>Camera</receiver> + <slot>setMuted(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>647</x> + <y>377</y> + </hint> + <hint type="destinationlabel"> + <x>5</x> + <y>280</y> + </hint> + </hints> + </connection> + <connection> + <sender>exposureCompensation</sender> + <signal>valueChanged(int)</signal> + <receiver>Camera</receiver> + <slot>setExposureCompensation(int)</slot> + <hints> + <hint type="sourcelabel"> + <x>559</x> + <y>367</y> + </hint> + <hint type="destinationlabel"> + <x>665</x> + <y>365</y> + </hint> + </hints> + </connection> + <connection> + <sender>actionSettings</sender> + <signal>triggered()</signal> + <receiver>Camera</receiver> + <slot>configureCaptureSettings()</slot> + <hints> + <hint type="sourcelabel"> + <x>-1</x> + <y>-1</y> + </hint> + <hint type="destinationlabel"> + <x>333</x> + <y>210</y> + </hint> + </hints> + </connection> + <connection> + <sender>actionStartCamera</sender> + <signal>triggered()</signal> + <receiver>Camera</receiver> + <slot>startCamera()</slot> + <hints> + <hint type="sourcelabel"> + <x>-1</x> + <y>-1</y> + </hint> + <hint type="destinationlabel"> + <x>333</x> + <y>210</y> + </hint> + </hints> + </connection> + <connection> + <sender>actionStopCamera</sender> + <signal>triggered()</signal> + <receiver>Camera</receiver> + <slot>stopCamera()</slot> + <hints> + <hint type="sourcelabel"> + <x>-1</x> + <y>-1</y> + </hint> + <hint type="destinationlabel"> + <x>333</x> + <y>210</y> + </hint> + </hints> + </connection> + </connections> + <slots> + <slot>record()</slot> + <slot>pause()</slot> + <slot>stop()</slot> + <slot>enablePreview(bool)</slot> + <slot>configureCaptureSettings()</slot> + <slot>takeImage()</slot> + <slot>startCamera()</slot> + <slot>toggleLock()</slot> + <slot>setMuted(bool)</slot> + <slot>stopCamera()</slot> + <slot>setExposureCompensation(int)</slot> + </slots> +</ui> diff --git a/examples/multimediawidgets/camera/doc/images/camera-example.png b/examples/multimediawidgets/camera/doc/images/camera-example.png Binary files differnew file mode 100644 index 000000000..12e1b5728 --- /dev/null +++ b/examples/multimediawidgets/camera/doc/images/camera-example.png 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 <QComboBox> +#include <QDebug> +#include <QCameraImageCapture> +#include <QMediaService> + + +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<QSize> 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 <QDialog> +#include <QAudioEncoderSettings> +#include <QVideoEncoderSettings> + +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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>ImageSettingsUi</class> + <widget class="QDialog" name="ImageSettingsUi"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>332</width> + <height>270</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QGroupBox" name="groupBox_2"> + <property name="title"> + <string>Image</string> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0" colspan="2"> + <widget class="QLabel" name="label_8"> + <property name="text"> + <string>Resolution:</string> + </property> + </widget> + </item> + <item row="1" column="0" colspan="2"> + <widget class="QComboBox" name="imageResolutionBox"/> + </item> + <item row="2" column="0" colspan="2"> + <widget class="QLabel" name="label_6"> + <property name="text"> + <string>Image Format:</string> + </property> + </widget> + </item> + <item row="3" column="0" colspan="2"> + <widget class="QComboBox" name="imageCodecBox"/> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="label_7"> + <property name="text"> + <string>Quality:</string> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QSlider" name="imageQualitySlider"> + <property name="maximum"> + <number>4</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="1" column="0"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>14</height> + </size> + </property> + </spacer> + </item> + <item row="2" column="0"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>ImageSettingsUi</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>322</x> + <y>272</y> + </hint> + <hint type="destinationlabel"> + <x>44</x> + <y>230</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>ImageSettingsUi</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>405</x> + <y>262</y> + </hint> + <hint type="destinationlabel"> + <x>364</x> + <y>227</y> + </hint> + </hints> + </connection> + </connections> +</ui> 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 <QtWidgets> + +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 <QComboBox> +#include <QDebug> +#include <QMediaRecorder> +#include <QMediaService> + + +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<QSize> 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<qreal> 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<qreal>()); + + 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<qreal>(); + 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 <QDialog> +#include <QAudioEncoderSettings> +#include <QVideoEncoderSettings> + +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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>VideoSettingsUi</class> + <widget class="QDialog" name="VideoSettingsUi"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>561</width> + <height>369</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QGridLayout" name="gridLayout_4"> + <item row="0" column="0"> + <widget class="QScrollArea" name="scrollArea"> + <property name="frameShape"> + <enum>QFrame::NoFrame</enum> + </property> + <property name="widgetResizable"> + <bool>true</bool> + </property> + <widget class="QWidget" name="scrollAreaWidgetContents"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>543</width> + <height>250</height> + </rect> + </property> + <layout class="QGridLayout" name="gridLayout_3"> + <item row="0" column="0"> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Audio</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0" colspan="2"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Audio Codec:</string> + </property> + </widget> + </item> + <item row="1" column="0" colspan="2"> + <widget class="QComboBox" name="audioCodecBox"/> + </item> + <item row="2" column="0" colspan="2"> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>Sample Rate:</string> + </property> + </widget> + </item> + <item row="3" column="0" colspan="2"> + <widget class="QComboBox" name="audioSampleRateBox"/> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Quality:</string> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QSlider" name="audioQualitySlider"> + <property name="maximum"> + <number>4</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="0" column="1" rowspan="3"> + <widget class="QGroupBox" name="groupBox_2"> + <property name="title"> + <string>Video</string> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0" colspan="2"> + <widget class="QLabel" name="label_8"> + <property name="text"> + <string>Resolution:</string> + </property> + </widget> + </item> + <item row="1" column="0" colspan="2"> + <widget class="QComboBox" name="videoResolutionBox"/> + </item> + <item row="2" column="0" colspan="2"> + <widget class="QLabel" name="label_9"> + <property name="text"> + <string>Framerate:</string> + </property> + </widget> + </item> + <item row="3" column="0" colspan="2"> + <widget class="QComboBox" name="videoFramerateBox"/> + </item> + <item row="4" column="0" colspan="2"> + <widget class="QLabel" name="label_6"> + <property name="text"> + <string>Video Codec:</string> + </property> + </widget> + </item> + <item row="5" column="0" colspan="2"> + <widget class="QComboBox" name="videoCodecBox"/> + </item> + <item row="6" column="0"> + <widget class="QLabel" name="label_7"> + <property name="text"> + <string>Quality:</string> + </property> + </widget> + </item> + <item row="6" column="1"> + <widget class="QSlider" name="videoQualitySlider"> + <property name="maximum"> + <number>4</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Container Format:</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QComboBox" name="containerFormatBox"/> + </item> + </layout> + </widget> + </widget> + </item> + <item row="1" column="0"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>14</height> + </size> + </property> + </spacer> + </item> + <item row="2" column="0"> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>VideoSettingsUi</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>322</x> + <y>272</y> + </hint> + <hint type="destinationlabel"> + <x>44</x> + <y>230</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>VideoSettingsUi</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>405</x> + <y>262</y> + </hint> + <hint type="destinationlabel"> + <x>364</x> + <y>227</y> + </hint> + </hints> + </connection> + </connections> +</ui> |