Implemented a component with a switch and a text label and use it in various dialogs
authorMohammed Sameer <msameer@foolab.org>
Sun, 10 Feb 2013 18:13:47 +0000 (20:13 +0200)
committerMohammed Sameer <msameer@foolab.org>
Sun, 10 Feb 2013 18:13:47 +0000 (20:13 +0200)
qml/CameraSettings.qml
qml/ImageSettingsDialog.qml
qml/TextSwitch.qml [new file with mode: 0644]
qml/qml.qrc

index 92db40d..6375392 100644 (file)
@@ -34,24 +34,14 @@ Column {
                 width: parent.width
         }
 
-        Item {
-                width: parent.width
-                height: Math.max(showGridLinesLabel.height, showGridLines.height);
-
-                Label {
-                        id: showGridLinesLabel
-                        anchors.left: parent.left
-                        text: qsTr("Show grid lines");
-                }
-
-                Switch {
-                        id: showGridLines
-                        anchors.right: parent.right
-                        // We have to do it that way because QML complains about a binding
-                        // loop for checked if we bind the checked property to the settings value.
-                        Component.onCompleted: checked = settings.gridEnabled;
-                        onCheckedChanged: settings.gridEnabled = checked;
-                }
+        TextSwitch {
+                text: qsTr("Show grid lines");
+
+                // We have to do it that way because QML complains about a binding
+                // loop for checked if we bind the checked property to the settings value.
+                Component.onCompleted: checked = settings.gridEnabled;
+
+                onCheckedChanged: settings.gridEnabled = checked;
         }
 
         SectionHeader {
@@ -66,66 +56,34 @@ Column {
                 onTextChanged: settings.creatorName = text;
         }
 
-        Item {
-                width: parent.width
-                height: Math.max(enableCameraSoundsLabel.height, enableCameraSounds.height);
-
-                Label {
-                        id: enableCameraSoundsLabel
-                        anchors.left: parent.left
-                        text: qsTr("Enable camera sounds");
-                }
-
-                Switch {
-                        id: enableCameraSounds
-                        anchors.right: parent.right
-                        // We have to do it that way because QML complains about a binding
-                        // loop for checked if we bind the checked property to the settings value.
-                        Component.onCompleted: checked = settings.soundEnabled;
-                        onCheckedChanged: settings.soundEnabled = checked;
-                }
-        }
+        TextSwitch {
+                text: qsTr("Enable camera sounds");
 
-        Item {
-                width: parent.width
-                height: Math.max(useGpsLabel.height, useGps.height);
-
-                Label {
-                        id: useGpsLabel
-                        anchors.left: parent.left
-                        text: qsTr("Use GPS");
-                }
-
-                Switch {
-                        id: useGps
-                        anchors.right: parent.right
-                        // We have to do it that way because QML complains about a binding
-                        // loop for checked if we bind the checked property to the settings value.
-                        Component.onCompleted: checked = settings.useGps;
-                        onCheckedChanged: settings.useGps = checked;
-                }
+                // We have to do it that way because QML complains about a binding
+                // loop for checked if we bind the checked property to the settings value.
+                Component.onCompleted: checked = settings.soundEnabled;
+                onCheckedChanged: settings.soundEnabled = checked;
         }
 
-        Item {
-                width: parent.width
-                height: Math.max(useGeotagsLabel.height, useGeotags.height);
+        TextSwitch {
+                id: useGps
+                text: qsTr("Use GPS");
 
+                // We have to do it that way because QML complains about a binding
+                // loop for checked if we bind the checked property to the settings value.
+                Component.onCompleted: checked = settings.useGps;
+                onCheckedChanged: settings.useGps = checked;
+        }
+
+        TextSwitch {
                 // TODO: transition when hiding/showing and we should scroll a bit to show it
                 visible: useGps.checked
 
-                Label {
-                        id: useGeotagsLabel
-                        anchors.left: parent.left
-                        text: qsTr("Use geotags");
-                }
-
-                Switch {
-                        id: useGeotags
-                        anchors.right: parent.right
-                        // We have to do it that way because QML complains about a binding
-                        // loop for checked if we bind the checked property to the settings value.
-                        Component.onCompleted: checked = settings.useGeotags;
-                        onCheckedChanged: settings.useGeotags = checked;
-                }
+                text: qsTr("Use geotags");
+
+                // We have to do it that way because QML complains about a binding
+                // loop for checked if we bind the checked property to the settings value.
+                Component.onCompleted: checked = settings.useGeotags;
+                onCheckedChanged: settings.useGeotags = checked;
         }
 }
index 5a64acf..7420c31 100644 (file)
@@ -125,24 +125,12 @@ Dialog {
                                         }
                                 }
 
-                                Item {
-                                        width: parent.width
-                                        height: Math.max(enableFaceDetectionLabel.height, enableFaceDetection.height);
-
-                                        Label {
-                                                id: enableFaceDetectionLabel
-                                                anchors.left: parent.left
-                                                text: qsTr("Enable face detection");
-                                        }
-
-                                        Switch {
-                                                id: enableFaceDetection
-                                                anchors.right: parent.right
-                                                // We have to do it that way because QML complains about a binding
-                                                // loop for checked if we bind the checked property to the settings value.
-                                                Component.onCompleted: checked = settings.faceDetectionEnabled;
-                                                onCheckedChanged: settings.faceDetectionEnabled = checked;
-                                        }
+                                TextSwitch {
+                                        text: qsTr("Enable face detection");
+                                        // We have to do it that way because QML complains about a binding
+                                        // loop for checked if we bind the checked property to the settings value.
+                                        Component.onCompleted: checked = settings.faceDetectionEnabled;
+                                        onCheckedChanged: settings.faceDetectionEnabled = checked;
                                 }
 
                                 CameraSettings {
diff --git a/qml/TextSwitch.qml b/qml/TextSwitch.qml
new file mode 100644 (file)
index 0000000..784c8c5
--- /dev/null
@@ -0,0 +1,47 @@
+// -*- qml -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+import QtQuick 1.1
+import com.nokia.meego 1.1
+
+Item {
+        property alias text: label.text
+        property alias checked: switchComponent.checked
+        width: parent.width
+        height: switchComponent.height
+
+        Text {
+                property Style platformStyle: LabelStyle {}
+
+                id: label
+                anchors.left: parent.left
+                font.family: platformStyle.fontFamily
+                font.pixelSize: platformStyle.fontPixelSize
+                color: platformStyle.textColor
+                wrapMode: Text.Wrap
+        }
+
+        Switch {
+                id: switchComponent
+                anchors.right: parent.right
+        }
+}
index fa4029d..048812b 100644 (file)
@@ -36,6 +36,7 @@
        <file>VideoMuteButton.qml</file>
        <file>VideoPlayerPage.qml</file>
        <file>SectionHeader.qml</file>
+       <file>TextSwitch.qml</file>
        <file>ImageSettingsDialog.qml</file>
        <file>ImageSettingsDialog.js</file>
        <file>VideoSettingsDialog.qml</file>