Diffstat (limited to 'inputmethods/multikey/configdlg.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | inputmethods/multikey/configdlg.cpp | 161 |
1 files changed, 78 insertions, 83 deletions
diff --git a/inputmethods/multikey/configdlg.cpp b/inputmethods/multikey/configdlg.cpp index f127d0e..d29109a 100644 --- a/inputmethods/multikey/configdlg.cpp +++ b/inputmethods/multikey/configdlg.cpp | |||
@@ -11,8 +11,9 @@ | |||
11 | #include <qpe/qpeapplication.h> | 11 | #include <qpe/qpeapplication.h> |
12 | #include <qpe/config.h> | 12 | #include <qpe/config.h> |
13 | #include <qpe/resource.h> | 13 | #include <qpe/resource.h> |
14 | 14 | ||
15 | #include <qlayout.h> | ||
15 | #include <qwidget.h> | 16 | #include <qwidget.h> |
16 | #include <qdialog.h> | 17 | #include <qdialog.h> |
17 | #include <qtabwidget.h> | 18 | #include <qtabwidget.h> |
18 | #include <qvbox.h> | 19 | #include <qvbox.h> |
@@ -32,9 +33,9 @@ | |||
32 | #include "configdlg.h" | 33 | #include "configdlg.h" |
33 | #include "keyboard.h" | 34 | #include "keyboard.h" |
34 | 35 | ||
35 | // ConfigDlg::ConfigDlg() {{{1 | 36 | // ConfigDlg::ConfigDlg() {{{1 |
36 | ConfigDlg::ConfigDlg () : QTabWidget () | 37 | ConfigDlg::ConfigDlg () : QDialog () |
37 | { | 38 | { |
38 | setCaption( tr("Multikey Configuration") ); | 39 | setCaption( tr("Multikey Configuration") ); |
39 | Config config ("multikey"); | 40 | Config config ("multikey"); |
40 | config.setGroup("keymaps"); | 41 | config.setGroup("keymaps"); |
@@ -43,12 +44,15 @@ ConfigDlg::ConfigDlg () : QTabWidget () | |||
43 | /* | 44 | /* |
44 | * 'general config' tab | 45 | * 'general config' tab |
45 | */ | 46 | */ |
46 | 47 | ||
47 | QVBox *gen_box = new QVBox (this); | 48 | QVBoxLayout *base_lay = new QVBoxLayout(this); |
48 | gen_box->setMargin(3); | ||
49 | addTab(gen_box, tr("General Settings")); | ||
50 | 49 | ||
50 | QTabWidget *tabs = new QTabWidget(this, "tabs"); | ||
51 | |||
52 | QWidget *gen_box = new QWidget(tabs, "gen_tab"); | ||
53 | QVBoxLayout *gen_lay = new QVBoxLayout(gen_box); | ||
54 | gen_lay->setMargin(3); | ||
51 | QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); | 55 | QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); |
52 | 56 | ||
53 | QHBox *hbox1 = new QHBox(map_group); | 57 | QHBox *hbox1 = new QHBox(map_group); |
54 | keymaps = new QListBox(hbox1); | 58 | keymaps = new QListBox(hbox1); |
@@ -128,9 +132,8 @@ ConfigDlg::ConfigDlg () : QTabWidget () | |||
128 | } | 132 | } |
129 | } | 133 | } |
130 | 134 | ||
131 | // have to "+1" because the "current language" listItem... remember? | 135 | // have to "+1" because the "current language" listItem... remember? |
132 | |||
133 | connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); | 136 | connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); |
134 | 137 | ||
135 | QGrid *add_remove_grid = new QGrid(2, map_group); | 138 | QGrid *add_remove_grid = new QGrid(2, map_group); |
136 | add_remove_grid->setMargin(3); | 139 | add_remove_grid->setMargin(3); |
@@ -141,12 +144,14 @@ ConfigDlg::ConfigDlg () : QTabWidget () | |||
141 | connect(add_button, SIGNAL(clicked()), SLOT(addMap())); | 144 | connect(add_button, SIGNAL(clicked()), SLOT(addMap())); |
142 | 145 | ||
143 | remove_button = new QPushButton(tr("Remove"), add_remove_grid); | 146 | remove_button = new QPushButton(tr("Remove"), add_remove_grid); |
144 | remove_button->setFlat(TRUE); | 147 | remove_button->setFlat(TRUE); |
145 | if (default_maps.find(QFileInfo(current_map).fileName()) != default_maps.end()) | 148 | if (keymaps->currentItem() == 0 || default_maps.find(QFileInfo(current_map).fileName()) != default_maps.end()) |
146 | remove_button->setDisabled(true); | 149 | remove_button->setDisabled(true); |
147 | connect(remove_button, SIGNAL(clicked()), SLOT(removeMap())); | 150 | connect(remove_button, SIGNAL(clicked()), SLOT(removeMap())); |
148 | 151 | ||
152 | gen_lay->addWidget(map_group); | ||
153 | |||
149 | // make a box that will contain the buttons on the bottom | 154 | // make a box that will contain the buttons on the bottom |
150 | QGrid *other_grid = new QGrid(2, gen_box); | 155 | QGrid *other_grid = new QGrid(2, gen_box); |
151 | pick_button = new QCheckBox(tr("Pickboard"), other_grid); | 156 | pick_button = new QCheckBox(tr("Pickboard"), other_grid); |
152 | 157 | ||
@@ -156,36 +161,39 @@ ConfigDlg::ConfigDlg () : QTabWidget () | |||
156 | 161 | ||
157 | pick_button->setChecked(true); | 162 | pick_button->setChecked(true); |
158 | } | 163 | } |
159 | 164 | ||
160 | // by connecting it after checking it, the signal isn't emmited | ||
161 | connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog())); | ||
162 | |||
163 | repeat_button = new QCheckBox(tr("Key Repeat"), other_grid); | 165 | repeat_button = new QCheckBox(tr("Key Repeat"), other_grid); |
164 | bool repeat_on = config.readBoolEntry ("useRepeat", TRUE); | 166 | bool repeat_on = config.readBoolEntry ("useRepeat", TRUE); |
165 | 167 | ||
166 | if (repeat_on) { | 168 | if (repeat_on) { |
167 | 169 | ||
168 | repeat_button->setChecked(true); | 170 | repeat_button->setChecked(true); |
169 | } | 171 | } |
170 | connect (repeat_button, SIGNAL(clicked()), this, SLOT(repeatTog())); | 172 | |
173 | gen_lay->addWidget(other_grid); | ||
174 | tabs->addTab(gen_box, tr("General Settings")); | ||
171 | 175 | ||
172 | /* | 176 | /* |
173 | * 'color' tab | 177 | * 'color' tab |
174 | */ | 178 | */ |
175 | 179 | ||
176 | QGrid *color_box = new QGrid(2, this); | 180 | QWidget *color_box = new QWidget(tabs, "color_tab"); |
177 | color_box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); | 181 | |
178 | color_box->setMargin(3); | 182 | QGridLayout *color_lay = new QGridLayout(color_box); |
179 | color_box->setSpacing(3); | 183 | QGrid *color_grid = new QGrid(2, color_box); |
180 | addTab(color_box, tr("Colors")); | 184 | color_lay->setAlignment(Qt::AlignTop); |
185 | color_grid->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); | ||
186 | color_grid->layout()->setAlignment(Qt::AlignTop); | ||
187 | color_grid->setMargin(3); | ||
188 | color_grid->setSpacing(3); | ||
181 | 189 | ||
182 | QLabel *label; | 190 | QLabel *label; |
183 | QStringList color; | 191 | QStringList color; |
184 | config.setGroup("colors"); | 192 | config.setGroup("colors"); |
185 | 193 | ||
186 | label = new QLabel(tr("Key Color"), color_box); | 194 | label = new QLabel(tr("Key Color"), color_grid); |
187 | keycolor_button = new QPushButton(color_box); | 195 | keycolor_button = new QPushButton(color_grid); |
188 | connect(keycolor_button, SIGNAL(clicked()), SLOT(keyColorClicked())); | 196 | connect(keycolor_button, SIGNAL(clicked()), SLOT(keyColorClicked())); |
189 | keycolor_button->setFlat(TRUE); | 197 | keycolor_button->setFlat(TRUE); |
190 | color = config.readListEntry("keycolor", QChar(',')); | 198 | color = config.readListEntry("keycolor", QChar(',')); |
191 | /* | 199 | /* |
@@ -199,37 +207,40 @@ ConfigDlg::ConfigDlg () : QTabWidget () | |||
199 | */ | 207 | */ |
200 | keycolor_button->setPalette(QPalette(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))); | 208 | keycolor_button->setPalette(QPalette(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))); |
201 | 209 | ||
202 | 210 | ||
203 | label = new QLabel(tr("Key Pressed Color"), color_box); | 211 | label = new QLabel(tr("Key Pressed Color"), color_grid); |
204 | keycolor_pressed_button = new QPushButton(color_box); | 212 | keycolor_pressed_button = new QPushButton(color_grid); |
205 | connect(keycolor_pressed_button, SIGNAL(clicked()), SLOT(keyColorPressedClicked())); | 213 | connect(keycolor_pressed_button, SIGNAL(clicked()), SLOT(keyColorPressedClicked())); |
206 | keycolor_pressed_button->setFlat(TRUE); | 214 | keycolor_pressed_button->setFlat(TRUE); |
207 | color = config.readListEntry("keycolor_pressed", QChar(',')); | 215 | color = config.readListEntry("keycolor_pressed", QChar(',')); |
208 | keycolor_pressed_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); | 216 | keycolor_pressed_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); |
209 | 217 | ||
210 | label = new QLabel(tr("Line Color"), color_box); | 218 | label = new QLabel(tr("Line Color"), color_grid); |
211 | keycolor_lines_button = new QPushButton(color_box); | 219 | keycolor_lines_button = new QPushButton(color_grid); |
212 | connect(keycolor_lines_button, SIGNAL(clicked()), SLOT(keyColorLinesClicked())); | 220 | connect(keycolor_lines_button, SIGNAL(clicked()), SLOT(keyColorLinesClicked())); |
213 | keycolor_lines_button->setFlat(TRUE); | 221 | keycolor_lines_button->setFlat(TRUE); |
214 | color = config.readListEntry("keycolor_lines", QChar(',')); | 222 | color = config.readListEntry("keycolor_lines", QChar(',')); |
215 | keycolor_lines_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); | 223 | keycolor_lines_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); |
216 | 224 | ||
217 | 225 | ||
218 | label = new QLabel(tr("Text Color"), color_box); | 226 | label = new QLabel(tr("Text Color"), color_grid); |
219 | textcolor_button = new QPushButton(color_box); | 227 | textcolor_button = new QPushButton(color_grid); |
220 | connect(textcolor_button, SIGNAL(clicked()), SLOT(textColorClicked())); | 228 | connect(textcolor_button, SIGNAL(clicked()), SLOT(textColorClicked())); |
221 | textcolor_button->setFlat(TRUE); | 229 | textcolor_button->setFlat(TRUE); |
222 | color = config.readListEntry("textcolor", QChar(',')); | 230 | color = config.readListEntry("textcolor", QChar(',')); |
223 | textcolor_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); | 231 | textcolor_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); |
224 | 232 | ||
225 | label = new QLabel("", color_box); // a spacer so the above buttons dont expand | 233 | label = new QLabel("", color_grid); // a spacer so the above buttons dont expand |
226 | label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); | 234 | label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); |
227 | } | 235 | /* FIXME: hacked spacer height */ |
236 | QSpacerItem *spacer = new QSpacerItem(0, 300, QSizePolicy::Expanding, QSizePolicy::Maximum); | ||
228 | 237 | ||
229 | ConfigDlg::~ConfigDlg() | 238 | color_lay->addWidget(color_grid, 0, 0); |
230 | { | 239 | color_lay->addItem(spacer); |
231 | emit reloadSw(); | 240 | |
241 | tabs->addTab(color_box, tr("Colors")); | ||
242 | base_lay->addWidget(tabs); | ||
232 | } | 243 | } |
233 | 244 | ||
234 | QStringList ConfigDlg::loadSw() | 245 | QStringList ConfigDlg::loadSw() |
235 | { | 246 | { |
@@ -247,9 +258,9 @@ QStringList ConfigDlg::loadSw() | |||
247 | } | 258 | } |
248 | else | 259 | else |
249 | { | 260 | { |
250 | /* Clear non existents entries */ | 261 | /* Clear non existents entries */ |
251 | QStringList s_copy = s_maps; | 262 | QStringList s_copy(s_maps); |
252 | for (uint i = 0; i < s_copy.count(); ++i) { | 263 | for (uint i = 0; i < s_copy.count(); ++i) { |
253 | if (d_maps.find(s_copy[i]) == d_maps.end() | 264 | if (d_maps.find(s_copy[i]) == d_maps.end() |
254 | && c_maps.find(s_copy[i]) == c_maps.end()) { | 265 | && c_maps.find(s_copy[i]) == c_maps.end()) { |
255 | s_maps.remove(s_copy[i]); | 266 | s_maps.remove(s_copy[i]); |
@@ -271,8 +282,46 @@ QStringList ConfigDlg::loadSw() | |||
271 | 282 | ||
272 | return s_maps; | 283 | return s_maps; |
273 | } | 284 | } |
274 | 285 | ||
286 | void ConfigDlg::accept() | ||
287 | { | ||
288 | /* Writing all stuffs to config */ | ||
289 | Config *config = new Config("multikey"); | ||
290 | config->setGroup("general"); | ||
291 | config->writeEntry("usePickboard", pick_button->isChecked()); // default closed | ||
292 | config->writeEntry("useRepeat", repeat_button->isChecked()); // default closed | ||
293 | |||
294 | config->setGroup("keymaps"); | ||
295 | config->writeEntry("sw", sw_maps, QChar('|')); | ||
296 | config->writeEntry("maps", custom_maps, QChar('|')); | ||
297 | delete config; | ||
298 | |||
299 | int index = keymaps->currentItem(); | ||
300 | if (index == 0) { | ||
301 | |||
302 | remove_button->setDisabled(true); | ||
303 | emit setMapToDefault(); | ||
304 | } | ||
305 | else if (default_maps.find(sw_maps[index-1]) != default_maps.end()) { | ||
306 | |||
307 | remove_button->setDisabled(true); | ||
308 | emit setMapToFile(QPEApplication::qpeDir() + "share/multikey/" + sw_maps[index - 1]); | ||
309 | |||
310 | } else { | ||
311 | |||
312 | remove_button->setEnabled(true); | ||
313 | emit setMapToFile(sw_maps[index - 1]); | ||
314 | } | ||
315 | |||
316 | emit pickboardToggled(pick_button->isChecked()); | ||
317 | emit repeatToggled(repeat_button->isChecked()); | ||
318 | emit reloadSw(); | ||
319 | |||
320 | QDialog::accept(); | ||
321 | emit configDlgClosed(); | ||
322 | } | ||
323 | |||
275 | void ConfigDlg::moveSelectedUp() | 324 | void ConfigDlg::moveSelectedUp() |
276 | { | 325 | { |
277 | int i = keymaps->currentItem(); | 326 | int i = keymaps->currentItem(); |
278 | /* Ignore Current Language */ | 327 | /* Ignore Current Language */ |
@@ -284,12 +333,8 @@ void ConfigDlg::moveSelectedUp() | |||
284 | QString item = keymaps->currentText(); | 333 | QString item = keymaps->currentText(); |
285 | keymaps->removeItem(i); | 334 | keymaps->removeItem(i); |
286 | keymaps->insertItem(item, i-1); | 335 | keymaps->insertItem(item, i-1); |
287 | keymaps->setCurrentItem(i-1); | 336 | keymaps->setCurrentItem(i-1); |
288 | |||
289 | Config config("multikey"); | ||
290 | config.setGroup("keymaps"); | ||
291 | config.writeEntry("sw", sw_maps, QChar('|')); | ||
292 | } | 337 | } |
293 | } | 338 | } |
294 | 339 | ||
295 | void ConfigDlg::moveSelectedDown() | 340 | void ConfigDlg::moveSelectedDown() |
@@ -304,64 +349,26 @@ void ConfigDlg::moveSelectedDown() | |||
304 | QString item = keymaps->currentText(); | 349 | QString item = keymaps->currentText(); |
305 | keymaps->removeItem(i); | 350 | keymaps->removeItem(i); |
306 | keymaps->insertItem(item, i+1); | 351 | keymaps->insertItem(item, i+1); |
307 | keymaps->setCurrentItem(i+1); | 352 | keymaps->setCurrentItem(i+1); |
308 | |||
309 | Config config("multikey"); | ||
310 | config.setGroup("keymaps"); | ||
311 | config.writeEntry("sw", sw_maps, QChar('|')); | ||
312 | } | ||
313 | } | 353 | } |
314 | |||
315 | void ConfigDlg::pickTog() { | ||
316 | |||
317 | Config config ("multikey"); | ||
318 | config.setGroup ("general"); | ||
319 | config.writeEntry ("usePickboard", pick_button->isChecked()); // default closed | ||
320 | |||
321 | emit pickboardToggled(pick_button->isChecked()); | ||
322 | } | ||
323 | |||
324 | void ConfigDlg::repeatTog() { | ||
325 | |||
326 | Config config ("multikey"); | ||
327 | config.setGroup ("general"); | ||
328 | config.writeEntry ("useRepeat", repeat_button->isChecked()); // default closed | ||
329 | |||
330 | emit repeatToggled(repeat_button->isChecked()); | ||
331 | } | 354 | } |
332 | 355 | ||
333 | void ConfigDlg::closeEvent(QCloseEvent *) { | 356 | void ConfigDlg::closeEvent(QCloseEvent *) { |
334 | 357 | ||
335 | // tell the parent it was closed, so delete me | 358 | // tell the parent it was closed, so delete me |
336 | emit configDlgClosed(); | 359 | emit configDlgClosed(); |
337 | } | 360 | } |
338 | 361 | ||
339 | // ConfigDlg::setMap {{{1 | ||
340 | |||
341 | /* | ||
342 | * the index is kinda screwy, because in the config file, index 0 is just the | ||
343 | * first element in the QStringList, but here it's the "Current Language" | ||
344 | * listItem. therefor you have to minus one to the index before you access it. | ||
345 | * | ||
346 | */ | ||
347 | |||
348 | void ConfigDlg::setMap(int index) { | 362 | void ConfigDlg::setMap(int index) { |
349 | 363 | ||
350 | if (index == 0) { | 364 | if (index == 0) { |
351 | |||
352 | remove_button->setDisabled(true); | 365 | remove_button->setDisabled(true); |
353 | emit setMapToDefault(); | ||
354 | } | 366 | } |
355 | else if (default_maps.find(sw_maps[index-1]) != default_maps.end()) { | 367 | else if (default_maps.find(sw_maps[index-1]) != default_maps.end()) { |
356 | |||
357 | remove_button->setDisabled(true); | 368 | remove_button->setDisabled(true); |
358 | emit setMapToFile(QPEApplication::qpeDir() + "share/multikey/" + sw_maps[index - 1]); | ||
359 | |||
360 | } else { | 369 | } else { |
361 | |||
362 | remove_button->setEnabled(true); | 370 | remove_button->setEnabled(true); |
363 | emit setMapToFile(sw_maps[index - 1]); | ||
364 | } | 371 | } |
365 | } | 372 | } |
366 | 373 | ||
367 | // ConfigDlg::addMap() {{{1 | 374 | // ConfigDlg::addMap() {{{1 |
@@ -400,14 +407,8 @@ void ConfigDlg::addMap() { | |||
400 | map_file.close(); | 407 | map_file.close(); |
401 | } | 408 | } |
402 | 409 | ||
403 | keymaps->setSelected(keymaps->count() - 1, true); | 410 | keymaps->setSelected(keymaps->count() - 1, true); |
404 | |||
405 | |||
406 | config.writeEntry("maps", maps, QChar('|')); | ||
407 | config.writeEntry("sw", sw_maps, QChar('|')); | ||
408 | config.writeEntry("current", map); | ||
409 | |||
410 | } | 411 | } |
411 | 412 | ||
412 | // ConfigDlg::removeMap() {{{1 | 413 | // ConfigDlg::removeMap() {{{1 |
413 | void ConfigDlg::removeMap() { | 414 | void ConfigDlg::removeMap() { |
@@ -418,14 +419,8 @@ void ConfigDlg::removeMap() { | |||
418 | keymaps->removeItem(keymaps->currentItem() + 1); | 419 | keymaps->removeItem(keymaps->currentItem() + 1); |
419 | 420 | ||
420 | custom_maps.remove(sw_maps[keymaps->currentItem()]); | 421 | custom_maps.remove(sw_maps[keymaps->currentItem()]); |
421 | sw_maps.remove(sw_maps.at(keymaps->currentItem())); | 422 | sw_maps.remove(sw_maps.at(keymaps->currentItem())); |
422 | |||
423 | // write the changes | ||
424 | Config config ("multikey"); | ||
425 | config.setGroup("keymaps"); | ||
426 | config.writeEntry("maps", custom_maps, QChar('|')); | ||
427 | config.writeEntry("sw", sw_maps, QChar('|')); | ||
428 | } | 423 | } |
429 | 424 | ||
430 | /* ConfigDlg::slots for the color buttons {{{1 | 425 | /* ConfigDlg::slots for the color buttons {{{1 |
431 | * | 426 | * |