From b2e97817684f40ab9353fa279a4c02ef9c12e13d Mon Sep 17 00:00:00 2001 From: Lincoln Ramsay Date: Tue, 19 Jun 2012 15:47:09 +1000 Subject: Remove the 'special' naming of examples. Just go back to the naming convention we had before. Change-Id: Iefecb7a5e0ab3aa4d22267b4f475a8e9c1c96058 Reviewed-by: Lorn Potter --- examples/sensors/sensor_explorer/PropertyList.qml | 130 +++++++++ examples/sensors/sensor_explorer/SensorList.qml | 149 ++++++++++ .../components/ApplicationWindow.qml | 51 ++++ .../sensors/sensor_explorer/components/Button.qml | 75 +++++ .../sensor_explorer/components/TextField.qml | 109 +++++++ .../images/button_background_disabled.png | Bin 0 -> 579 bytes .../components/images/button_background_normal.png | Bin 0 -> 901 bytes .../images/button_background_pressed.png | Bin 0 -> 334 bytes .../images/textfield_background_disabled.png | Bin 0 -> 936 bytes .../images/textfield_background_normal.png | Bin 0 -> 767 bytes .../sensor_explorer/content/listitem_select.png | Bin 0 -> 156 bytes examples/sensors/sensor_explorer/icon.png | Bin 0 -> 2205 bytes .../sensors/sensor_explorer/import/explorer.cpp | 143 +++++++++ examples/sensors/sensor_explorer/import/explorer.h | 79 +++++ examples/sensors/sensor_explorer/import/import.pro | 25 ++ examples/sensors/sensor_explorer/import/main.cpp | 66 +++++ .../sensors/sensor_explorer/import/plugin.json | 1 + .../sensor_explorer/import/propertyinfo.cpp | 140 +++++++++ .../sensors/sensor_explorer/import/propertyinfo.h | 83 ++++++ examples/sensors/sensor_explorer/import/qmldir | 1 + .../sensors/sensor_explorer/import/sensoritem.cpp | 322 +++++++++++++++++++++ .../sensors/sensor_explorer/import/sensoritem.h | 96 ++++++ examples/sensors/sensor_explorer/info.json | 15 + examples/sensors/sensor_explorer/qml.pro | 16 + .../sensors/sensor_explorer/sensor_explorer.pro | 6 + .../sensors/sensor_explorer/sensor_explorer.qml | 196 +++++++++++++ 26 files changed, 1703 insertions(+) create mode 100644 examples/sensors/sensor_explorer/PropertyList.qml create mode 100644 examples/sensors/sensor_explorer/SensorList.qml create mode 100644 examples/sensors/sensor_explorer/components/ApplicationWindow.qml create mode 100644 examples/sensors/sensor_explorer/components/Button.qml create mode 100644 examples/sensors/sensor_explorer/components/TextField.qml create mode 100644 examples/sensors/sensor_explorer/components/images/button_background_disabled.png create mode 100644 examples/sensors/sensor_explorer/components/images/button_background_normal.png create mode 100644 examples/sensors/sensor_explorer/components/images/button_background_pressed.png create mode 100644 examples/sensors/sensor_explorer/components/images/textfield_background_disabled.png create mode 100644 examples/sensors/sensor_explorer/components/images/textfield_background_normal.png create mode 100644 examples/sensors/sensor_explorer/content/listitem_select.png create mode 100644 examples/sensors/sensor_explorer/icon.png create mode 100644 examples/sensors/sensor_explorer/import/explorer.cpp create mode 100644 examples/sensors/sensor_explorer/import/explorer.h create mode 100644 examples/sensors/sensor_explorer/import/import.pro create mode 100644 examples/sensors/sensor_explorer/import/main.cpp create mode 100644 examples/sensors/sensor_explorer/import/plugin.json create mode 100644 examples/sensors/sensor_explorer/import/propertyinfo.cpp create mode 100644 examples/sensors/sensor_explorer/import/propertyinfo.h create mode 100644 examples/sensors/sensor_explorer/import/qmldir create mode 100644 examples/sensors/sensor_explorer/import/sensoritem.cpp create mode 100644 examples/sensors/sensor_explorer/import/sensoritem.h create mode 100644 examples/sensors/sensor_explorer/info.json create mode 100644 examples/sensors/sensor_explorer/qml.pro create mode 100644 examples/sensors/sensor_explorer/sensor_explorer.pro create mode 100644 examples/sensors/sensor_explorer/sensor_explorer.qml (limited to 'examples/sensors/sensor_explorer') diff --git a/examples/sensors/sensor_explorer/PropertyList.qml b/examples/sensors/sensor_explorer/PropertyList.qml new file mode 100644 index 00000000..846c4cca --- /dev/null +++ b/examples/sensors/sensor_explorer/PropertyList.qml @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module 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 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$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 +import Explorer 1.0 + +Rectangle { + id: controlrect + anchors.margins: 5 + color: "transparent" + + property PropertyInfo selectedItem: null; + signal selectedItemChanged(); + property alias listmodel: itemList.model + + onListmodelChanged: { + itemList.currentIndex = -1; + selectedItem = null; + selectedItemChanged(); + } + + Rectangle { + id: itemListRect + anchors.fill: parent + color: "transparent" + + ListView { + id: itemList + anchors.fill: itemListRect + anchors.leftMargin: 5 + anchors.rightMargin: 5 + focus: true + currentIndex: -1 + delegate: itemListDelegate + clip: true + + Rectangle { + id: scrollbar + anchors.right: itemList.right + y: itemList.visibleArea.yPosition * itemList.height + width: 2 + height: itemList.visibleArea.heightRatio * itemList.height + color: "black" + } + } + + Component { + id: itemListDelegate + + Rectangle { + width: itemList.width + height: itemNameText.font.pixelSize + 3 + color: "transparent" + + Image { + id: backgroundImage + anchors.fill: parent + source: "content/listitem_select.png" + visible: itemList.currentIndex === index + } + + Text { + id: itemNameText + text: model.modelData.name + font.pixelSize: 15 + color: (itemList.currentIndex === index ? "#1c94ff" : "black") + } + + Text { + id: itemValueText + anchors.left: parent.left + anchors.right: parent.right + anchors.rightMargin: 5 + font.pixelSize: 15 + horizontalAlignment: Text.AlignRight + text: model.modelData.value + color: (itemList.currentIndex === index ? "#1c94ff" : "black") + } + + MouseArea { + anchors.fill: parent + + onClicked: { + itemList.currentIndex = index; + selectedItem = model.modelData; + selectedItemChanged(); + } + } + } + } + } +} diff --git a/examples/sensors/sensor_explorer/SensorList.qml b/examples/sensors/sensor_explorer/SensorList.qml new file mode 100644 index 00000000..da157378 --- /dev/null +++ b/examples/sensors/sensor_explorer/SensorList.qml @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module 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 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$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 +import Explorer 1.0 + +Rectangle { + id: controlrect + anchors.margins: 5 + color: "transparent" + + property SensorItem selectedItem: null; + signal selectedItemChanged(); + property alias title: labelTitle.text + property alias listmodel: itemList.model + + onListmodelChanged: { + itemList.currentIndex = -1; + selectedItem = null; + selectedItemChanged(); + } + + Text { + id: labelTitle + anchors.top: controlrect.top + anchors.left: controlrect.left + anchors.right: controlrect.right + horizontalAlignment: Text.AlignHCenter + font.pixelSize: 30 + font.bold: true + text: "" + } + + Rectangle { + id: titleLine + anchors.top: labelTitle.bottom + anchors.left: controlrect.left + anchors.right: controlrect.right + height: 1 + border.width: 1 + border.color: "#999999" + } + + Rectangle { + id: itemListRect + anchors.top: titleLine.bottom + anchors.left: controlrect.left + anchors.right: controlrect.right + anchors.bottom: controlrect.bottom + color: "transparent" + + ListView { + id: itemList + anchors.fill: itemListRect + anchors.leftMargin: 5 + anchors.rightMargin: 5 + focus: true + currentIndex: -1 + delegate: itemListDelegate + clip: true + + Rectangle { + id: scrollbar + anchors.right: itemList.right + y: itemList.visibleArea.yPosition * itemList.height + width: 2 + height: itemList.visibleArea.heightRatio * itemList.height + color: "black" + } + } + + Component { + id: itemListDelegate + + Rectangle { + width: itemList.width + height: 30 + color: "transparent" + + Image { + id: backgroundImage + anchors.fill: parent + source: "content/listitem_select.png" + visible: itemList.currentIndex === index + } + + Text { + id: itemText + height: 30 + anchors.top: parent.top + anchors.left: parent.left + anchors.leftMargin: 5 + text: model.modelData.id + color: (itemList.currentIndex === index ? "#1c94ff" : "black") + verticalAlignment: Text.AlignVCenter + font.pixelSize: 15 + } + + MouseArea { + anchors.fill: parent + + onClicked: { + itemList.currentIndex = index; + selectedItem = model.modelData; + selectedItemChanged(); + } + } + } + } + } +} diff --git a/examples/sensors/sensor_explorer/components/ApplicationWindow.qml b/examples/sensors/sensor_explorer/components/ApplicationWindow.qml new file mode 100644 index 00000000..cab5e94c --- /dev/null +++ b/examples/sensors/sensor_explorer/components/ApplicationWindow.qml @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module 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 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$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +Rectangle { + id: appWnd + x: 0 + y: 0 + width: 320 + height: 480 + color: "#ececec" +} diff --git a/examples/sensors/sensor_explorer/components/Button.qml b/examples/sensors/sensor_explorer/components/Button.qml new file mode 100644 index 00000000..537a8bce --- /dev/null +++ b/examples/sensors/sensor_explorer/components/Button.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module 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 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$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +//Implementation of the Button control. +Item { + id: button + width: 30 + height: 100 + property alias text: innerText.text + signal clicked + + Image { + id: backgroundImage + anchors.fill: parent + source: (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") + } + + Text { + id: innerText + anchors.centerIn: parent + color: "white" + font.bold: true + } + + //Mouse area to react on click events + MouseArea { + anchors.fill: button + onClicked: { button.clicked();} + onPressed: { + backgroundImage.source = "images/button_background_pressed.png" } + onReleased: { + backgroundImage.source = (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") + } + } +} diff --git a/examples/sensors/sensor_explorer/components/TextField.qml b/examples/sensors/sensor_explorer/components/TextField.qml new file mode 100644 index 00000000..c1feaf21 --- /dev/null +++ b/examples/sensors/sensor_explorer/components/TextField.qml @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module 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 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$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 + +Item { + id: textInputFrame + property alias text: textInput.text + signal accepted + + resources: [ + Component{ + id: cursorA + Rectangle { + id: cursor_rect + width: 2 + height: 20 + color: "#1c94ff" + visible: textInput.cursorVisible + + PropertyAnimation on opacity { + easing.type: Easing.OutSine + loops: Animation.Infinite + from: 0 + to: 1.0 + duration: 750 + } + } + } + ] + + Image { + id: backgroundImage + anchors.fill: parent + source: (textInputFrame.enabled ? "images/textfield_background_normal.png" : "images/textfield_background_disabled.png") + } + + TextInput { + id: textInput + anchors.fill: parent + anchors.topMargin: 5 + anchors.leftMargin: 5 + anchors.rightMargin: 5 + activeFocusOnPress: false + + cursorDelegate: cursorA + + onEnabledChanged: { + textInput.focus = false; + } + + onAccepted: { + textInputFrame.accepted(); + } + + MouseArea { + anchors.fill: parent + + onClicked: { + if (!textInput.activeFocus) { + textInput.forceActiveFocus() + textInput.openSoftwareInputPanel(); + } else { + textInput.focus = false; + } + } + + onPressAndHold: textInput.closeSoftwareInputPanel(); + } + } +} diff --git a/examples/sensors/sensor_explorer/components/images/button_background_disabled.png b/examples/sensors/sensor_explorer/components/images/button_background_disabled.png new file mode 100644 index 00000000..62a00b9a Binary files /dev/null and b/examples/sensors/sensor_explorer/components/images/button_background_disabled.png differ diff --git a/examples/sensors/sensor_explorer/components/images/button_background_normal.png b/examples/sensors/sensor_explorer/components/images/button_background_normal.png new file mode 100644 index 00000000..1fecad5b Binary files /dev/null and b/examples/sensors/sensor_explorer/components/images/button_background_normal.png differ diff --git a/examples/sensors/sensor_explorer/components/images/button_background_pressed.png b/examples/sensors/sensor_explorer/components/images/button_background_pressed.png new file mode 100644 index 00000000..149529e1 Binary files /dev/null and b/examples/sensors/sensor_explorer/components/images/button_background_pressed.png differ diff --git a/examples/sensors/sensor_explorer/components/images/textfield_background_disabled.png b/examples/sensors/sensor_explorer/components/images/textfield_background_disabled.png new file mode 100644 index 00000000..98bc601f Binary files /dev/null and b/examples/sensors/sensor_explorer/components/images/textfield_background_disabled.png differ diff --git a/examples/sensors/sensor_explorer/components/images/textfield_background_normal.png b/examples/sensors/sensor_explorer/components/images/textfield_background_normal.png new file mode 100644 index 00000000..b90b50cd Binary files /dev/null and b/examples/sensors/sensor_explorer/components/images/textfield_background_normal.png differ diff --git a/examples/sensors/sensor_explorer/content/listitem_select.png b/examples/sensors/sensor_explorer/content/listitem_select.png new file mode 100644 index 00000000..def234f1 Binary files /dev/null and b/examples/sensors/sensor_explorer/content/listitem_select.png differ diff --git a/examples/sensors/sensor_explorer/icon.png b/examples/sensors/sensor_explorer/icon.png new file mode 100644 index 00000000..c48b6095 Binary files /dev/null and b/examples/sensors/sensor_explorer/icon.png differ diff --git a/examples/sensors/sensor_explorer/import/explorer.cpp b/examples/sensors/sensor_explorer/import/explorer.cpp new file mode 100644 index 00000000..12b35f9e --- /dev/null +++ b/examples/sensors/sensor_explorer/import/explorer.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "explorer.h" +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/* + \class QSensorExplorer + \brief The QSensorExplorer type provides an easy access for reading all avalaible sensors installed on the system. +*/ + +/* + Construct a QSensorExplorer object with parent \a parent +*/ +QSensorExplorer::QSensorExplorer(QObject* parent) + : QObject(parent) + , _selectedSensorItem(0) +{ + loadSensors(); +} + +/* + Destructor of a QSensorExplorer +*/ +QSensorExplorer::~QSensorExplorer() +{ +} + +/* + Load all available sensors and store it in a list. +*/ +void QSensorExplorer::loadSensors() +{ + //! [0] + _availableSensors.clear(); + + foreach (const QByteArray &type, QSensor::sensorTypes()) { + qDebug() << "Found type" << type; + foreach (const QByteArray &identifier, QSensor::sensorsForType(type)) { + qDebug() << "Found identifier" << identifier; + // Don't put in sensors we can't connect to + QSensor* sensor = new QSensor(type, this); + sensor->setIdentifier(identifier); + if (!sensor->connectToBackend()) { + qDebug() << "Couldn't connect to" << identifier; + continue; + } + + qDebug() << "Adding identifier" << identifier; + _availableSensors.append(new QSensorItem(sensor, this)); + } + } + emit availableSensorsChanged(); + //! [0] +} + +/* + \fn QSensorExplorer::availableSensorsChanged() + Notifies the client if the list of the available sensors was changed +*/ + +/* + \property QSensorExplorer::availableSensors + Returns a list of all available sensor. +*/ +QQmlListProperty QSensorExplorer::availableSensors() +{ + return QQmlListProperty(this,_availableSensors); +} + +/* + \fn QSensorExplorer::selectedSensorItemChanged() + Notifies the client if the selected sensor has been changed +*/ + +/* + \property QSensorExplorer::selectedSensorItem + Returns the current selected sensor item. +*/ +QSensorItem* QSensorExplorer::selectedSensorItem() +{ + return _selectedSensorItem; +} + +/* + \fn QSensorExplorer::setSelectedSensorItem(QSensorItem* selitem) + Sets the QSensorItem \a selitem as the current selected QSensorItem. +*/ +void QSensorExplorer::setSelectedSensorItem(QSensorItem* selitem) +{ + if (selitem && _selectedSensorItem != selitem) { + if (_selectedSensorItem) + _selectedSensorItem->unSelect(); + _selectedSensorItem = selitem; + _selectedSensorItem->select(); + emit selectedSensorItemChanged(); + } +} + +QT_END_NAMESPACE diff --git a/examples/sensors/sensor_explorer/import/explorer.h b/examples/sensors/sensor_explorer/import/explorer.h new file mode 100644 index 00000000..eaac8104 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/explorer.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSEONSOREXPLORER_H +#define QSEONSOREXPLORER_H + +#include +#include +#include "sensoritem.h" + +QT_BEGIN_NAMESPACE + +class QSensorExplorer : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty availableSensors READ availableSensors NOTIFY availableSensorsChanged) + Q_PROPERTY(QSensorItem* selectedSensorItem READ selectedSensorItem WRITE setSelectedSensorItem NOTIFY selectedSensorItemChanged) +public: + QSensorExplorer(QObject* parent = 0); + virtual ~QSensorExplorer(); + +private: + QQmlListProperty availableSensors(); + void loadSensors(); + void setSelectedSensorItem(QSensorItem* selitem); + QSensorItem* selectedSensorItem(); + +Q_SIGNALS: + void availableSensorsChanged(); + void selectedSensorItemChanged(); + +private: + QList _availableSensors; + QSensorItem* _selectedSensorItem; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QSensorExplorer) + +#endif // QSEONSOREXPLORER_H diff --git a/examples/sensors/sensor_explorer/import/import.pro b/examples/sensors/sensor_explorer/import/import.pro new file mode 100644 index 00000000..1f97b67e --- /dev/null +++ b/examples/sensors/sensor_explorer/import/import.pro @@ -0,0 +1,25 @@ +TEMPLATE = lib +CONFIG += plugin + +TARGET = $$qtLibraryTarget(declarative_explorer) +TARGETPATH = Explorer + +QT += qml sensors + +SOURCES = main.cpp explorer.cpp sensoritem.cpp propertyinfo.cpp +HEADERS = explorer.h sensoritem.h propertyinfo.h + +MT_SYSROOT=$$(MT_SYSROOT) +!isEmpty(MT_SYSROOT):EXAMPLES_PREFIX=/opt/mt/applications +!isEmpty(EXAMPLES_PREFIX):DESTPATH=$$EXAMPLES_PREFIX/com.nokia.mt.sensor_explorer/imports/Explorer +else:DESTPATH=$$[QT_INSTALL_IMPORTS]/Explorer + +target.path=$$DESTPATH +INSTALLS += target + +qmldir.files=$$PWD/qmldir +qmldir.path=$$DESTPATH +INSTALLS += qmldir + +OTHER_FILES += \ + plugin.json qmldir diff --git a/examples/sensors/sensor_explorer/import/main.cpp b/examples/sensors/sensor_explorer/import/main.cpp new file mode 100644 index 00000000..80e2510d --- /dev/null +++ b/examples/sensors/sensor_explorer/import/main.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module 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 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 +#include +#include "explorer.h" +#include + +QT_BEGIN_NAMESPACE + +class SensorExplorerDeclarativeModule : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface" FILE "plugin.json") +public: + virtual void registerTypes(const char *uri) + { + qDebug() << "SensorExplorerDeclarativeModule::registerTypes(const char *uri)"; + + Q_ASSERT(QLatin1String(uri) == QLatin1String("Explorer")); + qmlRegisterType(uri, 1, 0, "SensorExplorer"); + qmlRegisterType(uri, 1, 0, "SensorItem"); + qmlRegisterType(uri, 1, 0, "PropertyInfo"); + } +}; + +QT_END_NAMESPACE + +#include "main.moc" diff --git a/examples/sensors/sensor_explorer/import/plugin.json b/examples/sensors/sensor_explorer/import/plugin.json new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/plugin.json @@ -0,0 +1 @@ +{} diff --git a/examples/sensors/sensor_explorer/import/propertyinfo.cpp b/examples/sensors/sensor_explorer/import/propertyinfo.cpp new file mode 100644 index 00000000..00f43e44 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/propertyinfo.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensoritem.h" +#include +#include + +QT_BEGIN_NAMESPACE + +/* + \class QPropertyInfo + \brief The QPropertyInfo type provides an easy access for reading and writing the property values. +*/ + +/* + Construct a QPropertyInfo object with parent \a parent +*/ +QPropertyInfo::QPropertyInfo(QObject* parent) + : QObject(parent) + , _index(0) + , _isWriteable(false) + , _name("") + , _typeName("") + , _value("") +{} + +/* + Construct a QPropertyInfo object with parent \a parent, property name \a name, property index \a index, + property write access \a writeable, property type \a typeName and property value \a value +*/ +QPropertyInfo::QPropertyInfo(const QString& name, int index, bool writeable, const QString& typeName, const QString& value, QObject* parent) + : QObject(parent) + , _index(index) + , _isWriteable(writeable) + , _name(name) + , _typeName(typeName) + , _value(value) +{} + +/* + \property QPropertyInfo::name + Returns the name of the property +*/ +QString QPropertyInfo::name() +{ + return _name; +} + +/* + \property QPropertyInfo::typeName + Returns the type of the property +*/ +QString QPropertyInfo::typeName() +{ + return _typeName; +} + +/* + \property QPropertyInfo::value + Returns the current value of the property +*/ +QString QPropertyInfo::value() +{ + return _value; +} + +/* + \fn void QPropertyInfo::valueChanged() + Signal that notifies the client if the property value was changed. +*/ + +/* + \fn QPropertyInfo::setValue(const QString& value) + Sets the value \a value of the property +*/ +void QPropertyInfo::setValue(const QString& value) +{ + if (value != _value){ + _value = value; + emit valueChanged(); + } +} + +/* + \fn QPropertyInfo::index() + Returns the meta-data index of the property +*/ +int QPropertyInfo::index() +{ + return _index; +} + +/* + \property QPropertyInfo::isWriteable + Returns true if the property is writeable false if property is read only +*/ +bool QPropertyInfo::isWriteable() +{ + return _isWriteable; +} + +QT_END_NAMESPACE diff --git a/examples/sensors/sensor_explorer/import/propertyinfo.h b/examples/sensors/sensor_explorer/import/propertyinfo.h new file mode 100644 index 00000000..b3ebe4c0 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/propertyinfo.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPROPERTYINFO_H +#define QPROPERTYINFO_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class QPropertyInfo : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name READ name CONSTANT) + Q_PROPERTY(QString typeName READ typeName CONSTANT) + Q_PROPERTY(QString value READ value NOTIFY valueChanged) + Q_PROPERTY(bool isWriteable READ isWriteable CONSTANT) + +public: + QPropertyInfo(QObject* parent = 0); + QPropertyInfo(const QString& name, int index, bool writeable, const QString& typeName, const QString& value, QObject* parent=0); + QString name(); + QString typeName(); + QString value(); + void setValue(const QString& value); + int index(); + bool isWriteable(); + +Q_SIGNALS: + void valueChanged(); + +private: + int _index; + bool _isWriteable; + QString _name; + QString _typeName; + QString _value; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QPropertyInfo) + +#endif // QPROPERTYINFO_H diff --git a/examples/sensors/sensor_explorer/import/qmldir b/examples/sensors/sensor_explorer/import/qmldir new file mode 100644 index 00000000..60d8f883 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/qmldir @@ -0,0 +1 @@ +plugin declarative_explorer diff --git a/examples/sensors/sensor_explorer/import/sensoritem.cpp b/examples/sensors/sensor_explorer/import/sensoritem.cpp new file mode 100644 index 00000000..dd9d0365 --- /dev/null +++ b/examples/sensors/sensor_explorer/import/sensoritem.cpp @@ -0,0 +1,322 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "sensoritem.h" +#include +#include + +QT_BEGIN_NAMESPACE + +/* + \class QSensorItem + \brief The QSensorItem type provides information about the meta-datas from a sensors installed on the system. +*/ + +/* + Construct a QSensorItem object with parent \a parent +*/ +QSensorItem::QSensorItem(QObject* parent) + : QObject(parent) + , _qsensor(0) +{ +} + +/* + Construct a QSensorItem object with QSensor \a sensor and parent \a parent +*/ +QSensorItem::QSensorItem(QSensor* sensor, QObject* parent) + : QObject(parent) + , _qsensor(sensor) +{ +} + +/* + Destructor of a QSensorItem +*/ +QSensorItem::~QSensorItem() +{ +} + +/* + \fn QSensorItem::startChanged() + Notifies the client if the sensors has changed its start active status +*/ + +/* + \property QSensorItem::start + This property starts or stops the sensor +*/ +bool QSensorItem::start() +{ + return (_qsensor ? _qsensor->isActive() : false); +} + +void QSensorItem::setStart(bool run) +{ + if (_qsensor) + _qsensor->setActive(run); +} + +/* + \property QSensorItem::id + Returns the sensor id of the sensor item +*/ +QString QSensorItem::id() +{ + return (_qsensor ? _qsensor->identifier() : ""); +} + +/* + Set the new value \a val to the QPropertyInfo object \a property +*/ +void QSensorItem::changePropertyValue(QPropertyInfo* property, const QString& val) +{ + if (_qsensor && _sensorProperties.contains(property)){ + if ( _qsensor->setProperty(property->name().toLatin1().constData(), QVariant(val))) + updateSensorPropertyValues(); + else + qWarning() << "new property value couldn't be set"; + } +} + +/* + Reading the meta-datas and activates the sensor. +*/ +void QSensorItem::select() +{ + if (_sensorProperties.isEmpty()) { + // Probe the reading using Qt's meta-object facilities + //Read properties from reader + QSensorReading *reading = _qsensor->reading(); + const QMetaObject *mo = reading->metaObject(); + int firstProperty = QSensorReading::staticMetaObject.propertyOffset(); + + for (int i = firstProperty; i < mo->propertyCount(); ++i) { + QString typeName = QLatin1String(mo->property(i).typeName()); + int crap = typeName.lastIndexOf("::"); + if (crap != -1) + typeName = typeName.mid(crap + 2); + + QPropertyInfo* pi = new QPropertyInfo(mo->property(i).name() + , i + , isWriteable(mo->property(i).name()) + , typeName + , "-" + , this); + _readerProperties.append(pi); + } + + //Read properties from sensor + const QMetaObject *mo1 = _qsensor->metaObject(); + firstProperty = QSensorReading::staticMetaObject.propertyOffset(); + + for (int i = firstProperty; i < mo1->propertyCount(); ++i) { + QString propertyname = mo1->property(i).name(); + if (ignoreProperty(propertyname)) + continue; + + QString typeName = QLatin1String(mo1->property(i).typeName()); + int crap = typeName.lastIndexOf("::"); + if (crap != -1) + typeName = typeName.mid(crap + 2); + + QPropertyInfo* pi = new QPropertyInfo(propertyname + , i + , isWriteable(propertyname) + , typeName + , "-" + , this); + _sensorProperties.append(pi); + } + updateSensorPropertyValues(); + connect(_qsensor, SIGNAL(readingChanged()), this, SLOT(sensorReadingChanged())); + } + connect(_qsensor, SIGNAL(activeChanged()), SIGNAL(startChanged())); +} + +/* + Unselect the sensor by stopping the sensor. +*/ +void QSensorItem::unSelect() +{ + _qsensor->stop(); + disconnect(_qsensor, SIGNAL(activeChanged()), this , SIGNAL(startChanged())); +} + +/* + Updates the property values from QSensor +*/ +void QSensorItem::updateSensorPropertyValues() +{ + if (_qsensor){ + const QMetaObject *mo = _qsensor->metaObject(); + for (int i = 0; i < _sensorProperties.count(); i++){ + QVariant val = mo->property(_sensorProperties[i]->index()).read(_qsensor); + _sensorProperties[i]->setValue(convertValue(_sensorProperties[i]->typeName(), val)); + } + } +} + +/* + \fn QSensorItem::propertiesChanged() + Notifies the client if the list of the properties was changed +*/ + +/* + Updates the property values from the QSensorReader +*/ +void QSensorItem::sensorReadingChanged() +{ + QSensorReading *reading = _qsensor->reading(); + const QMetaObject *mo = reading->metaObject(); + for (int i = 0; i < _readerProperties.count(); i++){ + QVariant val = mo->property(_readerProperties[i]->index()).read(reading); + _readerProperties[i]->setValue(convertValue(_readerProperties[i]->typeName(), val)); + } +} + +/* + Returns true if the property with the name \a propertyname should be ignored +*/ +bool QSensorItem::ignoreProperty(const QString& propertyname) +{ + if (propertyname == "reading" || + propertyname == "active" || + propertyname == "sensorid" || + propertyname == "connectedToBackend" || + propertyname == "busy") + return true; + + return false; +} + +/* + Returns true if the property with the name \a propertyname is writeable +*/ +bool QSensorItem::isWriteable(const QString& propertyname) +{ + if (_qsensor){ + const QMetaObject *mo = _qsensor->metaObject(); + int propertyindex = mo->indexOfProperty(propertyname.toLocal8Bit().constData()); + if (propertyindex >= 0){ + QMetaProperty prop = mo->property(propertyindex); + return prop.isWritable(); + } + else { + QSensorReading *reading = _qsensor->reading(); + const QMetaObject *moreader = reading->metaObject(); + propertyindex = moreader->indexOfProperty(propertyname.toLocal8Bit().constData()); + if (propertyindex >= 0){ + QMetaProperty prop = mo->property(propertyindex); + return prop.isWritable(); + } + } + } + + return false; +} + +/* + Convert the variant \a val dependend on the type \a type and returns the converted value as a QString +*/ +QString QSensorItem::convertValue(const QString& type, const QVariant& val) +{ + if (type == "LightLevel"){ + switch (val.toInt()) { + case 1: return "Dark"; + case 2: return "Twilight"; + case 3: return "Light"; + case 4: return "Bright"; + case 5: return "Sunny"; + default: return "Undefined"; + } + } + else if (type == "Orientation"){ + switch (val.toInt()) { + case 1: return "TopUp"; + case 2: return "TopDown"; + case 3: return "LeftUp"; + case 4: return "RightUp"; + case 5: return "FaceUp"; + case 6: return "FaceDown"; + default: return "Undefined"; + } + } + else if (type == "qrangelist"){ + qrangelist rangelist = val.value(); + QStringList ranges; + foreach (const qrange &r, rangelist) { + if (r.first == r.second) + ranges << QString("%1 Hz").arg(r.first); + else + ranges << QString("%1-%2 Hz").arg(r.first).arg(r.second); + } + if (ranges.count() > 0) + return ranges.join(", "); + return "-"; + } + else if (type == "qoutputrangelist") { + qoutputrangelist rangelist = val.value(); + QStringList ranges; + foreach (const qoutputrange &r, rangelist) { + ranges << QString("(%1, %2) += %3").arg(r.minimum).arg(r.maximum).arg(r.accuracy); + } + if (ranges.count() > 0) + return ranges.join(", "); + return "-"; + } + + return val.toString(); +} + +/* + \property QSensorItem::properties + Returns a list of all properties from the sensor +*/ +QQmlListProperty QSensorItem::properties() +{ + _properties.clear(); + _properties.append(_sensorProperties); + _properties.append(_readerProperties); + return QQmlListProperty (this, _properties); +} + +QT_END_NAMESPACE diff --git a/examples/sensors/sensor_explorer/import/sensoritem.h b/examples/sensors/sensor_explorer/import/sensoritem.h new file mode 100644 index 00000000..b937687f --- /dev/null +++ b/examples/sensors/sensor_explorer/import/sensoritem.h @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSENSORITEM_H +#define QSENSORITEM_H + +#include +#include +#include "propertyinfo.h" + +QT_BEGIN_NAMESPACE + +class QSensor; +class QSensorItem : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool start READ start WRITE setStart NOTIFY startChanged) + Q_PROPERTY(QString id READ id CONSTANT) + Q_PROPERTY(QQmlListProperty properties READ properties NOTIFY propertiesChanged) +public: + QSensorItem(QObject* parent = 0); + QSensorItem(QSensor* sensor, QObject* parent = 0); + virtual ~QSensorItem(); + +public slots: + void select(); + void unSelect(); + void changePropertyValue(QPropertyInfo* property, const QString& val); + +private slots: + void sensorReadingChanged(); + +private: + QString id(); + bool start(); + void setStart(bool run); + QQmlListProperty properties(); + QString convertValue(const QString& type, const QVariant& val); + bool isWriteable(const QString& propertyname); + bool ignoreProperty(const QString& propertyname); + void updateSensorPropertyValues(); + +Q_SIGNALS: + void propertiesChanged(); + void startChanged(); + +private: + QSensor* _qsensor; + QList _properties; + QList _readerProperties; + QList _sensorProperties; +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QSensorItem) + +#endif // QSENSORITEM_H diff --git a/examples/sensors/sensor_explorer/info.json b/examples/sensors/sensor_explorer/info.json new file mode 100644 index 00000000..18f3e8d5 --- /dev/null +++ b/examples/sensors/sensor_explorer/info.json @@ -0,0 +1,15 @@ +{ + "info-version": "1.0", + "dict": { + "category": "application", + "runtime": "qml", + "displayName": { + "en_US": "Sensors Explorer" + }, + "subcategory": "utility", + "main": "QtSensors_sensor_explorer.qml", + "version": "1.0.0", + "identifier": "com.nokia.mt.sensorexplorer", + "author": "Qt" + } +} diff --git a/examples/sensors/sensor_explorer/qml.pro b/examples/sensors/sensor_explorer/qml.pro new file mode 100644 index 00000000..fae3705d --- /dev/null +++ b/examples/sensors/sensor_explorer/qml.pro @@ -0,0 +1,16 @@ +TEMPLATE = aux + +app.files = \ + info.json \ + $$files(*.qml) \ + icon.png \ + components \ + content + +MT_SYSROOT=$$(MT_SYSROOT) +!isEmpty(MT_SYSROOT):EXAMPLES_PREFIX=/opt/mt/applications +!isEmpty(EXAMPLES_PREFIX) { + app.path = $$EXAMPLES_PREFIX/com.nokia.mt.sensor_explorer + INSTALLS = app +} + diff --git a/examples/sensors/sensor_explorer/sensor_explorer.pro b/examples/sensors/sensor_explorer/sensor_explorer.pro new file mode 100644 index 00000000..85ba45ef --- /dev/null +++ b/examples/sensors/sensor_explorer/sensor_explorer.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs +CONFIG += ordered + +SUBDIRS = \ + import \ + qml.pro diff --git a/examples/sensors/sensor_explorer/sensor_explorer.qml b/examples/sensors/sensor_explorer/sensor_explorer.qml new file mode 100644 index 00000000..88641604 --- /dev/null +++ b/examples/sensors/sensor_explorer/sensor_explorer.qml @@ -0,0 +1,196 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtSensors module 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 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$ +** +****************************************************************************/ + +//Import the declarative plugins +import QtQuick 2.0 +import "components" + +//! [0] +import Explorer 1.0 +//! [0] + +ApplicationWindow { + id: mainWnd + +//! [1] + SensorExplorer { + id: explorer + } +//! [1] + + SensorList { + id: sensorList + anchors.top: parent.top + anchors.topMargin: 20 + anchors.left: parent.left + anchors.right: parent.right + height: 170 + title: "sensor explorer" + +//! [2] + listmodel: explorer.availableSensors +//! [2] + + onSelectedItemChanged: { + explorer.selectedSensorItem = sensorList.selectedItem; + startstopButton.text=(explorer.selectedSensorItem !== null ? + (explorer.selectedSensorItem.start === true ? "Stop" : "Start") : "Start") + if (sensorList.selectedItem !== null) + +//! [3] + propertyList.listmodel = sensorList.selectedItem.properties; +//! [3] + } + } + + Rectangle { + id: listSplitLine + anchors.top: sensorList.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.leftMargin: 5 + anchors.rightMargin: 5 + height: 1 + border.width: 1 + border.color: "#999999" + } + + PropertyList { + id: propertyList + anchors.top: listSplitLine.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: listPropertyEndLine.top + anchors.bottomMargin: 5 + + onSelectedItemChanged: { + textfield.enabled = (propertyList.selectedItem === null ? + false : propertyList.selectedItem.isWriteable); + } + } + + Rectangle { + id: listPropertyEndLine + anchors.bottom: startstopButton.top + anchors.bottomMargin: 5 + anchors.left: parent.left + anchors.right: parent.right + anchors.leftMargin: 5 + anchors.rightMargin: 5 + height: 1 + border.width: 1 + border.color: "#999999" + } + + + Button { + id: startstopButton + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.margins: 5 + text: (explorer.selectedSensorItem !== null ? + (explorer.selectedSensorItem.start === true ? "Stop" : "Start") : "Start") + enabled: true + height: 30 + width: 80 + + onClicked: { + if (explorer.selectedSensorItem !== null) { +//! [5] + if (text === "Start") { + explorer.selectedSensorItem.start = true; + text = "Stop"; + } + else { + explorer.selectedSensorItem.start = false; + text = "Start"; + } +//! [5] + } + + textfield.text = ""; + } + } + + TextField { + id: textfield + anchors.top: parent.bottom + anchors.topMargin: -35 + anchors.left: startstopButton.right + anchors.right: parent.right + anchors.margins: 5 + height: 30 + enabled: false + + onEnabledChanged: { + if (!textfield.enabled) { + textfield.closeSoftwareInputPanel(); + textfield.anchors.top= parent.bottom; + textfield.anchors.topMargin= -35; + textfield.text = ""; + } + } + + onFocusChanged: { + if (textfield.focus) { + textfield.anchors.top= sensorList.bottom + textfield.anchors.topMargin= -15 + } + else { + textfield.closeSoftwareInputPanel(); + textfield.anchors.top= parent.bottom; + textfield.anchors.topMargin= -35; + } + } + + onAccepted: { + + if (explorer.selectedSensorItem !== null + && propertyList.selectedItem !== null) { +//! [4] + explorer.selectedSensorItem.changePropertyValue(propertyList.selectedItem, textfield.text); +//! [4] + propertyList.focus=true; + } + textfield.text = ""; + } + } +} + -- cgit v1.2.3