Merge branch 'develop'
[lichviet] / qml / LichViet / Switch.qml
1 /*\r
2 Copyright (C) 2011  by Cuong Le <metacuong@gmail.com>\r
3 \r
4 This program is free software: you can redistribute it and/or modify\r
5 it under the terms of the GNU General Public License as published by\r
6 the Free Software Foundation, either version 2 of the License, or\r
7 (at your option) any later version.\r
8 \r
9 This program is distributed in the hope that it will be useful,\r
10 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12 GNU General Public License for more details.\r
13 \r
14 You should have received a copy of the GNU General Public License\r
15 along with this program.  If not, see <http://www.gnu.org/licenses/>\r
16 */\r
17 \r
18 import QtQuick 1.0\r
19 \r
20 import "Themes.js" as Themes\r
21 \r
22 Item {\r
23     id: container\r
24 \r
25     Loader {\r
26         id: theme_manager\r
27         property alias theme: theme_manager.item\r
28         source: Themes.default_theme()\r
29     }\r
30 \r
31 \r
32     // Font properties\r
33     property string fontName: "Nokia Sans"\r
34     property int fontSize: 18\r
35     property color fontColor: "black"\r
36     // Images for switch states\r
37     property string imageOn: theme_manager.theme.switch_on\r
38     property string imageOff:theme_manager.theme.switch_off\r
39     // Property indicating current state\r
40     property bool switchedOn: true\r
41     // Labels for the states\r
42     property alias textOn: textOn.text\r
43     property alias textOff: textOff.text\r
44     // Spacing between labels and switch\r
45     property alias spacing: row.spacing\r
46 \r
47     // Signal that gets fired when switch state has been toggled\r
48     signal switched(bool position)\r
49 \r
50     width: row.width\r
51     height: 44\r
52 \r
53     Row {\r
54         id: row\r
55         spacing: 8\r
56         Text {\r
57             id: textOn\r
58             text: "Bật"\r
59             height: container.height\r
60             color: container.fontColor\r
61             font {\r
62                 family: container.fontName\r
63                 pointSize: container.fontSize\r
64             }\r
65             verticalAlignment: Text.AlignVCenter\r
66         }\r
67         Image {\r
68             id: toggleSwitch\r
69             height: container.height\r
70             width: 2.22 * height\r
71             source: switchedOn ? imageOn : imageOff\r
72             fillMode: Image.PreserveAspectFit\r
73             smooth: true\r
74         }\r
75         Text {\r
76             id: textOff\r
77             height: container.height\r
78             text: "Tắt"\r
79             color: container.fontColor\r
80             font {\r
81                 family: container.fontName\r
82                 pointSize: container.fontSize\r
83             }\r
84             verticalAlignment: Text.AlignVCenter\r
85         }\r
86     }\r
87     MouseArea {\r
88         anchors.fill: row\r
89         onClicked: { switchedOn = !switchedOn; switched(switchedOn) }\r
90     }\r
91 }\r