summaryrefslogtreecommitdiff
path: root/inputmethods/multikey
Unidiff
Diffstat (limited to 'inputmethods/multikey') (more/less context) (show whitespace changes)
-rw-r--r--inputmethods/multikey/configdlg.cpp89
-rw-r--r--inputmethods/multikey/configdlg.h8
-rw-r--r--inputmethods/multikey/keyboard.cpp35
-rw-r--r--inputmethods/multikey/keyboard.h2
4 files changed, 92 insertions, 42 deletions
diff --git a/inputmethods/multikey/configdlg.cpp b/inputmethods/multikey/configdlg.cpp
index 157714c..a6e4dad 100644
--- a/inputmethods/multikey/configdlg.cpp
+++ b/inputmethods/multikey/configdlg.cpp
@@ -1,162 +1,219 @@
1/* 1/*
2 * TODO 2 * TODO
3 * make a font selection thing (size too) 3 * make a font selection thing (size too)
4 * 4 *
5 * 5 *
6 * 6 *
7 */ 7 */
8 8
9#include <iostream.h>
10
9#include <qpe/qpeapplication.h> 11#include <qpe/qpeapplication.h>
10#include <qpe/config.h> 12#include <qpe/config.h>
11 13
12#include <qwidget.h> 14#include <qwidget.h>
13#include <qdialog.h> 15#include <qdialog.h>
14#include <qtabwidget.h> 16#include <qtabwidget.h>
15#include <qvbox.h> 17#include <qvbox.h>
16#include <qgrid.h> 18#include <qgrid.h>
17#include <qgroupbox.h> 19#include <qgroupbox.h>
18#include <qlabel.h> 20#include <qlabel.h>
19#include <qcheckbox.h> 21#include <qcheckbox.h>
20#include <qsizepolicy.h> 22#include <qsizepolicy.h>
21#include <qpushbutton.h> 23#include <qpushbutton.h>
22#include <qlistbox.h> 24#include <qlistbox.h>
23#include <qstringlist.h> 25#include <qstringlist.h>
24#include <opie/ofiledialog.h> 26#include <opie/ofiledialog.h>
25#include <iostream.h> 27#include <qdir.h>
28#include <qfileinfo.h>
26#include "configdlg.h" 29#include "configdlg.h"
27#include "keyboard.h" 30#include "keyboard.h"
28 31
29ConfigDlg::ConfigDlg () : QTabWidget () 32ConfigDlg::ConfigDlg () : QTabWidget ()
30{ 33{
31 setCaption( tr("Multikey Configuration") ); 34 setCaption( tr("Multikey Configuration") );
32 Config config ("multikey"); 35 Config config ("multikey");
36 config.setGroup("keymaps");
37 QString current_map = config.readEntry("current", 0);
33 38
34 /* 39 /*
35 * 'general config' tab 40 * 'general config' tab
36 */ 41 */
37 42
38 QVBox *gen_box = new QVBox (this); 43 QVBox *gen_box = new QVBox (this);
39 gen_box->setMargin(3); 44 gen_box->setMargin(3);
40 addTab(gen_box, tr("General Settings")); 45 addTab(gen_box, tr("General Settings"));
41 46
42 QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); 47 QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box);
43 48
44 keymaps = new QListBox (map_group); 49 keymaps = new QListBox (map_group);
45 keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 50 keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
46 51
47 QString cur(tr("Current Language")); 52 QString cur(tr("Current Language"));
48 keymaps->insertItem(cur); 53 keymaps->insertItem(cur);
54 keymaps->setSelected(0, true);
49 55
50 config.setGroup ("keymaps"); 56 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap");
51 QStringList maps = config.readListEntry("maps", QChar('|')); 57 default_maps = map_dir.entryList(); // so i can access it in other places
58
59 for (uint i = 0; i <map_dir.count(); i++) {
60
61 keymaps->insertItem(map_dir.absPath() + "/" + map_dir[i]);
62 if (map_dir.absPath() + "/" + map_dir[i] == current_map) {
63
64 keymaps->setSelected(i + 1, true);
65 }
66
67 }
68
69 custom_maps = config.readListEntry("maps", QChar('|'));
70
71 for (uint i = 0; i < custom_maps.count(); i++) {
72
73 if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false)
74 || !QFile::exists(custom_maps[i])) {
75
76 custom_maps.remove(custom_maps.at(i));
77
78 // remove it from the list too
79 config.writeEntry("maps", custom_maps.join("|"));
52 80
53 for (unsigned int i = 0; i < maps.count(); i++) {
54 81
55 keymaps->insertItem(maps[i]); 82 } else {
83
84 keymaps->insertItem(custom_maps[i]);
85 if (custom_maps[i] == current_map) {
86
87 keymaps->setSelected(map_dir.count() + i + 1, true);
88 }
89 }
56 } 90 }
57 91
58 // have to "+1" because the "current language" listItem... remember? 92 // have to "+1" because the "current language" listItem... remember?
59 keymaps->setSelected(config.readNumEntry("current", 0) + 1, true);
60 93
61 connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); 94 connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int)));
62 95
63 96
64 QGrid *add_remove_grid = new QGrid(2, map_group); 97 QGrid *add_remove_grid = new QGrid(2, map_group);
65 add_remove_grid->setMargin(3); 98 add_remove_grid->setMargin(3);
66 add_remove_grid->setSpacing(3); 99 add_remove_grid->setSpacing(3);
67 100
68 add_button = new QPushButton(tr("Add"), add_remove_grid); 101 add_button = new QPushButton(tr("Add"), add_remove_grid);
69 add_button->setFlat((bool)1); 102 add_button->setFlat((bool)1);
70 connect(add_button, SIGNAL(clicked()), SLOT(addMap())); 103 connect(add_button, SIGNAL(clicked()), SLOT(addMap()));
71 104
72 remove_button = new QPushButton(tr("Remove"), add_remove_grid); 105 remove_button = new QPushButton(tr("Remove"), add_remove_grid);
73 remove_button->setFlat((bool)1); 106 remove_button->setFlat((bool)1);
107 connect(remove_button, SIGNAL(clicked()), SLOT(removeMap()));
74 108
75 pick_button = new QCheckBox(tr("Pickboard"), gen_box); 109 pick_button = new QCheckBox(tr("Pickboard"), gen_box);
76 110
77 config.setGroup ("pickboard"); 111 config.setGroup ("pickboard");
78 bool pick_open = config.readBoolEntry ("open", "0"); // default closed 112 bool pick_open = config.readBoolEntry ("open", "0"); // default closed
79 if (pick_open) { 113 if (pick_open) {
80 114
81 pick_button->setChecked(true); 115 pick_button->setChecked(true);
82 } 116 }
83 117
84 // by connecting it after checking it, the signal isn't emmited 118 // by connecting it after checking it, the signal isn't emmited
85 connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog())); 119 connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog()));
86 120
87 /* 121 /*
88 * 'color' tab 122 * 'color' tab
89 */ 123 */
90 124
91 QGrid *color_box = new QGrid(2, this); 125 QGrid *color_box = new QGrid(2, this);
92 color_box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); 126 color_box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
93 color_box->setMargin(3); 127 color_box->setMargin(3);
94 color_box->setSpacing(3); 128 color_box->setSpacing(3);
95 addTab(color_box, tr("Colors")); 129 addTab(color_box, tr("Colors"));
96 130
97 QLabel *label; 131 QLabel *label;
98 132
99 label = new QLabel(tr("Key Color"), color_box); 133 label = new QLabel(tr("Key Color"), color_box);
100 QPushButton *button = new QPushButton(color_box); 134 QPushButton *button = new QPushButton(color_box);
101 button->setFlat((bool)1); 135 button->setFlat((bool)1);
102 label = new QLabel(tr("Key Pressed Color"), color_box); 136 label = new QLabel(tr("Key Pressed Color"), color_box);
103 button = new QPushButton(color_box); 137 button = new QPushButton(color_box);
104 button->setFlat((bool)1); 138 button->setFlat((bool)1);
105 label = new QLabel(tr("Line Color"), color_box); 139 label = new QLabel(tr("Line Color"), color_box);
106 button = new QPushButton(color_box); 140 button = new QPushButton(color_box);
107 button->setFlat((bool)1); 141 button->setFlat((bool)1);
108 label = new QLabel(tr("Text Color"), color_box); 142 label = new QLabel(tr("Text Color"), color_box);
109 button = new QPushButton(color_box); 143 button = new QPushButton(color_box);
110 button->setFlat((bool)1); 144 button->setFlat((bool)1);
111 145
112 label = new QLabel("", color_box); // a spacer so the above buttons dont expand 146 label = new QLabel("", color_box); // a spacer so the above buttons dont expand
113 label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 147 label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
114 148
115} 149}
116 150
117void ConfigDlg::pickTog() { 151void ConfigDlg::pickTog() {
118 152
119 Config config ("multikey"); 153 Config config ("multikey");
120 config.setGroup ("pickboard"); 154 config.setGroup ("pickboard");
121 config.writeEntry ("open", pick_button->isChecked()); // default closed 155 config.writeEntry ("open", pick_button->isChecked()); // default closed
122 156
123 emit pickboardToggled(pick_button->isChecked()); 157 emit pickboardToggled(pick_button->isChecked());
124} 158}
125 159
126/* 160/*
127 * the index is kinda screwy, because in the config file, index 0 is just the 161 * the index is kinda screwy, because in the config file, index 0 is just the
128 * first element in the QStringList, but here it's the "Current Language" 162 * first element in the QStringList, but here it's the "Current Language"
129 * listItem. therefor you have to minus one to the index before you access 163 * listItem. therefor you have to minus one to the index before you access it.
130 * it from the config file.
131 * 164 *
132 * and later on, the "current language" setting should be -1 in the config file
133 */ 165 */
134 166
135void ConfigDlg::setMap(int index) { 167void ConfigDlg::setMap(int index) {
136 168
137 if (index == 0) { 169 if (index == 0) {
138 170
139 if (remove_button->isEnabled())
140 remove_button->setDisabled(true); 171 remove_button->setDisabled(true);
141 172
142 emit setMapToDefault(); 173 emit setMapToDefault();
143 } 174 }
144 else { 175 else if ((uint)index <= default_maps.count()) {
176
177 remove_button->setDisabled(true);
178
179 } else {
145 180
146 if (!remove_button->isEnabled())
147 remove_button->setEnabled(true); 181 remove_button->setEnabled(true);
148 182
149 emit setMapToFile(index - 1); 183 emit setMapToFile(keymaps->text(index));
150 } 184 }
151} 185}
152 186
153void ConfigDlg::addMap() { 187void ConfigDlg::addMap() {
154 188
155 QString map = OFileDialog::getOpenFileName(2, QPEApplication::qpeDir() + "/share/multikey"); 189 QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath());
156 cout << "added file " << map << "!\n"; 190 Config config ("multikey");
191 config.setGroup("keymaps");
192 QStringList maps = config.readListEntry("maps", QChar('|'));
193 maps.append(map);
194 keymaps->insertItem(map);
195 keymaps->setSelected(keymaps->count() - 1, true);
196
197
198 config.writeEntry("maps", maps.join("|"));
199 config.writeEntry("current", map);
157 200
158} 201}
159 202
160void ConfigDlg::removeMap(int index) { 203void ConfigDlg::removeMap() {
204
205 cout << "removing : " << custom_maps[keymaps->currentItem() - default_maps.count() - 1] << "\n";
206 cout << "currentItem : " << keymaps->currentItem() << "\n";
161 207
208 // move selection up one
209 keymaps->setSelected(keymaps->currentItem() - 1, true);
210 // delete the next selected item cus you just moved it up
211 keymaps->removeItem(keymaps->currentItem() + 1);
212
213 custom_maps.remove(custom_maps[keymaps->currentItem() - default_maps.count()]);
214
215 // write the changes
216 Config config ("multikey");
217 config.setGroup("keymaps");
218 config.writeEntry("maps", custom_maps.join("|"));
162} 219}
diff --git a/inputmethods/multikey/configdlg.h b/inputmethods/multikey/configdlg.h
index 03a3547..07d109c 100644
--- a/inputmethods/multikey/configdlg.h
+++ b/inputmethods/multikey/configdlg.h
@@ -1,36 +1,40 @@
1#include <qpe/qpeapplication.h> 1#include <qpe/qpeapplication.h>
2#include <qtabwidget.h> 2#include <qtabwidget.h>
3#include <qcheckbox.h> 3#include <qcheckbox.h>
4#include <qlistbox.h> 4#include <qlistbox.h>
5#include <qpushbutton.h> 5#include <qpushbutton.h>
6 6
7#ifndef CONFIGDLG_H 7#ifndef CONFIGDLG_H
8#define CONFIGDLG_H 8#define CONFIGDLG_H
9 9
10class ConfigDlg : public QTabWidget 10class ConfigDlg : public QTabWidget
11{ 11{
12 Q_OBJECT 12 Q_OBJECT
13 13
14public: 14public:
15 ConfigDlg (); 15 ConfigDlg ();
16 16
17signals: 17signals:
18 void pickboardToggled(bool on_off); 18 void pickboardToggled(bool on_off);
19 void setMapToDefault(); 19 void setMapToDefault();
20 void setMapToFile(int index); 20 void setMapToFile(QString map);
21 21
22private slots: 22private slots:
23 void pickTog(); 23 void pickTog();
24 void setMap(int index); 24 void setMap(int index);
25 void addMap(); 25 void addMap();
26 void removeMap(int index); 26 void removeMap();
27 27
28private: 28private:
29 QCheckBox *pick_button; 29 QCheckBox *pick_button;
30 QListBox *keymaps; 30 QListBox *keymaps;
31 QPushButton *add_button; 31 QPushButton *add_button;
32 QPushButton *remove_button; 32 QPushButton *remove_button;
33 33
34
35 QStringList default_maps; // the maps in your share/multikey/ dir
36 QStringList custom_maps; // maps you added with the 'add' button
37
34}; 38};
35 39
36#endif 40#endif
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index c53ae6c..ac3d9be 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -245,98 +245,98 @@ void Keyboard::drawKeyboard(QPainter &p, int row, int col)
245 x += keyWidthPix; 245 x += keyWidthPix;
246 } 246 }
247 247
248 248
249 } 249 }
250 p.drawLine(0, height() - 1, width(), height() - 1); 250 p.drawLine(0, height() - 1, width(), height() - 1);
251 p.drawLine(width() - 1, 0, width() - 1, height()); 251 p.drawLine(width() - 1, 0, width() - 1, height());
252 } 252 }
253 253
254} 254}
255 255
256 256
257/* Keyboard::mousePressEvent {{{1 */ 257/* Keyboard::mousePressEvent {{{1 */
258void Keyboard::mousePressEvent(QMouseEvent *e) 258void Keyboard::mousePressEvent(QMouseEvent *e)
259{ 259{
260 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; 260 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1;
261 if (row > 5) row = 5; 261 if (row > 5) row = 5;
262 262
263 // figure out the column 263 // figure out the column
264 int col = 0; 264 int col = 0;
265 for (int w = 0; e->x() >= w; col++) 265 for (int w = 0; e->x() >= w; col++)
266 if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys 266 if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys
267 w += keys->width(row,col) * defaultKeyWidth; 267 w += keys->width(row,col) * defaultKeyWidth;
268 else break; 268 else break;
269 269
270 col --; // rewind one... 270 col --; // rewind one...
271 271
272 qkeycode = keys->qcode(row, col); 272 qkeycode = keys->qcode(row, col);
273 unicode = keys->uni(row, col); 273 unicode = keys->uni(row, col);
274 274
275 // might need to repaint if two or more of the same keys. 275 // might need to repaint if two or more of the same keys.
276 // should be faster if just paint one key even though multiple keys exist. 276 // should be faster if just paint one key even though multiple keys exist.
277 bool need_repaint = FALSE; 277 bool need_repaint = FALSE;
278 278
279 if (unicode == 0) { // either Qt char, or nothing 279 if (unicode == 0) { // either Qt char, or nothing
280 280
281 if (qkeycode == Qt::Key_F1) { // toggle the pickboard 281 if (qkeycode == Qt::Key_F1) { // toggle the pickboard
282 282
283 if ( configdlg ) { 283 if ( configdlg ) {
284 delete (ConfigDlg *) configdlg; 284 delete (ConfigDlg *) configdlg;
285 configdlg = 0; 285 configdlg = 0;
286 } 286 }
287 else { 287 else {
288 configdlg = new ConfigDlg (); 288 configdlg = new ConfigDlg ();
289 connect(configdlg, SIGNAL(pickboardToggled(bool)), 289 connect(configdlg, SIGNAL(pickboardToggled(bool)),
290 this, SLOT(togglePickboard(bool))); 290 this, SLOT(togglePickboard(bool)));
291 connect(configdlg, SIGNAL(setMapToDefault()), 291 connect(configdlg, SIGNAL(setMapToDefault()),
292 this, SLOT(setMapToDefault())); 292 this, SLOT(setMapToDefault()));
293 connect(configdlg, SIGNAL(setMapToFile(int)), 293 connect(configdlg, SIGNAL(setMapToFile(QString)),
294 this, SLOT(setMapToFile(int))); 294 this, SLOT(setMapToFile(QString)));
295 configdlg->showMaximized(); 295 configdlg->showMaximized();
296 configdlg->show(); 296 configdlg->show();
297 configdlg->raise(); 297 configdlg->raise();
298 } 298 }
299 299
300 } else if (qkeycode == Qt::Key_Control) { 300 } else if (qkeycode == Qt::Key_Control) {
301 ctrl = keys->pressedPtr(row, col); 301 ctrl = keys->pressedPtr(row, col);
302 need_repaint = TRUE; 302 need_repaint = TRUE;
303 *ctrl = !keys->pressed(row, col); 303 *ctrl = !keys->pressed(row, col);
304 304
305 } else if (qkeycode == Qt::Key_Alt) { 305 } else if (qkeycode == Qt::Key_Alt) {
306 alt = keys->pressedPtr(row, col); 306 alt = keys->pressedPtr(row, col);
307 need_repaint = TRUE; 307 need_repaint = TRUE;
308 *alt = !keys->pressed(row, col); 308 *alt = !keys->pressed(row, col);
309 309
310 } else if (qkeycode == Qt::Key_Shift) { 310 } else if (qkeycode == Qt::Key_Shift) {
311 need_repaint = TRUE; 311 need_repaint = TRUE;
312 312
313 if (shift) { 313 if (shift) {
314 *shift = 0; 314 *shift = 0;
315 shift = 0; 315 shift = 0;
316 } 316 }
317 else { 317 else {
318 shift = keys->pressedPtr(row, col); 318 shift = keys->pressedPtr(row, col);
319 *shift = 1; 319 *shift = 1;
320 if (lock) { 320 if (lock) {
321 *lock = 0; 321 *lock = 0;
322 lock = 0; 322 lock = 0;
323 } 323 }
324 } 324 }
325 325
326 } else if (qkeycode == Qt::Key_CapsLock) { 326 } else if (qkeycode == Qt::Key_CapsLock) {
327 need_repaint = TRUE; 327 need_repaint = TRUE;
328 328
329 if (lock) { 329 if (lock) {
330 *lock = 0; 330 *lock = 0;
331 lock = 0; 331 lock = 0;
332 } 332 }
333 else { 333 else {
334 lock = keys->pressedPtr(row, col);; 334 lock = keys->pressedPtr(row, col);;
335 *lock = 1; 335 *lock = 1;
336 if (shift) { 336 if (shift) {
337 *shift = 0; 337 *shift = 0;
338 shift = 0; 338 shift = 0;
339 } 339 }
340 } 340 }
341 341
342 } 342 }
@@ -474,123 +474,120 @@ void Keyboard::resetState()
474{ 474{
475 schar = mchar = echar = 0; 475 schar = mchar = echar = 0;
476 picks->resetState(); 476 picks->resetState();
477} 477}
478 478
479/* Keyboard::togglePickboard {{{1 */ 479/* Keyboard::togglePickboard {{{1 */
480void Keyboard::togglePickboard(bool on_off) 480void Keyboard::togglePickboard(bool on_off)
481{ 481{
482 usePicks = on_off; 482 usePicks = on_off;
483 if (usePicks) { 483 if (usePicks) {
484 picks->show(); 484 picks->show();
485 //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send 485 //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send
486 //adjustSize(); 486 //adjustSize();
487 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 487 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
488 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 488 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
489 } else { 489 } else {
490 490
491 picks->hide(); 491 picks->hide();
492 picks->resetState(); 492 picks->resetState();
493 //move(x(), y() + picks->height()); 493 //move(x(), y() + picks->height());
494 //adjustSize(); 494 //adjustSize();
495 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 495 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
496 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 496 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
497 497
498 } 498 }
499 /* 499 /*
500 * this closes && opens the input method 500 * this closes && opens the input method
501 */ 501 */
502 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); 502 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
503 QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); 503 QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
504} 504}
505 505
506/* Keyboard::setMapTo ... {{{1 */ 506/* Keyboard::setMapTo ... {{{1 */
507void Keyboard::setMapToDefault() { 507void Keyboard::setMapToDefault() {
508 508
509 509
510 /* load current locale language map */ 510 /* load current locale language map */
511 Config *config = new Config("locale"); 511 Config *config = new Config("locale");
512 config->setGroup( "Language" ); 512 config->setGroup( "Language" );
513 QString l = config->readEntry( "Language" , "en" ); 513 QString l = config->readEntry( "Language" , "en" );
514 delete config; 514 delete config;
515 515
516 QString key_map = QPEApplication::qpeDir() + "/share/multikey/" 516 QString key_map = QPEApplication::qpeDir() + "/share/multikey/"
517 + l + ".keymap"; 517 + l + ".keymap";
518 518
519 /* save change to multikey config file */ 519 /* save change to multikey config file */
520 config = new Config("multikey"); 520 config = new Config("multikey");
521 config->setGroup ("keymaps"); 521 config->setGroup ("keymaps");
522 config->writeEntry ("current", -1); // default closed 522 config->writeEntry ("current", key_map); // default closed
523 delete config; 523 delete config;
524 524
525 delete keys; 525 delete keys;
526 keys = new Keys(key_map); 526 keys = new Keys(key_map);
527 527
528 // have to repaint the keyboard 528 // have to repaint the keyboard
529 repaint(FALSE); 529 repaint(FALSE);
530} 530}
531 531
532void Keyboard::setMapToFile(int index) { 532void Keyboard::setMapToFile(QString map) {
533 533
534 /* save change to multikey config file */ 534 /* save change to multikey config file */
535 Config *config = new Config("multikey"); 535 Config *config = new Config("multikey");
536 config->setGroup ("keymaps"); 536 config->setGroup ("keymaps");
537 config->writeEntry ("current", index); // default closed 537 config->writeEntry ("current", map); // default closed
538 538
539
540 /* now you have to retrieve the map */
541 QStringList maps = config->readListEntry("maps", QChar('|'));
542 delete config; 539 delete config;
543 540
544 delete keys; 541 delete keys;
545 if (index < 0 || (int)maps.count() <= index) 542 if (QFile(map).exists())
546 keys = new Keys(); 543 keys = new Keys(map);
547 else 544 else
548 keys = new Keys(maps[index]); 545 keys = new Keys();
549 546
550 repaint(FALSE); 547 repaint(FALSE);
551 548
552} 549}
553 550
554/* korean input functions {{{1 551/* korean input functions {{{1
555 * 552 *
556 * TODO 553 * TODO
557 * one major problem with this implementation is that you can't move the 554 * one major problem with this implementation is that you can't move the
558 * cursor after inputing korean chars, otherwise it will eat up and replace 555 * cursor after inputing korean chars, otherwise it will eat up and replace
559 * the char before the cursor you move to. fix that 556 * the char before the cursor you move to. fix that
560 * 557 *
561 * make backspace delete one single char, not the whole thing if still 558 * make backspace delete one single char, not the whole thing if still
562 * editing. 559 * editing.
563 * 560 *
564 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 561 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
565 * 562 *
566 * how korean input works 563 * how korean input works
567 * 564 *
568 * all following chars means unicode char value and are in hex 565 * all following chars means unicode char value and are in hex
569 * 566 *
570 * ÃÊÀ½ = schar (start char) 567 * ÃÊÀ½ = schar (start char)
571 * ÁßÀ½ = mchar (middle char) 568 * ÁßÀ½ = mchar (middle char)
572 * ³¡À½ = echar (end char) 569 * ³¡À½ = echar (end char)
573 * 570 *
574 * there are 19 schars. unicode position is at 1100 - 1112 571 * there are 19 schars. unicode position is at 1100 - 1112
575 * there are 21 mchars. unicode position is at 1161 - 1175 572 * there are 21 mchars. unicode position is at 1161 - 1175
576 * there are 27 echars. unicode position is at 11a8 - 11c2 573 * there are 27 echars. unicode position is at 11a8 - 11c2
577 * 574 *
578 * the map with everything combined is at ac00 - d7a3 575 * the map with everything combined is at ac00 - d7a3
579 * 576 *
580 */ 577 */
581 578
582ushort Keyboard::parseKoreanInput (ushort c) { 579ushort Keyboard::parseKoreanInput (ushort c) {
583 580
584 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) 581 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c))
585 || 582 ||
586 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode 583 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode
587 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { 584 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) {
588 585
589 schar = 0, mchar = 0, echar = 0; 586 schar = 0, mchar = 0, echar = 0;
590 return c; 587 return c;
591 } 588 }
592 589
593 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input 590 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input
594 591
595 if (schar == 0 || (schar != 0 && mchar == 0)) { 592 if (schar == 0 || (schar != 0 && mchar == 0)) {
596 schar = c; mchar = 0; echar = 0; 593 schar = c; mchar = 0; echar = 0;
@@ -814,120 +811,112 @@ ushort Keyboard::constoe(const ushort c) {
814 case 0x1106: return 0x11b7; 811 case 0x1106: return 0x11b7;
815 case 0x1107: return 0x11b8; 812 case 0x1107: return 0x11b8;
816 case 0x1109: return 0x11ba; 813 case 0x1109: return 0x11ba;
817 case 0x110a: return 0x11bb; 814 case 0x110a: return 0x11bb;
818 case 0x110b: return 0x11bc; 815 case 0x110b: return 0x11bc;
819 case 0x110c: return 0x11bd; 816 case 0x110c: return 0x11bd;
820 case 0x110e: return 0x11be; 817 case 0x110e: return 0x11be;
821 case 0x110f: return 0x11bf; 818 case 0x110f: return 0x11bf;
822 case 0x1110: return 0x11c0; 819 case 0x1110: return 0x11c0;
823 case 0x1111: return 0x11c1; 820 case 0x1111: return 0x11c1;
824 case 0x1112: return 0x11c2; 821 case 0x1112: return 0x11c2;
825 default: return 0; 822 default: return 0;
826 823
827 } 824 }
828 825
829 } else { //echar to schar 826 } else { //echar to schar
830 827
831 switch (c) { 828 switch (c) {
832 case 0x11a8: return 0x1100; 829 case 0x11a8: return 0x1100;
833 case 0x11a9: return 0x1101; 830 case 0x11a9: return 0x1101;
834 case 0x11ab: return 0x1102; 831 case 0x11ab: return 0x1102;
835 case 0x11ae: return 0x1103; 832 case 0x11ae: return 0x1103;
836 case 0x11af: return 0x1105; 833 case 0x11af: return 0x1105;
837 case 0x11b7: return 0x1106; 834 case 0x11b7: return 0x1106;
838 case 0x11b8: return 0x1107; 835 case 0x11b8: return 0x1107;
839 case 0x11ba: return 0x1109; 836 case 0x11ba: return 0x1109;
840 case 0x11bb: return 0x110a; 837 case 0x11bb: return 0x110a;
841 case 0x11bc: return 0x110b; 838 case 0x11bc: return 0x110b;
842 case 0x11bd: return 0x110c; 839 case 0x11bd: return 0x110c;
843 case 0x11be: return 0x110e; 840 case 0x11be: return 0x110e;
844 case 0x11bf: return 0x110f; 841 case 0x11bf: return 0x110f;
845 case 0x11c0: return 0x1110; 842 case 0x11c0: return 0x1110;
846 case 0x11c1: return 0x1111; 843 case 0x11c1: return 0x1111;
847 case 0x11c2: return 0x1112; 844 case 0x11c2: return 0x1112;
848 default: return 0; 845 default: return 0;
849 846
850 } 847 }
851 848
852 } 849 }
853} 850}
854 851
855 852
856// Keys::Keys {{{1 853// Keys::Keys {{{1
857 854
858Keys::Keys() { 855Keys::Keys() {
859 856
860 Config *config = new Config ("multikey"); 857 Config *config = new Config ("multikey");
861 config->setGroup( "keymaps" ); 858 config->setGroup( "keymaps" );
862 QStringList maps = config->readListEntry ("maps", QChar('|')); 859 QString map = config->readEntry( "current" );
863
864 int index = config->readNumEntry( "current", -1 );
865 delete config; 860 delete config;
866 861
867 QString key_map; 862 if (map.isNull() || !(QFile(map).exists())) {
868
869 if (index < 0 || (int)maps.count() <= index) {
870 863
871 Config *config = new Config("locale"); 864 Config *config = new Config("locale");
872 config->setGroup( "Language" ); 865 config->setGroup( "Language" );
873 QString l = config->readEntry( "Language" , "en" ); 866 QString l = config->readEntry( "Language" , "en" );
874 delete config; 867 delete config;
875 868
876 key_map = QPEApplication::qpeDir() + "/share/multikey/" 869 map = QPEApplication::qpeDir() + "/share/multikey/"
877 + l + ".keymap"; 870 + l + ".keymap";
878 871
879 } else {
880
881 key_map = maps[index];
882 } 872 }
883 873
884 874 setKeysFromFile(map);
885 setKeysFromFile(key_map);
886} 875}
887 876
888Keys::Keys(const char * filename) { 877Keys::Keys(const char * filename) {
889 878
890 setKeysFromFile(filename); 879 setKeysFromFile(filename);
891} 880}
892 881
893// Keys::setKeysFromFile {{{2 882// Keys::setKeysFromFile {{{2
894void Keys::setKeysFromFile(const char * filename) { 883void Keys::setKeysFromFile(const char * filename) {
895 884
896 QFile f(filename); 885 QFile f(filename);
897 886
898 if (f.open(IO_ReadOnly)) { 887 if (f.open(IO_ReadOnly)) {
899 888
900 QTextStream t(&f); 889 QTextStream t(&f);
901 int row; 890 int row;
902 int qcode; 891 int qcode;
903 ushort unicode; 892 ushort unicode;
904 int width; 893 int width;
905 QString buf; 894 QString buf;
906 QString comment; 895 QString comment;
907 char * xpm[256]; //couldnt be larger than that... could it? 896 char * xpm[256]; //couldnt be larger than that... could it?
908 QPixmap *xpm2pix = 0; 897 QPixmap *xpm2pix = 0;
909 898
910 buf = t.readLine(); 899 buf = t.readLine();
911 while (buf) { 900 while (buf) {
912 901
913 // key definition 902 // key definition
914 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { 903 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) {
915 // no $1 type referencing!!! this implementation of regexp sucks 904 // no $1 type referencing!!! this implementation of regexp sucks
916 905
917 // dont know of any sscanf() type funcs in Qt lib 906 // dont know of any sscanf() type funcs in Qt lib
918 QTextStream tmp (buf, IO_ReadOnly); 907 QTextStream tmp (buf, IO_ReadOnly);
919 tmp >> row >> qcode >> unicode >> width >> comment; 908 tmp >> row >> qcode >> unicode >> width >> comment;
920 909
921 buf = t.readLine(); 910 buf = t.readLine();
922 int xpmLineCount = 0; 911 int xpmLineCount = 0;
923 xpm2pix = 0; 912 xpm2pix = 0;
924 913
925 // erase blank space 914 // erase blank space
926 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); 915 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine();
927 916
928 while (buf.contains(QRegExp("^\\s*\".*\""))) { 917 while (buf.contains(QRegExp("^\\s*\".*\""))) {
929 918
930 QString xpmBuf = buf.stripWhiteSpace(); 919 QString xpmBuf = buf.stripWhiteSpace();
931 920
932 xpm[xpmLineCount] = new char [xpmBuf.length()]; 921 xpm[xpmLineCount] = new char [xpmBuf.length()];
933 922
diff --git a/inputmethods/multikey/keyboard.h b/inputmethods/multikey/keyboard.h
index 7a8d4b4..805f0ed 100644
--- a/inputmethods/multikey/keyboard.h
+++ b/inputmethods/multikey/keyboard.h
@@ -68,91 +68,91 @@ public:
68 void setKey(const int row, const int qcode, const ushort unicode, 68 void setKey(const int row, const int qcode, const ushort unicode,
69 const int width, QPixmap *pix); 69 const int width, QPixmap *pix);
70 void setPressed(const int row, const int col, const bool pressed); 70 void setPressed(const int row, const int col, const bool pressed);
71 QString lang; 71 QString lang;
72 QString title; 72 QString title;
73 73
74private: 74private:
75 75
76 typedef struct Key { 76 typedef struct Key {
77 int qcode; // are qt key codes just unicode values? 77 int qcode; // are qt key codes just unicode values?
78 ushort unicode; 78 ushort unicode;
79 int width; // not pixels but relative key width. normal key is 2 79 int width; // not pixels but relative key width. normal key is 2
80 80
81 // only needed for keys like ctrl that can have multiple keys pressed at once 81 // only needed for keys like ctrl that can have multiple keys pressed at once
82 bool *pressed; 82 bool *pressed;
83 QPixmap *pix; 83 QPixmap *pix;
84 }; 84 };
85 85
86 QList<Key> keys[6]; 86 QList<Key> keys[6];
87 QMap<ushort,ushort> shiftMap; 87 QMap<ushort,ushort> shiftMap;
88 88
89}; 89};
90 90
91class Keyboard : public QFrame 91class Keyboard : public QFrame
92{ 92{
93 Q_OBJECT 93 Q_OBJECT
94public: 94public:
95 Keyboard( QWidget* parent=0, const char* name=0, WFlags f=0 ); 95 Keyboard( QWidget* parent=0, const char* name=0, WFlags f=0 );
96 ~Keyboard(); 96 ~Keyboard();
97 97
98 void resetState(); 98 void resetState();
99 99
100 void mousePressEvent(QMouseEvent*); 100 void mousePressEvent(QMouseEvent*);
101 void mouseReleaseEvent(QMouseEvent*); 101 void mouseReleaseEvent(QMouseEvent*);
102 void resizeEvent(QResizeEvent*); 102 void resizeEvent(QResizeEvent*);
103 void paintEvent(QPaintEvent* e); 103 void paintEvent(QPaintEvent* e);
104 //void timerEvent(QTimerEvent* e); 104 //void timerEvent(QTimerEvent* e);
105 void drawKeyboard( QPainter &p, int row = -1, int col = -1); 105 void drawKeyboard( QPainter &p, int row = -1, int col = -1);
106 106
107 QSize sizeHint() const; 107 QSize sizeHint() const;
108 108
109signals: 109signals:
110 void key( ushort scancode, ushort unicode, ushort modifiers, bool, bool ); 110 void key( ushort scancode, ushort unicode, ushort modifiers, bool, bool );
111 111
112private slots: 112private slots:
113 void repeat(); 113 void repeat();
114 void togglePickboard(bool on_off); 114 void togglePickboard(bool on_off);
115 void setMapToDefault(); 115 void setMapToDefault();
116 void setMapToFile(int index); 116 void setMapToFile(QString map);
117 117
118private: 118private:
119 int getKey( int &w, int j = -1 ); 119 int getKey( int &w, int j = -1 );
120 void clearHighlight(); 120 void clearHighlight();
121 121
122 bool *shift; 122 bool *shift;
123 bool *lock; 123 bool *lock;
124 bool *ctrl; 124 bool *ctrl;
125 bool *alt; 125 bool *alt;
126 uint useLargeKeys:1; 126 uint useLargeKeys:1;
127 uint usePicks:1; 127 uint usePicks:1;
128 128
129 int pressedKeyRow; 129 int pressedKeyRow;
130 int pressedKeyCol; 130 int pressedKeyCol;
131 131
132 KeyboardPicks *picks; 132 KeyboardPicks *picks;
133 133
134 int keyHeight; 134 int keyHeight;
135 int defaultKeyWidth; 135 int defaultKeyWidth;
136 int xoffs; 136 int xoffs;
137 137
138 int unicode; 138 int unicode;
139 int qkeycode; 139 int qkeycode;
140 int modifiers; 140 int modifiers;
141 141
142 int pressTid; 142 int pressTid;
143 bool pressed; 143 bool pressed;
144 144
145 Keys *keys; 145 Keys *keys;
146 146
147 /* for korean input */ 147 /* for korean input */
148 ushort schar, mchar, echar; 148 ushort schar, mchar, echar;
149 ushort parseKoreanInput(ushort c); 149 ushort parseKoreanInput(ushort c);
150 ushort combineKoreanChars(const ushort s, const ushort m, const ushort e); 150 ushort combineKoreanChars(const ushort s, const ushort m, const ushort e);
151 ushort constoe(const ushort c); 151 ushort constoe(const ushort c);
152 152
153 QTimer *repeatTimer; 153 QTimer *repeatTimer;
154 154
155 ConfigDlg *configdlg; 155 ConfigDlg *configdlg;
156}; 156};
157 157
158 158