5e051d502609bc2b178ca1fed80194d0a4742e24
[qzeecontrol] / qml / QZeeControl / KeyBindingSettings.qml
1 /*
2  *  Copyright 2012 Ruediger Gad
3  *
4  *  This file is part of QZeeControl.
5  *
6  *  QZeeControl is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  QZeeControl is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with QZeeControl.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 import QtQuick 1.1
21 import com.nokia.meego 1.0
22 import "settingsstorage.js" as SettingsStorage
23
24 Sheet {
25     id: keyBindingSettings
26     anchors.fill: parent
27     visualParent: mainPage
28     z: 2
29
30     acceptButtonText: "Save"
31     rejectButtonText: "Cancel"
32
33     function loadBindings(){
34         console.log("Loading stored key bindings.")
35         fieldA.text = SettingsStorage.getSetting("A")
36         fieldB.text = SettingsStorage.getSetting("B")
37         fieldC.text = SettingsStorage.getSetting("C")
38         fieldD.text = SettingsStorage.getSetting("D")
39
40         fieldUp.text = SettingsStorage.getSetting("Up")
41         fieldDown.text = SettingsStorage.getSetting("Down")
42         fieldLeft.text = SettingsStorage.getSetting("Left")
43         fieldRight.text = SettingsStorage.getSetting("Right")
44     }
45
46     function saveBindings(){
47         console.log("Saving new key bindings.")
48         SettingsStorage.setSetting("A", fieldA.text)
49         SettingsStorage.setSetting("B", fieldB.text)
50         SettingsStorage.setSetting("C", fieldC.text)
51         SettingsStorage.setSetting("D", fieldD.text)
52
53         SettingsStorage.setSetting("Up", fieldUp.text)
54         SettingsStorage.setSetting("Down", fieldDown.text)
55         SettingsStorage.setSetting("Left", fieldLeft.text)
56         SettingsStorage.setSetting("Right", fieldRight.text)
57     }
58
59     onAccepted: saveBindings()
60
61     onStatusChanged:{
62         if(status === DialogStatus.Opening){
63             loadBindings()
64         }
65     }
66
67     content: Flickable{
68         anchors.fill: parent
69         anchors.margins: 10
70         contentHeight: contentGrid.height
71
72         Grid{
73             id: contentGrid
74
75             anchors{top: parent.top}
76             width: 300
77             spacing: 10
78
79             Label{
80                 text: "A"
81             }
82             TextField{
83                 id: fieldA
84                 text: "-"
85                 width: 150
86             }
87
88             Label{
89                 text: "B"
90             }
91             TextField{
92                 id: fieldB
93                 text: "-"
94                 width: 150
95             }
96
97             Label{
98                 text: "C"
99             }
100             TextField{
101                 id: fieldC
102                 text: "-"
103                 width: 150
104             }
105
106             Label{
107                 text: "D"
108             }
109             TextField{
110                 id: fieldD
111                 text: "-"
112                 width: 150
113             }
114
115             Label{
116                 text: "Up"
117             }
118             TextField{
119                 id: fieldUp
120                 text: "-"
121                 width: 150
122             }
123
124             Label{
125                 text: "Down"
126             }
127             TextField{
128                 id: fieldDown
129                 text: "-"
130                 width: 150
131             }
132
133             Label{
134                 text: "Left"
135             }
136             TextField{
137                 id: fieldLeft
138                 text: "-"
139                 width: 150
140             }
141
142             Label{
143                 text: "Right"
144             }
145             TextField{
146                 id: fieldRight
147                 text: "-"
148                 width: 150
149             }
150         }
151     }
152 }
153