From 888759e334e81117843afb6d0f8991db8aec5ca8 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Mon, 10 Feb 2014 19:33:51 +0100 Subject: New camera selection API in QML. Also added a new QtMultimedia global object which makes it possible to retrieve the list of available cameras. It can be extended with new utility functions in the future. Includes documentation, example and auto tests. Task-number: QTBUG-23770 Change-Id: Ifea076329c3582ea99246ee1131853344a7b773f Reviewed-by: Christian Stromme --- .../multimedia/declarative-camera/CameraButton.qml | 13 ++- .../declarative-camera/CameraListButton.qml | 76 +++++++++++++++++ .../declarative-camera/CameraListPopup.qml | 95 ++++++++++++++++++++++ .../declarative-camera/CameraPropertyButton.qml | 30 +------ .../declarative-camera/CameraPropertyPopup.qml | 10 +-- .../declarative-camera/PhotoCaptureControls.qml | 12 ++- examples/multimedia/declarative-camera/Popup.qml | 76 +++++++++++++++++ .../declarative-camera/VideoCaptureControls.qml | 11 ++- .../declarative-camera/declarative-camera.qml | 2 +- .../declarative-camera/declarative-camera.qrc | 3 + 10 files changed, 281 insertions(+), 47 deletions(-) create mode 100644 examples/multimedia/declarative-camera/CameraListButton.qml create mode 100644 examples/multimedia/declarative-camera/CameraListPopup.qml create mode 100644 examples/multimedia/declarative-camera/Popup.qml (limited to 'examples/multimedia') diff --git a/examples/multimedia/declarative-camera/CameraButton.qml b/examples/multimedia/declarative-camera/CameraButton.qml index b0353b4c3..394b210a8 100644 --- a/examples/multimedia/declarative-camera/CameraButton.qml +++ b/examples/multimedia/declarative-camera/CameraButton.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 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. @@ -63,9 +63,16 @@ Item { } Text { id: btnText + anchors.fill: buttonImage + anchors.margins: 5 + text: button.text + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight color: button.color - anchors.centerIn: buttonImage; font.bold: true - text: button.text; style: Text.Raised; styleColor: "black" + font.bold: true + style: Text.Raised + styleColor: "black" font.pixelSize: 14 } } diff --git a/examples/multimedia/declarative-camera/CameraListButton.qml b/examples/multimedia/declarative-camera/CameraListButton.qml new file mode 100644 index 000000000..71d9280bb --- /dev/null +++ b/examples/multimedia/declarative-camera/CameraListButton.qml @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Item { + id: cameraListButton + property alias value : popup.currentValue + property alias model : popup.model + + width : 144 + height: 70 + visible: model.length > 0 + + BorderImage { + id: buttonImage + source: "images/toolbutton.sci" + width: cameraListButton.width; height: cameraListButton.height + } + + CameraButton { + anchors.fill: parent + text: popup.currentItem != null ? popup.currentItem.displayName : "" + + onClicked: popup.toggle() + } + + CameraListPopup { + id: popup + anchors.right: parent.left + anchors.rightMargin: 16 + anchors.top: parent.top + visible: opacity > 0 + + currentValue: cameraListButton.value + + onSelected: popup.toggle() + } +} diff --git a/examples/multimedia/declarative-camera/CameraListPopup.qml b/examples/multimedia/declarative-camera/CameraListPopup.qml new file mode 100644 index 000000000..a28fd6cd2 --- /dev/null +++ b/examples/multimedia/declarative-camera/CameraListPopup.qml @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Popup { + id: cameraListPopup + + property alias model : view.model + property variant currentValue + property variant currentItem : model[view.currentIndex] + + property int itemWidth : 200 + property int itemHeight : 50 + + width: itemWidth + view.anchors.margins*2 + height: view.count * itemHeight + view.anchors.margins*2 + + signal selected + + ListView { + id: view + anchors.fill: parent + anchors.margins: 5 + snapMode: ListView.SnapOneItem + highlightFollowsCurrentItem: true + highlight: Rectangle { color: "gray"; radius: 5 } + currentIndex: 0 + + delegate: Item { + width: cameraListPopup.itemWidth + height: cameraListPopup.itemHeight + + Text { + text: modelData.displayName + + anchors.fill: parent + anchors.margins: 5 + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + elide: Text.ElideRight + color: "white" + font.bold: true + style: Text.Raised + styleColor: "black" + font.pixelSize: 14 + } + MouseArea { + anchors.fill: parent + onClicked: { + view.currentIndex = index + cameraListPopup.currentValue = modelData.deviceId + cameraListPopup.selected(modelData.deviceId) + } + } + } + } +} diff --git a/examples/multimedia/declarative-camera/CameraPropertyButton.qml b/examples/multimedia/declarative-camera/CameraPropertyButton.qml index 033f73415..fcb6bbba9 100644 --- a/examples/multimedia/declarative-camera/CameraPropertyButton.qml +++ b/examples/multimedia/declarative-camera/CameraPropertyButton.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 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. @@ -70,37 +70,11 @@ Item { anchors.right: parent.left anchors.rightMargin: 16 anchors.top: parent.top - state: "invisible" visible: opacity > 0 currentValue: propertyButton.value - states: [ - State { - name: "invisible" - PropertyChanges { target: popup; opacity: 0 } - }, - - State { - name: "visible" - PropertyChanges { target: popup; opacity: 1.0 } - } - ] - - transitions: Transition { - NumberAnimation { properties: "opacity"; duration: 100 } - } - - function toggle() { - if (state == "visible") - state = "invisible"; - else - state = "visible"; - } - - onSelected: { - popup.state = "invisible" - } + onSelected: popup.toggle() } } diff --git a/examples/multimedia/declarative-camera/CameraPropertyPopup.qml b/examples/multimedia/declarative-camera/CameraPropertyPopup.qml index 6ba8f36e7..0b00423c8 100644 --- a/examples/multimedia/declarative-camera/CameraPropertyPopup.qml +++ b/examples/multimedia/declarative-camera/CameraPropertyPopup.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 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. @@ -40,7 +40,7 @@ import QtQuick 2.0 -Rectangle { +Popup { id: propertyPopup property alias model : view.model @@ -54,12 +54,6 @@ Rectangle { width: columns*itemWidth + view.anchors.margins*2 height: Math.ceil(model.count/columns)*itemHeight + view.anchors.margins*2 + 25 - radius: 5 - border.color: "#000000" - border.width: 2 - smooth: true - color: "#5e5e5e" - signal selected function indexForValue(value) { diff --git a/examples/multimedia/declarative-camera/PhotoCaptureControls.qml b/examples/multimedia/declarative-camera/PhotoCaptureControls.qml index 2cd39b8cb..170114e3f 100644 --- a/examples/multimedia/declarative-camera/PhotoCaptureControls.qml +++ b/examples/multimedia/declarative-camera/PhotoCaptureControls.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 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. @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtMultimedia 5.0 +import QtMultimedia 5.4 FocusScope { property Camera camera @@ -53,7 +53,7 @@ FocusScope { Rectangle { id: buttonPaneShadow - width: buttonsColumn.width + 16 + width: bottomColumn.width + 16 height: parent.height anchors.top: parent.top anchors.right: parent.right @@ -130,12 +130,16 @@ FocusScope { id: bottomColumn spacing: 8 + CameraListButton { + model: QtMultimedia.availableCameras + onValueChanged: captureControls.camera.deviceId = value + } + CameraButton { text: "Switch to Video" onClicked: captureControls.videoModeSelected() } - CameraButton { id: quitButton text: "Quit" diff --git a/examples/multimedia/declarative-camera/Popup.qml b/examples/multimedia/declarative-camera/Popup.qml new file mode 100644 index 000000000..d93f6ecc1 --- /dev/null +++ b/examples/multimedia/declarative-camera/Popup.qml @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2014 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$ +** +****************************************************************************/ + +import QtQuick 2.0 + +Rectangle { + id: popup + + radius: 5 + border.color: "#000000" + border.width: 2 + smooth: true + color: "#5e5e5e" + + state: "invisible" + + states: [ + State { + name: "invisible" + PropertyChanges { target: popup; opacity: 0 } + }, + + State { + name: "visible" + PropertyChanges { target: popup; opacity: 1.0 } + } + ] + + transitions: Transition { + NumberAnimation { properties: "opacity"; duration: 100 } + } + + function toggle() { + if (state == "visible") + state = "invisible"; + else + state = "visible"; + } +} diff --git a/examples/multimedia/declarative-camera/VideoCaptureControls.qml b/examples/multimedia/declarative-camera/VideoCaptureControls.qml index e178ff15c..326467b46 100644 --- a/examples/multimedia/declarative-camera/VideoCaptureControls.qml +++ b/examples/multimedia/declarative-camera/VideoCaptureControls.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 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. @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtMultimedia 5.0 +import QtMultimedia 5.4 FocusScope { property Camera camera @@ -53,7 +53,7 @@ FocusScope { Rectangle { id: buttonPaneShadow - width: buttonsColumn.width + 16 + width: bottomColumn.width + 16 height: parent.height anchors.top: parent.top anchors.right: parent.right @@ -105,6 +105,11 @@ FocusScope { id: bottomColumn spacing: 8 + CameraListButton { + model: QtMultimedia.availableCameras + onValueChanged: captureControls.camera.deviceId = value + } + CameraButton { text: "Switch to Photo" onClicked: captureControls.photoModeSelected() diff --git a/examples/multimedia/declarative-camera/declarative-camera.qml b/examples/multimedia/declarative-camera/declarative-camera.qml index b22d5cfe9..751b38d71 100644 --- a/examples/multimedia/declarative-camera/declarative-camera.qml +++ b/examples/multimedia/declarative-camera/declarative-camera.qml @@ -39,7 +39,7 @@ ****************************************************************************/ import QtQuick 2.0 -import QtMultimedia 5.2 +import QtMultimedia 5.4 Rectangle { id : cameraUI diff --git a/examples/multimedia/declarative-camera/declarative-camera.qrc b/examples/multimedia/declarative-camera/declarative-camera.qrc index d99b86c0c..6d654d59f 100644 --- a/examples/multimedia/declarative-camera/declarative-camera.qrc +++ b/examples/multimedia/declarative-camera/declarative-camera.qrc @@ -7,9 +7,12 @@ FocusButton.qml PhotoCaptureControls.qml declarative-camera.qml + Popup.qml CameraPropertyPopup.qml CameraPropertyButton.qml CameraButton.qml + CameraListPopup.qml + CameraListButton.qml images/camera_auto_mode.png images/camera_camera_setting.png images/camera_flash_auto.png -- cgit v1.2.3