Diffstat (limited to 'inputmethods/multikey/configdlg.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | inputmethods/multikey/configdlg.cpp | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/inputmethods/multikey/configdlg.cpp b/inputmethods/multikey/configdlg.cpp index ac132d3..1e104a6 100644 --- a/inputmethods/multikey/configdlg.cpp +++ b/inputmethods/multikey/configdlg.cpp | |||
@@ -1,221 +1,259 @@ | |||
1 | /* | 1 | /* |
2 | * TODO | 2 | * TODO |
3 | * make a font selection thing (size too) | 3 | * make a font selection thing (size too) |
4 | * make a cursor thing | ||
4 | * | 5 | * |
5 | * | 6 | * |
6 | * | 7 | * |
7 | */ | 8 | */ |
8 | 9 | ||
9 | #include <iostream.h> | 10 | #include <iostream.h> |
10 | 11 | ||
11 | #include <qpe/qpeapplication.h> | 12 | #include <qpe/qpeapplication.h> |
12 | #include <qpe/config.h> | 13 | #include <qpe/config.h> |
13 | 14 | ||
14 | #include <qwidget.h> | 15 | #include <qwidget.h> |
15 | #include <qdialog.h> | 16 | #include <qdialog.h> |
16 | #include <qtabwidget.h> | 17 | #include <qtabwidget.h> |
17 | #include <qvbox.h> | 18 | #include <qvbox.h> |
18 | #include <qgrid.h> | 19 | #include <qgrid.h> |
19 | #include <qgroupbox.h> | 20 | #include <qgroupbox.h> |
20 | #include <qlabel.h> | 21 | #include <qlabel.h> |
21 | #include <qcheckbox.h> | 22 | #include <qcheckbox.h> |
22 | #include <qsizepolicy.h> | 23 | #include <qsizepolicy.h> |
23 | #include <qpushbutton.h> | 24 | #include <qpushbutton.h> |
24 | #include <qlistbox.h> | 25 | #include <qlistbox.h> |
25 | #include <qstringlist.h> | 26 | #include <qstringlist.h> |
26 | #include <opie/ofiledialog.h> | 27 | #include <opie/ofiledialog.h> |
28 | #include <opie/colordialog.h> | ||
27 | #include <qdir.h> | 29 | #include <qdir.h> |
28 | #include <qfileinfo.h> | 30 | #include <qfileinfo.h> |
29 | #include "configdlg.h" | 31 | #include "configdlg.h" |
30 | #include "keyboard.h" | 32 | #include "keyboard.h" |
31 | 33 | ||
34 | // ConfigDlg::ConfigDlg() {{{1 | ||
32 | ConfigDlg::ConfigDlg () : QTabWidget () | 35 | ConfigDlg::ConfigDlg () : QTabWidget () |
33 | { | 36 | { |
34 | setCaption( tr("Multikey Configuration") ); | 37 | setCaption( tr("Multikey Configuration") ); |
35 | Config config ("multikey"); | 38 | Config config ("multikey"); |
36 | config.setGroup("keymaps"); | 39 | config.setGroup("keymaps"); |
37 | QString current_map = config.readEntry("current", 0); | 40 | QString current_map = config.readEntry("current", 0); |
38 | 41 | ||
39 | /* | 42 | /* |
40 | * 'general config' tab | 43 | * 'general config' tab |
41 | */ | 44 | */ |
42 | 45 | ||
43 | QVBox *gen_box = new QVBox (this); | 46 | QVBox *gen_box = new QVBox (this); |
44 | gen_box->setMargin(3); | 47 | gen_box->setMargin(3); |
45 | addTab(gen_box, tr("General Settings")); | 48 | addTab(gen_box, tr("General Settings")); |
46 | 49 | ||
47 | QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); | 50 | QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); |
48 | 51 | ||
49 | keymaps = new QListBox (map_group); | 52 | keymaps = new QListBox (map_group); |
50 | keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); | 53 | keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); |
51 | 54 | ||
52 | QString cur(tr("Current Language")); | 55 | QString cur(tr("Current Language")); |
53 | keymaps->insertItem(cur); | 56 | keymaps->insertItem(cur); |
54 | keymaps->setSelected(0, true); | 57 | keymaps->setSelected(0, true); |
55 | 58 | ||
56 | QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap"); | 59 | QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap"); |
57 | default_maps = map_dir.entryList(); // so i can access it in other places | 60 | default_maps = map_dir.entryList(); // so i can access it in other places |
58 | 61 | ||
59 | for (uint i = 0; i <map_dir.count(); i++) { | 62 | for (uint i = 0; i <map_dir.count(); i++) { |
60 | 63 | ||
61 | keymaps->insertItem(map_dir.absPath() + "/" + map_dir[i]); | 64 | keymaps->insertItem(map_dir.absPath() + "/" + map_dir[i]); |
62 | if (map_dir.absPath() + "/" + map_dir[i] == current_map) { | 65 | if (map_dir.absPath() + "/" + map_dir[i] == current_map) { |
63 | 66 | ||
64 | keymaps->setSelected(i + 1, true); | 67 | keymaps->setSelected(i + 1, true); |
65 | } | 68 | } |
66 | 69 | ||
67 | } | 70 | } |
68 | 71 | ||
69 | custom_maps = config.readListEntry("maps", QChar('|')); | 72 | custom_maps = config.readListEntry("maps", QChar('|')); |
70 | 73 | ||
71 | for (uint i = 0; i < custom_maps.count(); i++) { | 74 | for (uint i = 0; i < custom_maps.count(); i++) { |
72 | 75 | ||
73 | if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false) | 76 | if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false) |
74 | || !QFile::exists(custom_maps[i])) { | 77 | || !QFile::exists(custom_maps[i])) { |
75 | 78 | ||
76 | custom_maps.remove(custom_maps.at(i)); | 79 | custom_maps.remove(custom_maps.at(i)); |
77 | 80 | ||
78 | // remove it from the list too | 81 | // remove it from the list too |
79 | config.writeEntry("maps", custom_maps.join("|")); | 82 | config.writeEntry("maps", custom_maps.join("|")); |
80 | 83 | ||
81 | 84 | ||
82 | } else { | 85 | } else { |
83 | 86 | ||
84 | keymaps->insertItem(custom_maps[i]); | 87 | keymaps->insertItem(custom_maps[i]); |
85 | if (custom_maps[i] == current_map) { | 88 | if (custom_maps[i] == current_map) { |
86 | 89 | ||
87 | keymaps->setSelected(map_dir.count() + i + 1, true); | 90 | keymaps->setSelected(map_dir.count() + i + 1, true); |
88 | } | 91 | } |
89 | } | 92 | } |
90 | } | 93 | } |
91 | 94 | ||
92 | // have to "+1" because the "current language" listItem... remember? | 95 | // have to "+1" because the "current language" listItem... remember? |
93 | 96 | ||
94 | connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); | 97 | connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); |
95 | 98 | ||
96 | 99 | ||
97 | QGrid *add_remove_grid = new QGrid(2, map_group); | 100 | QGrid *add_remove_grid = new QGrid(2, map_group); |
98 | add_remove_grid->setMargin(3); | 101 | add_remove_grid->setMargin(3); |
99 | add_remove_grid->setSpacing(3); | 102 | add_remove_grid->setSpacing(3); |
100 | 103 | ||
101 | add_button = new QPushButton(tr("Add"), add_remove_grid); | 104 | add_button = new QPushButton(tr("Add"), add_remove_grid); |
102 | add_button->setFlat((bool)1); | 105 | add_button->setFlat((bool)1); |
103 | connect(add_button, SIGNAL(clicked()), SLOT(addMap())); | 106 | connect(add_button, SIGNAL(clicked()), SLOT(addMap())); |
104 | 107 | ||
105 | remove_button = new QPushButton(tr("Remove"), add_remove_grid); | 108 | remove_button = new QPushButton(tr("Remove"), add_remove_grid); |
106 | remove_button->setFlat((bool)1); | 109 | remove_button->setFlat((bool)1); |
110 | if ((int)map_dir.count() >= keymaps->currentItem()) | ||
111 | remove_button->setDisabled(true); | ||
107 | connect(remove_button, SIGNAL(clicked()), SLOT(removeMap())); | 112 | connect(remove_button, SIGNAL(clicked()), SLOT(removeMap())); |
108 | 113 | ||
109 | pick_button = new QCheckBox(tr("Pickboard"), gen_box); | 114 | pick_button = new QCheckBox(tr("Pickboard"), gen_box); |
110 | 115 | ||
111 | config.setGroup ("pickboard"); | 116 | config.setGroup ("pickboard"); |
112 | bool pick_open = config.readBoolEntry ("open", "0"); // default closed | 117 | bool pick_open = config.readBoolEntry ("open", "0"); // default closed |
113 | if (pick_open) { | 118 | if (pick_open) { |
114 | 119 | ||
115 | pick_button->setChecked(true); | 120 | pick_button->setChecked(true); |
116 | } | 121 | } |
117 | 122 | ||
118 | // by connecting it after checking it, the signal isn't emmited | 123 | // by connecting it after checking it, the signal isn't emmited |
119 | connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog())); | 124 | connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog())); |
120 | 125 | ||
121 | /* | 126 | /* |
122 | * 'color' tab | 127 | * 'color' tab |
123 | */ | 128 | */ |
124 | 129 | ||
125 | QGrid *color_box = new QGrid(2, this); | 130 | QGrid *color_box = new QGrid(2, this); |
126 | color_box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); | 131 | color_box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); |
127 | color_box->setMargin(3); | 132 | color_box->setMargin(3); |
128 | color_box->setSpacing(3); | 133 | color_box->setSpacing(3); |
129 | addTab(color_box, tr("Colors")); | 134 | addTab(color_box, tr("Colors")); |
130 | 135 | ||
131 | QLabel *label; | 136 | QLabel *label; |
137 | QStringList color; | ||
132 | 138 | ||
133 | label = new QLabel(tr("Key Color"), color_box); | 139 | label = new QLabel(tr("Key Color"), color_box); |
134 | QPushButton *button = new QPushButton(color_box); | 140 | key_color_button = new QPushButton(color_box); |
135 | button->setFlat((bool)1); | 141 | connect(key_color_button, SIGNAL(clicked()), SLOT(keyColorButtonClicked())); |
142 | key_color_button->setFlat((bool)1); | ||
143 | |||
144 | config.setGroup("colors"); | ||
145 | color = config.readListEntry("keycolor", QChar(',')); | ||
146 | if (color.isEmpty()) { | ||
147 | color = QStringList::split(",", "240,240,240"); | ||
148 | config.writeEntry("keycolor", color.join(",")); | ||
149 | |||
150 | } | ||
151 | key_color_button->setBackgroundColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); | ||
152 | |||
153 | |||
136 | label = new QLabel(tr("Key Pressed Color"), color_box); | 154 | label = new QLabel(tr("Key Pressed Color"), color_box); |
137 | button = new QPushButton(color_box); | 155 | QPushButton *button = new QPushButton(color_box); |
138 | button->setFlat((bool)1); | 156 | button->setFlat((bool)1); |
139 | label = new QLabel(tr("Line Color"), color_box); | 157 | label = new QLabel(tr("Line Color"), color_box); |
140 | button = new QPushButton(color_box); | 158 | button = new QPushButton(color_box); |
141 | button->setFlat((bool)1); | 159 | button->setFlat((bool)1); |
142 | label = new QLabel(tr("Text Color"), color_box); | 160 | label = new QLabel(tr("Text Color"), color_box); |
143 | button = new QPushButton(color_box); | 161 | button = new QPushButton(color_box); |
144 | button->setFlat((bool)1); | 162 | button->setFlat((bool)1); |
145 | 163 | ||
146 | label = new QLabel("", color_box); // a spacer so the above buttons dont expand | 164 | label = new QLabel("", color_box); // a spacer so the above buttons dont expand |
147 | label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); | 165 | label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); |
148 | 166 | ||
149 | } | 167 | } |
150 | 168 | ||
151 | void ConfigDlg::pickTog() { | 169 | void ConfigDlg::pickTog() { |
152 | 170 | ||
153 | Config config ("multikey"); | 171 | Config config ("multikey"); |
154 | config.setGroup ("pickboard"); | 172 | config.setGroup ("pickboard"); |
155 | config.writeEntry ("open", pick_button->isChecked()); // default closed | 173 | config.writeEntry ("open", pick_button->isChecked()); // default closed |
156 | 174 | ||
157 | emit pickboardToggled(pick_button->isChecked()); | 175 | emit pickboardToggled(pick_button->isChecked()); |
158 | } | 176 | } |
159 | 177 | ||
160 | /* | 178 | /* |
161 | * the index is kinda screwy, because in the config file, index 0 is just the | 179 | * the index is kinda screwy, because in the config file, index 0 is just the |
162 | * first element in the QStringList, but here it's the "Current Language" | 180 | * first element in the QStringList, but here it's the "Current Language" |
163 | * listItem. therefor you have to minus one to the index before you access it. | 181 | * listItem. therefor you have to minus one to the index before you access it. |
164 | * | 182 | * |
165 | */ | 183 | */ |
166 | 184 | ||
185 | // ConfigDlg::setMap {{{1 | ||
167 | void ConfigDlg::setMap(int index) { | 186 | void ConfigDlg::setMap(int index) { |
168 | 187 | ||
169 | if (index == 0) { | 188 | if (index == 0) { |
170 | 189 | ||
171 | remove_button->setDisabled(true); | 190 | remove_button->setDisabled(true); |
172 | |||
173 | emit setMapToDefault(); | 191 | emit setMapToDefault(); |
174 | } | 192 | } |
175 | else if ((uint)index <= default_maps.count()) { | 193 | else if ((uint)index <= default_maps.count()) { |
176 | 194 | ||
177 | remove_button->setDisabled(true); | 195 | remove_button->setDisabled(true); |
178 | |||
179 | emit setMapToFile(keymaps->text(index)); | 196 | emit setMapToFile(keymaps->text(index)); |
180 | 197 | ||
181 | } else { | 198 | } else { |
182 | 199 | ||
183 | remove_button->setEnabled(true); | 200 | remove_button->setEnabled(true); |
184 | |||
185 | emit setMapToFile(keymaps->text(index)); | 201 | emit setMapToFile(keymaps->text(index)); |
186 | } | 202 | } |
187 | } | 203 | } |
188 | 204 | ||
205 | // ConfigDlg::addMap() {{{1 | ||
189 | void ConfigDlg::addMap() { | 206 | void ConfigDlg::addMap() { |
190 | 207 | ||
191 | QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath()); | 208 | QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath()); |
192 | Config config ("multikey"); | 209 | Config config ("multikey"); |
193 | config.setGroup("keymaps"); | 210 | config.setGroup("keymaps"); |
194 | QStringList maps = config.readListEntry("maps", QChar('|')); | 211 | QStringList maps = config.readListEntry("maps", QChar('|')); |
195 | maps.append(map); | 212 | maps.append(map); |
196 | keymaps->insertItem(map); | 213 | keymaps->insertItem(map); |
197 | keymaps->setSelected(keymaps->count() - 1, true); | 214 | keymaps->setSelected(keymaps->count() - 1, true); |
198 | 215 | ||
199 | 216 | ||
200 | config.writeEntry("maps", maps.join("|")); | 217 | config.writeEntry("maps", maps, QChar('|')); |
201 | config.writeEntry("current", map); | 218 | config.writeEntry("current", map); |
202 | 219 | ||
203 | } | 220 | } |
204 | 221 | ||
222 | // ConfigDlg::removeMap() {{{1 | ||
205 | void ConfigDlg::removeMap() { | 223 | void ConfigDlg::removeMap() { |
206 | 224 | ||
207 | cout << "removing : " << custom_maps[keymaps->currentItem() - default_maps.count() - 1] << "\n"; | 225 | cout << "removing : " << custom_maps[keymaps->currentItem() - default_maps.count() - 1] << "\n"; |
208 | cout << "currentItem : " << keymaps->currentItem() << "\n"; | 226 | cout << "currentItem : " << keymaps->currentItem() << "\n"; |
209 | 227 | ||
210 | // move selection up one | 228 | // move selection up one |
211 | keymaps->setSelected(keymaps->currentItem() - 1, true); | 229 | keymaps->setSelected(keymaps->currentItem() - 1, true); |
212 | // delete the next selected item cus you just moved it up | 230 | // delete the next selected item cus you just moved it up |
213 | keymaps->removeItem(keymaps->currentItem() + 1); | 231 | keymaps->removeItem(keymaps->currentItem() + 1); |
214 | 232 | ||
215 | custom_maps.remove(custom_maps[keymaps->currentItem() - default_maps.count()]); | 233 | custom_maps.remove(custom_maps[keymaps->currentItem() - default_maps.count()]); |
216 | 234 | ||
217 | // write the changes | 235 | // write the changes |
218 | Config config ("multikey"); | 236 | Config config ("multikey"); |
219 | config.setGroup("keymaps"); | 237 | config.setGroup("keymaps"); |
220 | config.writeEntry("maps", custom_maps.join("|")); | 238 | config.writeEntry("maps", custom_maps, QChar('|')); |
239 | } | ||
240 | |||
241 | // ConfigDlg::color {{{1 | ||
242 | void ConfigDlg::keyColorButtonClicked() { | ||
243 | |||
244 | Config config ("multikey"); | ||
245 | config.setGroup ("colors"); | ||
246 | |||
247 | QStringList color = config.readListEntry("keycolor", QChar(',')); | ||
248 | |||
249 | QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); | ||
250 | |||
251 | color[0].setNum(newcolor.red()); | ||
252 | color[1].setNum(newcolor.green()); | ||
253 | color[2].setNum(newcolor.blue()); | ||
254 | |||
255 | config.writeEntry("keycolor", color, QChar(',')); | ||
256 | |||
257 | key_color_button->setBackgroundColor(newcolor); | ||
258 | emit reloadKeyboard(); | ||
221 | } | 259 | } |