| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | 
| 4 | ** Contact: https://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the plugins of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU Lesser General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
| 19 | ** General Public License version 3 as published by the Free Software | 
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | 
| 21 | ** packaging of this file. Please review the following information to | 
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | 
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | 
| 24 | ** | 
| 25 | ** GNU General Public License Usage | 
| 26 | ** Alternatively, this file may be used under the terms of the GNU | 
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | 
| 28 | ** Public license version 3 or any later version approved by the KDE Free | 
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | 
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | 
| 31 | ** included in the packaging of this file. Please review the following | 
| 32 | ** information to ensure the GNU General Public License requirements will | 
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | 
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | 
| 35 | ** | 
| 36 | ** $QT_END_LICENSE$ | 
| 37 | ** | 
| 38 | ****************************************************************************/ | 
| 39 |  | 
| 40 | #include "qdeclarativecamera_p.h" | 
| 41 | #include "qdeclarativecameraflash_p.h" | 
| 42 |  | 
| 43 | QT_BEGIN_NAMESPACE | 
| 44 |  | 
| 45 | /*! | 
| 46 |     \qmltype CameraFlash | 
| 47 |     \instantiates QDeclarativeCameraFlash | 
| 48 |     \inqmlmodule QtMultimedia | 
| 49 |     \brief An interface for flash related camera settings. | 
| 50 |     \ingroup multimedia_qml | 
| 51 |     \ingroup camera_qml | 
| 52 |  | 
| 53 |     This type allows you to operate the camera flash | 
| 54 |     hardware and control the flash mode used.  Not all cameras have | 
| 55 |     flash hardware (and in some cases it is shared with the | 
| 56 |     \l {Torch}{torch} hardware). | 
| 57 |  | 
| 58 |     It should not be constructed separately, instead the | 
| 59 |     \c flash property of a \l Camera should be used. | 
| 60 |  | 
| 61 |     \qml | 
| 62 |  | 
| 63 |     Camera { | 
| 64 |         id: camera | 
| 65 |  | 
| 66 |         exposure.exposureCompensation: -1.0 | 
| 67 |         flash.mode: Camera.FlashRedEyeReduction | 
| 68 |     } | 
| 69 |  | 
| 70 |     \endqml | 
| 71 | */ | 
| 72 |  | 
| 73 | /*! | 
| 74 |     Construct a declarative camera flash object using \a parent object. | 
| 75 |  */ | 
| 76 | QDeclarativeCameraFlash::QDeclarativeCameraFlash(QCamera *camera, QObject *parent) | 
| 77 |     : QObject(parent) | 
| 78 | { | 
| 79 |     m_exposure = camera->exposure(); | 
| 80 |     connect(sender: m_exposure, SIGNAL(flashReady(bool)), receiver: this, SIGNAL(flashReady(bool))); | 
| 81 |     connect(sender: camera, SIGNAL(statusChanged(QCamera::Status)), | 
| 82 |             receiver: this, SLOT(_q_cameraStatusChanged(QCamera::Status))); | 
| 83 | } | 
| 84 |  | 
| 85 | QDeclarativeCameraFlash::~QDeclarativeCameraFlash() | 
| 86 | { | 
| 87 | } | 
| 88 |  | 
| 89 | /*! | 
| 90 |     \qmlproperty bool QtMultimedia::CameraFlash::ready | 
| 91 |  | 
| 92 |     This property indicates whether the flash is charged. | 
| 93 | */ | 
| 94 | bool QDeclarativeCameraFlash::isFlashReady() const | 
| 95 | { | 
| 96 |     return m_exposure->isFlashReady(); | 
| 97 | } | 
| 98 |  | 
| 99 | /*! | 
| 100 |     \qmlproperty enumeration QtMultimedia::CameraFlash::mode | 
| 101 |  | 
| 102 |     This property holds the camera flash mode. | 
| 103 |  | 
| 104 |     The mode can be one of the following: | 
| 105 |     \table | 
| 106 |     \header \li Value \li Description | 
| 107 |     \row \li Camera.FlashOff             \li Flash is Off. | 
| 108 |     \row \li Camera.FlashOn              \li Flash is On. | 
| 109 |     \row \li Camera.FlashAuto            \li Automatic flash. | 
| 110 |     \row \li Camera.FlashRedEyeReduction \li Red eye reduction flash. | 
| 111 |     \row \li Camera.FlashFill            \li Use flash to fillin shadows. | 
| 112 |     \row \li Camera.FlashTorch           \li Constant light source. If supported, torch can be | 
| 113 |                                              enabled without loading the camera. | 
| 114 |     \row \li Camera.FlashVideoLight      \li Constant light source, useful for video capture. | 
| 115 |                                              The light is turned on only while the camera is active. | 
| 116 |     \row \li Camera.FlashSlowSyncFrontCurtain | 
| 117 |                                 \li Use the flash in conjunction with a slow shutter speed. | 
| 118 |                                 This mode allows better exposure of distant objects and/or motion blur effect. | 
| 119 |     \row \li Camera.FlashSlowSyncRearCurtain | 
| 120 |                                 \li The similar mode to FlashSlowSyncFrontCurtain but flash is fired at the end of exposure. | 
| 121 |     \row \li Camera.FlashManual          \li Flash power is manually set. | 
| 122 |     \endtable | 
| 123 |  | 
| 124 | */ | 
| 125 | QDeclarativeCameraFlash::FlashMode QDeclarativeCameraFlash::flashMode() const | 
| 126 | { | 
| 127 |     return QDeclarativeCameraFlash::FlashMode(int(m_exposure->flashMode())); | 
| 128 | } | 
| 129 |  | 
| 130 | void QDeclarativeCameraFlash::setFlashMode(QDeclarativeCameraFlash::FlashMode mode) | 
| 131 | { | 
| 132 |     if (flashMode() != mode) { | 
| 133 |         m_exposure->setFlashMode(QCameraExposure::FlashModes(mode)); | 
| 134 |         emit flashModeChanged(mode); | 
| 135 |     } | 
| 136 | } | 
| 137 |  | 
| 138 | void QDeclarativeCameraFlash::_q_cameraStatusChanged(QCamera::Status status) | 
| 139 | { | 
| 140 |     if (status != QCamera::UnloadedStatus && status != QCamera::LoadedStatus && | 
| 141 |             status != QCamera::ActiveStatus) | 
| 142 |         return; | 
| 143 |  | 
| 144 |     emit supportedModesChanged(); | 
| 145 | } | 
| 146 |  | 
| 147 | /*! | 
| 148 |     \qmlproperty list<FlashMode> QtMultimedia::CameraFlash::supportedModes | 
| 149 |  | 
| 150 |     This property holds the supported flash modes of the camera. If the list | 
| 151 |     only contains Camera.FlashOff, no flash is supported. | 
| 152 |  | 
| 153 |     \code | 
| 154 |         Camera { | 
| 155 |             id: camera | 
| 156 |             flash { | 
| 157 |                 onSupportedModesChanged { | 
| 158 |                     if (flash.supportedModes.length == 1) { | 
| 159 |                         // no flash supported | 
| 160 |                     } else { | 
| 161 |                         // some flash is supported | 
| 162 |                     } | 
| 163 |                 } | 
| 164 |             } | 
| 165 |         } | 
| 166 |     \endcode | 
| 167 |  | 
| 168 |     \since 5.9 | 
| 169 |     \sa mode | 
| 170 |  */ | 
| 171 | QVariantList QDeclarativeCameraFlash::supportedModes() const | 
| 172 | { | 
| 173 |     QVariantList supportedModes; | 
| 174 |  | 
| 175 |     for (int i=1; i <= (int) QCameraExposure::FlashManual; i = (i << 1)) { | 
| 176 |         if (m_exposure->isFlashModeSupported(mode: (QCameraExposure::FlashMode) i)) | 
| 177 |             supportedModes.append(t: QVariant(i)); | 
| 178 |     } | 
| 179 |  | 
| 180 |     return supportedModes; | 
| 181 | } | 
| 182 |  | 
| 183 | /*! | 
| 184 |     \qmlsignal QtMultimedia::CameraFlash::flashModeChanged() | 
| 185 |     This signal is emitted when the \c flashMode property is changed. | 
| 186 |     The corresponding handler is \c onFlashModeChanged. | 
| 187 | */ | 
| 188 |  | 
| 189 | /*! | 
| 190 |     \qmlsignal QtMultimedia::CameraFlash::flashReady() | 
| 191 |     This signal is emitted when QCameraExposure indicates that | 
| 192 |     the flash is ready to use. | 
| 193 |     The corresponding handler is \c onFlashReadyChanged. | 
| 194 | */ | 
| 195 |  | 
| 196 | QT_END_NAMESPACE | 
| 197 |  | 
| 198 | #include "moc_qdeclarativecameraflash_p.cpp" | 
| 199 |  |