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 <christian.stromme@digia.com>
This commit is contained in:
Yoann Lopes
2014-02-10 19:33:51 +01:00
parent cddbe8736d
commit 888759e334
32 changed files with 1297 additions and 89 deletions

View File

@@ -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
}
}

View File

@@ -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()
}
}

View File

@@ -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)
}
}
}
}
}

View File

@@ -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()
}
}

View File

@@ -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) {

View File

@@ -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"

View File

@@ -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";
}
}

View File

@@ -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()

View File

@@ -39,7 +39,7 @@
****************************************************************************/
import QtQuick 2.0
import QtMultimedia 5.2
import QtMultimedia 5.4
Rectangle {
id : cameraUI

View File

@@ -7,9 +7,12 @@
<file>FocusButton.qml</file>
<file>PhotoCaptureControls.qml</file>
<file>declarative-camera.qml</file>
<file>Popup.qml</file>
<file>CameraPropertyPopup.qml</file>
<file>CameraPropertyButton.qml</file>
<file>CameraButton.qml</file>
<file>CameraListPopup.qml</file>
<file>CameraListButton.qml</file>
<file>images/camera_auto_mode.png</file>
<file>images/camera_camera_setting.png</file>
<file>images/camera_flash_auto.png</file>