Added ROI an face detection
[harmattan/cameraplus] / qml / ImageSettingsDialog.qml
1 // -*- qml -*-
2
3 /*!
4  * This file is part of CameraPlus.
5  *
6  * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21  */
22
23 import QtQuick 1.1
24 import com.nokia.meego 1.1
25 import QtCamera 1.0
26 import "ImageSettingsDialog.js" as Util
27
28 Dialog {
29         id: dialog
30
31         content: item
32
33         Connections {
34                 target: Qt.application
35                 onActiveChanged: {
36                         if (!Qt.application.active) {
37                                 dialog.close();
38                         }
39                 }
40         }
41
42         onStatusChanged: {
43                 if (status == DialogStatus.Open) {
44                         cam.renderingEnabled = false;
45                 }
46                 else if (status == DialogStatus.Closing) {
47                         cam.renderingEnabled = true;
48                 }
49         }
50
51         Item {
52                 id: item
53                 width: parent.width
54                 height: root.height
55
56                 Flickable {
57                         id: flickable
58                         anchors.fill: parent
59                         anchors.margins: 10
60                         contentHeight: col.height
61
62                         Column {
63                                 id: col
64
65                                 width: parent.width
66                                 spacing: 10
67
68                                 Label {
69                                         font.pixelSize: 36
70                                         text: qsTr("Image settings");
71                                 }
72
73                                 SectionHeader {
74                                         text: qsTr("Aspect ratio");
75                                 }
76
77                                 ButtonRow {
78                                         id: aspectRatioRow
79                                         width: parent.width
80
81                                         exclusive: false
82                                         onCheckedButtonChanged: {
83                                                 // This is needed to initially setup the
84                                                 // resolutions buttons
85                                                 Util.resetAspectRatio(aspectRatioRow);
86                                         }
87
88                                         Repeater {
89                                                 model: imageSettings.aspectRatios
90                                                 delegate: Button {
91                                                         property string aspect: modelData;
92                                                         text: qsTr(modelData);
93                                                         checked: settings.imageAspectRatio == modelData;
94                                                         onClicked: Util.setAspectRatio(modelData);
95                                                 }
96                                         }
97                                 }
98
99                                 SectionHeader {
100                                         text: qsTr("Resolution");
101                                 }
102
103                                 ButtonRow {
104                                         id: resolutionsRow
105                                         width: parent.width
106
107                                         exclusive: false
108
109                                         Repeater {
110                                                 id: resolutions
111                                                 model: imageSettings.resolutions
112
113                                                 // http://stackoverflow.com/questions/1026069/capitalize-the-first-letter-of-string-in-javascript
114                                                 function name(name, mp) {
115                                                         return name.charAt(0).toUpperCase() + name.slice(1) + " " + mp + " Mpx";
116                                                 }
117
118                                                 delegate: Button {
119                                                         property string resolution: resolutionName
120                                                         property string aspectRatio: resolutionAspectRatio
121                                                         text: resolutions.name(resolutionName, megaPixels);
122                                                         checked: settings.imageResolution == resolutionName
123                                                         onClicked: Util.setResolution(resolutionName);
124                                                 }
125                                         }
126                                 }
127
128                                 Item {
129                                         width: parent.width
130                                         height: Math.max(enableFaceDetectionLabel.height, enableFaceDetection.height);
131
132                                         Label {
133                                                 id: enableFaceDetectionLabel
134                                                 anchors.left: parent.left
135                                                 text: qsTr("Enable face detection");
136                                         }
137
138                                         Switch {
139                                                 id: enableFaceDetection
140                                                 anchors.right: parent.right
141                                                 // We have to do it that way because QML complains about a binding
142                                                 // loop for checked if we bind the checked property to the settings value.
143                                                 Component.onCompleted: checked = settings.faceDetectionEnabled;
144                                                 onCheckedChanged: settings.faceDetectionEnabled = checked;
145                                         }
146                                 }
147
148                                 CameraSettings {
149                                         anchors.horizontalCenter: parent.horizontalCenter
150                                 }
151                         }
152                 }
153         }
154 }