Initial copy of QtMultimediaKit.
Comes from original repo, with SHA1: 2c82d5611655e5967f5c5095af50c0991c4378b2
This commit is contained in:
440
examples/camera/camera.cpp
Normal file
440
examples/camera/camera.cpp
Normal file
@@ -0,0 +1,440 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Mobility Components.
|
||||
**
|
||||
** $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 Nokia Corporation 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.h>
|
||||
#include <qmediarecorder.h>
|
||||
#include <qcamera.h>
|
||||
#include <qcameraviewfinder.h>
|
||||
|
||||
#include <qmessagebox.h>
|
||||
#include <qpalette.h>
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#if (defined(Q_WS_MAEMO_5) || 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*)), this, 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(QtMultimediaKit::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()) {
|
||||
#if QT_VERSION >= 0x040700
|
||||
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;
|
||||
#endif
|
||||
default:
|
||||
QMainWindow::keyPressEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Camera::keyReleaseEvent(QKeyEvent * event)
|
||||
{
|
||||
if (event->isAutoRepeat())
|
||||
return;
|
||||
|
||||
switch (event->key()) {
|
||||
#if QT_VERSION >= 0x040700
|
||||
case Qt::Key_CameraFocus:
|
||||
camera->unlock();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
QMainWindow::keyReleaseEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
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::CaptureMode 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();
|
||||
}
|
||||
}
|
||||
126
examples/camera/camera.h
Normal file
126
examples/camera/camera.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Mobility Components.
|
||||
**
|
||||
** $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 Nokia Corporation 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.h>
|
||||
#include <qmediarecorder.h>
|
||||
#include <qcameraimagecapture.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
class Camera;
|
||||
}
|
||||
class QCameraViewfinder;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QDir>
|
||||
|
||||
QT_USE_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*);
|
||||
|
||||
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);
|
||||
void imageSaved(int, const QString&);
|
||||
|
||||
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
|
||||
33
examples/camera/camera.pro
Normal file
33
examples/camera/camera.pro
Normal file
@@ -0,0 +1,33 @@
|
||||
TEMPLATE = app
|
||||
TARGET = camera
|
||||
|
||||
INCLUDEPATH+=../../src/multimedia \
|
||||
../../src/multimedia/video
|
||||
|
||||
include(../mobility_examples.pri)
|
||||
|
||||
CONFIG += mobility
|
||||
MOBILITY = multimedia
|
||||
|
||||
HEADERS = \
|
||||
camera.h \
|
||||
imagesettings.h \
|
||||
videosettings.h
|
||||
|
||||
SOURCES = \
|
||||
main.cpp \
|
||||
camera.cpp \
|
||||
imagesettings.cpp \
|
||||
videosettings.cpp
|
||||
|
||||
FORMS += \
|
||||
camera.ui \
|
||||
videosettings.ui \
|
||||
imagesettings.ui
|
||||
|
||||
symbian {
|
||||
include(camerakeyevent_symbian/camerakeyevent_symbian.pri)
|
||||
TARGET.CAPABILITY += UserEnvironment WriteUserData ReadUserData
|
||||
TARGET.EPOCHEAPSIZE = 0x20000 0x3000000
|
||||
LIBS += -lavkon -leiksrv -lcone -leikcore
|
||||
}
|
||||
492
examples/camera/camera.ui
Normal file
492
examples/camera/camera.ui
Normal file
@@ -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>
|
||||
@@ -0,0 +1,101 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Mobility Components.
|
||||
**
|
||||
** $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 Nokia Corporation 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 "camerakeyevent_symbian.h"
|
||||
|
||||
#include <QtGui/QWidget> // WId
|
||||
#include <eikon.hrh> // EKeyCamera
|
||||
#include <coecntrl.h> // CCoeControl (WId)
|
||||
#include <w32std.h> // RWindowbase, RWindowGroup, RWsSession
|
||||
|
||||
QSymbianCameraKeyListener::QSymbianCameraKeyListener(QWidget *widget):
|
||||
QObject(widget),
|
||||
m_widget(widget)
|
||||
{
|
||||
if (!m_widget)
|
||||
return;
|
||||
|
||||
// Get view's native Symbian window
|
||||
WId windowId = 0;
|
||||
if (m_widget->internalWinId())
|
||||
windowId = m_widget->internalWinId();
|
||||
else if (m_widget->parentWidget() && m_widget->effectiveWinId())
|
||||
windowId = m_widget->effectiveWinId();
|
||||
RWindowBase *window = windowId ? static_cast<RWindowBase*>(windowId->DrawableWindow()) : 0;
|
||||
|
||||
// Get hold of the window group
|
||||
TInt wGroupId = window ? window->WindowGroupId() : 0;
|
||||
if (!wGroupId)
|
||||
return;
|
||||
RWsSession &wsSession = CCoeEnv::Static()->WsSession();
|
||||
TUint wGroupHandle = wsSession.GetWindowGroupHandle(wGroupId);
|
||||
if (wGroupHandle) {
|
||||
RWindowGroup wGroup(wsSession);
|
||||
wGroup.Construct(wGroupHandle);
|
||||
if (wGroup.CaptureKey(EKeyCamera, 0, 0, 100) < 0)
|
||||
qWarning("Unable to register for camera capture key events, SwEvent capability may be missing");
|
||||
}
|
||||
}
|
||||
|
||||
QSymbianCameraKeyListener::~QSymbianCameraKeyListener()
|
||||
{
|
||||
if (!m_widget)
|
||||
return;
|
||||
|
||||
// Get view's native Symbian window
|
||||
WId windowId = 0;
|
||||
if (m_widget->internalWinId())
|
||||
windowId = m_widget->internalWinId();
|
||||
else if (m_widget->parentWidget() && m_widget->effectiveWinId())
|
||||
windowId = m_widget->effectiveWinId();
|
||||
RWindowBase *window = windowId ? static_cast<RWindowBase*>(windowId->DrawableWindow()) : 0;
|
||||
|
||||
// Get hold of the window group
|
||||
TInt wGroupId = window ? window->WindowGroupId() : 0;
|
||||
if (!wGroupId)
|
||||
return;
|
||||
RWsSession &wsSession = CCoeEnv::Static()->WsSession();
|
||||
TUint wGroupHandle = wsSession.GetWindowGroupHandle(wGroupId);
|
||||
if (wGroupHandle) {
|
||||
RWindowGroup wGroup(wsSession);
|
||||
wGroup.Construct(wGroupHandle);
|
||||
wGroup.CancelCaptureKey(EKeyCamera);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
#ifndef CAMERAKEYEVENT_SYMBIAN_H
|
||||
#define CAMERAKEYEVENT_SYMBIAN_H
|
||||
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Mobility Components.
|
||||
**
|
||||
** $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 Nokia Corporation 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$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Description:
|
||||
* This header can be used to register application on Symbian platforms
|
||||
* for the Camera capture button key events. Application can avoid native
|
||||
* camera application from starting by not forwarding the key event.
|
||||
*
|
||||
* Usage:
|
||||
* Application needs to include this header and include the needed Symbian
|
||||
* libraries. Optionally application can include camerakeyevent_symbian.pri
|
||||
* file. Application can register and unregister for the Camera capture
|
||||
* key events by creating/destructing the QSymbianCameraKeyListener helper
|
||||
* object. The widget needs to be shown before it registers for the
|
||||
* Camera key event.
|
||||
*
|
||||
* Libraries needed:
|
||||
* User needs to define following in the .pro file (or optionally include
|
||||
* the camerakeyevent_symbian.pri):
|
||||
* LIBS += -lcone -lws32
|
||||
*
|
||||
* Symbian Capabilities needed:
|
||||
* To use this header user needs to have SwEvent capability (included in
|
||||
* the camerakeyevent_symbian.pri):
|
||||
* TARGET.CAPABILITY += SwEvent
|
||||
*/
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
QT_FORWARD_DECLARE_CLASS(QWidget)
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
class QSymbianCameraKeyListener : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QSymbianCameraKeyListener(QWidget *parent = 0);
|
||||
~QSymbianCameraKeyListener();
|
||||
private:
|
||||
QWidget *m_widget;
|
||||
};
|
||||
|
||||
#endif // CAMERAKEYEVENT_SYMBIAN_H
|
||||
@@ -0,0 +1,7 @@
|
||||
message("camerakeyevent_symbian: Including Symbian camera capture key event register methods")
|
||||
|
||||
HEADERS += $$PWD/camerakeyevent_symbian.h
|
||||
SOURCES += $$PWD/camerakeyevent_symbian.cpp
|
||||
INCLUDEPATH += $$PWD
|
||||
LIBS *= -lcone -lws32
|
||||
TARGET.CAPABILITY *= SwEvent
|
||||
126
examples/camera/imagesettings.cpp
Normal file
126
examples/camera/imagesettings.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Mobility Components.
|
||||
**
|
||||
** $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 Nokia Corporation 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 <QtGui/qcombobox.h>
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <qcameraimagecapture.h>
|
||||
#include <qmediaservice.h>
|
||||
|
||||
|
||||
|
||||
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(QtMultimediaKit::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(QtMultimediaKit::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;
|
||||
}
|
||||
}
|
||||
}
|
||||
84
examples/camera/imagesettings.h
Normal file
84
examples/camera/imagesettings.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Mobility Components.
|
||||
**
|
||||
** $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 Nokia Corporation 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 <QtGui/QDialog>
|
||||
#include <qmediaencodersettings.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QComboBox;
|
||||
namespace Ui {
|
||||
class ImageSettingsUi;
|
||||
}
|
||||
|
||||
class QCameraImageCapture;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
class ImageSettings : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ImageSettings(QCameraImageCapture *imageCapture, QWidget *parent = 0);
|
||||
~ImageSettings();
|
||||
|
||||
QAudioEncoderSettings audioSettings() const;
|
||||
void setAudioSettings(const QAudioEncoderSettings&);
|
||||
|
||||
QImageEncoderSettings imageSettings() const;
|
||||
void setImageSettings(const QImageEncoderSettings&);
|
||||
|
||||
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::ImageSettingsUi *ui;
|
||||
QCameraImageCapture *imagecapture;
|
||||
};
|
||||
|
||||
#endif // IMAGESETTINGS_H
|
||||
123
examples/camera/imagesettings.ui
Normal file
123
examples/camera/imagesettings.ui
Normal file
@@ -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>
|
||||
72
examples/camera/main.cpp
Normal file
72
examples/camera/main.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Mobility Components.
|
||||
**
|
||||
** $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 Nokia Corporation 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"
|
||||
#ifdef Q_OS_SYMBIAN
|
||||
#include "camerakeyevent_symbian.h"
|
||||
#endif // Q_OS_SYMBIAN
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
#if defined (Q_OS_SYMBIAN)
|
||||
QApplication::setGraphicsSystem("raster");
|
||||
QApplication app(argc, argv);
|
||||
// lock orientation before constructing camera
|
||||
CAknAppUi* appUi = dynamic_cast<CAknAppUi*>(CEikonEnv::Static()->AppUi());
|
||||
if(appUi){
|
||||
QT_TRAP_THROWING(appUi ->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape));
|
||||
}
|
||||
#else
|
||||
QApplication app(argc, argv);
|
||||
#endif
|
||||
|
||||
Camera camera;
|
||||
|
||||
#ifdef Q_OS_SYMBIAN
|
||||
camera.showMaximized();
|
||||
new QSymbianCameraKeyListener(&camera);
|
||||
#else
|
||||
camera.show();
|
||||
#endif
|
||||
|
||||
return app.exec();
|
||||
};
|
||||
191
examples/camera/videosettings.cpp
Normal file
191
examples/camera/videosettings.cpp
Normal file
@@ -0,0 +1,191 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Mobility Components.
|
||||
**
|
||||
** $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 Nokia Corporation 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 <QtGui/qcombobox.h>
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <qmediarecorder.h>
|
||||
#include <qmediaservice.h>
|
||||
|
||||
|
||||
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(QtMultimediaKit::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(QtMultimediaKit::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(QtMultimediaKit::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(QtMultimediaKit::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;
|
||||
}
|
||||
}
|
||||
}
|
||||
84
examples/camera/videosettings.h
Normal file
84
examples/camera/videosettings.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the examples of the Qt Mobility Components.
|
||||
**
|
||||
** $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 Nokia Corporation 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 <QtGui/QDialog>
|
||||
#include <qmediaencodersettings.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QComboBox;
|
||||
namespace Ui {
|
||||
class VideoSettingsUi;
|
||||
}
|
||||
|
||||
class QMediaRecorder;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
QT_USE_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
|
||||
211
examples/camera/videosettings.ui
Normal file
211
examples/camera/videosettings.ui
Normal file
@@ -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>
|
||||
Reference in New Issue
Block a user