Merge branch 'develop'
[lichviet] / qml / LichViet / OptionsScreen.qml
1 /*
2 Copyright (C) 2011  by Cuong Le <metacuong@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>
16 */
17
18 import QtQuick 1.0
19 import "Settings.js" as Settings
20 import "Themes.js" as Themes
21
22 Item{
23
24     id:optionsscreen
25
26     anchors.verticalCenter: parent.verticalCenter
27     width: parent.width; height: parent.height;
28     x:-(parent.width * 1.5)
29
30     signal close
31
32     Loader {
33         id: theme_manager
34         property alias theme: theme_manager.item
35         source: Themes.default_theme()
36     }
37
38     Connections {
39         target: optionsscreen.parent
40
41         onDialogClose: {
42             optionsscreen.state = "close";
43             optionsscreen.destroy(600);
44         }
45     }
46
47     Rectangle {
48         id: rectangle1
49         anchors.fill: parent; anchors.bottomMargin: 16
50         visible: true
51         opacity:0.9
52
53         Component {
54                 id: listDelegate
55                  Rectangle {
56                      height:60
57
58                      Rectangle {
59                                          width:rectangle1.width;
60                                          y:0;
61                                          x:0
62                                          height:1
63                                          border.color: "#b57e8f"
64                      }
65
66                      Text {
67                          id: text1
68                          text:name
69                          font.pixelSize: 21
70                          font.family: "Nokia Sans"
71                          x:20
72                          anchors.verticalCenter: parent.verticalCenter
73
74                      }
75                         Switch {
76                             id: switch_me
77                             x:rectangle1.width-220
78                             onSwitched:{
79                                 listModel.setProperty(index, "selected", switchedOn);
80                             }
81                             switchedOn: selected
82                             anchors.verticalCenter: parent.verticalCenter
83                         }
84
85                  }
86
87             }
88
89         ListModel {
90                  id: listModel
91                  Component.onCompleted: {
92                      Settings.restore(listModel);
93                      var cdx = Settings.chedoxoay();
94                      ROOT.initScreenOrientation(cdx);
95                  }
96          }
97
98         ListView {
99               id: listView
100               anchors.fill: parent;anchors.topMargin: 45;anchors.leftMargin: 0;
101               model: listModel
102               delegate: listDelegate
103               focus: true
104               ScrollBar{}
105         }
106
107     }
108
109     Rectangle {
110         width : optionsscreen.width
111         height: 45
112         color:"white"
113         opacity: 0.5
114     }
115
116     Text {
117         id: title
118
119         anchors { horizontalCenter: optionsscreen.horizontalCenter; top: optionsscreen.top; topMargin: 10 }
120         font.pixelSize: 22
121         color: "black"
122         text: "Lựa Chọn"
123         smooth: true
124         font.bold: true
125     }
126
127     ToolBar {
128         id: toolBar; height: 42;
129         y: parent.height-52
130         width: parent.width;
131         button1Label: "Đồng Ý"
132         button2Label: "Hủy Bỏ"
133         onButton1Clicked:
134         {
135             Settings.save(listModel)
136             optionsscreen.close();
137
138             var cdx = Settings.chedoxoay();
139             ROOT.initScreenOrientation(cdx);
140         }
141         onButton2Clicked: {
142             Settings.restore(listModel)
143             optionsscreen.close();
144         }
145     }
146
147     states: [
148         State {
149             name: "show"
150             AnchorChanges { target: optionsscreen; anchors.right: parent.right }
151         },
152         State {
153             name: "close"
154             AnchorChanges { target: optionsscreen; anchors.right: parent.left }
155         }
156     ]
157
158     transitions: Transition {
159         AnchorAnimation { easing.type: Easing.OutQuart; duration: 300 }
160     }
161 }