summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/configdlg.cpp238
-rw-r--r--inputmethods/multikey/configdlg.h8
-rw-r--r--inputmethods/multikey/keyboard.cpp42
-rw-r--r--inputmethods/multikey/keyboard.h2
4 files changed, 209 insertions, 81 deletions
diff --git a/inputmethods/multikey/configdlg.cpp b/inputmethods/multikey/configdlg.cpp
index a8206b7..f127d0e 100644
--- a/inputmethods/multikey/configdlg.cpp
+++ b/inputmethods/multikey/configdlg.cpp
@@ -1,428 +1,514 @@
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 keymap editor 4 * make a keymap editor
5 * make keys translucent 5 * make keys translucent
6 * make vertical keys possible 6 * make vertical keys possible
7 * 7 *
8 * 8 *
9 */ 9 */
10 10
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 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>
27#include <qtoolbutton.h>
26#include <opie/ofiledialog.h> 28#include <opie/ofiledialog.h>
27#include <opie/colordialog.h> 29#include <opie/colordialog.h>
28#include <qdir.h> 30#include <qdir.h>
29#include <qfileinfo.h> 31#include <qfileinfo.h>
30#include "configdlg.h" 32#include "configdlg.h"
31#include "keyboard.h" 33#include "keyboard.h"
32 34
33// ConfigDlg::ConfigDlg() {{{1 35// ConfigDlg::ConfigDlg() {{{1
34ConfigDlg::ConfigDlg () : QTabWidget () 36ConfigDlg::ConfigDlg () : QTabWidget ()
35{ 37{
36 setCaption( tr("Multikey Configuration") ); 38 setCaption( tr("Multikey Configuration") );
37 Config config ("multikey"); 39 Config config ("multikey");
38 config.setGroup("keymaps"); 40 config.setGroup("keymaps");
39 QString current_map = config.readEntry("current", 0); 41 QString current_map = config.readEntry("current", 0);
40 42
41 /* 43 /*
42 * 'general config' tab 44 * 'general config' tab
43 */ 45 */
44 46
45 QVBox *gen_box = new QVBox (this); 47 QVBox *gen_box = new QVBox (this);
46 gen_box->setMargin(3); 48 gen_box->setMargin(3);
47 addTab(gen_box, tr("General Settings")); 49 addTab(gen_box, tr("General Settings"));
48 50
49 QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); 51 QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box);
50 52
51 keymaps = new QListBox (map_group); 53 QHBox *hbox1 = new QHBox(map_group);
54 keymaps = new QListBox(hbox1);
52 keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 55 keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
56 QVBox *vbox1 = new QVBox(hbox1);
57
58 QToolButton *tb1 = new QToolButton(vbox1, tr("Move Up"));
59 tb1->setPixmap(Resource::loadPixmap("up"));
60 tb1->setAutoRaise(TRUE);
61 tb1->setFocusPolicy(QWidget::NoFocus);
62 tb1->setToggleButton(FALSE);
63 connect(tb1, SIGNAL(clicked()), this, SLOT(moveSelectedUp()));
64
65 QToolButton *tb2 = new QToolButton(vbox1, tr("Move Down"));
66 tb2->setPixmap(Resource::loadPixmap("down"));
67 tb2->setAutoRaise(TRUE);
68 tb2->setFocusPolicy(QWidget::NoFocus);
69 tb2->setToggleButton(FALSE);
70 connect(tb2, SIGNAL(clicked()), this, SLOT(moveSelectedDown()));
53 71
54 QString cur(tr("Current Language")); 72 QString cur(tr("Current Language"));
55 keymaps->insertItem(cur); 73 keymaps->insertItem(cur);
56 keymaps->setSelected(0, true); 74 keymaps->setSelected(0, true);
57 75
58 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap"); 76 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap");
59 default_maps = map_dir.entryList(); // so i can access it in other places 77 default_maps = map_dir.entryList(); // so i can access it in other places
60
61 for (uint i = 0; i < map_dir.count(); i++) {
62
63 QFile map (map_dir.absPath() + "/" + map_dir[i]);
64 if (map.open(IO_ReadOnly)) {
65
66 QString line; bool found = 0;
67
68 map.readLine(line, 1024);
69 while (!map.atEnd()) {
70
71 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) {
72
73 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
74 found = 1;
75 break;
76 }
77 map.readLine(line, 1024);
78 }
79 if (!found) keymaps->insertItem(map_dir.absPath() + "/" + map_dir[i]);
80
81 map.close();
82 }
83 if (map_dir.absPath() + "/" + map_dir[i] == current_map) {
84
85 keymaps->setSelected(i + 1, true);
86 }
87
88 }
89
90 custom_maps = config.readListEntry("maps", QChar('|')); 78 custom_maps = config.readListEntry("maps", QChar('|'));
79 sw_maps = ConfigDlg::loadSw();
91 80
92 for (uint i = 0; i < custom_maps.count(); i++) { 81 QStringList sw_copy(sw_maps);
82 for (uint i = 0; i < sw_copy.count(); i++) {
93 83
94 if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false) 84 QString keymap_map;
95 || !QFile::exists(custom_maps[i])) { 85 if (sw_copy[i][0] != '/') { /* share/multikey */
96 86
97 custom_maps.remove(custom_maps.at(i)); 87 keymap_map = map_dir.absPath() + "/" + sw_copy[i];
88 } else {
98 89
99 // remove it from the list too 90 if (map_dir.exists(QFileInfo(sw_copy[i]).fileName(), false)
100 config.writeEntry("maps", custom_maps.join("|")); 91 || !QFile::exists(sw_copy[i])) {
101 92
93 custom_maps.remove(sw_copy[i]);
94 sw_maps.remove(sw_copy[i]);
102 95
103 } else { 96 // remove it from the list too
97 config.writeEntry("maps", custom_maps.join("|"));
104 98
105 QFile map (custom_maps[i]); 99 continue;
106 if (map.open(IO_ReadOnly)) { 100 }
101 keymap_map = sw_copy[i];
102 }
107 103
108 QString line; bool found = 0; 104 QFile map(keymap_map);
105 if (map.open(IO_ReadOnly)) {
109 106
110 map.readLine(line, 1024); 107 QString line; bool found = 0;
111 while (!map.atEnd()) {
112 108
113 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) { 109 map.readLine(line, 1024);
114 110 while (!map.atEnd()) {
115 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
116 found = 1;
117 break;
118 }
119 map.readLine(line, 1024);
120 }
121 if (!found) keymaps->insertItem(custom_maps[i]);
122
123 map.close();
124 }
125 if (custom_maps[i] == current_map) {
126 111
127 keymaps->setSelected(map_dir.count() + i + 1, true); 112 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) {
128 } 113
129 } 114 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
115 found = 1;
116 break;
117 }
118 map.readLine(line, 1024);
119 }
120 if (!found)
121 keymaps->insertItem(keymap_map);
122
123 map.close();
124 }
125
126 if (keymap_map == current_map) {
127 keymaps->setSelected(i + 1, true);
128 }
130 } 129 }
131 130
132 // have to "+1" because the "current language" listItem... remember? 131 // have to "+1" because the "current language" listItem... remember?
133 132
134 connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); 133 connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int)));
135 134
136
137 QGrid *add_remove_grid = new QGrid(2, map_group); 135 QGrid *add_remove_grid = new QGrid(2, map_group);
138 add_remove_grid->setMargin(3); 136 add_remove_grid->setMargin(3);
139 add_remove_grid->setSpacing(3); 137 add_remove_grid->setSpacing(3);
140 138
141 add_button = new QPushButton(tr("Add"), add_remove_grid); 139 add_button = new QPushButton(tr("Add"), add_remove_grid);
142 add_button->setFlat((bool)1); 140 add_button->setFlat(TRUE);
143 connect(add_button, SIGNAL(clicked()), SLOT(addMap())); 141 connect(add_button, SIGNAL(clicked()), SLOT(addMap()));
144 142
145 remove_button = new QPushButton(tr("Remove"), add_remove_grid); 143 remove_button = new QPushButton(tr("Remove"), add_remove_grid);
146 remove_button->setFlat((bool)1); 144 remove_button->setFlat(TRUE);
147 if ((int)map_dir.count() >= keymaps->currentItem()) 145 if (default_maps.find(QFileInfo(current_map).fileName()) != default_maps.end())
148 remove_button->setDisabled(true); 146 remove_button->setDisabled(true);
149 connect(remove_button, SIGNAL(clicked()), SLOT(removeMap())); 147 connect(remove_button, SIGNAL(clicked()), SLOT(removeMap()));
150 148
151 // make a box that will contain the buttons on the bottom 149 // make a box that will contain the buttons on the bottom
152 QGrid *other_grid = new QGrid(2, gen_box); 150 QGrid *other_grid = new QGrid(2, gen_box);
153 pick_button = new QCheckBox(tr("Pickboard"), other_grid); 151 pick_button = new QCheckBox(tr("Pickboard"), other_grid);
154 152
155 config.setGroup ("general"); 153 config.setGroup ("general");
156 bool pick_open = config.readBoolEntry ("usePickboard", (bool)0); // default closed 154 bool pick_open = config.readBoolEntry ("usePickboard", FALSE); // default closed
157 if (pick_open) { 155 if (pick_open) {
158 156
159 pick_button->setChecked(true); 157 pick_button->setChecked(true);
160 } 158 }
161 159
162 // by connecting it after checking it, the signal isn't emmited 160 // by connecting it after checking it, the signal isn't emmited
163 connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog())); 161 connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog()));
164 162
165 repeat_button = new QCheckBox(tr("Key Repeat"), other_grid); 163 repeat_button = new QCheckBox(tr("Key Repeat"), other_grid);
166 bool repeat_on = config.readBoolEntry ("useRepeat", (bool)1); 164 bool repeat_on = config.readBoolEntry ("useRepeat", TRUE);
167 165
168 if (repeat_on) { 166 if (repeat_on) {
169 167
170 repeat_button->setChecked(true); 168 repeat_button->setChecked(true);
171 } 169 }
172 connect (repeat_button, SIGNAL(clicked()), this, SLOT(repeatTog())); 170 connect (repeat_button, SIGNAL(clicked()), this, SLOT(repeatTog()));
173 171
174
175 /* 172 /*
176 * 'color' tab 173 * 'color' tab
177 */ 174 */
178 175
179 QGrid *color_box = new QGrid(2, this); 176 QGrid *color_box = new QGrid(2, this);
180 color_box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); 177 color_box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
181 color_box->setMargin(3); 178 color_box->setMargin(3);
182 color_box->setSpacing(3); 179 color_box->setSpacing(3);
183 addTab(color_box, tr("Colors")); 180 addTab(color_box, tr("Colors"));
184 181
185 QLabel *label; 182 QLabel *label;
186 QStringList color; 183 QStringList color;
187 config.setGroup("colors"); 184 config.setGroup("colors");
188 185
189 label = new QLabel(tr("Key Color"), color_box); 186 label = new QLabel(tr("Key Color"), color_box);
190 keycolor_button = new QPushButton(color_box); 187 keycolor_button = new QPushButton(color_box);
191 connect(keycolor_button, SIGNAL(clicked()), SLOT(keyColorClicked())); 188 connect(keycolor_button, SIGNAL(clicked()), SLOT(keyColorClicked()));
192 keycolor_button->setFlat((bool)1); 189 keycolor_button->setFlat(TRUE);
193 color = config.readListEntry("keycolor", QChar(',')); 190 color = config.readListEntry("keycolor", QChar(','));
194 /* 191 /*
195 * hopefully not required 192 * hopefully not required
196 193
197 if (color.isEmpty()) { 194 if (color.isEmpty()) {
198 color = QStringList::split(",", "240,240,240"); 195 color = QStringList::split(",", "240,240,240");
199 config.writeEntry("keycolor", color.join(",")); 196 config.writeEntry("keycolor", color.join(","));
200 197
201 } 198 }
202 */ 199 */
203 keycolor_button->setPalette(QPalette(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))); 200 keycolor_button->setPalette(QPalette(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())));
204 201
205 202
206 label = new QLabel(tr("Key Pressed Color"), color_box); 203 label = new QLabel(tr("Key Pressed Color"), color_box);
207 keycolor_pressed_button = new QPushButton(color_box); 204 keycolor_pressed_button = new QPushButton(color_box);
208 connect(keycolor_pressed_button, SIGNAL(clicked()), SLOT(keyColorPressedClicked())); 205 connect(keycolor_pressed_button, SIGNAL(clicked()), SLOT(keyColorPressedClicked()));
209 keycolor_pressed_button->setFlat((bool)1); 206 keycolor_pressed_button->setFlat(TRUE);
210 color = config.readListEntry("keycolor_pressed", QChar(',')); 207 color = config.readListEntry("keycolor_pressed", QChar(','));
211 keycolor_pressed_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); 208 keycolor_pressed_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))));
212 209
213 label = new QLabel(tr("Line Color"), color_box); 210 label = new QLabel(tr("Line Color"), color_box);
214 keycolor_lines_button = new QPushButton(color_box); 211 keycolor_lines_button = new QPushButton(color_box);
215 connect(keycolor_lines_button, SIGNAL(clicked()), SLOT(keyColorLinesClicked())); 212 connect(keycolor_lines_button, SIGNAL(clicked()), SLOT(keyColorLinesClicked()));
216 keycolor_lines_button->setFlat((bool)1); 213 keycolor_lines_button->setFlat(TRUE);
217 color = config.readListEntry("keycolor_lines", QChar(',')); 214 color = config.readListEntry("keycolor_lines", QChar(','));
218 keycolor_lines_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); 215 keycolor_lines_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))));
219 216
220 217
221 label = new QLabel(tr("Text Color"), color_box); 218 label = new QLabel(tr("Text Color"), color_box);
222 textcolor_button = new QPushButton(color_box); 219 textcolor_button = new QPushButton(color_box);
223 connect(textcolor_button, SIGNAL(clicked()), SLOT(textColorClicked())); 220 connect(textcolor_button, SIGNAL(clicked()), SLOT(textColorClicked()));
224 textcolor_button->setFlat((bool)1); 221 textcolor_button->setFlat(TRUE);
225 color = config.readListEntry("textcolor", QChar(',')); 222 color = config.readListEntry("textcolor", QChar(','));
226 textcolor_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())))); 223 textcolor_button->setPalette(QPalette((QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()))));
227 224
228
229 label = new QLabel("", color_box); // a spacer so the above buttons dont expand 225 label = new QLabel("", color_box); // a spacer so the above buttons dont expand
230 label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 226 label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
227}
228
229ConfigDlg::~ConfigDlg()
230{
231 emit reloadSw();
232}
233
234QStringList ConfigDlg::loadSw()
235{
236 Config *config = new Config("multikey");
237 config->setGroup("keymaps");
238 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap");
239 QStringList d_maps = map_dir.entryList(); // so i can access it in other places
240 QStringList c_maps = config->readListEntry("maps", QChar('|'));
241 QStringList s_maps = config->readListEntry("sw", QChar('|'));
242 delete config;
243
244 if (!s_maps.count())
245 {
246 s_maps = d_maps+c_maps;
247 }
248 else
249 {
250 /* Clear non existents entries */
251 QStringList s_copy = s_maps;
252 for (uint i = 0; i < s_copy.count(); ++i) {
253 if (d_maps.find(s_copy[i]) == d_maps.end()
254 && c_maps.find(s_copy[i]) == c_maps.end()) {
255 s_maps.remove(s_copy[i]);
256 }
257 }
258 /* Update sw_maps from default_maps */
259 for (uint i = 0; i < d_maps.count(); ++i) {
260 if (s_maps.find(d_maps[i]) == s_maps.end()) {
261 s_maps.append(d_maps[i]);
262 }
263 }
264 /* Update sw_maps from custom_maps */
265 for (uint i = 0; i < c_maps.count(); ++i) {
266 if (s_maps.find(c_maps[i]) == s_maps.end()) {
267 s_maps.append(c_maps[i]);
268 }
269 }
270 }
271
272 return s_maps;
273}
274
275void ConfigDlg::moveSelectedUp()
276{
277 int i = keymaps->currentItem();
278 /* Ignore Current Language */
279 if (i > 1) {
280 QString t = sw_maps[i-1];
281 sw_maps[i-1] = sw_maps[i-2];
282 sw_maps[i-2] = t;
283
284 QString item = keymaps->currentText();
285 keymaps->removeItem(i);
286 keymaps->insertItem(item, i-1);
287 keymaps->setCurrentItem(i-1);
288
289 Config config("multikey");
290 config.setGroup("keymaps");
291 config.writeEntry("sw", sw_maps, QChar('|'));
292 }
293}
231 294
295void ConfigDlg::moveSelectedDown()
296{
297 int i = keymaps->currentItem();
298 /* Ignore Current Language */
299 if (i > 0 && i < (int)keymaps->count() - 1) {
300 QString t = sw_maps[i-1];
301 sw_maps[i-1] = sw_maps[i];
302 sw_maps[i] = t;
303
304 QString item = keymaps->currentText();
305 keymaps->removeItem(i);
306 keymaps->insertItem(item, i+1);
307 keymaps->setCurrentItem(i+1);
308
309 Config config("multikey");
310 config.setGroup("keymaps");
311 config.writeEntry("sw", sw_maps, QChar('|'));
312 }
232} 313}
233 314
234void ConfigDlg::pickTog() { 315void ConfigDlg::pickTog() {
235 316
236 Config config ("multikey"); 317 Config config ("multikey");
237 config.setGroup ("general"); 318 config.setGroup ("general");
238 config.writeEntry ("usePickboard", pick_button->isChecked()); // default closed 319 config.writeEntry ("usePickboard", pick_button->isChecked()); // default closed
239 320
240 emit pickboardToggled(pick_button->isChecked()); 321 emit pickboardToggled(pick_button->isChecked());
241} 322}
242 323
243void ConfigDlg::repeatTog() { 324void ConfigDlg::repeatTog() {
244 325
245 Config config ("multikey"); 326 Config config ("multikey");
246 config.setGroup ("general"); 327 config.setGroup ("general");
247 config.writeEntry ("useRepeat", repeat_button->isChecked()); // default closed 328 config.writeEntry ("useRepeat", repeat_button->isChecked()); // default closed
248 329
249 emit repeatToggled(repeat_button->isChecked()); 330 emit repeatToggled(repeat_button->isChecked());
250} 331}
251 332
252void ConfigDlg::closeEvent(QCloseEvent *) { 333void ConfigDlg::closeEvent(QCloseEvent *) {
253 334
254 // tell the parent it was closed, so delete me 335 // tell the parent it was closed, so delete me
255 emit configDlgClosed(); 336 emit configDlgClosed();
256} 337}
257 338
258// ConfigDlg::setMap {{{1 339// ConfigDlg::setMap {{{1
259 340
260/* 341/*
261 * the index is kinda screwy, because in the config file, index 0 is just the 342 * the index is kinda screwy, because in the config file, index 0 is just the
262 * first element in the QStringList, but here it's the "Current Language" 343 * first element in the QStringList, but here it's the "Current Language"
263 * listItem. therefor you have to minus one to the index before you access it. 344 * listItem. therefor you have to minus one to the index before you access it.
264 * 345 *
265 */ 346 */
266 347
267void ConfigDlg::setMap(int index) { 348void ConfigDlg::setMap(int index) {
268 349
269 if (index == 0) { 350 if (index == 0) {
270 351
271 remove_button->setDisabled(true); 352 remove_button->setDisabled(true);
272 emit setMapToDefault(); 353 emit setMapToDefault();
273 } 354 }
274 else if ((uint)index <= default_maps.count()) { 355 else if (default_maps.find(sw_maps[index-1]) != default_maps.end()) {
275 356
276 remove_button->setDisabled(true); 357 remove_button->setDisabled(true);
277 emit setMapToFile(QPEApplication::qpeDir() + "share/multikey/" + default_maps[index - 1]); 358 emit setMapToFile(QPEApplication::qpeDir() + "share/multikey/" + sw_maps[index - 1]);
278 359
279 } else { 360 } else {
280 361
281 remove_button->setEnabled(true); 362 remove_button->setEnabled(true);
282 emit setMapToFile(custom_maps[index - default_maps.count() - 1]); 363 emit setMapToFile(sw_maps[index - 1]);
283 } 364 }
284} 365}
285 366
286// ConfigDlg::addMap() {{{1 367// ConfigDlg::addMap() {{{1
287void ConfigDlg::addMap() { 368void ConfigDlg::addMap() {
288 369
289 QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath()); 370 QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath());
290 371
291 if (map.isNull()) return; 372 if (map.isNull()) return;
292 373
293 Config config ("multikey"); 374 Config config ("multikey");
294 config.setGroup("keymaps"); 375 config.setGroup("keymaps");
295 QStringList maps = config.readListEntry("maps", QChar('|')); 376 QStringList maps = config.readListEntry("maps", QChar('|'));
296 maps.append(map); 377 maps.append(map);
297 custom_maps.append(map); 378 custom_maps.append(map);
379 if (sw_maps.find(map) == sw_maps.end())
380 sw_maps.append(map);
298 381
299 QFile map_file (map); 382 QFile map_file (map);
300 if (map_file.open(IO_ReadOnly)) { 383 if (map_file.open(IO_ReadOnly)) {
301 384
302 QString line; bool found = 0; 385 QString line; bool found = 0;
303 386
304 map_file.readLine(line, 1024); 387 map_file.readLine(line, 1024);
305 while (!map_file.atEnd()) { 388 while (!map_file.atEnd()) {
306 389
307 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) { 390 if (line.find(QRegExp("^title\\s*=\\s*")) != -1) {
308 391
309 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace()); 392 keymaps->insertItem(line.right(line.length() - line.find(QChar('=')) - 1).stripWhiteSpace());
310 found = 1; 393 found = 1;
311 break; 394 break;
312 } 395 }
313 map_file.readLine(line, 1024); 396 map_file.readLine(line, 1024);
314 } 397 }
315 if (!found) keymaps->insertItem(map); 398 if (!found) keymaps->insertItem(map);
316 399
317 map_file.close(); 400 map_file.close();
318 } 401 }
319 402
320 keymaps->setSelected(keymaps->count() - 1, true); 403 keymaps->setSelected(keymaps->count() - 1, true);
321 404
322 405
323 config.writeEntry("maps", maps, QChar('|')); 406 config.writeEntry("maps", maps, QChar('|'));
407 config.writeEntry("sw", sw_maps, QChar('|'));
324 config.writeEntry("current", map); 408 config.writeEntry("current", map);
325 409
326} 410}
327 411
328// ConfigDlg::removeMap() {{{1 412// ConfigDlg::removeMap() {{{1
329void ConfigDlg::removeMap() { 413void ConfigDlg::removeMap() {
330 414
331 // move selection up one 415 // move selection up one
332 keymaps->setSelected(keymaps->currentItem() - 1, true); 416 keymaps->setSelected(keymaps->currentItem() - 1, true);
333 // delete the next selected item cus you just moved it up 417 // delete the next selected item cus you just moved it up
334 keymaps->removeItem(keymaps->currentItem() + 1); 418 keymaps->removeItem(keymaps->currentItem() + 1);
335 419
336 custom_maps.remove(custom_maps.at(keymaps->currentItem() - default_maps.count())); 420 custom_maps.remove(sw_maps[keymaps->currentItem()]);
421 sw_maps.remove(sw_maps.at(keymaps->currentItem()));
337 422
338 // write the changes 423 // write the changes
339 Config config ("multikey"); 424 Config config ("multikey");
340 config.setGroup("keymaps"); 425 config.setGroup("keymaps");
341 config.writeEntry("maps", custom_maps, QChar('|')); 426 config.writeEntry("maps", custom_maps, QChar('|'));
427 config.writeEntry("sw", sw_maps, QChar('|'));
342} 428}
343 429
344/* ConfigDlg::slots for the color buttons {{{1 430/* ConfigDlg::slots for the color buttons {{{1
345 * 431 *
346 * these four slots are almost the same, except for the names. i was thinking 432 * these four slots are almost the same, except for the names. i was thinking
347 * of making a map with pointers to the buttons and names of the configEntry 433 * of making a map with pointers to the buttons and names of the configEntry
348 * so it could be one slot, but then there would be no way of telling which 434 * so it could be one slot, but then there would be no way of telling which
349 * of the buttons was clicked if they all connect to the same slot. 435 * of the buttons was clicked if they all connect to the same slot.
350 * 436 *
351 */ 437 */
352 438
353void ConfigDlg::keyColorClicked() { 439void ConfigDlg::keyColorClicked() {
354 440
355 Config config ("multikey"); 441 Config config ("multikey");
356 config.setGroup ("colors"); 442 config.setGroup ("colors");
357 443
358 QStringList color = config.readListEntry("keycolor", QChar(',')); 444 QStringList color = config.readListEntry("keycolor", QChar(','));
359 445
360 QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); 446 QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
361 447
362 color[0].setNum(newcolor.red()); 448 color[0].setNum(newcolor.red());
363 color[1].setNum(newcolor.green()); 449 color[1].setNum(newcolor.green());
364 color[2].setNum(newcolor.blue()); 450 color[2].setNum(newcolor.blue());
365 451
366 config.writeEntry("keycolor", color, QChar(',')); 452 config.writeEntry("keycolor", color, QChar(','));
367 config.write(); 453 config.write();
368 454
369 keycolor_button->setPalette(QPalette(newcolor)); 455 keycolor_button->setPalette(QPalette(newcolor));
370 emit reloadKeyboard(); 456 emit reloadKeyboard();
371} 457}
372void ConfigDlg::keyColorPressedClicked() { 458void ConfigDlg::keyColorPressedClicked() {
373 459
374 Config config ("multikey"); 460 Config config ("multikey");
375 config.setGroup ("colors"); 461 config.setGroup ("colors");
376 462
377 QStringList color = config.readListEntry("keycolor_pressed", QChar(',')); 463 QStringList color = config.readListEntry("keycolor_pressed", QChar(','));
378 464
379 QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); 465 QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
380 466
381 color[0].setNum(newcolor.red()); 467 color[0].setNum(newcolor.red());
382 color[1].setNum(newcolor.green()); 468 color[1].setNum(newcolor.green());
383 color[2].setNum(newcolor.blue()); 469 color[2].setNum(newcolor.blue());
384 470
385 config.writeEntry("keycolor_pressed", color, QChar(',')); 471 config.writeEntry("keycolor_pressed", color, QChar(','));
386 config.write(); 472 config.write();
387 473
388 keycolor_pressed_button->setPalette(QPalette(newcolor)); 474 keycolor_pressed_button->setPalette(QPalette(newcolor));
389 emit reloadKeyboard(); 475 emit reloadKeyboard();
390} 476}
391void ConfigDlg::keyColorLinesClicked() { 477void ConfigDlg::keyColorLinesClicked() {
392 478
393 Config config ("multikey"); 479 Config config ("multikey");
394 config.setGroup ("colors"); 480 config.setGroup ("colors");
395 481
396 QStringList color = config.readListEntry("keycolor_lines", QChar(',')); 482 QStringList color = config.readListEntry("keycolor_lines", QChar(','));
397 483
398 QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); 484 QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
399 485
400 color[0].setNum(newcolor.red()); 486 color[0].setNum(newcolor.red());
401 color[1].setNum(newcolor.green()); 487 color[1].setNum(newcolor.green());
402 color[2].setNum(newcolor.blue()); 488 color[2].setNum(newcolor.blue());
403 489
404 config.writeEntry("keycolor_lines", color, QChar(',')); 490 config.writeEntry("keycolor_lines", color, QChar(','));
405 config.write(); 491 config.write();
406 492
407 keycolor_lines_button->setPalette(QPalette(newcolor)); 493 keycolor_lines_button->setPalette(QPalette(newcolor));
408 emit reloadKeyboard(); 494 emit reloadKeyboard();
409} 495}
410void ConfigDlg::textColorClicked() { 496void ConfigDlg::textColorClicked() {
411 497
412 Config config ("multikey"); 498 Config config ("multikey");
413 config.setGroup ("colors"); 499 config.setGroup ("colors");
414 500
415 QStringList color = config.readListEntry("textcolor", QChar(',')); 501 QStringList color = config.readListEntry("textcolor", QChar(','));
416 502
417 QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); 503 QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
418 504
419 color[0].setNum(newcolor.red()); 505 color[0].setNum(newcolor.red());
420 color[1].setNum(newcolor.green()); 506 color[1].setNum(newcolor.green());
421 color[2].setNum(newcolor.blue()); 507 color[2].setNum(newcolor.blue());
422 508
423 config.writeEntry("textcolor", color, QChar(',')); 509 config.writeEntry("textcolor", color, QChar(','));
424 config.write(); 510 config.write();
425 511
426 textcolor_button->setPalette(QPalette(newcolor)); 512 textcolor_button->setPalette(QPalette(newcolor));
427 emit reloadKeyboard(); 513 emit reloadKeyboard();
428} 514}
diff --git a/inputmethods/multikey/configdlg.h b/inputmethods/multikey/configdlg.h
index 336932b..ea157c5 100644
--- a/inputmethods/multikey/configdlg.h
+++ b/inputmethods/multikey/configdlg.h
@@ -1,59 +1,67 @@
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 ~ConfigDlg ();
17 static QStringList ConfigDlg::loadSw();
16 18
17signals: 19signals:
18 void pickboardToggled(bool on_off); 20 void pickboardToggled(bool on_off);
19 void repeatToggled(bool on_off); 21 void repeatToggled(bool on_off);
20 void setMapToDefault(); 22 void setMapToDefault();
21 void setMapToFile(QString map); 23 void setMapToFile(QString map);
22 void reloadKeyboard(); 24 void reloadKeyboard();
23 void configDlgClosed(); 25 void configDlgClosed();
26 void reloadSw();
27
28protected slots:
29 void moveSelectedUp();
30 void moveSelectedDown();
24 31
25private slots: 32private slots:
26 void pickTog(); 33 void pickTog();
27 void repeatTog(); 34 void repeatTog();
28 void setMap(int index); 35 void setMap(int index);
29 void addMap(); 36 void addMap();
30 void removeMap(); 37 void removeMap();
31 virtual void closeEvent ( QCloseEvent * ); 38 virtual void closeEvent ( QCloseEvent * );
32 39
33 40
34 // all those required slots for the color push buttons 41 // all those required slots for the color push buttons
35 void keyColorClicked(); 42 void keyColorClicked();
36 void keyColorPressedClicked(); 43 void keyColorPressedClicked();
37 void keyColorLinesClicked(); 44 void keyColorLinesClicked();
38 void textColorClicked(); 45 void textColorClicked();
39 46
40private: 47private:
41 QCheckBox *pick_button; 48 QCheckBox *pick_button;
42 QCheckBox *repeat_button; 49 QCheckBox *repeat_button;
43 QListBox *keymaps; 50 QListBox *keymaps;
44 QPushButton *add_button; 51 QPushButton *add_button;
45 QPushButton *remove_button; 52 QPushButton *remove_button;
46 53
47 54
48 QStringList default_maps; // the maps in your share/multikey/ dir 55 QStringList default_maps; // the maps in your share/multikey/ dir
49 QStringList custom_maps; // maps you added with the 'add' button 56 QStringList custom_maps; // maps you added with the 'add' button
57 QStringList sw_maps; // maps, which used in keyboard switch rotation ring
50 58
51 /* color buttons */ 59 /* color buttons */
52 QPushButton *keycolor_button; 60 QPushButton *keycolor_button;
53 QPushButton *keycolor_pressed_button; 61 QPushButton *keycolor_pressed_button;
54 QPushButton *keycolor_lines_button; 62 QPushButton *keycolor_lines_button;
55 QPushButton *textcolor_button; 63 QPushButton *textcolor_button;
56 64
57}; 65};
58 66
59#endif 67#endif
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index 2ce6dd3..aec0ad3 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -1,1120 +1,1152 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "keyboard.h" 21#include "keyboard.h"
22#include "configdlg.h" 22#include "configdlg.h"
23 23
24#include <qpe/global.h> 24#include <qpe/global.h>
25#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
26 26
27#include <qwindowsystem_qws.h> 27#include <qwindowsystem_qws.h>
28#include <qpainter.h> 28#include <qpainter.h>
29#include <qfontmetrics.h> 29#include <qfontmetrics.h>
30#include <qtimer.h> 30#include <qtimer.h>
31#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
32#include <qpe/config.h> 32#include <qpe/config.h>
33#include <ctype.h> 33#include <ctype.h>
34#include <qfile.h> 34#include <qdir.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qstringlist.h> 36#include <qstringlist.h>
37 37
38#include <sys/utsname.h> 38#include <sys/utsname.h>
39 39
40using namespace MultiKey; 40using namespace MultiKey;
41 41
42static const char * const kb_config_xpm[] = { 42static const char * const kb_config_xpm[] = {
43"13 7 2 1", 43"13 7 2 1",
44" c None", 44" c None",
45". c #000000", 45". c #000000",
46" ", 46" ",
47" . ", 47" . ",
48" ... ", 48" ... ",
49" ..... ", 49" ..... ",
50" . ", 50" . ",
51" . ", 51" . ",
52" "}; 52" "};
53 53
54/* Keyboard::Keyboard {{{1 */ 54/* Keyboard::Keyboard {{{1 */
55Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : 55Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) :
56 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0), 56 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0),
57 meta(0), circumflex(0), diaeresis(0), baccent(0), accent(0), 57 meta(0), circumflex(0), diaeresis(0), baccent(0), accent(0),
58 useLargeKeys(TRUE), usePicks(0), useRepeat(0), 58 useLargeKeys(TRUE), usePicks(0), useRepeat(0),
59 pressedKeyRow(-1), pressedKeyCol(-1), 59 pressedKeyRow(-1), pressedKeyCol(-1),
60 unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), 60 unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0),
61 configdlg(0) 61 configdlg(0)
62 62
63{ 63{
64 64
65 // get the default font 65 // get the default font
66 Config *config = new Config( "qpe" ); 66 Config *config = new Config( "qpe" );
67 config->setGroup( "Appearance" ); 67 config->setGroup( "Appearance" );
68 QString familyStr = config->readEntry( "FontFamily", "smallsmooth" ); 68 QString familyStr = config->readEntry( "FontFamily", "smallsmooth" );
69 delete config; 69 delete config;
70 70
71 config = new Config("multikey"); 71 config = new Config("multikey");
72 config->setGroup ("general"); 72 config->setGroup ("general");
73 usePicks = config->readBoolEntry ("usePickboard", 0); // default closed 73 usePicks = config->readBoolEntry ("usePickboard", 0); // default closed
74 useRepeat = config->readBoolEntry ("useRepeat", 1); 74 useRepeat = config->readBoolEntry ("useRepeat", 1);
75 delete config; 75 delete config;
76 76
77 77
78 setFont( QFont( familyStr, 10 ) ); 78 setFont( QFont( familyStr, 10 ) );
79 79
80 picks = new KeyboardPicks( this ); 80 picks = new KeyboardPicks( this );
81 picks->setFont( QFont( familyStr, 10 ) ); 81 picks->setFont( QFont( familyStr, 10 ) );
82 picks->initialise(); 82 picks->initialise();
83 if (usePicks) { 83 if (usePicks) {
84 84
85 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 85 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
86 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 86 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
87 87
88 } else picks->hide(); 88 } else picks->hide();
89 89
90 loadKeyboardColors(); 90 loadKeyboardColors();
91 91
92 keys = new Keys(); 92 keys = new Keys();
93 93
94 repeatTimer = new QTimer( this ); 94 repeatTimer = new QTimer( this );
95 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); 95 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) );
96 96
97 QCopChannel* kbdChannel = new QCopChannel("MultiKey/Keyboard", this);
98 connect(kbdChannel, SIGNAL(received(const QCString &, const QByteArray &)),
99 this, SLOT(receive(const QCString &, const QByteArray &)));
97} 100}
98 101
99Keyboard::~Keyboard() { 102Keyboard::~Keyboard() {
100 103
101 if ( configdlg ) { 104 if ( configdlg ) {
102 delete (ConfigDlg *) configdlg; 105 delete configdlg;
103 configdlg = 0; 106 configdlg = 0;
104 } 107 }
105 108
106} 109}
107 110
108/* Keyboard::resizeEvent {{{1 */ 111/* Keyboard::resizeEvent {{{1 */
109void Keyboard::resizeEvent(QResizeEvent*) 112void Keyboard::resizeEvent(QResizeEvent*)
110{ 113{
111 int ph = picks->sizeHint().height(); 114 int ph = picks->sizeHint().height();
112 picks->setGeometry( 0, 0, width(), ph ); 115 picks->setGeometry( 0, 0, width(), ph );
113 keyHeight = (height()-(usePicks ? ph : 0))/(keys->rows()?keys->rows():1); 116 keyHeight = (height()-(usePicks ? ph : 0))/(keys->rows()?keys->rows():1);
114 117
115 int nk; // number of keys? 118 int nk; // number of keys?
116 if ( useLargeKeys ) { 119 if ( useLargeKeys ) {
117 nk = 15; 120 nk = 15;
118 } else { 121 } else {
119 nk = 19; 122 nk = 19;
120 } 123 }
121 defaultKeyWidth = (width()/nk)/2; 124 defaultKeyWidth = (width()/nk)/2;
122 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? 125 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces?
123 126
124} 127}
125 128
126/* KeyboardPicks::initialize {{{1 */ 129/* KeyboardPicks::initialize {{{1 */
127void KeyboardPicks::initialise() 130void KeyboardPicks::initialise()
128{ 131{
129 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); 132 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
130 mode = 0; 133 mode = 0;
131 dc = new KeyboardConfig(this); 134 dc = new KeyboardConfig(this);
132 configs.append(dc); 135 configs.append(dc);
133} 136}
134 137
135/* KeyboardPicks::sizeHint {{{1 */ 138/* KeyboardPicks::sizeHint {{{1 */
136QSize KeyboardPicks::sizeHint() const 139QSize KeyboardPicks::sizeHint() const
137{ 140{
138 return QSize(240,fontMetrics().lineSpacing()); 141 return QSize(240,fontMetrics().lineSpacing());
139} 142}
140 143
141 144
142/* KeyboardConfig::generateText {{{1 */ 145/* KeyboardConfig::generateText {{{1 */
143void KeyboardConfig::generateText(const QString &s) 146void KeyboardConfig::generateText(const QString &s)
144{ 147{
145#if defined(Q_WS_QWS) || defined(_WS_QWS_) 148#if defined(Q_WS_QWS) || defined(_WS_QWS_)
146 for (int i=0; i<(int)backspaces; i++) { 149 for (int i=0; i<(int)backspaces; i++) {
147 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); 150 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false );
148 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); 151 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false );
149 } 152 }
150 for (int i=0; i<(int)s.length(); i++) { 153 for (int i=0; i<(int)s.length(); i++) {
151 parent->emitKey( s[i].unicode(), 0, 0, true, false ); 154 parent->emitKey( s[i].unicode(), 0, 0, true, false );
152 parent->emitKey( s[i].unicode(), 0, 0, false, false ); 155 parent->emitKey( s[i].unicode(), 0, 0, false, false );
153 } 156 }
154 parent->emitKey( 0, Qt::Key_Space, 0, true, false ); 157 parent->emitKey( 0, Qt::Key_Space, 0, true, false );
155 parent->emitKey( 0, Qt::Key_Space, 0, false, false ); 158 parent->emitKey( 0, Qt::Key_Space, 0, false, false );
156 backspaces = 0; 159 backspaces = 0;
157#endif 160#endif
158} 161}
159 162
160 163
161 164
162 165
163/* Keyboard::paintEvent {{{1 */ 166/* Keyboard::paintEvent {{{1 */
164void Keyboard::paintEvent(QPaintEvent* e) 167void Keyboard::paintEvent(QPaintEvent* e)
165{ 168{
166 QPainter painter(this); 169 QPainter painter(this);
167 painter.setClipRect(e->rect()); 170 painter.setClipRect(e->rect());
168 drawKeyboard( painter ); 171 drawKeyboard( painter );
169 picks->dc->draw( &painter ); 172 picks->dc->draw( &painter );
170} 173}
171 174
172 175
173/* Keyboard::drawKeyboard {{{1 */ 176/* Keyboard::drawKeyboard {{{1 */
174 177
175void Keyboard::drawKeyboard(QPainter &p, int row, int col) 178void Keyboard::drawKeyboard(QPainter &p, int row, int col)
176{ 179{
177 180
178 181
179 if (row != -1 && col != -1) { //just redraw one key 182 if (row != -1 && col != -1) { //just redraw one key
180 183
181 int x = 0; 184 int x = 0;
182 for (int i = 0; i < col; i++) { 185 for (int i = 0; i < col; i++) {
183 186
184 x += keys->width(row, i) * defaultKeyWidth; 187 x += keys->width(row, i) * defaultKeyWidth;
185 } 188 }
186 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 189 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
187 190
188 int keyWidth = keys->width(row, col); 191 int keyWidth = keys->width(row, col);
189 192
190 p.fillRect(x + 1, y + 1, 193 p.fillRect(x + 1, y + 1,
191 keyWidth * defaultKeyWidth - 1, keyHeight - 1, 194 keyWidth * defaultKeyWidth - 1, keyHeight - 1,
192 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); 195 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor);
193 196
194 QImage *pix = keys->pix(row,col); 197 QImage *pix = keys->pix(row,col);
195 198
196 ushort c = keys->uni(row, col); 199 ushort c = keys->uni(row, col);
197 200
198 p.setPen(textcolor); 201 p.setPen(textcolor);
199 if (!pix) { 202 if (!pix) {
200 if ((shift || lock) && keys->shift(c)) 203 if ((shift || lock) && keys->shift(c))
201 204
202 if (circumflex && keys->circumflex(keys->shift(c))) 205 if (circumflex && keys->circumflex(keys->shift(c)))
203 c = keys->circumflex(keys->shift(c)); 206 c = keys->circumflex(keys->shift(c));
204 else if (diaeresis && keys->diaeresis(keys->shift(c))) 207 else if (diaeresis && keys->diaeresis(keys->shift(c)))
205 c = keys->diaeresis(keys->shift(c)); 208 c = keys->diaeresis(keys->shift(c));
206 else if (baccent && keys->baccent(keys->shift(c))) 209 else if (baccent && keys->baccent(keys->shift(c)))
207 c = keys->baccent(keys->shift(c)); 210 c = keys->baccent(keys->shift(c));
208 else if (accent && keys->accent(keys->shift(c))) 211 else if (accent && keys->accent(keys->shift(c)))
209 c = keys->accent(keys->shift(c)); 212 c = keys->accent(keys->shift(c));
210 else if (meta && keys->meta(keys->shift(c))) 213 else if (meta && keys->meta(keys->shift(c)))
211 c = keys->meta(keys->shift(c)); 214 c = keys->meta(keys->shift(c));
212 else 215 else
213 c = keys->shift(c); 216 c = keys->shift(c);
214 217
215 else if (meta && keys->meta(c)) 218 else if (meta && keys->meta(c))
216 c = keys->meta(c); 219 c = keys->meta(c);
217 else if (circumflex && keys->circumflex(c)) 220 else if (circumflex && keys->circumflex(c))
218 c = keys->circumflex(c); 221 c = keys->circumflex(c);
219 else if (baccent && keys->baccent(c)) 222 else if (baccent && keys->baccent(c))
220 c = keys->baccent(c); 223 c = keys->baccent(c);
221 else if (accent && keys->accent(c)) 224 else if (accent && keys->accent(c))
222 c = keys->accent(c); 225 c = keys->accent(c);
223 else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { 226 else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) {
224 227
225 // the diaeresis key itself has to be in the diaeresisMap, 228 // the diaeresis key itself has to be in the diaeresisMap,
226 // or just do this to make it display the diaeresis char. 229 // or just do this to make it display the diaeresis char.
227 230
228 if (c == 0x2c6) 231 if (c == 0x2c6)
229 c = 0xa8; 232 c = 0xa8;
230 else 233 else
231 c = keys->diaeresis(c); 234 c = keys->diaeresis(c);
232 } 235 }
233 236
234 p.drawText(x, y, 237 p.drawText(x, y,
235 defaultKeyWidth * keyWidth + 3, keyHeight, 238 defaultKeyWidth * keyWidth + 3, keyHeight,
236 AlignCenter, (QChar)c); 239 AlignCenter, (QChar)c);
237 } 240 }
238 else 241 else
239 // center the image in the middle of the key 242 // center the image in the middle of the key
240 p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2 + 1, 243 p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2 + 1,
241 y + (keyHeight - pix->height())/2 + 1, 244 y + (keyHeight - pix->height())/2 + 1,
242 *pix ); 245 *pix );
243 246
244 // this fixes the problem that the very right end of the board's vertical line 247 // this fixes the problem that the very right end of the board's vertical line
245 // gets painted over, because it's one pixel shorter than all other keys 248 // gets painted over, because it's one pixel shorter than all other keys
246 p.setPen(keycolor_lines); 249 p.setPen(keycolor_lines);
247 p.drawLine(width() - 1, 0, width() - 1, height()); 250 p.drawLine(width() - 1, 0, width() - 1, height());
248 251
249 } else { 252 } else {
250 253
251 254
252 p.fillRect(0, 0, width(), height(), keycolor); 255 p.fillRect(0, 0, width(), height(), keycolor);
253 256
254 for (row = 1; row <= keys->rows(); row++) { 257 for (row = 1; row <= keys->rows(); row++) {
255 258
256 int x = 0; 259 int x = 0;
257 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 260 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
258 261
259 p.setPen(keycolor_lines); 262 p.setPen(keycolor_lines);
260 p.drawLine(x, y, x + width(), y); 263 p.drawLine(x, y, x + width(), y);
261 264
262 for (int col = 0; col < keys->numKeys(row); col++) { 265 for (int col = 0; col < keys->numKeys(row); col++) {
263 266
264 QImage *pix = keys->pix(row, col); 267 QImage *pix = keys->pix(row, col);
265 int keyWidth = keys->width(row, col); 268 int keyWidth = keys->width(row, col);
266 269
267 270
268 int keyWidthPix = defaultKeyWidth * keyWidth; 271 int keyWidthPix = defaultKeyWidth * keyWidth;
269 272
270 if (keys->pressed(row, col)) 273 if (keys->pressed(row, col))
271 p.fillRect(x+1, y+1, keyWidthPix - 1, 274 p.fillRect(x+1, y+1, keyWidthPix - 1,
272 keyHeight - 1, keycolor_pressed); 275 keyHeight - 1, keycolor_pressed);
273 276
274 ushort c = keys->uni(row, col); 277 ushort c = keys->uni(row, col);
275 278
276 p.setPen(textcolor); 279 p.setPen(textcolor);
277 if (!pix) { 280 if (!pix) {
278 if ((shift || lock) && keys->shift(c)) 281 if ((shift || lock) && keys->shift(c))
279 282
280 if (circumflex && keys->circumflex(keys->shift(c))) 283 if (circumflex && keys->circumflex(keys->shift(c)))
281 c = keys->circumflex(keys->shift(c)); 284 c = keys->circumflex(keys->shift(c));
282 else if (diaeresis && keys->diaeresis(keys->shift(c))) 285 else if (diaeresis && keys->diaeresis(keys->shift(c)))
283 c = keys->diaeresis(keys->shift(c)); 286 c = keys->diaeresis(keys->shift(c));
284 else if (baccent && keys->baccent(keys->shift(c))) 287 else if (baccent && keys->baccent(keys->shift(c)))
285 c = keys->baccent(keys->shift(c)); 288 c = keys->baccent(keys->shift(c));
286 else if (accent && keys->accent(keys->shift(c))) 289 else if (accent && keys->accent(keys->shift(c)))
287 c = keys->accent(keys->shift(c)); 290 c = keys->accent(keys->shift(c));
288 else if (meta && keys->meta(keys->shift(c))) 291 else if (meta && keys->meta(keys->shift(c)))
289 c = keys->meta(keys->shift(c)); 292 c = keys->meta(keys->shift(c));
290 else 293 else
291 c = keys->shift(c); 294 c = keys->shift(c);
292 295
293 else if (meta && keys->meta(c)) 296 else if (meta && keys->meta(c))
294 c = keys->meta(c); 297 c = keys->meta(c);
295 else if (circumflex && keys->circumflex(c)) 298 else if (circumflex && keys->circumflex(c))
296 c = keys->circumflex(c); 299 c = keys->circumflex(c);
297 else if (baccent && keys->baccent(c)) 300 else if (baccent && keys->baccent(c))
298 c = keys->baccent(c); 301 c = keys->baccent(c);
299 else if (accent && keys->accent(c)) 302 else if (accent && keys->accent(c))
300 c = keys->accent(c); 303 c = keys->accent(c);
301 else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { 304 else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) {
302 305
303 if (c == 0x2c6) 306 if (c == 0x2c6)
304 c = 0xa8; 307 c = 0xa8;
305 else 308 else
306 c = keys->diaeresis(c); 309 c = keys->diaeresis(c);
307 } 310 }
308 311
309 p.drawText(x, y, 312 p.drawText(x, y,
310 keyWidthPix + 3, keyHeight, 313 keyWidthPix + 3, keyHeight,
311 AlignCenter, (QChar)c); 314 AlignCenter, (QChar)c);
312 } 315 }
313 else { 316 else {
314 // center the image in the middle of the key 317 // center the image in the middle of the key
315 pix->setColor(1, textcolor.rgb()); 318 pix->setColor(1, textcolor.rgb());
316 p.drawImage( x + (keyWidthPix - pix->width())/2 + 1, 319 p.drawImage( x + (keyWidthPix - pix->width())/2 + 1,
317 y + (keyHeight - pix->height())/2 + 1, 320 y + (keyHeight - pix->height())/2 + 1,
318 QImage(*pix) ); 321 QImage(*pix) );
319 } 322 }
320 323
321 p.setPen(keycolor_lines); 324 p.setPen(keycolor_lines);
322 p.drawLine(x, y, x, y + keyHeight); 325 p.drawLine(x, y, x, y + keyHeight);
323 326
324 x += keyWidthPix; 327 x += keyWidthPix;
325 } 328 }
326 329
327 330
328 } 331 }
329 p.setPen(keycolor_lines); 332 p.setPen(keycolor_lines);
330 p.drawLine(0, height() - 1, width(), height() - 1); 333 p.drawLine(0, height() - 1, width(), height() - 1);
331 p.drawLine(width() - 1, 0, width() - 1, height()); 334 p.drawLine(width() - 1, 0, width() - 1, height());
332 } 335 }
333 336
334} 337}
335 338
336 339
337/* Keyboard::mousePressEvent {{{1 */ 340/* Keyboard::mousePressEvent {{{1 */
338void Keyboard::mousePressEvent(QMouseEvent *e) 341void Keyboard::mousePressEvent(QMouseEvent *e)
339{ 342{
340 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; 343 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1;
341 if (row > 5) row = 5; 344 if (row > 5) row = 5;
342 345
343 // figure out the column 346 // figure out the column
344 int col = 0; 347 int col = 0;
345 for (int w = 0; e->x() >= w; col++) 348 for (int w = 0; e->x() >= w; col++)
346 if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys 349 if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys
347 w += keys->width(row,col) * defaultKeyWidth; 350 w += keys->width(row,col) * defaultKeyWidth;
348 else break; 351 else break;
349 352
350 if (col <= 0) return; 353 if (col <= 0) return;
351 354
352 col --; // rewind one... 355 col --; // rewind one...
353 356
354 qkeycode = keys->qcode(row, col); 357 qkeycode = keys->qcode(row, col);
355 unicode = keys->uni(row, col); 358 unicode = keys->uni(row, col);
356 359
357 // might need to repaint if two or more of the same keys. 360 // might need to repaint if two or more of the same keys.
358 // should be faster if just paint one key even though multiple keys exist. 361 // should be faster if just paint one key even though multiple keys exist.
359 bool need_repaint = FALSE; 362 bool need_repaint = FALSE;
360 363
361 // circumflex and diaeresis support 364 // circumflex and diaeresis support
362 // messy to have this here, but too hard to implement any other method 365 // messy to have this here, but too hard to implement any other method
363 if (unicode == 0x2c6) { 366 if (unicode == 0x2c6) {
364 367
365 unicode = 0; 368 unicode = 0;
366 if (shift || lock) { 369 if (shift || lock) {
367 370
368 // diaeresis 371 // diaeresis
369 qkeycode = 0x2001; 372 qkeycode = 0x2001;
370 } 373 }
371 else { 374 else {
372 375
373 // circumflex 376 // circumflex
374 qkeycode = 0x2000; 377 qkeycode = 0x2000;
375 } 378 }
376 } 379 }
377 380
378 // Back accent character support 381 // Back accent character support
379 382
380 // the keys from 2c6 ~ 2cf should be used instead of the ascii one 383 // the keys from 2c6 ~ 2cf should be used instead of the ascii one
381 if (unicode == 0x2cb) { 384 if (unicode == 0x2cb) {
382 385
383 unicode = 0; 386 unicode = 0;
384 if (shift || lock) { 387 if (shift || lock) {
385 388
386 // circumblex 389 // circumblex
387 qkeycode = 0x2000; 390 qkeycode = 0x2000;
388 } 391 }
389 else { 392 else {
390 393
391 // back accent 394 // back accent
392 qkeycode = 0x2002; 395 qkeycode = 0x2002;
393 } 396 }
394 } 397 }
395 398
396 // Accent character support 399 // Accent character support
397 400
398 if (unicode == 0x2ca) { 401 if (unicode == 0x2ca) {
399 402
400 unicode = 0; 403 unicode = 0;
401 if (shift || lock) { 404 if (shift || lock) {
402 405
403 // diaeresis 406 // diaeresis
404 qkeycode = 0x2001; 407 qkeycode = 0x2001;
405 } 408 }
406 else { 409 else {
407 410
408 // accent 411 // accent
409 qkeycode = 0x2003; 412 qkeycode = 0x2003;
410 } 413 }
411 } 414 }
412 415
413 416
414 if (unicode == 0) { // either Qt char, or nothing 417 if (unicode == 0) { // either Qt char, or nothing
415 418
416 if (qkeycode == Qt::Key_F1) { // toggle the pickboard 419 if (qkeycode == Qt::Key_F1) { // toggle the pickboard
417 420
418 if ( configdlg ) { 421 if ( configdlg ) {
419 422
420 delete (ConfigDlg *) configdlg; 423 delete configdlg;
421 configdlg = 0; 424 configdlg = 0;
422 } 425 }
423 else { 426 else {
424 configdlg = new ConfigDlg (); 427 configdlg = new ConfigDlg ();
425 connect(configdlg, SIGNAL(setMapToDefault()), 428 connect(configdlg, SIGNAL(setMapToDefault()),
426 this, SLOT(setMapToDefault())); 429 this, SLOT(setMapToDefault()));
427 connect(configdlg, SIGNAL(setMapToFile(QString)), 430 connect(configdlg, SIGNAL(setMapToFile(QString)),
428 this, SLOT(setMapToFile(QString))); 431 this, SLOT(setMapToFile(QString)));
429 connect(configdlg, SIGNAL(pickboardToggled(bool)), 432 connect(configdlg, SIGNAL(pickboardToggled(bool)),
430 this, SLOT(togglePickboard(bool))); 433 this, SLOT(togglePickboard(bool)));
431 connect(configdlg, SIGNAL(repeatToggled(bool)), 434 connect(configdlg, SIGNAL(repeatToggled(bool)),
432 this, SLOT(toggleRepeat(bool))); 435 this, SLOT(toggleRepeat(bool)));
433 connect(configdlg, SIGNAL(reloadKeyboard()), 436 connect(configdlg, SIGNAL(reloadKeyboard()),
434 this, SLOT(reloadKeyboard())); 437 this, SLOT(reloadKeyboard()));
435 connect(configdlg, SIGNAL(configDlgClosed()), 438 connect(configdlg, SIGNAL(configDlgClosed()),
436 this, SLOT(cleanupConfigDlg())); 439 this, SLOT(cleanupConfigDlg()));
440 connect(configdlg, SIGNAL(reloadSw()),
441 this, SLOT(reloadSw()));
437 configdlg->showMaximized(); 442 configdlg->showMaximized();
438 configdlg->show(); 443 configdlg->show();
439 configdlg->raise(); 444 configdlg->raise();
440 } 445 }
441 446
442 } else if (qkeycode == Qt::Key_Control) { 447 } else if (qkeycode == Qt::Key_Control) {
443 need_repaint = TRUE; 448 need_repaint = TRUE;
444 449
445 if (ctrl) { 450 if (ctrl) {
446 451
447 *ctrl = 0; 452 *ctrl = 0;
448 ctrl = 0; 453 ctrl = 0;
449 454
450 } else { 455 } else {
451 456
452 ctrl = keys->pressedPtr(row, col); 457 ctrl = keys->pressedPtr(row, col);
453 need_repaint = TRUE; 458 need_repaint = TRUE;
454 *ctrl = !keys->pressed(row, col); 459 *ctrl = !keys->pressed(row, col);
455 460
456 } 461 }
457 462
458 } else if (qkeycode == Qt::Key_Alt) { 463 } else if (qkeycode == Qt::Key_Alt) {
459 need_repaint = TRUE; 464 need_repaint = TRUE;
460 465
461 if (alt) { 466 if (alt) {
462 *alt = 0; 467 *alt = 0;
463 alt = 0; 468 alt = 0;
464 469
465 } else { 470 } else {
466 471
467 alt = keys->pressedPtr(row, col); 472 alt = keys->pressedPtr(row, col);
468 need_repaint = TRUE; 473 need_repaint = TRUE;
469 *alt = !keys->pressed(row, col); 474 *alt = !keys->pressed(row, col);
470 } 475 }
471 476
472 } else if (qkeycode == Qt::Key_Shift) { 477 } else if (qkeycode == Qt::Key_Shift) {
473 need_repaint = TRUE; 478 need_repaint = TRUE;
474 479
475 if (shift) { 480 if (shift) {
476 *shift = 0; 481 *shift = 0;
477 shift = 0; 482 shift = 0;
478 } 483 }
479 else { 484 else {
480 shift = keys->pressedPtr(row, col); 485 shift = keys->pressedPtr(row, col);
481 *shift = 1; 486 *shift = 1;
482 if (lock) { 487 if (lock) {
483 *lock = 0; 488 *lock = 0;
484 lock = 0; 489 lock = 0;
485 } 490 }
486 } 491 }
487 492
488 493
489 /* 494 /*
490 * want to be able to hit circumflex/diaeresis -> shift 495 * want to be able to hit circumflex/diaeresis -> shift
491 * to type in shifted circumflex/diaeresis chars. 496 * to type in shifted circumflex/diaeresis chars.
492 * same thing with meta 497 * same thing with meta
493 498
494 if (meta) { *meta = 0; meta = 0; } 499 if (meta) { *meta = 0; meta = 0; }
495 if (circumflex) { *circumflex = 0; circumflex = 0; } 500 if (circumflex) { *circumflex = 0; circumflex = 0; }
496 if (diaeresis) { *diaeresis = 0; diaeresis = 0; } 501 if (diaeresis) { *diaeresis = 0; diaeresis = 0; }
497 502
498 */ 503 */
499 504
500 } else if (qkeycode == Qt::Key_CapsLock) { 505 } else if (qkeycode == Qt::Key_CapsLock) {
501 need_repaint = TRUE; 506 need_repaint = TRUE;
502 507
503 if (lock) { 508 if (lock) {
504 *lock = 0; 509 *lock = 0;
505 lock = 0; 510 lock = 0;
506 } 511 }
507 else { 512 else {
508 lock = keys->pressedPtr(row, col);; 513 lock = keys->pressedPtr(row, col);;
509 *lock = true;; 514 *lock = true;;
510 if (shift) { 515 if (shift) {
511 *shift = 0; 516 *shift = 0;
512 shift = 0; 517 shift = 0;
513 } 518 }
514 } 519 }
515 520
516 /* 521 /*
517 if (meta) { *meta = 0; meta = 0; } 522 if (meta) { *meta = 0; meta = 0; }
518 if (circumflex) { *circumflex = 0; circumflex = 0; } 523 if (circumflex) { *circumflex = 0; circumflex = 0; }
519 if (diaeresis) { *diaeresis = 0; diaeresis = 0; } 524 if (diaeresis) { *diaeresis = 0; diaeresis = 0; }
520 */ 525 */
521 526
522 } else if (qkeycode == Qt::Key_Meta) { 527 } else if (qkeycode == Qt::Key_Meta) {
523 need_repaint = TRUE; 528 need_repaint = TRUE;
524 529
525 if (meta) { 530 if (meta) {
526 *meta = 0; 531 *meta = 0;
527 meta = 0; 532 meta = 0;
528 533
529 } else { 534 } else {
530 535
531 meta = keys->pressedPtr(row, col); 536 meta = keys->pressedPtr(row, col);
532 *meta = true; 537 *meta = true;
533 } 538 }
534 539
535 // reset all the other keys 540 // reset all the other keys
536 if (shift) { *shift = 0; shift = 0; } 541 if (shift) { *shift = 0; shift = 0; }
537 if (lock) { *lock = 0; lock = 0; } 542 if (lock) { *lock = 0; lock = 0; }
538 if (circumflex) { *circumflex = 0; circumflex = 0; } 543 if (circumflex) { *circumflex = 0; circumflex = 0; }
539 if (diaeresis) { *diaeresis = 0; diaeresis = 0; } 544 if (diaeresis) { *diaeresis = 0; diaeresis = 0; }
540 if (baccent) { *baccent = 0; baccent = 0; } 545 if (baccent) { *baccent = 0; baccent = 0; }
541 if (accent) { *accent = 0; accent = 0; } 546 if (accent) { *accent = 0; accent = 0; }
542 547
543 // dont need to emit this key... acts same as alt 548 // dont need to emit this key... acts same as alt
544 qkeycode = 0; 549 qkeycode = 0;
545 550
546 // circumflex 551 // circumflex
547 } else if (qkeycode == 0x2000) { 552 } else if (qkeycode == 0x2000) {
548 need_repaint = TRUE; 553 need_repaint = TRUE;
549 554
550 if (circumflex) { 555 if (circumflex) {
551 556
552 *circumflex = 0; 557 *circumflex = 0;
553 circumflex = 0; 558 circumflex = 0;
554 559
555 } else { 560 } else {
556 561
557 circumflex = keys->pressedPtr(row, col); 562 circumflex = keys->pressedPtr(row, col);
558 *circumflex = true; 563 *circumflex = true;
559 } 564 }
560 565
561 /* no need to turn off shift or lock if circumflex 566 /* no need to turn off shift or lock if circumflex
562 * keys are pressed 567 * keys are pressed
563 568
564 if (shift) { *shift = 0; shift = 0; } 569 if (shift) { *shift = 0; shift = 0; }
565 if (lock) { *lock = 0; lock = 0; } 570 if (lock) { *lock = 0; lock = 0; }
566 571
567 */ 572 */
568 573
569 // have to reset all the other keys 574 // have to reset all the other keys
570 if (meta) { *meta = 0; meta = 0; } 575 if (meta) { *meta = 0; meta = 0; }
571 if (diaeresis) { 576 if (diaeresis) {
572 577
573 // *diaeresis and *circumflex point to the same thing 578 // *diaeresis and *circumflex point to the same thing
574 // when diaeresis is enabled and you hit the circumflex 579 // when diaeresis is enabled and you hit the circumflex
575 // since they are the same key, it should turn off the 580 // since they are the same key, it should turn off the
576 // key 581 // key
577 582
578 *diaeresis = 0; 583 *diaeresis = 0;
579 diaeresis = 0; 584 diaeresis = 0;
580 circumflex = 0; 585 circumflex = 0;
581 } 586 }
582 587
583 qkeycode = 0; 588 qkeycode = 0;
584 589
585 // diaeresis 590 // diaeresis
586 } else if (qkeycode == 0x2001) { 591 } else if (qkeycode == 0x2001) {
587 need_repaint = TRUE; 592 need_repaint = TRUE;
588 593
589 if (diaeresis) { 594 if (diaeresis) {
590 595
591 *diaeresis = 0; 596 *diaeresis = 0;
592 diaeresis = 0; 597 diaeresis = 0;
593 598
594 } else { 599 } else {
595 600
596 diaeresis = keys->pressedPtr(row, col); 601 diaeresis = keys->pressedPtr(row, col);
597 *diaeresis = true; 602 *diaeresis = true;
598 } 603 }
599 604
600 605
601 if (shift) { *shift = 0; shift = 0; } 606 if (shift) { *shift = 0; shift = 0; }
602 607
603 /* 608 /*
604 * 609 *
605 if (lock) { *lock = 0; lock = 0; } 610 if (lock) { *lock = 0; lock = 0; }
606 * 611 *
607 */ 612 */
608 613
609 if (meta) { *meta = 0; meta = 0; } 614 if (meta) { *meta = 0; meta = 0; }
610 if (circumflex) { 615 if (circumflex) {
611 616
612 // *circumflex = 0; 617 // *circumflex = 0;
613 // 618 //
614 // same thing the diaeresis pointer points too 619 // same thing the diaeresis pointer points too
615 620
616 circumflex = 0; 621 circumflex = 0;
617 } 622 }
618 623
619 624
620 qkeycode = 0; 625 qkeycode = 0;
621 626
622 // Back accent 627 // Back accent
623 } else if (qkeycode == 0x2002) { 628 } else if (qkeycode == 0x2002) {
624 need_repaint = TRUE; 629 need_repaint = TRUE;
625 630
626 if (baccent) { 631 if (baccent) {
627 632
628 *baccent = 0; 633 *baccent = 0;
629 baccent = 0; 634 baccent = 0;
630 635
631 } else { 636 } else {
632 637
633 baccent = keys->pressedPtr(row, col); 638 baccent = keys->pressedPtr(row, col);
634 *baccent = true; 639 *baccent = true;
635 } 640 }
636 641
637 642
638 if (shift) { *shift = 0; shift = 0; } 643 if (shift) { *shift = 0; shift = 0; }
639 if (meta) { *meta = 0; meta = 0; } 644 if (meta) { *meta = 0; meta = 0; }
640 if (accent) { *accent = 0; accent = 0; } 645 if (accent) { *accent = 0; accent = 0; }
641 646
642 qkeycode = 0; 647 qkeycode = 0;
643 648
644 // Accent 649 // Accent
645 } else if (qkeycode == 0x2003) { 650 } else if (qkeycode == 0x2003) {
646 need_repaint = TRUE; 651 need_repaint = TRUE;
647 652
648 if (accent) { 653 if (accent) {
649 654
650 *accent = 0; 655 *accent = 0;
651 accent = 0; 656 accent = 0;
652 657
653 } else { 658 } else {
654 659
655 accent = keys->pressedPtr(row, col); 660 accent = keys->pressedPtr(row, col);
656 *accent = true; 661 *accent = true;
657 } 662 }
658 663
659 664
660 if (shift) { *shift = 0; shift = 0; } 665 if (shift) { *shift = 0; shift = 0; }
661 if (meta) { *meta = 0; meta = 0; } 666 if (meta) { *meta = 0; meta = 0; }
662 if (baccent) { *baccent = 0; } 667 if (baccent) { *baccent = 0; }
663 668
664 qkeycode = 0; 669 qkeycode = 0;
665 } 670 }
666 671
667 } 672 }
668 else { // normal char 673 else { // normal char
669 if ((shift || lock) && keys->shift(unicode)) { 674 if ((shift || lock) && keys->shift(unicode)) {
670 675
671 // make diaeresis/circumflex -> shift input shifted 676 // make diaeresis/circumflex -> shift input shifted
672 // diaeresis/circumflex chars 677 // diaeresis/circumflex chars
673 678
674 if (circumflex && keys->circumflex(keys->shift(unicode))) 679 if (circumflex && keys->circumflex(keys->shift(unicode)))
675 unicode = keys->circumflex(keys->shift(unicode)); 680 unicode = keys->circumflex(keys->shift(unicode));
676 else if (diaeresis && keys->diaeresis(keys->shift(unicode))) 681 else if (diaeresis && keys->diaeresis(keys->shift(unicode)))
677 unicode = keys->diaeresis(keys->shift(unicode)); 682 unicode = keys->diaeresis(keys->shift(unicode));
678 else if (baccent && keys->baccent(keys->shift(unicode))) 683 else if (baccent && keys->baccent(keys->shift(unicode)))
679 unicode = keys->baccent(keys->shift(unicode)); 684 unicode = keys->baccent(keys->shift(unicode));
680 else if (accent && keys->accent(keys->shift(unicode))) 685 else if (accent && keys->accent(keys->shift(unicode)))
681 unicode = keys->accent(keys->shift(unicode)); 686 unicode = keys->accent(keys->shift(unicode));
682 else if (meta && keys->meta(keys->shift(unicode))) 687 else if (meta && keys->meta(keys->shift(unicode)))
683 unicode = keys->meta(keys->shift(unicode)); 688 unicode = keys->meta(keys->shift(unicode));
684 else 689 else
685 unicode = keys->shift(unicode); 690 unicode = keys->shift(unicode);
686 } 691 }
687 else if (meta && keys->meta(unicode)) { 692 else if (meta && keys->meta(unicode)) {
688 unicode = keys->meta(unicode); 693 unicode = keys->meta(unicode);
689 } 694 }
690 else if (circumflex && keys->circumflex(unicode)) { 695 else if (circumflex && keys->circumflex(unicode)) {
691 unicode = keys->circumflex(unicode); 696 unicode = keys->circumflex(unicode);
692 } 697 }
693 else if (diaeresis && keys->diaeresis(unicode)) { 698 else if (diaeresis && keys->diaeresis(unicode)) {
694 699
695 unicode = keys->diaeresis(unicode); 700 unicode = keys->diaeresis(unicode);
696 } 701 }
697 else if (baccent && keys->baccent(unicode)) { 702 else if (baccent && keys->baccent(unicode)) {
698 unicode = keys->baccent(unicode); 703 unicode = keys->baccent(unicode);
699 } 704 }
700 else if (accent && keys->accent(unicode)) { 705 else if (accent && keys->accent(unicode)) {
701 unicode = keys->accent(unicode); 706 unicode = keys->accent(unicode);
702 } 707 }
703 } 708 }
704 709
705 // korean parsing 710 // korean parsing
706 if (keys->lang == "ko") { 711 if (keys->lang == "ko") {
707 712
708 unicode = parseKoreanInput(unicode); 713 unicode = parseKoreanInput(unicode);
709 } 714 }
710 715
711 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); 716 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0);
712 717
713 if ('A' <= unicode && unicode <= 'z' && modifiers) { 718 if ('A' <= unicode && unicode <= 'z' && modifiers) {
714 719
715 qkeycode = QChar(unicode).upper(); 720 qkeycode = QChar(unicode).upper();
716 unicode = qkeycode - '@'; 721 unicode = qkeycode - '@';
717 } 722 }
718 723
719 QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); 724 QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false);
720 725
721 // pickboard stuff 726 // pickboard stuff
722 if (usePicks) { 727 if (usePicks) {
723 728
724 KeyboardConfig *dc = picks->dc; 729 KeyboardConfig *dc = picks->dc;
725 730
726 if (dc) { 731 if (dc) {
727 if (qkeycode == Qt::Key_Backspace) { 732 if (qkeycode == Qt::Key_Backspace) {
728 dc->input.remove(dc->input.last()); // remove last input 733 dc->input.remove(dc->input.last()); // remove last input
729 dc->decBackspaces(); 734 dc->decBackspaces();
730 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { 735 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) {
731 dc->input.clear(); 736 dc->input.clear();
732 dc->resetBackspaces(); 737 dc->resetBackspaces();
733 } else { 738 } else {
734 dc->add(QString(QChar(unicode))); 739 dc->add(QString(QChar(unicode)));
735 dc->incBackspaces(); 740 dc->incBackspaces();
736 } 741 }
737 } 742 }
738 picks->repaint(); 743 picks->repaint();
739 } 744 }
740 745
741 746
742 // painting 747 // painting
743 pressed = TRUE; 748 pressed = TRUE;
744 749
745 pressedKeyRow = row; 750 pressedKeyRow = row;
746 pressedKeyCol = col; 751 pressedKeyCol = col;
747 752
748 if (need_repaint) repaint(FALSE); 753 if (need_repaint) repaint(FALSE);
749 else { // just paint the one key pressed 754 else { // just paint the one key pressed
750 755
751 756
752 757
753 QPainter p(this); 758 QPainter p(this);
754 drawKeyboard(p, row, col); 759 drawKeyboard(p, row, col);
755 760
756 } 761 }
757 762
758 if (useRepeat) repeatTimer->start( 800 ); 763 if (useRepeat) repeatTimer->start( 800 );
759 //pressTid = startTimer(80); 764 //pressTid = startTimer(80);
760 765
761} 766}
762 767
768void Keyboard::receive(const QCString &msg, const QByteArray &data)
769{
770 if (msg == "setmultikey(QString)") {
771 QDataStream stream(data, IO_ReadOnly);
772 QString map;
773 stream >> map;
774 setMapToFile(map);
775 } else if (msg == "getmultikey()") {
776 reloadSw();
777 }
778}
763 779
764/* Keyboard::mouseReleaseEvent {{{1 */ 780/* Keyboard::mouseReleaseEvent {{{1 */
765void Keyboard::mouseReleaseEvent(QMouseEvent*) 781void Keyboard::mouseReleaseEvent(QMouseEvent*)
766{ 782{
767 pressed = FALSE; 783 pressed = FALSE;
768 //if ( pressTid == 0 ) 784 //if ( pressTid == 0 )
769#if defined(Q_WS_QWS) || defined(_WS_QWS_) 785#if defined(Q_WS_QWS) || defined(_WS_QWS_)
770 if ( unicode != -1 ) { 786 if ( unicode != -1 ) {
771 emit key( unicode, qkeycode, modifiers, false, false ); 787 emit key( unicode, qkeycode, modifiers, false, false );
772 repeatTimer->stop(); 788 repeatTimer->stop();
773 } 789 }
774#endif 790#endif
775 if (shift && unicode != 0) { 791 if (shift && unicode != 0) {
776 792
777 793
778 *shift = 0; // unpress shift key 794 *shift = 0; // unpress shift key
779 shift = 0; // reset the shift pointer 795 shift = 0; // reset the shift pointer
780 repaint(FALSE); 796 repaint(FALSE);
781 797
782 } 798 }
783 if (ctrl && unicode != 0) { 799 if (ctrl && unicode != 0) {
784 800
785 *ctrl = 0; 801 *ctrl = 0;
786 ctrl = 0; 802 ctrl = 0;
787 repaint(FALSE); 803 repaint(FALSE);
788 804
789 } 805 }
790 if (alt && alt != 0) { 806 if (alt && alt != 0) {
791 807
792 *alt = 0; 808 *alt = 0;
793 alt = 0; 809 alt = 0;
794 repaint(FALSE); 810 repaint(FALSE);
795 811
796 } 812 }
797 813
798 /* 814 /*
799 * do not make the meta key release after being pressed 815 * do not make the meta key release after being pressed
800 * 816 *
801 817
802 else if (meta && unicode != 0) { 818 else if (meta && unicode != 0) {
803 819
804 *meta = 0; 820 *meta = 0;
805 meta = 0; 821 meta = 0;
806 repaint(FALSE); 822 repaint(FALSE);
807 } 823 }
808 824
809 */ 825 */
810 826
811 else clearHighlight(); 827 else clearHighlight();
812} 828}
813 829
814/* Keyboard::timerEvent {{{1 */ 830/* Keyboard::timerEvent {{{1 */
815 831
816/* dont know what this does, but i think it is here so that if your screen 832/* dont know what this does, but i think it is here so that if your screen
817 * sticks (like on an ipaq) then it will stop repeating if you click another 833 * sticks (like on an ipaq) then it will stop repeating if you click another
818 * key... but who knows what anything does in this thing anyway? 834 * key... but who knows what anything does in this thing anyway?
819 835
820 void Keyboard::timerEvent(QTimerEvent* e) 836 void Keyboard::timerEvent(QTimerEvent* e)
821{ 837{
822 if ( e->timerId() == pressTid ) { 838 if ( e->timerId() == pressTid ) {
823 killTimer(pressTid); 839 killTimer(pressTid);
824 pressTid = 0; 840 pressTid = 0;
825 if ( !pressed ) 841 if ( !pressed )
826 cout << "calling clearHighlight from timerEvent\n"; 842 cout << "calling clearHighlight from timerEvent\n";
827 //clearHighlight(); 843 //clearHighlight();
828 } 844 }
829} 845}
830*/ 846*/
831 847
832void Keyboard::repeat() 848void Keyboard::repeat()
833{ 849{
834 850
835 repeatTimer->start( 200 ); 851 repeatTimer->start( 200 );
836 emit key( unicode, qkeycode, modifiers, true, true ); 852 emit key( unicode, qkeycode, modifiers, true, true );
837} 853}
838 854
839void Keyboard::clearHighlight() 855void Keyboard::clearHighlight()
840{ 856{
841 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { 857 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) {
842 int tmpRow = pressedKeyRow; 858 int tmpRow = pressedKeyRow;
843 int tmpCol = pressedKeyCol; 859 int tmpCol = pressedKeyCol;
844 860
845 pressedKeyRow = -1; 861 pressedKeyRow = -1;
846 pressedKeyCol = -1; 862 pressedKeyCol = -1;
847 863
848 QPainter p(this); 864 QPainter p(this);
849 drawKeyboard(p, tmpRow, tmpCol); 865 drawKeyboard(p, tmpRow, tmpCol);
850 } 866 }
851} 867}
852 868
853 869
854/* Keyboard::sizeHint {{{1 */ 870/* Keyboard::sizeHint {{{1 */
855QSize Keyboard::sizeHint() const 871QSize Keyboard::sizeHint() const
856{ 872{
857 QFontMetrics fm=fontMetrics(); 873 QFontMetrics fm=fontMetrics();
858 int keyHeight = fm.lineSpacing() + 2; 874 int keyHeight = fm.lineSpacing() + 2;
859 875
860 return QSize( 240, keyHeight * keys->rows() + (usePicks ? picks->sizeHint().height() : 0) + 1); 876 return QSize( 240, keyHeight * keys->rows() + (usePicks ? picks->sizeHint().height() : 0) + 1);
861} 877}
862 878
863 879
864void Keyboard::resetState() 880void Keyboard::resetState()
865{ 881{
866 if (shift) { *shift = 0; shift = 0; } 882 if (shift) { *shift = 0; shift = 0; }
867 if (lock) {*lock = 0; lock = 0; } 883 if (lock) {*lock = 0; lock = 0; }
868 if (meta) { *meta = 0; meta = 0; } 884 if (meta) { *meta = 0; meta = 0; }
869 if (circumflex) { *circumflex = 0; circumflex = 0; } 885 if (circumflex) { *circumflex = 0; circumflex = 0; }
870 if (diaeresis) { *diaeresis = 0; diaeresis = 0; } 886 if (diaeresis) { *diaeresis = 0; diaeresis = 0; }
871 if (baccent) { *baccent = 0; baccent = 0; } 887 if (baccent) { *baccent = 0; baccent = 0; }
872 if (accent) { *accent = 0; accent = 0; } 888 if (accent) { *accent = 0; accent = 0; }
873 889
874 schar = mchar = echar = 0; 890 schar = mchar = echar = 0;
875 picks->resetState(); 891 picks->resetState();
876} 892}
877 893
878/* Keyboard::togglePickboard {{{1 */ 894/* Keyboard::togglePickboard {{{1 */
879void Keyboard::togglePickboard(bool on_off) 895void Keyboard::togglePickboard(bool on_off)
880{ 896{
881 usePicks = on_off; 897 usePicks = on_off;
882 if (usePicks) { 898 if (usePicks) {
883 picks->show(); 899 picks->show();
884 //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send 900 //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send
885 //adjustSize(); 901 //adjustSize();
886 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 902 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
887 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 903 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
888 } else { 904 } else {
889 905
890 picks->hide(); 906 picks->hide();
891 picks->resetState(); 907 picks->resetState();
892 //move(x(), y() + picks->height()); 908 //move(x(), y() + picks->height());
893 //adjustSize(); 909 //adjustSize();
894 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 910 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
895 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 911 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
896 912
897 } 913 }
898 /* 914 /*
899 * this closes && opens the input method 915 * this closes && opens the input method
900 */ 916 */
901 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); 917 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
902 QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); 918 QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
903} 919}
904 920
905void Keyboard::toggleRepeat(bool on) { 921void Keyboard::toggleRepeat(bool on) {
906 922
907 useRepeat = on; 923 useRepeat = on;
908 //cout << "setting useRepeat to: " << useRepeat << "\n"; 924 //cout << "setting useRepeat to: " << useRepeat << "\n";
909} 925}
910 926
911void Keyboard::cleanupConfigDlg() { 927void Keyboard::cleanupConfigDlg() {
912 928
913 if ( configdlg ) { 929 if ( configdlg ) {
914 delete (ConfigDlg *) configdlg; 930 delete configdlg;
915 configdlg = 0; 931 configdlg = 0;
916 } 932 }
917} 933}
918 934
935void Keyboard::reloadSw() {
936 QCopEnvelope e("MultiKey/Switcher", "setsw(QString,QString)");
937
938 Config* config = new Config("multikey");
939 config->setGroup("keymaps");
940 QString current_map = config->readEntry("current", "en.keymap");
941 delete config;
942
943 e << ConfigDlg::loadSw().join("|") << current_map;
944}
945
919/* Keyboard::setMapTo ... {{{1 */ 946/* Keyboard::setMapTo ... {{{1 */
920void Keyboard::setMapToDefault() { 947void Keyboard::setMapToDefault() {
921 948
922 949
923 /* load current locale language map */ 950 /* load current locale language map */
924 Config *config = new Config("locale"); 951 Config *config = new Config("locale");
925 config->setGroup( "Language" ); 952 config->setGroup( "Language" );
926 QString l = config->readEntry( "Language" , "en" ); 953 QString l = config->readEntry( "Language" , "en" );
927 delete config; 954 delete config;
928 955
956 /* if Language represents as en_US, ru_RU, etc... */
957 int d = l.find('_');
958 if (d != -1) {
959 l.remove(d, l.length()-d);
960 }
929 QString key_map = QPEApplication::qpeDir() + "share/multikey/" 961 QString key_map = QPEApplication::qpeDir() + "share/multikey/"
930 + l + ".keymap"; 962 + l + ".keymap";
931 963
932 /* save change to multikey config file */ 964 /* save change to multikey config file */
933 config = new Config("multikey"); 965 config = new Config("multikey");
934 config->setGroup ("keymaps"); 966 config->setGroup ("keymaps");
935 config->writeEntry ("current", key_map); // default closed 967 config->writeEntry ("current", key_map); // default closed
936 delete config; 968 delete config;
937 969
938 int prevRows = keys->rows(); 970 int prevRows = keys->rows();
939 971
940 delete keys; 972 delete keys;
941 keys = new Keys(key_map); 973 keys = new Keys(key_map);
942 974
943 // have to repaint the keyboard 975 // have to repaint the keyboard
944 if (prevRows != keys->rows()) { 976 if (prevRows != keys->rows()) {
945 977
946 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); 978 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
947 QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); 979 QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
948 980
949 } else repaint(FALSE); 981 } else repaint(FALSE);
950 982
951 resetState(); 983 resetState();
952} 984}
953 985
954void Keyboard::setMapToFile(QString map) { 986void Keyboard::setMapToFile(QString map) {
955 987
956 /* save change to multikey config file */ 988 /* save change to multikey config file */
957 Config *config = new Config("multikey"); 989 Config *config = new Config("multikey");
958 config->setGroup ("keymaps"); 990 config->setGroup ("keymaps");
959 config->writeEntry ("current", map); // default closed 991 config->writeEntry ("current", map); // default closed
960 992
961 delete config; 993 delete config;
962 994
963 int prevRows = keys->rows(); 995 int prevRows = keys->rows();
964 996
965 delete keys; 997 delete keys;
966 if (QFile(map).exists()) 998 if (QFile(map).exists())
967 keys = new Keys(map); 999 keys = new Keys(map);
968 else 1000 else
969 keys = new Keys(); 1001 keys = new Keys();
970 1002
971 if (keys->rows() != prevRows) { 1003 if (keys->rows() != prevRows) {
972 1004
973 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); 1005 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
974 QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); 1006 QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
975 } 1007 }
976 else repaint(FALSE); 1008 else repaint(FALSE);
977 1009
978 resetState(); 1010 resetState();
979} 1011}
980 1012
981/* Keybaord::reloadKeyboard {{{1 */ 1013/* Keybaord::reloadKeyboard {{{1 */
982void Keyboard::reloadKeyboard() { 1014void Keyboard::reloadKeyboard() {
983 1015
984 // reload colors and redraw 1016 // reload colors and redraw
985 loadKeyboardColors(); 1017 loadKeyboardColors();
986 repaint(); 1018 repaint();
987 1019
988} 1020}
989 1021
990void Keyboard::loadKeyboardColors() { 1022void Keyboard::loadKeyboardColors() {
991 1023
992 Config config ("multikey"); 1024 Config config ("multikey");
993 config.setGroup("colors"); 1025 config.setGroup("colors");
994 1026
995 QStringList color; 1027 QStringList color;
996 color = config.readListEntry("keycolor", QChar(',')); 1028 color = config.readListEntry("keycolor", QChar(','));
997 if (color.isEmpty()) { 1029 if (color.isEmpty()) {
998 color = QStringList::split(",", "240,240,240"); 1030 color = QStringList::split(",", "240,240,240");
999 config.writeEntry("keycolor", color.join(",")); 1031 config.writeEntry("keycolor", color.join(","));
1000 1032
1001 } 1033 }
1002 keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 1034 keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
1003 1035
1004 color = config.readListEntry("keycolor_pressed", QChar(',')); 1036 color = config.readListEntry("keycolor_pressed", QChar(','));
1005 if (color.isEmpty()) { 1037 if (color.isEmpty()) {
1006 color = QStringList::split(",", "171,183,198"); 1038 color = QStringList::split(",", "171,183,198");
1007 config.writeEntry("keycolor_pressed", color.join(",")); 1039 config.writeEntry("keycolor_pressed", color.join(","));
1008 1040
1009 } 1041 }
1010 keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 1042 keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
1011 1043
1012 color = config.readListEntry("keycolor_lines", QChar(',')); 1044 color = config.readListEntry("keycolor_lines", QChar(','));
1013 if (color.isEmpty()) { 1045 if (color.isEmpty()) {
1014 color = QStringList::split(",", "138,148,160"); 1046 color = QStringList::split(",", "138,148,160");
1015 config.writeEntry("keycolor_lines", color.join(",")); 1047 config.writeEntry("keycolor_lines", color.join(","));
1016 1048
1017 } 1049 }
1018 keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 1050 keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
1019 1051
1020 color = config.readListEntry("textcolor", QChar(',')); 1052 color = config.readListEntry("textcolor", QChar(','));
1021 if (color.isEmpty()) { 1053 if (color.isEmpty()) {
1022 color = QStringList::split(",", "43,54,68"); 1054 color = QStringList::split(",", "43,54,68");
1023 config.writeEntry("textcolor", color.join(",")); 1055 config.writeEntry("textcolor", color.join(","));
1024 1056
1025 } 1057 }
1026 textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 1058 textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
1027 1059
1028} 1060}
1029 1061
1030/* korean input functions {{{1 1062/* korean input functions {{{1
1031 * 1063 *
1032 * TODO 1064 * TODO
1033 * one major problem with this implementation is that you can't move the 1065 * one major problem with this implementation is that you can't move the
1034 * cursor after inputing korean chars, otherwise it will eat up and replace 1066 * cursor after inputing korean chars, otherwise it will eat up and replace
1035 * the char before the cursor you move to. fix that 1067 * the char before the cursor you move to. fix that
1036 * 1068 *
1037 * make backspace delete one single char, not the whole thing if still 1069 * make backspace delete one single char, not the whole thing if still
1038 * editing. 1070 * editing.
1039 * 1071 *
1040 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 1072 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1041 * 1073 *
1042 * how korean input works 1074 * how korean input works
1043 * 1075 *
1044 * all following chars means unicode char value and are in hex 1076 * all following chars means unicode char value and are in hex
1045 * 1077 *
1046 * 초음 = schar (start char) 1078 * 초음 = schar (start char)
1047 * 중음 = mchar (middle char) 1079 * 중음 = mchar (middle char)
1048 * 끝음 = echar (end char) 1080 * 끝음 = echar (end char)
1049 * 1081 *
1050 * there are 19 schars. unicode position is at 1100 - 1112 1082 * there are 19 schars. unicode position is at 1100 - 1112
1051 * there are 21 mchars. unicode position is at 1161 - 1175 1083 * there are 21 mchars. unicode position is at 1161 - 1175
1052 * there are 27 echars. unicode position is at 11a8 - 11c2 1084 * there are 27 echars. unicode position is at 11a8 - 11c2
1053 * 1085 *
1054 * the map with everything combined is at ac00 - d7a3 1086 * the map with everything combined is at ac00 - d7a3
1055 * 1087 *
1056 */ 1088 */
1057 1089
1058ushort Keyboard::parseKoreanInput (ushort c) { 1090ushort Keyboard::parseKoreanInput (ushort c) {
1059 1091
1060 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) 1092 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c))
1061 || 1093 ||
1062 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode 1094 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode
1063 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { 1095 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) {
1064 1096
1065 schar = 0, mchar = 0, echar = 0; 1097 schar = 0, mchar = 0, echar = 0;
1066 return c; 1098 return c;
1067 } 1099 }
1068 1100
1069 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input 1101 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input
1070 1102
1071 if (schar == 0 || (schar != 0 && mchar == 0)) { 1103 if (schar == 0 || (schar != 0 && mchar == 0)) {
1072 schar = c; mchar = 0; echar = 0; 1104 schar = c; mchar = 0; echar = 0;
1073 return c; 1105 return c;
1074 } 1106 }
1075 else if (mchar != 0) { 1107 else if (mchar != 0) {
1076 1108
1077 if (echar == 0) { 1109 if (echar == 0) {
1078 1110
1079 if (!(echar = constoe(c))) { 1111 if (!(echar = constoe(c))) {
1080 1112
1081 schar = c; mchar = 0; echar = 0; 1113 schar = c; mchar = 0; echar = 0;
1082 return c; 1114 return c;
1083 } 1115 }
1084 1116
1085 } 1117 }
1086 else { // must figure out what the echar is 1118 else { // must figure out what the echar is
1087 1119
1088 if (echar == 0x11a8) { // ㄱ 1120 if (echar == 0x11a8) { // ㄱ
1089 1121
1090 if (c == 0x1100) echar = 0x11a9; // ㄱ + ㄱ 1122 if (c == 0x1100) echar = 0x11a9; // ㄱ + ㄱ
1091 else if (c == 0x1109) echar = 0x11aa; // ㄱ + ㅅ 1123 else if (c == 0x1109) echar = 0x11aa; // ㄱ + ㅅ
1092 else { 1124 else {
1093 schar = c; mchar = 0; echar = 0; 1125 schar = c; mchar = 0; echar = 0;
1094 return c; 1126 return c;
1095 } 1127 }
1096 1128
1097 } else if (echar == 0x11ab) { // ㄴ 1129 } else if (echar == 0x11ab) { // ㄴ
1098 1130
1099 if (c == 0x110c) echar = 0x11ac; // ㄴ + ㅈ 1131 if (c == 0x110c) echar = 0x11ac; // ㄴ + ㅈ
1100 else if (c == 0x1112) echar = 0x11ad; // ㄴ + ㅎ 1132 else if (c == 0x1112) echar = 0x11ad; // ㄴ + ㅎ
1101 else { 1133 else {
1102 schar = c; mchar = 0; echar = 0; 1134 schar = c; mchar = 0; echar = 0;
1103 return c; 1135 return c;
1104 } 1136 }
1105 1137
1106 } else if (echar == 0x11af) { // ㄹ 1138 } else if (echar == 0x11af) { // ㄹ
1107 1139
1108 if (c == 0x1100) echar = 0x11b0; // ㄹ + ㄱ 1140 if (c == 0x1100) echar = 0x11b0; // ㄹ + ㄱ
1109 else if (c == 0x1106) echar = 0x11b1; // ㄹ + ㅁ 1141 else if (c == 0x1106) echar = 0x11b1; // ㄹ + ㅁ
1110 else if (c == 0x1107) echar = 0x11b2; // ㄹ + ㅂ 1142 else if (c == 0x1107) echar = 0x11b2; // ㄹ + ㅂ
1111 else if (c == 0x1109) echar = 0x11b3; // ㄹ + ㅅ 1143 else if (c == 0x1109) echar = 0x11b3; // ㄹ + ㅅ
1112 else if (c == 0x1110) echar = 0x11b4; // ㄹ + ㅌ 1144 else if (c == 0x1110) echar = 0x11b4; // ㄹ + ㅌ
1113 else if (c == 0x1111) echar = 0x11b5; // ㄹ + ㅍ 1145 else if (c == 0x1111) echar = 0x11b5; // ㄹ + ㅍ
1114 else if (c == 0x1112) echar = 0x11b6; // ㄹ + ㅎ 1146 else if (c == 0x1112) echar = 0x11b6; // ㄹ + ㅎ
1115 else { 1147 else {
1116 schar = c; mchar = 0; echar = 0; 1148 schar = c; mchar = 0; echar = 0;
1117 return c; 1149 return c;
1118 } 1150 }
1119 1151
1120 } else if (echar == 0x11b8) { // ㅂ 1152 } else if (echar == 0x11b8) { // ㅂ
@@ -1317,362 +1349,362 @@ ushort Keyboard::constoe(const ushort c) {
1317 case 0x11bc: return 0x110b; 1349 case 0x11bc: return 0x110b;
1318 case 0x11bd: return 0x110c; 1350 case 0x11bd: return 0x110c;
1319 case 0x11be: return 0x110e; 1351 case 0x11be: return 0x110e;
1320 case 0x11bf: return 0x110f; 1352 case 0x11bf: return 0x110f;
1321 case 0x11c0: return 0x1110; 1353 case 0x11c0: return 0x1110;
1322 case 0x11c1: return 0x1111; 1354 case 0x11c1: return 0x1111;
1323 case 0x11c2: return 0x1112; 1355 case 0x11c2: return 0x1112;
1324 default: return 0; 1356 default: return 0;
1325 1357
1326 } 1358 }
1327 1359
1328 } 1360 }
1329} 1361}
1330 1362
1331 1363
1332// Keys::Keys {{{1 1364// Keys::Keys {{{1
1333 1365
1334Keys::Keys() { 1366Keys::Keys() {
1335 1367
1336 Config *config = new Config ("multikey"); 1368 Config *config = new Config ("multikey");
1337 config->setGroup( "keymaps" ); 1369 config->setGroup( "keymaps" );
1338 QString map = config->readEntry( "current" ); 1370 QString map = config->readEntry( "current" );
1339 delete config; 1371 delete config;
1340 1372
1341 if (map.isNull() || !(QFile(map).exists())) { 1373 if (map.isNull() || !(QFile(map).exists())) {
1342 1374
1343 Config *config = new Config("locale"); 1375 Config *config = new Config("locale");
1344 config->setGroup( "Language" ); 1376 config->setGroup( "Language" );
1345 QString l = config->readEntry( "Language" , "en" ); 1377 QString l = config->readEntry( "Language" , "en" );
1346 delete config; 1378 delete config;
1347 1379
1348 map = QPEApplication::qpeDir() + "/share/multikey/" 1380 map = QPEApplication::qpeDir() + "/share/multikey/"
1349 + l + ".keymap"; 1381 + l + ".keymap";
1350 1382
1351 } 1383 }
1352 if (map.isNull() || !(QFile(map).exists())) { 1384 if (map.isNull() || !(QFile(map).exists())) {
1353 map = QPEApplication::qpeDir() + "/share/multikey/en.keymap"; 1385 map = QPEApplication::qpeDir() + "/share/multikey/en.keymap";
1354 } 1386 }
1355 1387
1356 setKeysFromFile(map); 1388 setKeysFromFile(map);
1357} 1389}
1358 1390
1359Keys::Keys(const char * filename) { 1391Keys::Keys(const char * filename) {
1360 1392
1361 setKeysFromFile(filename); 1393 setKeysFromFile(filename);
1362} 1394}
1363 1395
1364// Keys::setKeysFromFile {{{2 1396// Keys::setKeysFromFile {{{2
1365void Keys::setKeysFromFile(const char * filename) { 1397void Keys::setKeysFromFile(const char * filename) {
1366 1398
1367 QFile f(filename); 1399 QFile f(filename);
1368 1400
1369 if (f.open(IO_ReadOnly)) { 1401 if (f.open(IO_ReadOnly)) {
1370 1402
1371 QTextStream t(&f); 1403 QTextStream t(&f);
1372 int row; 1404 int row;
1373 int qcode; 1405 int qcode;
1374 ushort unicode; 1406 ushort unicode;
1375 int width; 1407 int width;
1376 QString buf; 1408 QString buf;
1377 QString comment; 1409 QString comment;
1378 char * xpm[256]; //couldnt be larger than that... could it? 1410 char * xpm[256]; //couldnt be larger than that... could it?
1379 QImage *xpm2pix = 0; 1411 QImage *xpm2pix = 0;
1380 1412
1381 buf = t.readLine(); 1413 buf = t.readLine();
1382 while (buf) { 1414 while (buf) {
1383 1415
1384 // get rid of comments 1416 // get rid of comments
1385 buf.replace(QRegExp("#.*$", FALSE, FALSE), ""); 1417 buf.replace(QRegExp("#.*$", FALSE, FALSE), "");
1386 1418
1387 // key definition 1419 // key definition
1388 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { 1420 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) {
1389 // no $1 type referencing!!! this implementation of regexp sucks 1421 // no $1 type referencing!!! this implementation of regexp sucks
1390 1422
1391 // dont know of any sscanf() type funcs in Qt lib 1423 // dont know of any sscanf() type funcs in Qt lib
1392 QTextStream tmp (buf, IO_ReadOnly); 1424 QTextStream tmp (buf, IO_ReadOnly);
1393 tmp >> row >> qcode >> unicode >> width >> comment; 1425 tmp >> row >> qcode >> unicode >> width >> comment;
1394 1426
1395 buf = t.readLine(); 1427 buf = t.readLine();
1396 int xpmLineCount = 0; 1428 int xpmLineCount = 0;
1397 xpm2pix = 0; 1429 xpm2pix = 0;
1398 1430
1399 // erase blank space 1431 // erase blank space
1400 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); 1432 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine();
1401 1433
1402 while (buf.contains(QRegExp("^\\s*\".*\""))) { 1434 while (buf.contains(QRegExp("^\\s*\".*\""))) {
1403 1435
1404 QString xpmBuf = buf.stripWhiteSpace(); 1436 QString xpmBuf = buf.stripWhiteSpace();
1405 1437
1406 xpm[xpmLineCount] = new char [xpmBuf.length()]; 1438 xpm[xpmLineCount] = new char [xpmBuf.length()];
1407 1439
1408 int j = 0; 1440 int j = 0;
1409 for (ushort i = 0; i < xpmBuf.length(); i++) { 1441 for (ushort i = 0; i < xpmBuf.length(); i++) {
1410 if (xpmBuf[i].latin1() != '"') { 1442 if (xpmBuf[i].latin1() != '"') {
1411 1443
1412 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); 1444 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1();
1413 j++; 1445 j++;
1414 } 1446 }
1415 1447
1416 } 1448 }
1417 // have to close that facker up 1449 // have to close that facker up
1418 ((char *)xpm[xpmLineCount])[j] = '\0'; 1450 ((char *)xpm[xpmLineCount])[j] = '\0';
1419 1451
1420 xpmLineCount++; 1452 xpmLineCount++;
1421 buf = t.readLine(); 1453 buf = t.readLine();
1422 } 1454 }
1423 if (xpmLineCount) { 1455 if (xpmLineCount) {
1424 1456
1425 xpm2pix = new QImage((const char **)xpm); 1457 xpm2pix = new QImage((const char **)xpm);
1426 for (int i = 0; i < xpmLineCount; i++) 1458 for (int i = 0; i < xpmLineCount; i++)
1427 1459
1428 delete [] (xpm[i]); 1460 delete [] (xpm[i]);
1429 1461
1430 } 1462 }
1431 setKey(row, qcode, unicode, width, xpm2pix); 1463 setKey(row, qcode, unicode, width, xpm2pix);
1432 } 1464 }
1433 1465
1434 // shift map 1466 // shift map
1435 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1467 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1436 1468
1437 QTextStream tmp (buf, IO_ReadOnly); 1469 QTextStream tmp (buf, IO_ReadOnly);
1438 ushort lower, shift; 1470 ushort lower, shift;
1439 tmp >> lower >> shift; 1471 tmp >> lower >> shift;
1440 1472
1441 shiftMap.insert(lower, shift); 1473 shiftMap.insert(lower, shift);
1442 1474
1443 buf = t.readLine(); 1475 buf = t.readLine();
1444 } 1476 }
1445 1477
1446 // meta key map 1478 // meta key map
1447 else if (buf.contains(QRegExp("^\\s*m\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1479 else if (buf.contains(QRegExp("^\\s*m\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1448 1480
1449 QTextStream tmp (buf, IO_ReadOnly); 1481 QTextStream tmp (buf, IO_ReadOnly);
1450 ushort lower, shift; 1482 ushort lower, shift;
1451 QChar m; 1483 QChar m;
1452 tmp >> m >> lower >> shift; 1484 tmp >> m >> lower >> shift;
1453 1485
1454 metaMap.insert(lower, shift); 1486 metaMap.insert(lower, shift);
1455 1487
1456 buf = t.readLine(); 1488 buf = t.readLine();
1457 } 1489 }
1458 1490
1459 // circumflex 1491 // circumflex
1460 else if (buf.contains(QRegExp("^\\s*c\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1492 else if (buf.contains(QRegExp("^\\s*c\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1461 1493
1462 QTextStream tmp (buf, IO_ReadOnly); 1494 QTextStream tmp (buf, IO_ReadOnly);
1463 ushort lower, shift; 1495 ushort lower, shift;
1464 QChar c; 1496 QChar c;
1465 tmp >> c >> lower >> shift; 1497 tmp >> c >> lower >> shift;
1466 1498
1467 circumflexMap.insert(lower, shift); 1499 circumflexMap.insert(lower, shift);
1468 1500
1469 buf = t.readLine(); 1501 buf = t.readLine();
1470 } 1502 }
1471 // diaeresis 1503 // diaeresis
1472 else if (buf.contains(QRegExp("^\\s*d\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1504 else if (buf.contains(QRegExp("^\\s*d\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1473 1505
1474 QTextStream tmp (buf, IO_ReadOnly); 1506 QTextStream tmp (buf, IO_ReadOnly);
1475 ushort lower, shift; 1507 ushort lower, shift;
1476 QChar d; 1508 QChar d;
1477 tmp >> d >> lower >> shift; 1509 tmp >> d >> lower >> shift;
1478 1510
1479 diaeresisMap.insert(lower, shift); 1511 diaeresisMap.insert(lower, shift);
1480 1512
1481 buf = t.readLine(); 1513 buf = t.readLine();
1482 } 1514 }
1483 // back accent 1515 // back accent
1484 else if (buf.contains(QRegExp("^\\s*b\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1516 else if (buf.contains(QRegExp("^\\s*b\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1485 1517
1486 QTextStream tmp (buf, IO_ReadOnly); 1518 QTextStream tmp (buf, IO_ReadOnly);
1487 ushort lower, shift; 1519 ushort lower, shift;
1488 QChar d; 1520 QChar d;
1489 tmp >> d >> lower >> shift; 1521 tmp >> d >> lower >> shift;
1490 1522
1491 baccentMap.insert(lower, shift); 1523 baccentMap.insert(lower, shift);
1492 1524
1493 qDebug ("Estoy aadiendo %i con %i", lower, shift); 1525 qDebug ("Estoy aadiendo %i con %i", lower, shift);
1494 buf = t.readLine(); 1526 buf = t.readLine();
1495 } 1527 }
1496 // accent 1528 // accent
1497 else if (buf.contains(QRegExp("^\\s*a\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1529 else if (buf.contains(QRegExp("^\\s*a\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1498 1530
1499 QTextStream tmp (buf, IO_ReadOnly); 1531 QTextStream tmp (buf, IO_ReadOnly);
1500 ushort lower, shift; 1532 ushort lower, shift;
1501 QChar d; 1533 QChar d;
1502 tmp >> d >> lower >> shift; 1534 tmp >> d >> lower >> shift;
1503 1535
1504 accentMap.insert(lower, shift); 1536 accentMap.insert(lower, shift);
1505 1537
1506 buf = t.readLine(); 1538 buf = t.readLine();
1507 } 1539 }
1508 1540
1509 // other variables like lang & title 1541 // other variables like lang & title & sw
1510 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { 1542 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) {
1511 1543
1512 QTextStream tmp (buf, IO_ReadOnly); 1544 QTextStream tmp (buf, IO_ReadOnly);
1513 QString name, equals, value; 1545 QString name, equals, value;
1514 1546
1515 tmp >> name >> equals >> value; 1547 tmp >> name >> equals >> value;
1516 1548
1517 if (name == "lang") { 1549 if (name == "lang") {
1518 1550
1519 lang = value; 1551 lang = value;
1520 1552
1521 } 1553 }
1522 1554
1523 buf = t.readLine(); 1555 buf = t.readLine();
1524 } 1556 }
1525 // comments 1557 // comments
1526 else if (buf.contains(QRegExp("^\\s*#"))) { 1558 else if (buf.contains(QRegExp("^\\s*#"))) {
1527 1559
1528 buf = t.readLine(); 1560 buf = t.readLine();
1529 1561
1530 } else { // blank line, or garbage 1562 } else { // blank line, or garbage
1531 1563
1532 buf = t.readLine(); 1564 buf = t.readLine();
1533 1565
1534 } 1566 }
1535 1567
1536 } 1568 }
1537 1569
1538 f.close(); 1570 f.close();
1539 } else { 1571 } else {
1540 // We couldnt find the selected keymap, give them a configure button 1572 // We couldnt find the selected keymap, give them a configure button
1541 QImage * btn = new QImage((const char ** )kb_config_xpm); 1573 QImage * btn = new QImage((const char ** )kb_config_xpm);
1542 setKey(1, 0x1030, 0, 2, btn); 1574 setKey(1, 0x1030, 0, 2, btn);
1543 } 1575 }
1544 1576
1545} 1577}
1546 1578
1547 1579
1548// Keys::setKey {{{2 1580// Keys::setKey {{{2
1549void Keys::setKey(const int row, const int qcode, const ushort unicode, 1581void Keys::setKey(const int row, const int qcode, const ushort unicode,
1550 const int width, QImage *pix) { 1582 const int width, QImage *pix) {
1551 1583
1552 Key * key; 1584 Key * key;
1553 key = new Key; 1585 key = new Key;
1554 key->qcode = qcode; 1586 key->qcode = qcode;
1555 key->unicode = unicode; 1587 key->unicode = unicode;
1556 key->width = width; 1588 key->width = width;
1557 1589
1558 // share key->pressed between same keys 1590 // share key->pressed between same keys
1559 bool found = 0; 1591 bool found = 0;
1560 for (int i = 1; i <= 5; i++) { 1592 for (int i = 1; i <= 5; i++) {
1561 for (unsigned int j = 0; j < keys[i].count(); j++) 1593 for (unsigned int j = 0; j < keys[i].count(); j++)
1562 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { 1594 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) {
1563 1595
1564 key->pressed = keys[i].at(j)->pressed; 1596 key->pressed = keys[i].at(j)->pressed;
1565 found = 1; 1597 found = 1;
1566 } 1598 }
1567 1599
1568 } 1600 }
1569 if (!found) { 1601 if (!found) {
1570 1602
1571 key->pressed = new bool; 1603 key->pressed = new bool;
1572 *(key->pressed) = 0; 1604 *(key->pressed) = 0;
1573 } 1605 }
1574 1606
1575 key->pix = pix; 1607 key->pix = pix;
1576 1608
1577 1609
1578 keys[row].append(key); 1610 keys[row].append(key);
1579} 1611}
1580 1612
1581// Keys::~Keys {{{2 1613// Keys::~Keys {{{2
1582Keys::~Keys() { 1614Keys::~Keys() {
1583 1615
1584 for (int i = 1; i <= 5; i++) 1616 for (int i = 1; i <= 5; i++)
1585 for (unsigned int j = 0; j < keys[i].count(); j++) 1617 for (unsigned int j = 0; j < keys[i].count(); j++)
1586 delete keys[i].at(j); 1618 delete keys[i].at(j);
1587 1619
1588} 1620}
1589 1621
1590// Keys:: other functions {{{2 1622// Keys:: other functions {{{2
1591int Keys::width(const int row, const int col) { 1623int Keys::width(const int row, const int col) {
1592 1624
1593 return keys[row].at(col)->width; 1625 return keys[row].at(col)->width;
1594 1626
1595} 1627}
1596 1628
1597int Keys::rows() { 1629int Keys::rows() {
1598 1630
1599 for (int i = 1; i <= 5; i++) { 1631 for (int i = 1; i <= 5; i++) {
1600 1632
1601 if (keys[i].count() == 0) 1633 if (keys[i].count() == 0)
1602 return i - 1; 1634 return i - 1;
1603 1635
1604 } 1636 }
1605 return 5; 1637 return 5;
1606} 1638}
1607 1639
1608ushort Keys::uni(const int row, const int col) { 1640ushort Keys::uni(const int row, const int col) {
1609 1641
1610 return keys[row].at(col)->unicode; 1642 return keys[row].at(col)->unicode;
1611 1643
1612} 1644}
1613 1645
1614int Keys::qcode(const int row, const int col) { 1646int Keys::qcode(const int row, const int col) {
1615 1647
1616 return keys[row].at(col)->qcode; 1648 return keys[row].at(col)->qcode;
1617} 1649}
1618 1650
1619QImage *Keys::pix(const int row, const int col) { 1651QImage *Keys::pix(const int row, const int col) {
1620 1652
1621 return keys[row].at(col)->pix; 1653 return keys[row].at(col)->pix;
1622 1654
1623} 1655}
1624bool Keys::pressed(const int row, const int col) { 1656bool Keys::pressed(const int row, const int col) {
1625 1657
1626 return *(keys[row].at(col)->pressed); 1658 return *(keys[row].at(col)->pressed);
1627} 1659}
1628 1660
1629int Keys::numKeys(const int row) { 1661int Keys::numKeys(const int row) {
1630 1662
1631 return keys[row].count(); 1663 return keys[row].count();
1632} 1664}
1633 1665
1634void Keys::setPressed(const int row, const int col, const bool pressed) { 1666void Keys::setPressed(const int row, const int col, const bool pressed) {
1635 1667
1636 *(keys[row].at(col)->pressed) = pressed; 1668 *(keys[row].at(col)->pressed) = pressed;
1637} 1669}
1638 1670
1639ushort Keys::shift(const ushort uni) { 1671ushort Keys::shift(const ushort uni) {
1640 1672
1641 if (shiftMap[uni]) return shiftMap[uni]; 1673 if (shiftMap[uni]) return shiftMap[uni];
1642 else return 0; 1674 else return 0;
1643} 1675}
1644 1676
1645ushort Keys::meta(const ushort uni) { 1677ushort Keys::meta(const ushort uni) {
1646 1678
1647 if (metaMap[uni]) return metaMap[uni]; 1679 if (metaMap[uni]) return metaMap[uni];
1648 else return 0; 1680 else return 0;
1649} 1681}
1650 1682
1651ushort Keys::circumflex(const ushort uni) { 1683ushort Keys::circumflex(const ushort uni) {
1652 1684
1653 if (circumflexMap[uni]) return circumflexMap[uni]; 1685 if (circumflexMap[uni]) return circumflexMap[uni];
1654 else return 0; 1686 else return 0;
1655} 1687}
1656 1688
1657ushort Keys::diaeresis(const ushort uni) { 1689ushort Keys::diaeresis(const ushort uni) {
1658 1690
1659 if(diaeresisMap[uni]) return diaeresisMap[uni]; 1691 if(diaeresisMap[uni]) return diaeresisMap[uni];
1660 else return 0; 1692 else return 0;
1661} 1693}
1662 1694
1663ushort Keys::baccent(const ushort uni) { 1695ushort Keys::baccent(const ushort uni) {
1664 1696
1665 if(baccentMap[uni]) return baccentMap[uni]; 1697 if(baccentMap[uni]) return baccentMap[uni];
1666 else return 0; 1698 else return 0;
1667} 1699}
1668 1700
1669ushort Keys::accent(const ushort uni) { 1701ushort Keys::accent(const ushort uni) {
1670 1702
1671 if(accentMap[uni]) return accentMap[uni]; 1703 if(accentMap[uni]) return accentMap[uni];
1672 else return 0; 1704 else return 0;
1673} 1705}
1674 1706
1675bool *Keys::pressedPtr(const int row, const int col) { 1707bool *Keys::pressedPtr(const int row, const int col) {
1676 1708
1677 return keys[row].at(col)->pressed; 1709 return keys[row].at(col)->pressed;
1678} 1710}
diff --git a/inputmethods/multikey/keyboard.h b/inputmethods/multikey/keyboard.h
index 20c5cee..0b56988 100644
--- a/inputmethods/multikey/keyboard.h
+++ b/inputmethods/multikey/keyboard.h
@@ -1,191 +1,193 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qframe.h> 20#include <qframe.h>
21#include <qmap.h> 21#include <qmap.h>
22#include "../pickboard/pickboardcfg.h" 22#include "../pickboard/pickboardcfg.h"
23#include "../pickboard/pickboardpicks.h" 23#include "../pickboard/pickboardpicks.h"
24#include "configdlg.h" 24#include "configdlg.h"
25 25
26class QTimer; 26class QTimer;
27 27
28namespace MultiKey 28namespace MultiKey
29{ 29{
30 30
31class KeyboardConfig : public DictFilterConfig 31class KeyboardConfig : public DictFilterConfig
32{ 32{
33public: 33public:
34 KeyboardConfig(PickboardPicks* p) : DictFilterConfig(p), backspaces(0) { nrows = 1; } 34 KeyboardConfig(PickboardPicks* p) : DictFilterConfig(p), backspaces(0) { nrows = 1; }
35 virtual void generateText(const QString &s); 35 virtual void generateText(const QString &s);
36 void decBackspaces() { if (backspaces) backspaces--; } 36 void decBackspaces() { if (backspaces) backspaces--; }
37 void incBackspaces() { backspaces++; } 37 void incBackspaces() { backspaces++; }
38 void resetBackspaces() { backspaces = 0; } 38 void resetBackspaces() { backspaces = 0; }
39private: 39private:
40 int backspaces; 40 int backspaces;
41}; 41};
42 42
43 43
44class KeyboardPicks : public PickboardPicks 44class KeyboardPicks : public PickboardPicks
45{ 45{
46 Q_OBJECT 46 Q_OBJECT
47public: 47public:
48 KeyboardPicks(QWidget* parent=0, const char* name=0, WFlags f=0) 48 KeyboardPicks(QWidget* parent=0, const char* name=0, WFlags f=0)
49 : PickboardPicks(parent, name, f) { } 49 : PickboardPicks(parent, name, f) { }
50 void initialise(); 50 void initialise();
51 virtual QSize sizeHint() const; 51 virtual QSize sizeHint() const;
52 KeyboardConfig *dc; 52 KeyboardConfig *dc;
53}; 53};
54 54
55 55
56class Keys { 56class Keys {
57public: 57public:
58 58
59 Keys(); 59 Keys();
60 Keys(const char * filename); 60 Keys(const char * filename);
61 ~Keys(); 61 ~Keys();
62 int width(const int row, const int col); 62 int width(const int row, const int col);
63 int rows(); 63 int rows();
64 ushort uni(const int row, const int col); 64 ushort uni(const int row, const int col);
65 int qcode(const int row, const int col); 65 int qcode(const int row, const int col);
66 bool pressed(const int row, const int col); 66 bool pressed(const int row, const int col);
67 bool *pressedPtr(const int row, const int col); 67 bool *pressedPtr(const int row, const int col);
68 ushort shift(const ushort); 68 ushort shift(const ushort);
69 ushort meta(const ushort); 69 ushort meta(const ushort);
70 ushort circumflex(const ushort); 70 ushort circumflex(const ushort);
71 ushort diaeresis(const ushort); 71 ushort diaeresis(const ushort);
72 ushort baccent(const ushort); 72 ushort baccent(const ushort);
73 ushort accent(const ushort); 73 ushort accent(const ushort);
74 QImage *pix(const int row, const int col); 74 QImage *pix(const int row, const int col);
75 int numKeys(const int row); 75 int numKeys(const int row);
76 void setKeysFromFile(const char *filename); 76 void setKeysFromFile(const char *filename);
77 void setKey(const int row, const int qcode, const ushort unicode, 77 void setKey(const int row, const int qcode, const ushort unicode,
78 const int width, QImage *pix); 78 const int width, QImage *pix);
79 void setPressed(const int row, const int col, const bool pressed); 79 void setPressed(const int row, const int col, const bool pressed);
80 QString lang; 80 QString lang;
81 QString label; 81 QString label;
82 82
83private: 83private:
84 84
85 typedef struct Key { 85 typedef struct Key {
86 int qcode; // are qt key codes just unicode values? 86 int qcode; // are qt key codes just unicode values?
87 ushort unicode; 87 ushort unicode;
88 int width; // not pixels but relative key width. normal key is 2 88 int width; // not pixels but relative key width. normal key is 2
89 89
90 // only needed for keys like ctrl that can have multiple keys pressed at once 90 // only needed for keys like ctrl that can have multiple keys pressed at once
91 bool *pressed; 91 bool *pressed;
92 QImage *pix; 92 QImage *pix;
93 }; 93 };
94 94
95 QList<Key> keys[6]; 95 QList<Key> keys[6];
96 QMap<ushort,ushort> shiftMap; 96 QMap<ushort,ushort> shiftMap;
97 QMap<ushort,ushort> metaMap; 97 QMap<ushort,ushort> metaMap;
98 QMap<ushort,ushort> circumflexMap; 98 QMap<ushort,ushort> circumflexMap;
99 QMap<ushort,ushort> diaeresisMap; 99 QMap<ushort,ushort> diaeresisMap;
100 QMap<ushort,ushort> baccentMap; 100 QMap<ushort,ushort> baccentMap;
101 QMap<ushort,ushort> accentMap; 101 QMap<ushort,ushort> accentMap;
102 102
103}; 103};
104 104
105class Keyboard : public QFrame 105class Keyboard : public QFrame
106{ 106{
107 Q_OBJECT 107 Q_OBJECT
108public: 108public:
109 Keyboard( QWidget* parent=0, const char* name=0, WFlags f=0 ); 109 Keyboard( QWidget* parent=0, const char* name=0, WFlags f=0 );
110 ~Keyboard(); 110 ~Keyboard();
111 111
112 void resetState(); 112 void resetState();
113 113
114 void mousePressEvent(QMouseEvent*); 114 void mousePressEvent(QMouseEvent*);
115 void mouseReleaseEvent(QMouseEvent*); 115 void mouseReleaseEvent(QMouseEvent*);
116 void resizeEvent(QResizeEvent*); 116 void resizeEvent(QResizeEvent*);
117 void paintEvent(QPaintEvent* e); 117 void paintEvent(QPaintEvent* e);
118 //void timerEvent(QTimerEvent* e); 118 //void timerEvent(QTimerEvent* e);
119 void drawKeyboard( QPainter &p, int row = -1, int col = -1); 119 void drawKeyboard( QPainter &p, int row = -1, int col = -1);
120 120
121 QSize sizeHint() const; 121 QSize sizeHint() const;
122 122
123signals: 123signals:
124 void key( ushort scancode, ushort unicode, ushort modifiers, bool, bool ); 124 void key( ushort scancode, ushort unicode, ushort modifiers, bool, bool );
125 125
126private slots: 126private slots:
127 void repeat(); 127 void repeat();
128 void togglePickboard(bool on_off); 128 void togglePickboard(bool on_off);
129 void toggleRepeat(bool on_off); 129 void toggleRepeat(bool on_off);
130 void setMapToDefault(); 130 void setMapToDefault();
131 void setMapToFile(QString map); 131 void setMapToFile(QString map);
132 void cleanupConfigDlg(); 132 void cleanupConfigDlg();
133 void reloadSw();
133 134
134 // used to redraw keyboard after edited colors 135 // used to redraw keyboard after edited colors
135 void reloadKeyboard(); 136 void reloadKeyboard();
137 void receive( const QCString &msg, const QByteArray &data );
136 138
137private: 139private:
138 int getKey( int &w, int j = -1 ); 140 int getKey( int &w, int j = -1 );
139 void clearHighlight(); 141 void clearHighlight();
140 142
141 bool *shift; 143 bool *shift;
142 bool *lock; 144 bool *lock;
143 bool *ctrl; 145 bool *ctrl;
144 bool *alt; 146 bool *alt;
145 bool *meta; 147 bool *meta;
146 bool *circumflex; 148 bool *circumflex;
147 bool *diaeresis; 149 bool *diaeresis;
148 bool *baccent; 150 bool *baccent;
149 bool *accent; 151 bool *accent;
150 152
151 uint useLargeKeys:1; 153 uint useLargeKeys:1;
152 uint usePicks:1; 154 uint usePicks:1;
153 uint useRepeat:1; 155 uint useRepeat:1;
154 156
155 int pressedKeyRow; 157 int pressedKeyRow;
156 int pressedKeyCol; 158 int pressedKeyCol;
157 159
158 KeyboardPicks *picks; 160 KeyboardPicks *picks;
159 161
160 int keyHeight; 162 int keyHeight;
161 int defaultKeyWidth; 163 int defaultKeyWidth;
162 int xoffs; 164 int xoffs;
163 165
164 int unicode; 166 int unicode;
165 int qkeycode; 167 int qkeycode;
166 int modifiers; 168 int modifiers;
167 169
168 int pressTid; 170 int pressTid;
169 bool pressed; 171 bool pressed;
170 172
171 Keys *keys; 173 Keys *keys;
172 174
173 /* for korean input */ 175 /* for korean input */
174 ushort schar, mchar, echar; 176 ushort schar, mchar, echar;
175 ushort parseKoreanInput(ushort c); 177 ushort parseKoreanInput(ushort c);
176 ushort combineKoreanChars(const ushort s, const ushort m, const ushort e); 178 ushort combineKoreanChars(const ushort s, const ushort m, const ushort e);
177 ushort constoe(const ushort c); 179 ushort constoe(const ushort c);
178 180
179 QTimer *repeatTimer; 181 QTimer *repeatTimer;
180 182
181 /* colors */ 183 /* colors */
182 void loadKeyboardColors(); 184 void loadKeyboardColors();
183 QColor keycolor; 185 QColor keycolor;
184 QColor keycolor_pressed; 186 QColor keycolor_pressed;
185 QColor keycolor_lines; 187 QColor keycolor_lines;
186 QColor textcolor; 188 QColor textcolor;
187 189
188 ConfigDlg *configdlg; 190 ConfigDlg *configdlg;
189}; 191};
190 192
191} // namespace MultiKey 193} // namespace MultiKey