From ca01d5f9f5e960337a044be6e00de58fd4fbdb05 Mon Sep 17 00:00:00 2001 From: Topi Reinio Date: Fri, 24 Jan 2014 13:22:02 +0100 Subject: Make basicsuite demos run stand-alone This change will make the demos run standalone when built in Qt Creator. - Rename example directories to lowercase/non-whitespace to avoid build & deployment problems - Add title.txt files so titles remain displayed correctly in the launcher - Add a common shared source files used for the standalone apps, and .pro-files for each example - Remove .qmlproject files (not needed) - Adjust documentation to match the new directory structure Change-Id: Ib24e461952da3b2c88aab0363249115ea44ee0f2 Reviewed-by: Eirik Aavitsland --- basicsuite/camera/camerautils/camerautils.cpp | 229 ++++++++++++++++++++++++++ basicsuite/camera/camerautils/camerautils.h | 127 ++++++++++++++ basicsuite/camera/camerautils/camerautils.pro | 19 +++ basicsuite/camera/camerautils/plugin.cpp | 60 +++++++ basicsuite/camera/camerautils/qmldir | 2 + 5 files changed, 437 insertions(+) create mode 100644 basicsuite/camera/camerautils/camerautils.cpp create mode 100644 basicsuite/camera/camerautils/camerautils.h create mode 100644 basicsuite/camera/camerautils/camerautils.pro create mode 100644 basicsuite/camera/camerautils/plugin.cpp create mode 100644 basicsuite/camera/camerautils/qmldir (limited to 'basicsuite/camera/camerautils') diff --git a/basicsuite/camera/camerautils/camerautils.cpp b/basicsuite/camera/camerautils/camerautils.cpp new file mode 100644 index 0000000..f6b6672 --- /dev/null +++ b/basicsuite/camera/camerautils/camerautils.cpp @@ -0,0 +1,229 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: For any questions to Digia, please use the contact form at +** http://qt.digia.com/ +** +** This file is part of the examples of the Qt Enterprise Embedded. +** +** $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 "camerautils.h" + +#include +#include +#include +#include +#include +#include + +static QList g_commonResolutions; +static QList g_commonVideoResolutions; +static QList g_whiteBalanceModes; +static QList g_sceneModes; +static QList g_flashModes; +static QList g_focusModes; + +QDebug operator<<(QDebug dbg, const CameraSettingsValue &r) { + dbg.nospace() << "CameraSettingsValue(" << r.name() << ", " << r.value() << ')'; + return dbg.space(); +} + +CameraUtils::CameraUtils(QObject *parent) + : QObject(parent) + , m_camera(0) +{ + if (g_commonResolutions.isEmpty()) { + g_commonResolutions << new CameraSettingsValue(QStringLiteral("QVGA"), QSize(320, 240)) + << new CameraSettingsValue(QStringLiteral("0.3M"), QSize(640, 480)) + << new CameraSettingsValue(QStringLiteral("0.8M"), QSize(1024, 768)) + << new CameraSettingsValue(QStringLiteral("1.2M"), QSize(1280, 960)) + << new CameraSettingsValue(QStringLiteral("2M"), QSize(1600, 1200)) + << new CameraSettingsValue(QStringLiteral("5M"), QSize(2560, 1920)) + << new CameraSettingsValue(QStringLiteral("8M"), QSize(3264, 2448)); + + g_commonVideoResolutions << new CameraSettingsValue(QStringLiteral("1080p (16:9)"), QSize(1920, 1080)) + << new CameraSettingsValue(QStringLiteral("1080p (16:9)"), QSize(1920, 1088)) + << new CameraSettingsValue(QStringLiteral("1080p (4:3)"), QSize(1440, 1080)) + << new CameraSettingsValue(QStringLiteral("1080p (4:3)"), QSize(1440, 1088)) + << new CameraSettingsValue(QStringLiteral("720p (16:9)"), QSize(1280, 720)) + << new CameraSettingsValue(QStringLiteral("720p (4:3)"), QSize(960, 720)) + << new CameraSettingsValue(QStringLiteral("480p (16:9)"), QSize(720, 480)) + << new CameraSettingsValue(QStringLiteral("480p (4:3)"), QSize(640, 480)) + << new CameraSettingsValue(QStringLiteral("QVGA"), QSize(320, 240)); + + g_whiteBalanceModes << new CameraSettingsValue(QStringLiteral("Auto"), QCameraImageProcessing::WhiteBalanceAuto) + << new CameraSettingsValue(QStringLiteral("Manual"), QCameraImageProcessing::WhiteBalanceManual) + << new CameraSettingsValue(QStringLiteral("Sunlight"), QCameraImageProcessing::WhiteBalanceSunlight) + << new CameraSettingsValue(QStringLiteral("Cloudy"), QCameraImageProcessing::WhiteBalanceCloudy) + << new CameraSettingsValue(QStringLiteral("Shade"), QCameraImageProcessing::WhiteBalanceShade) + << new CameraSettingsValue(QStringLiteral("Tungsten"), QCameraImageProcessing::WhiteBalanceTungsten) + << new CameraSettingsValue(QStringLiteral("Fluorescent"), QCameraImageProcessing::WhiteBalanceFluorescent) + << new CameraSettingsValue(QStringLiteral("Flash"), QCameraImageProcessing::WhiteBalanceFlash) + << new CameraSettingsValue(QStringLiteral("Sunset"), QCameraImageProcessing::WhiteBalanceSunset); + + g_sceneModes << new CameraSettingsValue(QStringLiteral("Auto"), QCameraExposure::ExposureAuto) + << new CameraSettingsValue(QStringLiteral("Manual"), QCameraExposure::ExposureManual) + << new CameraSettingsValue(QStringLiteral("Portrait"), QCameraExposure::ExposurePortrait) + << new CameraSettingsValue(QStringLiteral("Night"), QCameraExposure::ExposureNight) + << new CameraSettingsValue(QStringLiteral("Backlight"), QCameraExposure::ExposureBacklight) + << new CameraSettingsValue(QStringLiteral("Spotlight"), QCameraExposure::ExposureSpotlight) + << new CameraSettingsValue(QStringLiteral("Sports"), QCameraExposure::ExposureSports) + << new CameraSettingsValue(QStringLiteral("Snow"), QCameraExposure::ExposureSnow) + << new CameraSettingsValue(QStringLiteral("Beach"), QCameraExposure::ExposureBeach) + << new CameraSettingsValue(QStringLiteral("Large Aperture"), QCameraExposure::ExposureLargeAperture) + << new CameraSettingsValue(QStringLiteral("Small Aperture"), QCameraExposure::ExposureSmallAperture); + + g_flashModes << new CameraSettingsValue(QStringLiteral("Auto"), QCameraExposure::FlashAuto) + << new CameraSettingsValue(QStringLiteral("Off"), QCameraExposure::FlashOff) + << new CameraSettingsValue(QStringLiteral("On"), QCameraExposure::FlashOn) + << new CameraSettingsValue(QStringLiteral("Red-Eye"), QCameraExposure::FlashRedEyeReduction) + << new CameraSettingsValue(QStringLiteral("Torch"), QCameraExposure::FlashVideoLight); + + g_focusModes << new CameraSettingsValue(QStringLiteral("Auto"), QCameraFocus::AutoFocus) + << new CameraSettingsValue(QStringLiteral("Continuous"), QCameraFocus::ContinuousFocus) + << new CameraSettingsValue(QStringLiteral("Hyperfocal"), QCameraFocus::HyperfocalFocus) + << new CameraSettingsValue(QStringLiteral("Infinity"), QCameraFocus::InfinityFocus) + << new CameraSettingsValue(QStringLiteral("Macro"), QCameraFocus::MacroFocus) + << new CameraSettingsValue(QStringLiteral("Off"), QCameraFocus::ManualFocus); + } + +} + +CameraUtils::~CameraUtils() +{ +} + +void CameraUtils::init() +{ + m_camera = new QCamera; + connect(m_camera, SIGNAL(statusChanged(QCamera::Status)), this, SLOT(onCameraStatusChanged())); + connect(m_camera, SIGNAL(error(QCamera::Error)), this, SLOT(onError())); + m_camera->load(); +} + +void CameraUtils::setCamera(QObject *obj) +{ + QObject *mediaObject = qvariant_cast(obj->property("mediaObject")); + if (!mediaObject) + return; + + m_camera = qobject_cast(mediaObject); + if (!m_camera) + return; + + if (m_camera->status() >= QCamera::LoadedStatus) + onCameraStatusChanged(); + else + connect(m_camera, SIGNAL(statusChanged(QCamera::Status)), this, SLOT(onCameraStatusChanged())); +} + +void CameraUtils::onError() +{ + if (m_camera && m_camera->status() == QCamera::UnavailableStatus) { + delete m_camera; + m_camera = 0; + + emit done(); + } +} + +void CameraUtils::onCameraStatusChanged() +{ + if (!m_camera || m_camera->status() < QCamera::LoadedStatus) + return; + + disconnect(m_camera, SIGNAL(statusChanged(QCamera::Status)), this, SLOT(onCameraStatusChanged())); + + QCameraImageCapture *imageCapture = new QCameraImageCapture(m_camera); + QCameraImageProcessing *imageProc = m_camera->imageProcessing(); + QCameraExposure *exposure = m_camera->exposure(); + QCameraFocus *focus = m_camera->focus(); + QMediaRecorder rec(m_camera); + + // Supported image resolutions + QList resolutions = imageCapture->supportedResolutions(); + for (int i = resolutions.size() - 1; i >= 0; --i) { + QSize reso = resolutions.at(i); + int mp = reso.width() * reso.height(); + CameraSettingsValue *r = new CameraSettingsValue(QString::number(mp / double(1000000), 'f', 1) + QLatin1String("M"), reso); + m_supportedResolutions.append(r); + } + + // Supported video resolutions + QList suppRes = rec.supportedResolutions(); + for (int i = 0; i < g_commonVideoResolutions.size(); ++i) { + CameraSettingsValue *r = g_commonVideoResolutions.at(i); + if (suppRes.contains(r->value().toSize())) + m_supportedVideoResolutions.append(r); + } + + + // Supported white balance modes + for (int i = 0; i < g_whiteBalanceModes.size(); ++i) { + CameraSettingsValue *m = g_whiteBalanceModes.at(i); + if (imageProc->isWhiteBalanceModeSupported(QCameraImageProcessing::WhiteBalanceMode(m->value().toInt()))) + m_supportedWhiteBalanceModes.append(m); + } + + // Supported scene modes + for (int i = 0; i < g_sceneModes.size(); ++i) { + CameraSettingsValue *sm = g_sceneModes.at(i); + if (exposure->isExposureModeSupported(QCameraExposure::ExposureMode(sm->value().toInt()))) + m_supportedSceneModes.append(sm); + } + + // Supported flash modes + for (int i = 0; i < g_flashModes.size(); ++i) { + CameraSettingsValue *sm = g_flashModes.at(i); + if (exposure->isFlashModeSupported(QCameraExposure::FlashModes(sm->value().toInt()))) + m_supportedFlashModes.append(sm); + } + + // Supported focus modes + for (int i = 0; i < g_focusModes.size(); ++i) { + CameraSettingsValue *sm = g_focusModes.at(i); + if (focus->isFocusModeSupported(QCameraFocus::FocusModes(sm->value().toInt()))) + m_supportedFocusModes.append(sm); + } + + delete imageCapture; + + emit supportedCaptureResolutionsChanged(); + emit supportedVideoResolutionsChanged(); + emit supportedWhiteBalanceModesChanged(); + emit supportedSceneModesChanged(); + emit supportedFlashModesChanged(); +} + + diff --git a/basicsuite/camera/camerautils/camerautils.h b/basicsuite/camera/camerautils/camerautils.h new file mode 100644 index 0000000..1f61c7c --- /dev/null +++ b/basicsuite/camera/camerautils/camerautils.h @@ -0,0 +1,127 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: For any questions to Digia, please use the contact form at +** http://qt.digia.com/ +** +** This file is part of the examples of the Qt Enterprise Embedded. +** +** $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 CAMERAUTILS_H +#define CAMERAUTILS_H + +#include +#include + +class QCamera; + +class CameraSettingsValue : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) + +public: + CameraSettingsValue(const QString &n, const QVariant &v) + : QObject() + , m_name(n) + , m_value(v) + { } + + QString name() const { return m_name; } + void setName(const QString &n) { m_name = n; emit nameChanged(); } + + QVariant value() const { return m_value; } + void setValue(const QVariant &v) { m_value = v; emit valueChanged(); } + +Q_SIGNALS: + void nameChanged(); + void valueChanged(); + +private: + QString m_name; + QVariant m_value; +}; + +QDebug operator<<(QDebug, const CameraSettingsValue &); + +class CameraUtils : public QObject +{ + Q_OBJECT + Q_PROPERTY(QList supportedCaptureResolutions READ supportedCaptureResolutions NOTIFY supportedCaptureResolutionsChanged) + Q_PROPERTY(QList supportedWhiteBalanceModes READ supportedWhiteBalanceModes NOTIFY supportedWhiteBalanceModesChanged) + Q_PROPERTY(QList supportedSceneModes READ supportedSceneModes NOTIFY supportedSceneModesChanged) + Q_PROPERTY(QList supportedFlashModes READ supportedFlashModes NOTIFY supportedFlashModesChanged) + Q_PROPERTY(QList supportedFocusModes READ supportedFocusModes NOTIFY supportedFocusModesChanged) + Q_PROPERTY(QList supportedVideoResolutions READ supportedVideoResolutions NOTIFY supportedVideoResolutionsChanged) +public: + explicit CameraUtils(QObject *parent = 0); + ~CameraUtils(); + + Q_INVOKABLE void init(); + Q_INVOKABLE void setCamera(QObject *cam); + + QList supportedCaptureResolutions() const { return m_supportedResolutions; } + QList supportedVideoResolutions() const { return m_supportedVideoResolutions; } + QList supportedWhiteBalanceModes() const { return m_supportedWhiteBalanceModes; } + QList supportedSceneModes() const { return m_supportedSceneModes; } + QList supportedFlashModes() const { return m_supportedFlashModes; } + QList supportedFocusModes() const { return m_supportedFocusModes; } + +Q_SIGNALS: + void supportedCaptureResolutionsChanged(); + void supportedWhiteBalanceModesChanged(); + void supportedSceneModesChanged(); + void supportedFlashModesChanged(); + void supportedFocusModesChanged(); + void supportedVideoResolutionsChanged(); + + void done(); + +private Q_SLOTS: + void onCameraStatusChanged(); + void onError(); + +private: + QCamera *m_camera; + + QList m_supportedResolutions; + QList m_supportedVideoResolutions; + QList m_supportedWhiteBalanceModes; + QList m_supportedSceneModes; + QList m_supportedFlashModes; + QList m_supportedFocusModes; +}; + +#endif // CAMERAUTILS_H diff --git a/basicsuite/camera/camerautils/camerautils.pro b/basicsuite/camera/camerautils/camerautils.pro new file mode 100644 index 0000000..938a0a9 --- /dev/null +++ b/basicsuite/camera/camerautils/camerautils.pro @@ -0,0 +1,19 @@ +TEMPLATE = lib +CONFIG += plugin +QT += qml multimedia + +TARGET = camerautilsplugin + +SOURCES += plugin.cpp \ + camerautils.cpp + +HEADERS += camerautils.h + +pluginfiles.files += \ + qmldir \ + +target.path += $$[QT_INSTALL_QML]/CameraUtils +pluginfiles.path += $$[QT_INSTALL_QML]/CameraUtils + +INSTALLS += target pluginfiles + diff --git a/basicsuite/camera/camerautils/plugin.cpp b/basicsuite/camera/camerautils/plugin.cpp new file mode 100644 index 0000000..2a8c3ea --- /dev/null +++ b/basicsuite/camera/camerautils/plugin.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2013 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 +#include +#include + +#include "camerautils.h" + +class QExampleQmlPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri) + { + qmlRegisterType(uri, 1, 0, "CameraUtils"); + } +}; + + +#include "plugin.moc" diff --git a/basicsuite/camera/camerautils/qmldir b/basicsuite/camera/camerautils/qmldir new file mode 100644 index 0000000..a5ab412 --- /dev/null +++ b/basicsuite/camera/camerautils/qmldir @@ -0,0 +1,2 @@ +module CameraUtils +plugin camerautilsplugin -- cgit v1.2.3