summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/configdlg.cpp1
-rw-r--r--inputmethods/multikey/keyboard.cpp2
2 files changed, 2 insertions, 1 deletions
diff --git a/inputmethods/multikey/configdlg.cpp b/inputmethods/multikey/configdlg.cpp
index 1e104a6..59a290b 100644
--- a/inputmethods/multikey/configdlg.cpp
+++ b/inputmethods/multikey/configdlg.cpp
@@ -1,259 +1,260 @@
1/* 1/*
2 * TODO 2 * TODO
3 * make a font selection thing (size too) 3 * make a font selection thing (size too)
4 * make a cursor thing 4 * make a cursor thing
5 * 5 *
6 * 6 *
7 * 7 *
8 */ 8 */
9 9
10#include <iostream.h> 10#include <iostream.h>
11 11
12#include <qpe/qpeapplication.h> 12#include <qpe/qpeapplication.h>
13#include <qpe/config.h> 13#include <qpe/config.h>
14 14
15#include <qwidget.h> 15#include <qwidget.h>
16#include <qdialog.h> 16#include <qdialog.h>
17#include <qtabwidget.h> 17#include <qtabwidget.h>
18#include <qvbox.h> 18#include <qvbox.h>
19#include <qgrid.h> 19#include <qgrid.h>
20#include <qgroupbox.h> 20#include <qgroupbox.h>
21#include <qlabel.h> 21#include <qlabel.h>
22#include <qcheckbox.h> 22#include <qcheckbox.h>
23#include <qsizepolicy.h> 23#include <qsizepolicy.h>
24#include <qpushbutton.h> 24#include <qpushbutton.h>
25#include <qlistbox.h> 25#include <qlistbox.h>
26#include <qstringlist.h> 26#include <qstringlist.h>
27#include <opie/ofiledialog.h> 27#include <opie/ofiledialog.h>
28#include <opie/colordialog.h> 28#include <opie/colordialog.h>
29#include <qdir.h> 29#include <qdir.h>
30#include <qfileinfo.h> 30#include <qfileinfo.h>
31#include "configdlg.h" 31#include "configdlg.h"
32#include "keyboard.h" 32#include "keyboard.h"
33 33
34// ConfigDlg::ConfigDlg() {{{1 34// ConfigDlg::ConfigDlg() {{{1
35ConfigDlg::ConfigDlg () : QTabWidget () 35ConfigDlg::ConfigDlg () : QTabWidget ()
36{ 36{
37 setCaption( tr("Multikey Configuration") ); 37 setCaption( tr("Multikey Configuration") );
38 Config config ("multikey"); 38 Config config ("multikey");
39 config.setGroup("keymaps"); 39 config.setGroup("keymaps");
40 QString current_map = config.readEntry("current", 0); 40 QString current_map = config.readEntry("current", 0);
41 41
42 /* 42 /*
43 * 'general config' tab 43 * 'general config' tab
44 */ 44 */
45 45
46 QVBox *gen_box = new QVBox (this); 46 QVBox *gen_box = new QVBox (this);
47 gen_box->setMargin(3); 47 gen_box->setMargin(3);
48 addTab(gen_box, tr("General Settings")); 48 addTab(gen_box, tr("General Settings"));
49 49
50 QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box); 50 QGroupBox *map_group = new QGroupBox (2, Qt::Vertical, tr("Keymap File"), gen_box);
51 51
52 keymaps = new QListBox (map_group); 52 keymaps = new QListBox (map_group);
53 keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 53 keymaps->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
54 54
55 QString cur(tr("Current Language")); 55 QString cur(tr("Current Language"));
56 keymaps->insertItem(cur); 56 keymaps->insertItem(cur);
57 keymaps->setSelected(0, true); 57 keymaps->setSelected(0, true);
58 58
59 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap"); 59 QDir map_dir(QPEApplication::qpeDir() + "/share/multikey", "*.keymap");
60 default_maps = map_dir.entryList(); // so i can access it in other places 60 default_maps = map_dir.entryList(); // so i can access it in other places
61 61
62 for (uint i = 0; i <map_dir.count(); i++) { 62 for (uint i = 0; i <map_dir.count(); i++) {
63 63
64 keymaps->insertItem(map_dir.absPath() + "/" + map_dir[i]); 64 keymaps->insertItem(map_dir.absPath() + "/" + map_dir[i]);
65 if (map_dir.absPath() + "/" + map_dir[i] == current_map) { 65 if (map_dir.absPath() + "/" + map_dir[i] == current_map) {
66 66
67 keymaps->setSelected(i + 1, true); 67 keymaps->setSelected(i + 1, true);
68 } 68 }
69 69
70 } 70 }
71 71
72 custom_maps = config.readListEntry("maps", QChar('|')); 72 custom_maps = config.readListEntry("maps", QChar('|'));
73 73
74 for (uint i = 0; i < custom_maps.count(); i++) { 74 for (uint i = 0; i < custom_maps.count(); i++) {
75 75
76 if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false) 76 if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false)
77 || !QFile::exists(custom_maps[i])) { 77 || !QFile::exists(custom_maps[i])) {
78 78
79 custom_maps.remove(custom_maps.at(i)); 79 custom_maps.remove(custom_maps.at(i));
80 80
81 // remove it from the list too 81 // remove it from the list too
82 config.writeEntry("maps", custom_maps.join("|")); 82 config.writeEntry("maps", custom_maps.join("|"));
83 83
84 84
85 } else { 85 } else {
86 86
87 keymaps->insertItem(custom_maps[i]); 87 keymaps->insertItem(custom_maps[i]);
88 if (custom_maps[i] == current_map) { 88 if (custom_maps[i] == current_map) {
89 89
90 keymaps->setSelected(map_dir.count() + i + 1, true); 90 keymaps->setSelected(map_dir.count() + i + 1, true);
91 } 91 }
92 } 92 }
93 } 93 }
94 94
95 // have to "+1" because the "current language" listItem... remember? 95 // have to "+1" because the "current language" listItem... remember?
96 96
97 connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int))); 97 connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int)));
98 98
99 99
100 QGrid *add_remove_grid = new QGrid(2, map_group); 100 QGrid *add_remove_grid = new QGrid(2, map_group);
101 add_remove_grid->setMargin(3); 101 add_remove_grid->setMargin(3);
102 add_remove_grid->setSpacing(3); 102 add_remove_grid->setSpacing(3);
103 103
104 add_button = new QPushButton(tr("Add"), add_remove_grid); 104 add_button = new QPushButton(tr("Add"), add_remove_grid);
105 add_button->setFlat((bool)1); 105 add_button->setFlat((bool)1);
106 connect(add_button, SIGNAL(clicked()), SLOT(addMap())); 106 connect(add_button, SIGNAL(clicked()), SLOT(addMap()));
107 107
108 remove_button = new QPushButton(tr("Remove"), add_remove_grid); 108 remove_button = new QPushButton(tr("Remove"), add_remove_grid);
109 remove_button->setFlat((bool)1); 109 remove_button->setFlat((bool)1);
110 if ((int)map_dir.count() >= keymaps->currentItem()) 110 if ((int)map_dir.count() >= keymaps->currentItem())
111 remove_button->setDisabled(true); 111 remove_button->setDisabled(true);
112 connect(remove_button, SIGNAL(clicked()), SLOT(removeMap())); 112 connect(remove_button, SIGNAL(clicked()), SLOT(removeMap()));
113 113
114 pick_button = new QCheckBox(tr("Pickboard"), gen_box); 114 pick_button = new QCheckBox(tr("Pickboard"), gen_box);
115 115
116 config.setGroup ("pickboard"); 116 config.setGroup ("pickboard");
117 bool pick_open = config.readBoolEntry ("open", "0"); // default closed 117 bool pick_open = config.readBoolEntry ("open", "0"); // default closed
118 if (pick_open) { 118 if (pick_open) {
119 119
120 pick_button->setChecked(true); 120 pick_button->setChecked(true);
121 } 121 }
122 122
123 // by connecting it after checking it, the signal isn't emmited 123 // by connecting it after checking it, the signal isn't emmited
124 connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog())); 124 connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog()));
125 125
126 /* 126 /*
127 * 'color' tab 127 * 'color' tab
128 */ 128 */
129 129
130 QGrid *color_box = new QGrid(2, this); 130 QGrid *color_box = new QGrid(2, this);
131 color_box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); 131 color_box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
132 color_box->setMargin(3); 132 color_box->setMargin(3);
133 color_box->setSpacing(3); 133 color_box->setSpacing(3);
134 addTab(color_box, tr("Colors")); 134 addTab(color_box, tr("Colors"));
135 135
136 QLabel *label; 136 QLabel *label;
137 QStringList color; 137 QStringList color;
138 138
139 label = new QLabel(tr("Key Color"), color_box); 139 label = new QLabel(tr("Key Color"), color_box);
140 key_color_button = new QPushButton(color_box); 140 key_color_button = new QPushButton(color_box);
141 connect(key_color_button, SIGNAL(clicked()), SLOT(keyColorButtonClicked())); 141 connect(key_color_button, SIGNAL(clicked()), SLOT(keyColorButtonClicked()));
142 key_color_button->setFlat((bool)1); 142 key_color_button->setFlat((bool)1);
143 143
144 config.setGroup("colors"); 144 config.setGroup("colors");
145 color = config.readListEntry("keycolor", QChar(',')); 145 color = config.readListEntry("keycolor", QChar(','));
146 if (color.isEmpty()) { 146 if (color.isEmpty()) {
147 color = QStringList::split(",", "240,240,240"); 147 color = QStringList::split(",", "240,240,240");
148 config.writeEntry("keycolor", color.join(",")); 148 config.writeEntry("keycolor", color.join(","));
149 149
150 } 150 }
151 key_color_button->setBackgroundColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); 151 key_color_button->setBackgroundColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
152 152
153 153
154 label = new QLabel(tr("Key Pressed Color"), color_box); 154 label = new QLabel(tr("Key Pressed Color"), color_box);
155 QPushButton *button = new QPushButton(color_box); 155 QPushButton *button = new QPushButton(color_box);
156 button->setFlat((bool)1); 156 button->setFlat((bool)1);
157 label = new QLabel(tr("Line Color"), color_box); 157 label = new QLabel(tr("Line Color"), color_box);
158 button = new QPushButton(color_box); 158 button = new QPushButton(color_box);
159 button->setFlat((bool)1); 159 button->setFlat((bool)1);
160 label = new QLabel(tr("Text Color"), color_box); 160 label = new QLabel(tr("Text Color"), color_box);
161 button = new QPushButton(color_box); 161 button = new QPushButton(color_box);
162 button->setFlat((bool)1); 162 button->setFlat((bool)1);
163 163
164 label = new QLabel("", color_box); // a spacer so the above buttons dont expand 164 label = new QLabel("", color_box); // a spacer so the above buttons dont expand
165 label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); 165 label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
166 166
167} 167}
168 168
169void ConfigDlg::pickTog() { 169void ConfigDlg::pickTog() {
170 170
171 Config config ("multikey"); 171 Config config ("multikey");
172 config.setGroup ("pickboard"); 172 config.setGroup ("pickboard");
173 config.writeEntry ("open", pick_button->isChecked()); // default closed 173 config.writeEntry ("open", pick_button->isChecked()); // default closed
174 174
175 emit pickboardToggled(pick_button->isChecked()); 175 emit pickboardToggled(pick_button->isChecked());
176} 176}
177 177
178/* 178/*
179 * the index is kinda screwy, because in the config file, index 0 is just the 179 * the index is kinda screwy, because in the config file, index 0 is just the
180 * first element in the QStringList, but here it's the "Current Language" 180 * first element in the QStringList, but here it's the "Current Language"
181 * listItem. therefor you have to minus one to the index before you access it. 181 * listItem. therefor you have to minus one to the index before you access it.
182 * 182 *
183 */ 183 */
184 184
185// ConfigDlg::setMap {{{1 185// ConfigDlg::setMap {{{1
186void ConfigDlg::setMap(int index) { 186void ConfigDlg::setMap(int index) {
187 187
188 if (index == 0) { 188 if (index == 0) {
189 189
190 remove_button->setDisabled(true); 190 remove_button->setDisabled(true);
191 emit setMapToDefault(); 191 emit setMapToDefault();
192 } 192 }
193 else if ((uint)index <= default_maps.count()) { 193 else if ((uint)index <= default_maps.count()) {
194 194
195 remove_button->setDisabled(true); 195 remove_button->setDisabled(true);
196 emit setMapToFile(keymaps->text(index)); 196 emit setMapToFile(keymaps->text(index));
197 197
198 } else { 198 } else {
199 199
200 remove_button->setEnabled(true); 200 remove_button->setEnabled(true);
201 emit setMapToFile(keymaps->text(index)); 201 emit setMapToFile(keymaps->text(index));
202 } 202 }
203} 203}
204 204
205// ConfigDlg::addMap() {{{1 205// ConfigDlg::addMap() {{{1
206void ConfigDlg::addMap() { 206void ConfigDlg::addMap() {
207 207
208 QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath()); 208 QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath());
209 Config config ("multikey"); 209 Config config ("multikey");
210 config.setGroup("keymaps"); 210 config.setGroup("keymaps");
211 QStringList maps = config.readListEntry("maps", QChar('|')); 211 QStringList maps = config.readListEntry("maps", QChar('|'));
212 maps.append(map); 212 maps.append(map);
213 keymaps->insertItem(map); 213 keymaps->insertItem(map);
214 keymaps->setSelected(keymaps->count() - 1, true); 214 keymaps->setSelected(keymaps->count() - 1, true);
215 215
216 216
217 config.writeEntry("maps", maps, QChar('|')); 217 config.writeEntry("maps", maps, QChar('|'));
218 config.writeEntry("current", map); 218 config.writeEntry("current", map);
219 219
220} 220}
221 221
222// ConfigDlg::removeMap() {{{1 222// ConfigDlg::removeMap() {{{1
223void ConfigDlg::removeMap() { 223void ConfigDlg::removeMap() {
224 224
225 cout << "removing : " << custom_maps[keymaps->currentItem() - default_maps.count() - 1] << "\n"; 225 cout << "removing : " << custom_maps[keymaps->currentItem() - default_maps.count() - 1] << "\n";
226 cout << "currentItem : " << keymaps->currentItem() << "\n"; 226 cout << "currentItem : " << keymaps->currentItem() << "\n";
227 227
228 // move selection up one 228 // move selection up one
229 keymaps->setSelected(keymaps->currentItem() - 1, true); 229 keymaps->setSelected(keymaps->currentItem() - 1, true);
230 // delete the next selected item cus you just moved it up 230 // delete the next selected item cus you just moved it up
231 keymaps->removeItem(keymaps->currentItem() + 1); 231 keymaps->removeItem(keymaps->currentItem() + 1);
232 232
233 custom_maps.remove(custom_maps[keymaps->currentItem() - default_maps.count()]); 233 custom_maps.remove(custom_maps[keymaps->currentItem() - default_maps.count()]);
234 234
235 // write the changes 235 // write the changes
236 Config config ("multikey"); 236 Config config ("multikey");
237 config.setGroup("keymaps"); 237 config.setGroup("keymaps");
238 config.writeEntry("maps", custom_maps, QChar('|')); 238 config.writeEntry("maps", custom_maps, QChar('|'));
239} 239}
240 240
241// ConfigDlg::color {{{1 241// ConfigDlg::color {{{1
242void ConfigDlg::keyColorButtonClicked() { 242void ConfigDlg::keyColorButtonClicked() {
243 243
244 Config config ("multikey"); 244 Config config ("multikey");
245 config.setGroup ("colors"); 245 config.setGroup ("colors");
246 246
247 QStringList color = config.readListEntry("keycolor", QChar(',')); 247 QStringList color = config.readListEntry("keycolor", QChar(','));
248 248
249 QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); 249 QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
250 250
251 color[0].setNum(newcolor.red()); 251 color[0].setNum(newcolor.red());
252 color[1].setNum(newcolor.green()); 252 color[1].setNum(newcolor.green());
253 color[2].setNum(newcolor.blue()); 253 color[2].setNum(newcolor.blue());
254 254
255 config.writeEntry("keycolor", color, QChar(',')); 255 config.writeEntry("keycolor", color, QChar(','));
256 config.write();
256 257
257 key_color_button->setBackgroundColor(newcolor); 258 key_color_button->setBackgroundColor(newcolor);
258 emit reloadKeyboard(); 259 emit reloadKeyboard();
259} 260}
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index 68918a6..8280297 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -1,1136 +1,1136 @@
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 <qfile.h>
35#include <qtextstream.h> 35#include <qtextstream.h>
36#include <qstringlist.h> 36#include <qstringlist.h>
37#include <iostream.h> 37#include <iostream.h>
38 38
39#include <sys/utsname.h> 39#include <sys/utsname.h>
40 40
41 41
42#define USE_SMALL_BACKSPACE 42#define USE_SMALL_BACKSPACE
43 43
44/* Keyboard::Keyboard {{{1 */ 44/* Keyboard::Keyboard {{{1 */
45Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : 45Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) :
46 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), 46 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0),
47 alt(0), useLargeKeys(TRUE), usePicks(0), pressedKeyRow(-1), pressedKeyCol(-1), 47 alt(0), useLargeKeys(TRUE), usePicks(0), pressedKeyRow(-1), pressedKeyCol(-1),
48 unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), 48 unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0),
49 configdlg(0) 49 configdlg(0)
50 50
51{ 51{
52 52
53 // get the default font 53 // get the default font
54 Config *config = new Config( "qpe" ); 54 Config *config = new Config( "qpe" );
55 config->setGroup( "Appearance" ); 55 config->setGroup( "Appearance" );
56 QString familyStr = config->readEntry( "FontFamily", "fixed" ); 56 QString familyStr = config->readEntry( "FontFamily", "fixed" );
57 delete config; 57 delete config;
58 58
59 config = new Config("multikey"); 59 config = new Config("multikey");
60 config->setGroup ("pickboard"); 60 config->setGroup ("pickboard");
61 usePicks = config->readBoolEntry ("open", "0"); // default closed 61 usePicks = config->readBoolEntry ("open", "0"); // default closed
62 delete config; 62 delete config;
63 63
64 setFont( QFont( familyStr, 10 ) ); 64 setFont( QFont( familyStr, 10 ) );
65 65
66 picks = new KeyboardPicks( this ); 66 picks = new KeyboardPicks( this );
67 picks->setFont( QFont( familyStr, 10 ) ); 67 picks->setFont( QFont( familyStr, 10 ) );
68 picks->initialise(); 68 picks->initialise();
69 if (usePicks) { 69 if (usePicks) {
70 70
71 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 71 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
72 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 72 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
73 73
74 } else picks->hide(); 74 } else picks->hide();
75 75
76 loadKeyboardColors(); 76 loadKeyboardColors();
77 77
78 keys = new Keys(); 78 keys = new Keys();
79 79
80 repeatTimer = new QTimer( this ); 80 repeatTimer = new QTimer( this );
81 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); 81 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) );
82 82
83} 83}
84 84
85Keyboard::~Keyboard() { 85Keyboard::~Keyboard() {
86 86
87 if ( configdlg ) { 87 if ( configdlg ) {
88 delete (ConfigDlg *) configdlg; 88 delete (ConfigDlg *) configdlg;
89 configdlg = 0; 89 configdlg = 0;
90 } 90 }
91 91
92} 92}
93 93
94/* Keyboard::resizeEvent {{{1 */ 94/* Keyboard::resizeEvent {{{1 */
95void Keyboard::resizeEvent(QResizeEvent*) 95void Keyboard::resizeEvent(QResizeEvent*)
96{ 96{
97 int ph = picks->sizeHint().height(); 97 int ph = picks->sizeHint().height();
98 picks->setGeometry( 0, 0, width(), ph ); 98 picks->setGeometry( 0, 0, width(), ph );
99 keyHeight = (height()-(usePicks ? ph : 0))/5; 99 keyHeight = (height()-(usePicks ? ph : 0))/5;
100 100
101 int nk; // number of keys? 101 int nk; // number of keys?
102 if ( useLargeKeys ) { 102 if ( useLargeKeys ) {
103 nk = 15; 103 nk = 15;
104 } else { 104 } else {
105 nk = 19; 105 nk = 19;
106 } 106 }
107 defaultKeyWidth = (width()/nk)/2; 107 defaultKeyWidth = (width()/nk)/2;
108 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? 108 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces?
109 109
110} 110}
111 111
112/* KeyboardPicks::initialize {{{1 */ 112/* KeyboardPicks::initialize {{{1 */
113void KeyboardPicks::initialise() 113void KeyboardPicks::initialise()
114{ 114{
115 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); 115 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
116 mode = 0; 116 mode = 0;
117 dc = new KeyboardConfig(this); 117 dc = new KeyboardConfig(this);
118 configs.append(dc); 118 configs.append(dc);
119} 119}
120 120
121/* KeyboardPicks::sizeHint {{{1 */ 121/* KeyboardPicks::sizeHint {{{1 */
122QSize KeyboardPicks::sizeHint() const 122QSize KeyboardPicks::sizeHint() const
123{ 123{
124 return QSize(240,fontMetrics().lineSpacing()); 124 return QSize(240,fontMetrics().lineSpacing());
125} 125}
126 126
127 127
128/* KeyboardConfig::generateText {{{1 */ 128/* KeyboardConfig::generateText {{{1 */
129void KeyboardConfig::generateText(const QString &s) 129void KeyboardConfig::generateText(const QString &s)
130{ 130{
131#if defined(Q_WS_QWS) || defined(_WS_QWS_) 131#if defined(Q_WS_QWS) || defined(_WS_QWS_)
132 for (int i=0; i<(int)backspaces; i++) { 132 for (int i=0; i<(int)backspaces; i++) {
133 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); 133 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false );
134 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); 134 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false );
135 } 135 }
136 for (int i=0; i<(int)s.length(); i++) { 136 for (int i=0; i<(int)s.length(); i++) {
137 parent->emitKey( s[i].unicode(), 0, 0, true, false ); 137 parent->emitKey( s[i].unicode(), 0, 0, true, false );
138 parent->emitKey( s[i].unicode(), 0, 0, false, false ); 138 parent->emitKey( s[i].unicode(), 0, 0, false, false );
139 } 139 }
140 parent->emitKey( 0, Qt::Key_Space, 0, true, false ); 140 parent->emitKey( 0, Qt::Key_Space, 0, true, false );
141 parent->emitKey( 0, Qt::Key_Space, 0, false, false ); 141 parent->emitKey( 0, Qt::Key_Space, 0, false, false );
142 backspaces = 0; 142 backspaces = 0;
143#endif 143#endif
144} 144}
145 145
146 146
147 147
148 148
149/* Keyboard::paintEvent {{{1 */ 149/* Keyboard::paintEvent {{{1 */
150void Keyboard::paintEvent(QPaintEvent* e) 150void Keyboard::paintEvent(QPaintEvent* e)
151{ 151{
152 QPainter painter(this); 152 QPainter painter(this);
153 painter.setClipRect(e->rect()); 153 painter.setClipRect(e->rect());
154 drawKeyboard( painter ); 154 drawKeyboard( painter );
155 picks->dc->draw( &painter ); 155 picks->dc->draw( &painter );
156} 156}
157 157
158 158
159/* Keyboard::drawKeyboard {{{1 */ 159/* Keyboard::drawKeyboard {{{1 */
160 160
161void Keyboard::drawKeyboard(QPainter &p, int row, int col) 161void Keyboard::drawKeyboard(QPainter &p, int row, int col)
162{ 162{
163 163
164 164
165 if (row != -1 && col != -1) { //just redraw one key 165 if (row != -1 && col != -1) { //just redraw one key
166 166
167 int x = 0; 167 int x = 0;
168 for (int i = 0; i < col; i++) { 168 for (int i = 0; i < col; i++) {
169 169
170 x += keys->width(row, i) * defaultKeyWidth; 170 x += keys->width(row, i) * defaultKeyWidth;
171 } 171 }
172 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 172 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
173 173
174 int keyWidth = keys->width(row, col); 174 int keyWidth = keys->width(row, col);
175 175
176 p.fillRect(x + 1, y + 1, 176 p.fillRect(x + 1, y + 1,
177 keyWidth * defaultKeyWidth - 1, keyHeight - 1, 177 keyWidth * defaultKeyWidth - 1, keyHeight - 1,
178 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); 178 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor);
179 179
180 QPixmap *pix = keys->pix(row,col); 180 QPixmap *pix = keys->pix(row,col);
181 181
182 ushort c = keys->uni(row, col); 182 ushort c = keys->uni(row, col);
183 183
184 p.setPen(textcolor); 184 p.setPen(textcolor);
185 if (!pix) 185 if (!pix)
186 p.drawText(x, y, 186 p.drawText(x, y,
187 defaultKeyWidth * keyWidth, keyHeight, 187 defaultKeyWidth * keyWidth, keyHeight,
188 AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); 188 AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c);
189 else 189 else
190 // center the image in the middle of the key 190 // center the image in the middle of the key
191 p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, 191 p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2,
192 y + (keyHeight - pix->height())/2 + 1, 192 y + (keyHeight - pix->height())/2 + 1,
193 *pix ); 193 *pix );
194 194
195 // this fixes the problem that the very right end of the board's vertical line 195 // this fixes the problem that the very right end of the board's vertical line
196 // gets painted over, because it's one pixel shorter than all other keys 196 // gets painted over, because it's one pixel shorter than all other keys
197 p.setPen(keycolor_lines); 197 p.setPen(keycolor_lines);
198 p.drawLine(width() - 1, 0, width() - 1, height()); 198 p.drawLine(width() - 1, 0, width() - 1, height());
199 199
200 } else { 200 } else {
201 201
202 202
203 p.fillRect(0, 0, width(), height(), keycolor); 203 p.fillRect(0, 0, width(), height(), keycolor);
204 204
205 for (row = 1; row <= 5; row++) { 205 for (row = 1; row <= 5; row++) {
206 206
207 int x = 0; 207 int x = 0;
208 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 208 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
209 209
210 p.setPen(keycolor_lines); 210 p.setPen(keycolor_lines);
211 p.drawLine(x, y, x + width(), y); 211 p.drawLine(x, y, x + width(), y);
212 212
213 for (int col = 0; col < keys->numKeys(row); col++) { 213 for (int col = 0; col < keys->numKeys(row); col++) {
214 214
215 QPixmap *pix = keys->pix(row, col); 215 QPixmap *pix = keys->pix(row, col);
216 int keyWidth = keys->width(row, col); 216 int keyWidth = keys->width(row, col);
217 217
218 218
219 int keyWidthPix = defaultKeyWidth * keyWidth; 219 int keyWidthPix = defaultKeyWidth * keyWidth;
220 220
221 if (keys->pressed(row, col)) 221 if (keys->pressed(row, col))
222 p.fillRect(x+1, y+1, keyWidthPix - 1, 222 p.fillRect(x+1, y+1, keyWidthPix - 1,
223 keyHeight - 1, keycolor_pressed); 223 keyHeight - 1, keycolor_pressed);
224 224
225 ushort c = keys->uni(row, col); 225 ushort c = keys->uni(row, col);
226 226
227 if (!pix) { 227 if (!pix) {
228 p.setPen(textcolor); 228 p.setPen(textcolor);
229 p.drawText(x, y, 229 p.drawText(x, y,
230 keyWidthPix, keyHeight, 230 keyWidthPix, keyHeight,
231 AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); 231 AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c);
232 } 232 }
233 else { 233 else {
234 // center the image in the middle of the key 234 // center the image in the middle of the key
235 p.drawPixmap( x + (keyWidthPix - pix->width())/2, 235 p.drawPixmap( x + (keyWidthPix - pix->width())/2,
236 y + (keyHeight - pix->height())/2 + 1, 236 y + (keyHeight - pix->height())/2 + 1,
237 QPixmap(*pix) ); 237 QPixmap(*pix) );
238 } 238 }
239 239
240 p.setPen(keycolor_lines); 240 p.setPen(keycolor_lines);
241 p.drawLine(x, y, x, y + keyHeight); 241 p.drawLine(x, y, x, y + keyHeight);
242 242
243 x += keyWidthPix; 243 x += keyWidthPix;
244 } 244 }
245 245
246 246
247 } 247 }
248 p.drawLine(0, height() - 1, width(), height() - 1); 248 p.drawLine(0, height() - 1, width(), height() - 1);
249 p.drawLine(width() - 1, 0, width() - 1, height()); 249 p.drawLine(width() - 1, 0, width() - 1, height());
250 } 250 }
251 251
252} 252}
253 253
254 254
255/* Keyboard::mousePressEvent {{{1 */ 255/* Keyboard::mousePressEvent {{{1 */
256void Keyboard::mousePressEvent(QMouseEvent *e) 256void Keyboard::mousePressEvent(QMouseEvent *e)
257{ 257{
258 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; 258 int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1;
259 if (row > 5) row = 5; 259 if (row > 5) row = 5;
260 260
261 // figure out the column 261 // figure out the column
262 int col = 0; 262 int col = 0;
263 for (int w = 0; e->x() >= w; col++) 263 for (int w = 0; e->x() >= w; col++)
264 if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys 264 if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys
265 w += keys->width(row,col) * defaultKeyWidth; 265 w += keys->width(row,col) * defaultKeyWidth;
266 else break; 266 else break;
267 267
268 col --; // rewind one... 268 col --; // rewind one...
269 269
270 qkeycode = keys->qcode(row, col); 270 qkeycode = keys->qcode(row, col);
271 unicode = keys->uni(row, col); 271 unicode = keys->uni(row, col);
272 272
273 // might need to repaint if two or more of the same keys. 273 // might need to repaint if two or more of the same keys.
274 // should be faster if just paint one key even though multiple keys exist. 274 // should be faster if just paint one key even though multiple keys exist.
275 bool need_repaint = FALSE; 275 bool need_repaint = FALSE;
276 276
277 if (unicode == 0) { // either Qt char, or nothing 277 if (unicode == 0) { // either Qt char, or nothing
278 278
279 if (qkeycode == Qt::Key_F1) { // toggle the pickboard 279 if (qkeycode == Qt::Key_F1) { // toggle the pickboard
280 280
281 if ( configdlg ) { 281 if ( configdlg ) {
282 delete (ConfigDlg *) configdlg; 282 delete (ConfigDlg *) configdlg;
283 configdlg = 0; 283 configdlg = 0;
284 } 284 }
285 else { 285 else {
286 configdlg = new ConfigDlg (); 286 configdlg = new ConfigDlg ();
287 connect(configdlg, SIGNAL(pickboardToggled(bool)), 287 connect(configdlg, SIGNAL(pickboardToggled(bool)),
288 this, SLOT(togglePickboard(bool))); 288 this, SLOT(togglePickboard(bool)));
289 connect(configdlg, SIGNAL(setMapToDefault()), 289 connect(configdlg, SIGNAL(setMapToDefault()),
290 this, SLOT(setMapToDefault())); 290 this, SLOT(setMapToDefault()));
291 connect(configdlg, SIGNAL(setMapToFile(QString)), 291 connect(configdlg, SIGNAL(setMapToFile(QString)),
292 this, SLOT(setMapToFile(QString))); 292 this, SLOT(setMapToFile(QString)));
293 connect(configdlg, SIGNAL(reloadKeyboard()), 293 connect(configdlg, SIGNAL(reloadKeyboard()),
294 this, SLOT(reloadKeyboard())); 294 this, SLOT(reloadKeyboard()));
295 configdlg->showMaximized(); 295 configdlg->showMaximized();
296 configdlg->show(); 296 configdlg->show();
297 configdlg->raise(); 297 configdlg->raise();
298 } 298 }
299 299
300 } else if (qkeycode == Qt::Key_Control) { 300 } else if (qkeycode == Qt::Key_Control) {
301 ctrl = keys->pressedPtr(row, col); 301 ctrl = keys->pressedPtr(row, col);
302 need_repaint = TRUE; 302 need_repaint = TRUE;
303 *ctrl = !keys->pressed(row, col); 303 *ctrl = !keys->pressed(row, col);
304 304
305 } else if (qkeycode == Qt::Key_Alt) { 305 } else if (qkeycode == Qt::Key_Alt) {
306 alt = keys->pressedPtr(row, col); 306 alt = keys->pressedPtr(row, col);
307 need_repaint = TRUE; 307 need_repaint = TRUE;
308 *alt = !keys->pressed(row, col); 308 *alt = !keys->pressed(row, col);
309 309
310 } else if (qkeycode == Qt::Key_Shift) { 310 } else if (qkeycode == Qt::Key_Shift) {
311 need_repaint = TRUE; 311 need_repaint = TRUE;
312 312
313 if (shift) { 313 if (shift) {
314 *shift = 0; 314 *shift = 0;
315 shift = 0; 315 shift = 0;
316 } 316 }
317 else { 317 else {
318 shift = keys->pressedPtr(row, col); 318 shift = keys->pressedPtr(row, col);
319 *shift = 1; 319 *shift = 1;
320 if (lock) { 320 if (lock) {
321 *lock = 0; 321 *lock = 0;
322 lock = 0; 322 lock = 0;
323 } 323 }
324 } 324 }
325 325
326 } else if (qkeycode == Qt::Key_CapsLock) { 326 } else if (qkeycode == Qt::Key_CapsLock) {
327 need_repaint = TRUE; 327 need_repaint = TRUE;
328 328
329 if (lock) { 329 if (lock) {
330 *lock = 0; 330 *lock = 0;
331 lock = 0; 331 lock = 0;
332 } 332 }
333 else { 333 else {
334 lock = keys->pressedPtr(row, col);; 334 lock = keys->pressedPtr(row, col);;
335 *lock = 1; 335 *lock = 1;
336 if (shift) { 336 if (shift) {
337 *shift = 0; 337 *shift = 0;
338 shift = 0; 338 shift = 0;
339 } 339 }
340 } 340 }
341 341
342 } 342 }
343 343
344 } 344 }
345 else { // normal char 345 else { // normal char
346 if ((shift || lock) && keys->shift(unicode)) { 346 if ((shift || lock) && keys->shift(unicode)) {
347 unicode = keys->shift(unicode); 347 unicode = keys->shift(unicode);
348 } 348 }
349 } 349 }
350 350
351 // korean parsing 351 // korean parsing
352 if (keys->lang == "ko") { 352 if (keys->lang == "ko") {
353 353
354 unicode = parseKoreanInput(unicode); 354 unicode = parseKoreanInput(unicode);
355 } 355 }
356 356
357 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); 357 modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0);
358 358
359 emit key(unicode, qkeycode, modifiers, true, false); 359 emit key(unicode, qkeycode, modifiers, true, false);
360 360
361 // pickboard stuff 361 // pickboard stuff
362 if (usePicks) { 362 if (usePicks) {
363 363
364 KeyboardConfig *dc = picks->dc; 364 KeyboardConfig *dc = picks->dc;
365 365
366 if (dc) { 366 if (dc) {
367 if (qkeycode == Qt::Key_Backspace) { 367 if (qkeycode == Qt::Key_Backspace) {
368 dc->input.remove(dc->input.last()); // remove last input 368 dc->input.remove(dc->input.last()); // remove last input
369 dc->decBackspaces(); 369 dc->decBackspaces();
370 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { 370 } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) {
371 dc->input.clear(); 371 dc->input.clear();
372 dc->resetBackspaces(); 372 dc->resetBackspaces();
373 } else { 373 } else {
374 dc->add(QString(QChar(unicode))); 374 dc->add(QString(QChar(unicode)));
375 dc->incBackspaces(); 375 dc->incBackspaces();
376 } 376 }
377 } 377 }
378 picks->repaint(); 378 picks->repaint();
379 } 379 }
380 380
381 381
382 // painting 382 // painting
383 pressed = TRUE; 383 pressed = TRUE;
384 384
385 pressedKeyRow = row; 385 pressedKeyRow = row;
386 pressedKeyCol = col; 386 pressedKeyCol = col;
387 387
388 if (need_repaint) repaint(FALSE); 388 if (need_repaint) repaint(FALSE);
389 else { // just paint the one key pressed 389 else { // just paint the one key pressed
390 390
391 391
392 392
393 QPainter p(this); 393 QPainter p(this);
394 drawKeyboard(p, row, col); 394 drawKeyboard(p, row, col);
395 395
396 } 396 }
397 397
398 pressTid = startTimer(80); 398 pressTid = startTimer(80);
399 399
400} 400}
401 401
402 402
403/* Keyboard::mouseReleaseEvent {{{1 */ 403/* Keyboard::mouseReleaseEvent {{{1 */
404void Keyboard::mouseReleaseEvent(QMouseEvent*) 404void Keyboard::mouseReleaseEvent(QMouseEvent*)
405{ 405{
406 pressed = FALSE; 406 pressed = FALSE;
407 if ( pressTid == 0 ) 407 if ( pressTid == 0 )
408#if defined(Q_WS_QWS) || defined(_WS_QWS_) 408#if defined(Q_WS_QWS) || defined(_WS_QWS_)
409 if ( unicode != -1 ) { 409 if ( unicode != -1 ) {
410 emit key( unicode, qkeycode, modifiers, false, false ); 410 emit key( unicode, qkeycode, modifiers, false, false );
411 repeatTimer->stop(); 411 repeatTimer->stop();
412 } 412 }
413#endif 413#endif
414 if (shift && unicode != 0) { 414 if (shift && unicode != 0) {
415 415
416 416
417 *shift = 0; // unpress shift key 417 *shift = 0; // unpress shift key
418 shift = 0; // reset the shift pointer 418 shift = 0; // reset the shift pointer
419 repaint(FALSE); 419 repaint(FALSE);
420 420
421 } 421 }
422 else 422 else
423 423
424 clearHighlight(); 424 clearHighlight();
425} 425}
426 426
427/* Keyboard::timerEvent {{{1 */ 427/* Keyboard::timerEvent {{{1 */
428/* 428/*
429void Keyboard::timerEvent(QTimerEvent* e) 429void Keyboard::timerEvent(QTimerEvent* e)
430{ 430{
431 if ( e->timerId() == pressTid ) { 431 if ( e->timerId() == pressTid ) {
432 killTimer(pressTid); 432 killTimer(pressTid);
433 pressTid = 0; 433 pressTid = 0;
434 if ( !pressed ) 434 if ( !pressed )
435 cout << "calling clearHighlight from timerEvent\n"; 435 cout << "calling clearHighlight from timerEvent\n";
436 clearHighlight(); 436 clearHighlight();
437 } 437 }
438} 438}
439*/ 439*/
440 440
441void Keyboard::repeat() 441void Keyboard::repeat()
442{ 442{
443 443
444 repeatTimer->start( 200 ); 444 repeatTimer->start( 200 );
445 emit key( unicode, 0, modifiers, true, true ); 445 emit key( unicode, 0, modifiers, true, true );
446} 446}
447 447
448void Keyboard::clearHighlight() 448void Keyboard::clearHighlight()
449{ 449{
450 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { 450 if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) {
451 int tmpRow = pressedKeyRow; 451 int tmpRow = pressedKeyRow;
452 int tmpCol = pressedKeyCol; 452 int tmpCol = pressedKeyCol;
453 453
454 pressedKeyRow = -1; 454 pressedKeyRow = -1;
455 pressedKeyCol = -1; 455 pressedKeyCol = -1;
456 456
457 QPainter p(this); 457 QPainter p(this);
458 drawKeyboard(p, tmpRow, tmpCol); 458 drawKeyboard(p, tmpRow, tmpCol);
459 } 459 }
460} 460}
461 461
462 462
463/* Keyboard::sizeHint {{{1 */ 463/* Keyboard::sizeHint {{{1 */
464QSize Keyboard::sizeHint() const 464QSize Keyboard::sizeHint() const
465{ 465{
466 QFontMetrics fm=fontMetrics(); 466 QFontMetrics fm=fontMetrics();
467 int keyHeight = fm.lineSpacing() + 2; 467 int keyHeight = fm.lineSpacing() + 2;
468 468
469 return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1); 469 return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1);
470} 470}
471 471
472 472
473void Keyboard::resetState() 473void Keyboard::resetState()
474{ 474{
475 schar = mchar = echar = 0; 475 schar = mchar = echar = 0;
476 picks->resetState(); 476 picks->resetState();
477} 477}
478 478
479/* Keyboard::togglePickboard {{{1 */ 479/* Keyboard::togglePickboard {{{1 */
480void Keyboard::togglePickboard(bool on_off) 480void Keyboard::togglePickboard(bool on_off)
481{ 481{
482 usePicks = on_off; 482 usePicks = on_off;
483 if (usePicks) { 483 if (usePicks) {
484 picks->show(); 484 picks->show();
485 //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send 485 //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send
486 //adjustSize(); 486 //adjustSize();
487 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 487 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
488 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 488 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
489 } else { 489 } else {
490 490
491 picks->hide(); 491 picks->hide();
492 picks->resetState(); 492 picks->resetState();
493 //move(x(), y() + picks->height()); 493 //move(x(), y() + picks->height());
494 //adjustSize(); 494 //adjustSize();
495 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 495 QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
496 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 496 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
497 497
498 } 498 }
499 /* 499 /*
500 * this closes && opens the input method 500 * this closes && opens the input method
501 */ 501 */
502 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); 502 QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
503 QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); 503 QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
504} 504}
505 505
506/* Keyboard::setMapTo ... {{{1 */ 506/* Keyboard::setMapTo ... {{{1 */
507void Keyboard::setMapToDefault() { 507void Keyboard::setMapToDefault() {
508 508
509 509
510 /* load current locale language map */ 510 /* load current locale language map */
511 Config *config = new Config("locale"); 511 Config *config = new Config("locale");
512 config->setGroup( "Language" ); 512 config->setGroup( "Language" );
513 QString l = config->readEntry( "Language" , "en" ); 513 QString l = config->readEntry( "Language" , "en" );
514 delete config; 514 delete config;
515 515
516 QString key_map = QPEApplication::qpeDir() + "/share/multikey/" 516 QString key_map = QPEApplication::qpeDir() + "/share/multikey/"
517 + l + ".keymap"; 517 + l + ".keymap";
518 518
519 /* save change to multikey config file */ 519 /* save change to multikey config file */
520 config = new Config("multikey"); 520 config = new Config("multikey");
521 config->setGroup ("keymaps"); 521 config->setGroup ("keymaps");
522 config->writeEntry ("current", key_map); // default closed 522 config->writeEntry ("current", key_map); // default closed
523 delete config; 523 delete config;
524 524
525 delete keys; 525 delete keys;
526 keys = new Keys(key_map); 526 keys = new Keys(key_map);
527 527
528 // have to repaint the keyboard 528 // have to repaint the keyboard
529 repaint(FALSE); 529 repaint(FALSE);
530} 530}
531 531
532void Keyboard::setMapToFile(QString map) { 532void Keyboard::setMapToFile(QString map) {
533 533
534 /* save change to multikey config file */ 534 /* save change to multikey config file */
535 Config *config = new Config("multikey"); 535 Config *config = new Config("multikey");
536 config->setGroup ("keymaps"); 536 config->setGroup ("keymaps");
537 config->writeEntry ("current", map); // default closed 537 config->writeEntry ("current", map); // default closed
538 538
539 delete config; 539 delete config;
540 540
541 delete keys; 541 delete keys;
542 if (QFile(map).exists()) 542 if (QFile(map).exists())
543 keys = new Keys(map); 543 keys = new Keys(map);
544 else 544 else
545 keys = new Keys(); 545 keys = new Keys();
546 546
547 repaint(FALSE); 547 repaint(FALSE);
548 548
549} 549}
550 550
551/* Keybaord::setColor {{{1 */ 551/* Keybaord::reloadKeyboard {{{1 */
552void Keyboard::reloadKeyboard() { 552void Keyboard::reloadKeyboard() {
553 553
554 // reload colors and redraw 554 // reload colors and redraw
555 loadKeyboardColors(); 555 loadKeyboardColors();
556 repaint(); 556 repaint();
557 557
558} 558}
559 559
560void Keyboard::loadKeyboardColors() { 560void Keyboard::loadKeyboardColors() {
561 561
562 Config config ("multikey"); 562 Config config ("multikey");
563 config.setGroup("colors"); 563 config.setGroup("colors");
564 564
565 QStringList color; 565 QStringList color;
566 color = config.readListEntry("keycolor", QChar(',')); 566 color = config.readListEntry("keycolor", QChar(','));
567 if (color.isEmpty()) { 567 if (color.isEmpty()) {
568 color = QStringList::split(",", "240,240,240"); 568 color = QStringList::split(",", "240,240,240");
569 config.writeEntry("keycolor", color.join(",")); 569 config.writeEntry("keycolor", color.join(","));
570 570
571 } 571 }
572 keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 572 keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
573 573
574 color = config.readListEntry("keycolor_pressed", QChar(',')); 574 color = config.readListEntry("keycolor_pressed", QChar(','));
575 if (color.isEmpty()) { 575 if (color.isEmpty()) {
576 color = QStringList::split(",", "171,183,198"); 576 color = QStringList::split(",", "171,183,198");
577 config.writeEntry("keycolor_pressed", color.join(",")); 577 config.writeEntry("keycolor_pressed", color.join(","));
578 578
579 } 579 }
580 keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 580 keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
581 581
582 color = config.readListEntry("keycolor_lines", QChar(',')); 582 color = config.readListEntry("keycolor_lines", QChar(','));
583 if (color.isEmpty()) { 583 if (color.isEmpty()) {
584 color = QStringList::split(",", "138,148,160"); 584 color = QStringList::split(",", "138,148,160");
585 config.writeEntry("keycolor_lines", color.join(",")); 585 config.writeEntry("keycolor_lines", color.join(","));
586 586
587 } 587 }
588 keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 588 keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
589 589
590 color = config.readListEntry("textcolor", QChar(',')); 590 color = config.readListEntry("textcolor", QChar(','));
591 if (color.isEmpty()) { 591 if (color.isEmpty()) {
592 color = QStringList::split(",", "43,54,68"); 592 color = QStringList::split(",", "43,54,68");
593 config.writeEntry("textcolor", color.join(",")); 593 config.writeEntry("textcolor", color.join(","));
594 594
595 } 595 }
596 textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); 596 textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
597 597
598} 598}
599 599
600/* korean input functions {{{1 600/* korean input functions {{{1
601 * 601 *
602 * TODO 602 * TODO
603 * one major problem with this implementation is that you can't move the 603 * one major problem with this implementation is that you can't move the
604 * cursor after inputing korean chars, otherwise it will eat up and replace 604 * cursor after inputing korean chars, otherwise it will eat up and replace
605 * the char before the cursor you move to. fix that 605 * the char before the cursor you move to. fix that
606 * 606 *
607 * make backspace delete one single char, not the whole thing if still 607 * make backspace delete one single char, not the whole thing if still
608 * editing. 608 * editing.
609 * 609 *
610 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 610 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
611 * 611 *
612 * how korean input works 612 * how korean input works
613 * 613 *
614 * all following chars means unicode char value and are in hex 614 * all following chars means unicode char value and are in hex
615 * 615 *
616 * ÃÊÀ½ = schar (start char) 616 * ÃÊÀ½ = schar (start char)
617 * ÁßÀ½ = mchar (middle char) 617 * ÁßÀ½ = mchar (middle char)
618 * ³¡À½ = echar (end char) 618 * ³¡À½ = echar (end char)
619 * 619 *
620 * there are 19 schars. unicode position is at 1100 - 1112 620 * there are 19 schars. unicode position is at 1100 - 1112
621 * there are 21 mchars. unicode position is at 1161 - 1175 621 * there are 21 mchars. unicode position is at 1161 - 1175
622 * there are 27 echars. unicode position is at 11a8 - 11c2 622 * there are 27 echars. unicode position is at 11a8 - 11c2
623 * 623 *
624 * the map with everything combined is at ac00 - d7a3 624 * the map with everything combined is at ac00 - d7a3
625 * 625 *
626 */ 626 */
627 627
628ushort Keyboard::parseKoreanInput (ushort c) { 628ushort Keyboard::parseKoreanInput (ushort c) {
629 629
630 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) 630 if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c))
631 || 631 ||
632 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode 632 (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode
633 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { 633 && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) {
634 634
635 schar = 0, mchar = 0, echar = 0; 635 schar = 0, mchar = 0, echar = 0;
636 return c; 636 return c;
637 } 637 }
638 638
639 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input 639 if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input
640 640
641 if (schar == 0 || (schar != 0 && mchar == 0)) { 641 if (schar == 0 || (schar != 0 && mchar == 0)) {
642 schar = c; mchar = 0; echar = 0; 642 schar = c; mchar = 0; echar = 0;
643 return c; 643 return c;
644 } 644 }
645 else if (mchar != 0) { 645 else if (mchar != 0) {
646 646
647 if (echar == 0) { 647 if (echar == 0) {
648 648
649 if (!(echar = constoe(c))) { 649 if (!(echar = constoe(c))) {
650 650
651 schar = c; mchar = 0; echar = 0; 651 schar = c; mchar = 0; echar = 0;
652 return c; 652 return c;
653 } 653 }
654 654
655 } 655 }
656 else { // must figure out what the echar is 656 else { // must figure out what the echar is
657 657
658 if (echar == 0x11a8) { // ¤¡ 658 if (echar == 0x11a8) { // ¤¡
659 659
660 if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡ 660 if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡
661 else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ 661 else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ
662 else { 662 else {
663 schar = c; mchar = 0; echar = 0; 663 schar = c; mchar = 0; echar = 0;
664 return c; 664 return c;
665 } 665 }
666 666
667 } else if (echar == 0x11ab) { // ¤¤ 667 } else if (echar == 0x11ab) { // ¤¤
668 668
669 if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸ 669 if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸
670 else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾ 670 else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾
671 else { 671 else {
672 schar = c; mchar = 0; echar = 0; 672 schar = c; mchar = 0; echar = 0;
673 return c; 673 return c;
674 } 674 }
675 675
676 } else if (echar == 0x11af) { // ¤© 676 } else if (echar == 0x11af) { // ¤©
677 677
678 if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡ 678 if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡
679 else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤± 679 else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤±
680 else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤² 680 else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤²
681 else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ 681 else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ
682 else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼ 682 else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼
683 else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½ 683 else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½
684 else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾ 684 else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾
685 else { 685 else {
686 schar = c; mchar = 0; echar = 0; 686 schar = c; mchar = 0; echar = 0;
687 return c; 687 return c;
688 } 688 }
689 689
690 } else if (echar == 0x11b8) { // ¤² 690 } else if (echar == 0x11b8) { // ¤²
691 691
692 if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ 692 if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ
693 else { 693 else {
694 schar = c; mchar = 0; echar = 0; 694 schar = c; mchar = 0; echar = 0;
695 return c; 695 return c;
696 } 696 }
697 697
698 } else if (echar == 0x11ba) { // ¤µ 698 } else if (echar == 0x11ba) { // ¤µ
699 699
700 if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ 700 if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ
701 else { 701 else {
702 schar = c; mchar = 0; echar = 0; 702 schar = c; mchar = 0; echar = 0;
703 return c; 703 return c;
704 } 704 }
705 705
706 } else { // if any other char, cannot combine chars 706 } else { // if any other char, cannot combine chars
707 707
708 schar = c; mchar = 0; echar = 0; 708 schar = c; mchar = 0; echar = 0;
709 return c; 709 return c;
710 } 710 }
711 711
712 unicode = echar; 712 unicode = echar;
713 } 713 }
714 } 714 }
715 715
716 } 716 }
717 else if (0x1161 <= c && c <= 0x1175) { // mchar was input 717 else if (0x1161 <= c && c <= 0x1175) { // mchar was input
718 718
719 if (schar != 0 && mchar == 0) { mchar = c; } 719 if (schar != 0 && mchar == 0) { mchar = c; }
720 720
721 else if (schar != 0 && mchar != 0 && echar == 0) { 721 else if (schar != 0 && mchar != 0 && echar == 0) {
722 722
723 switch (mchar) { 723 switch (mchar) {
724 case 0x1169: 724 case 0x1169:
725 if (c == 0x1161) mchar = 0x116a; 725 if (c == 0x1161) mchar = 0x116a;
726 else if (c == 0x1162) mchar = 0x116b; 726 else if (c == 0x1162) mchar = 0x116b;
727 else if (c == 0x1175) mchar = 0x116c; 727 else if (c == 0x1175) mchar = 0x116c;
728 else { 728 else {
729 schar = 0; mchar = 0; echar = 0; 729 schar = 0; mchar = 0; echar = 0;
730 return c; 730 return c;
731 } 731 }
732 break; 732 break;
733 case 0x116e: 733 case 0x116e:
734 if (c == 0x1165) mchar = 0x116f; 734 if (c == 0x1165) mchar = 0x116f;
735 else if (c == 0x1166) mchar = 0x1170; 735 else if (c == 0x1166) mchar = 0x1170;
736 else if (c == 0x1175) mchar = 0x1171; 736 else if (c == 0x1175) mchar = 0x1171;
737 else { 737 else {
738 schar = 0; mchar = 0; echar = 0; 738 schar = 0; mchar = 0; echar = 0;
739 return c; 739 return c;
740 } 740 }
741 break; 741 break;
742 case 0x1173: 742 case 0x1173:
743 if (c == 0x1175) mchar = 0x1174; 743 if (c == 0x1175) mchar = 0x1174;
744 else { 744 else {
745 schar = 0; mchar = 0; echar = 0; 745 schar = 0; mchar = 0; echar = 0;
746 return c; 746 return c;
747 } 747 }
748 break; 748 break;
749 default: 749 default:
750 schar = 0; mchar = 0; echar = 0; 750 schar = 0; mchar = 0; echar = 0;
751 return c; 751 return c;
752 } 752 }
753 } 753 }
754 else if (schar != 0 && mchar != 0 && echar != 0) { 754 else if (schar != 0 && mchar != 0 && echar != 0) {
755 755
756 emit key( 8, Qt::Key_Backspace, 0, true, false ); 756 emit key( 8, Qt::Key_Backspace, 0, true, false );
757 757
758 ushort prev = 0; 758 ushort prev = 0;
759 switch (echar) { 759 switch (echar) {
760 /* 760 /*
761 case 0x11a9: 761 case 0x11a9:
762 prev = combineKoreanChars(schar, mchar, 0x11a8); 762 prev = combineKoreanChars(schar, mchar, 0x11a8);
763 schar = 0x1100; 763 schar = 0x1100;
764 break; 764 break;
765 */ 765 */
766 case 0x11aa: 766 case 0x11aa:
767 prev = combineKoreanChars(schar, mchar, 0x11a8); 767 prev = combineKoreanChars(schar, mchar, 0x11a8);
768 schar = 0x1109; 768 schar = 0x1109;
769 break; 769 break;
770 case 0x11ac: 770 case 0x11ac:
771 prev = combineKoreanChars(schar, mchar, 0x11ab); 771 prev = combineKoreanChars(schar, mchar, 0x11ab);
772 schar = 0x110c; 772 schar = 0x110c;
773 break; 773 break;
774 case 0x11ad: 774 case 0x11ad:
775 prev = combineKoreanChars(schar, mchar, 0x11ab); 775 prev = combineKoreanChars(schar, mchar, 0x11ab);
776 schar = 0x1112; 776 schar = 0x1112;
777 break; 777 break;
778 case 0x11b0: 778 case 0x11b0:
779 prev = combineKoreanChars(schar, mchar, 0x11af); 779 prev = combineKoreanChars(schar, mchar, 0x11af);
780 schar = 0x1100; 780 schar = 0x1100;
781 break; 781 break;
782 case 0x11b1: 782 case 0x11b1:
783 prev = combineKoreanChars(schar, mchar, 0x11af); 783 prev = combineKoreanChars(schar, mchar, 0x11af);
784 schar = 0x1106; 784 schar = 0x1106;
785 break; 785 break;
786 case 0x11b2: 786 case 0x11b2:
787 prev = combineKoreanChars(schar, mchar, 0x11af); 787 prev = combineKoreanChars(schar, mchar, 0x11af);
788 schar = 0x1107; 788 schar = 0x1107;
789 break; 789 break;
790 case 0x11b3: 790 case 0x11b3:
791 prev = combineKoreanChars(schar, mchar, 0x11af); 791 prev = combineKoreanChars(schar, mchar, 0x11af);
792 schar = 0x1109; 792 schar = 0x1109;
793 break; 793 break;
794 case 0x11b4: 794 case 0x11b4:
795 prev = combineKoreanChars(schar, mchar, 0x11af); 795 prev = combineKoreanChars(schar, mchar, 0x11af);
796 schar = 0x1110; 796 schar = 0x1110;
797 break; 797 break;
798 case 0x11b9: 798 case 0x11b9:
799 prev = combineKoreanChars(schar, mchar, 0x11b8); 799 prev = combineKoreanChars(schar, mchar, 0x11b8);
800 schar = 0x1109; 800 schar = 0x1109;
801 break; 801 break;
802 /* 802 /*
803 case 0x11bb: 803 case 0x11bb:
804 prev = combineKoreanChars(schar, mchar, 0x11ba); 804 prev = combineKoreanChars(schar, mchar, 0x11ba);
805 schar = 0x1109; 805 schar = 0x1109;
806 break; 806 break;
807 */ 807 */
808 default: 808 default:
809 809
810 if (constoe(echar)) { 810 if (constoe(echar)) {
811 811
812 prev = combineKoreanChars(schar, mchar, 0); 812 prev = combineKoreanChars(schar, mchar, 0);
813 schar = constoe(echar); 813 schar = constoe(echar);
814 } 814 }
815 break; 815 break;
816 } 816 }
817 817
818 emit key( prev, prev, 0, true, false ); 818 emit key( prev, prev, 0, true, false );
819 819
820 mchar = c; echar = 0; 820 mchar = c; echar = 0;
821 821
822 return combineKoreanChars(schar, mchar, 0); 822 return combineKoreanChars(schar, mchar, 0);
823 823
824 } 824 }
825 else { 825 else {
826 schar = 0; mchar = 0; echar = 0; 826 schar = 0; mchar = 0; echar = 0;
827 return c; 827 return c;
828 } 828 }
829 829
830 } 830 }
831 else /*if (c == ' ')*/ return c; 831 else /*if (c == ' ')*/ return c;
832 832
833 833
834 // and now... finally delete previous char, and return new char 834 // and now... finally delete previous char, and return new char
835 emit key( 8, Qt::Key_Backspace, 0, true, false ); 835 emit key( 8, Qt::Key_Backspace, 0, true, false );
836 836
837 837
838 return combineKoreanChars( schar, mchar, echar); 838 return combineKoreanChars( schar, mchar, echar);
839 839
840} 840}
841 841
842ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { 842ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) {
843 843
844 return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; 844 return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00;
845 845
846} 846}
847 847
848ushort Keyboard::constoe(const ushort c) { 848ushort Keyboard::constoe(const ushort c) {
849 849
850 // converts schars to echars if possible 850 // converts schars to echars if possible
851 851
852 if (0x1100 <= c && c <= 0x1112) { // schar to echar 852 if (0x1100 <= c && c <= 0x1112) { // schar to echar
853 853
854 switch (c) { 854 switch (c) {
855 case 0x1100: return 0x11a8; 855 case 0x1100: return 0x11a8;
856 case 0x1101: return 0x11a9; 856 case 0x1101: return 0x11a9;
857 case 0x1102: return 0x11ab; 857 case 0x1102: return 0x11ab;
858 case 0x1103: return 0x11ae; 858 case 0x1103: return 0x11ae;
859 case 0x1105: return 0x11af; 859 case 0x1105: return 0x11af;
860 case 0x1106: return 0x11b7; 860 case 0x1106: return 0x11b7;
861 case 0x1107: return 0x11b8; 861 case 0x1107: return 0x11b8;
862 case 0x1109: return 0x11ba; 862 case 0x1109: return 0x11ba;
863 case 0x110a: return 0x11bb; 863 case 0x110a: return 0x11bb;
864 case 0x110b: return 0x11bc; 864 case 0x110b: return 0x11bc;
865 case 0x110c: return 0x11bd; 865 case 0x110c: return 0x11bd;
866 case 0x110e: return 0x11be; 866 case 0x110e: return 0x11be;
867 case 0x110f: return 0x11bf; 867 case 0x110f: return 0x11bf;
868 case 0x1110: return 0x11c0; 868 case 0x1110: return 0x11c0;
869 case 0x1111: return 0x11c1; 869 case 0x1111: return 0x11c1;
870 case 0x1112: return 0x11c2; 870 case 0x1112: return 0x11c2;
871 default: return 0; 871 default: return 0;
872 872
873 } 873 }
874 874
875 } else { //echar to schar 875 } else { //echar to schar
876 876
877 switch (c) { 877 switch (c) {
878 case 0x11a8: return 0x1100; 878 case 0x11a8: return 0x1100;
879 case 0x11a9: return 0x1101; 879 case 0x11a9: return 0x1101;
880 case 0x11ab: return 0x1102; 880 case 0x11ab: return 0x1102;
881 case 0x11ae: return 0x1103; 881 case 0x11ae: return 0x1103;
882 case 0x11af: return 0x1105; 882 case 0x11af: return 0x1105;
883 case 0x11b7: return 0x1106; 883 case 0x11b7: return 0x1106;
884 case 0x11b8: return 0x1107; 884 case 0x11b8: return 0x1107;
885 case 0x11ba: return 0x1109; 885 case 0x11ba: return 0x1109;
886 case 0x11bb: return 0x110a; 886 case 0x11bb: return 0x110a;
887 case 0x11bc: return 0x110b; 887 case 0x11bc: return 0x110b;
888 case 0x11bd: return 0x110c; 888 case 0x11bd: return 0x110c;
889 case 0x11be: return 0x110e; 889 case 0x11be: return 0x110e;
890 case 0x11bf: return 0x110f; 890 case 0x11bf: return 0x110f;
891 case 0x11c0: return 0x1110; 891 case 0x11c0: return 0x1110;
892 case 0x11c1: return 0x1111; 892 case 0x11c1: return 0x1111;
893 case 0x11c2: return 0x1112; 893 case 0x11c2: return 0x1112;
894 default: return 0; 894 default: return 0;
895 895
896 } 896 }
897 897
898 } 898 }
899} 899}
900 900
901 901
902// Keys::Keys {{{1 902// Keys::Keys {{{1
903 903
904Keys::Keys() { 904Keys::Keys() {
905 905
906 Config *config = new Config ("multikey"); 906 Config *config = new Config ("multikey");
907 config->setGroup( "keymaps" ); 907 config->setGroup( "keymaps" );
908 QString map = config->readEntry( "current" ); 908 QString map = config->readEntry( "current" );
909 delete config; 909 delete config;
910 910
911 if (map.isNull() || !(QFile(map).exists())) { 911 if (map.isNull() || !(QFile(map).exists())) {
912 912
913 Config *config = new Config("locale"); 913 Config *config = new Config("locale");
914 config->setGroup( "Language" ); 914 config->setGroup( "Language" );
915 QString l = config->readEntry( "Language" , "en" ); 915 QString l = config->readEntry( "Language" , "en" );
916 delete config; 916 delete config;
917 917
918 map = QPEApplication::qpeDir() + "/share/multikey/" 918 map = QPEApplication::qpeDir() + "/share/multikey/"
919 + l + ".keymap"; 919 + l + ".keymap";
920 920
921 } 921 }
922 922
923 setKeysFromFile(map); 923 setKeysFromFile(map);
924} 924}
925 925
926Keys::Keys(const char * filename) { 926Keys::Keys(const char * filename) {
927 927
928 setKeysFromFile(filename); 928 setKeysFromFile(filename);
929} 929}
930 930
931// Keys::setKeysFromFile {{{2 931// Keys::setKeysFromFile {{{2
932void Keys::setKeysFromFile(const char * filename) { 932void Keys::setKeysFromFile(const char * filename) {
933 933
934 QFile f(filename); 934 QFile f(filename);
935 935
936 if (f.open(IO_ReadOnly)) { 936 if (f.open(IO_ReadOnly)) {
937 937
938 QTextStream t(&f); 938 QTextStream t(&f);
939 int row; 939 int row;
940 int qcode; 940 int qcode;
941 ushort unicode; 941 ushort unicode;
942 int width; 942 int width;
943 QString buf; 943 QString buf;
944 QString comment; 944 QString comment;
945 char * xpm[256]; //couldnt be larger than that... could it? 945 char * xpm[256]; //couldnt be larger than that... could it?
946 QPixmap *xpm2pix = 0; 946 QPixmap *xpm2pix = 0;
947 947
948 buf = t.readLine(); 948 buf = t.readLine();
949 while (buf) { 949 while (buf) {
950 950
951 // key definition 951 // key definition
952 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { 952 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) {
953 // no $1 type referencing!!! this implementation of regexp sucks 953 // no $1 type referencing!!! this implementation of regexp sucks
954 954
955 // dont know of any sscanf() type funcs in Qt lib 955 // dont know of any sscanf() type funcs in Qt lib
956 QTextStream tmp (buf, IO_ReadOnly); 956 QTextStream tmp (buf, IO_ReadOnly);
957 tmp >> row >> qcode >> unicode >> width >> comment; 957 tmp >> row >> qcode >> unicode >> width >> comment;
958 958
959 buf = t.readLine(); 959 buf = t.readLine();
960 int xpmLineCount = 0; 960 int xpmLineCount = 0;
961 xpm2pix = 0; 961 xpm2pix = 0;
962 962
963 // erase blank space 963 // erase blank space
964 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); 964 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine();
965 965
966 while (buf.contains(QRegExp("^\\s*\".*\""))) { 966 while (buf.contains(QRegExp("^\\s*\".*\""))) {
967 967
968 QString xpmBuf = buf.stripWhiteSpace(); 968 QString xpmBuf = buf.stripWhiteSpace();
969 969
970 xpm[xpmLineCount] = new char [xpmBuf.length()]; 970 xpm[xpmLineCount] = new char [xpmBuf.length()];
971 971
972 int j = 0; 972 int j = 0;
973 for (ushort i = 0; i < xpmBuf.length(); i++) { 973 for (ushort i = 0; i < xpmBuf.length(); i++) {
974 if (xpmBuf[i].latin1() != '"') { 974 if (xpmBuf[i].latin1() != '"') {
975 975
976 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); 976 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1();
977 j++; 977 j++;
978 } 978 }
979 979
980 } 980 }
981 // have to close that facker up 981 // have to close that facker up
982 ((char *)xpm[xpmLineCount])[j] = '\0'; 982 ((char *)xpm[xpmLineCount])[j] = '\0';
983 983
984 xpmLineCount++; 984 xpmLineCount++;
985 buf = t.readLine(); 985 buf = t.readLine();
986 } 986 }
987 if (xpmLineCount) { 987 if (xpmLineCount) {
988 988
989 xpm2pix = new QPixmap((const char **)xpm); 989 xpm2pix = new QPixmap((const char **)xpm);
990 for (int i = 0; i < xpmLineCount; i++) 990 for (int i = 0; i < xpmLineCount; i++)
991 991
992 delete [] (xpm[i]); 992 delete [] (xpm[i]);
993 993
994 } 994 }
995 setKey(row, qcode, unicode, width, xpm2pix); 995 setKey(row, qcode, unicode, width, xpm2pix);
996 } 996 }
997 997
998 // shift map 998 // shift map
999 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 999 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1000 1000
1001 QTextStream tmp (buf, IO_ReadOnly); 1001 QTextStream tmp (buf, IO_ReadOnly);
1002 ushort lower, shift; 1002 ushort lower, shift;
1003 tmp >> lower >> shift; 1003 tmp >> lower >> shift;
1004 1004
1005 shiftMap.insert(lower, shift); 1005 shiftMap.insert(lower, shift);
1006 1006
1007 buf = t.readLine(); 1007 buf = t.readLine();
1008 } 1008 }
1009 1009
1010 // other variables like lang & title 1010 // other variables like lang & title
1011 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { 1011 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) {
1012 1012
1013 QTextStream tmp (buf, IO_ReadOnly); 1013 QTextStream tmp (buf, IO_ReadOnly);
1014 QString name, equals, value; 1014 QString name, equals, value;
1015 1015
1016 tmp >> name >> equals >> value; 1016 tmp >> name >> equals >> value;
1017 1017
1018 if (name == "lang") { 1018 if (name == "lang") {
1019 1019
1020 lang = value; 1020 lang = value;
1021 1021
1022 } 1022 }
1023 1023
1024 buf = t.readLine(); 1024 buf = t.readLine();
1025 } 1025 }
1026 // comments 1026 // comments
1027 else if (buf.contains(QRegExp("^\\s*#"))) { 1027 else if (buf.contains(QRegExp("^\\s*#"))) {
1028 1028
1029 buf = t.readLine(); 1029 buf = t.readLine();
1030 1030
1031 } else { // blank line, or garbage 1031 } else { // blank line, or garbage
1032 1032
1033 buf = t.readLine(); 1033 buf = t.readLine();
1034 1034
1035 } 1035 }
1036 1036
1037 } 1037 }
1038 f.close(); 1038 f.close();
1039 } 1039 }
1040 1040
1041} 1041}
1042 1042
1043// Keys::setKey {{{2 1043// Keys::setKey {{{2
1044void Keys::setKey(const int row, const int qcode, const ushort unicode, 1044void Keys::setKey(const int row, const int qcode, const ushort unicode,
1045 const int width, QPixmap *pix) { 1045 const int width, QPixmap *pix) {
1046 1046
1047 Key * key; 1047 Key * key;
1048 key = new Key; 1048 key = new Key;
1049 key->qcode = qcode; 1049 key->qcode = qcode;
1050 key->unicode = unicode; 1050 key->unicode = unicode;
1051 key->width = width; 1051 key->width = width;
1052 1052
1053 // share key->pressed between same keys 1053 // share key->pressed between same keys
1054 bool found = 0; 1054 bool found = 0;
1055 for (int i = 1; i <= 5; i++) { 1055 for (int i = 1; i <= 5; i++) {
1056 for (unsigned int j = 0; j < keys[i].count(); j++) 1056 for (unsigned int j = 0; j < keys[i].count(); j++)
1057 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { 1057 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) {
1058 1058
1059 key->pressed = keys[i].at(j)->pressed; 1059 key->pressed = keys[i].at(j)->pressed;
1060 found = 1; 1060 found = 1;
1061 } 1061 }
1062 1062
1063 } 1063 }
1064 if (!found) { 1064 if (!found) {
1065 1065
1066 key->pressed = new bool; 1066 key->pressed = new bool;
1067 *(key->pressed) = 0; 1067 *(key->pressed) = 0;
1068 } 1068 }
1069 1069
1070 key->pix = pix; 1070 key->pix = pix;
1071 1071
1072 1072
1073 keys[row].append(key); 1073 keys[row].append(key);
1074} 1074}
1075 1075
1076// Keys::~Keys {{{2 1076// Keys::~Keys {{{2
1077Keys::~Keys() { 1077Keys::~Keys() {
1078 1078
1079 for (int i = 1; i <= 5; i++) 1079 for (int i = 1; i <= 5; i++)
1080 for (unsigned int j = 0; j < keys[i].count(); j++) 1080 for (unsigned int j = 0; j < keys[i].count(); j++)
1081 delete keys[i].at(j); 1081 delete keys[i].at(j);
1082 1082
1083} 1083}
1084 1084
1085// Keys:: other functions {{{2 1085// Keys:: other functions {{{2
1086int Keys::width(const int row, const int col) { 1086int Keys::width(const int row, const int col) {
1087 1087
1088 return keys[row].at(col)->width; 1088 return keys[row].at(col)->width;
1089 1089
1090} 1090}
1091ushort Keys::uni(const int row, const int col) { 1091ushort Keys::uni(const int row, const int col) {
1092 1092
1093 return keys[row].at(col)->unicode; 1093 return keys[row].at(col)->unicode;
1094 1094
1095} 1095}
1096 1096
1097int Keys::qcode(const int row, const int col) { 1097int Keys::qcode(const int row, const int col) {
1098 1098
1099 return keys[row].at(col)->qcode; 1099 return keys[row].at(col)->qcode;
1100} 1100}
1101 1101
1102QPixmap *Keys::pix(const int row, const int col) { 1102QPixmap *Keys::pix(const int row, const int col) {
1103 1103
1104 return keys[row].at(col)->pix; 1104 return keys[row].at(col)->pix;
1105 1105
1106} 1106}
1107bool Keys::pressed(const int row, const int col) { 1107bool Keys::pressed(const int row, const int col) {
1108 1108
1109 return *(keys[row].at(col)->pressed); 1109 return *(keys[row].at(col)->pressed);
1110} 1110}
1111 1111
1112int Keys::numKeys(const int row) { 1112int Keys::numKeys(const int row) {
1113 1113
1114 return keys[row].count(); 1114 return keys[row].count();
1115} 1115}
1116 1116
1117void Keys::setPressed(const int row, const int col, const bool pressed) { 1117void Keys::setPressed(const int row, const int col, const bool pressed) {
1118 1118
1119 *(keys[row].at(col)->pressed) = pressed; 1119 *(keys[row].at(col)->pressed) = pressed;
1120} 1120}
1121 1121
1122ushort Keys::shift(const ushort uni) { 1122ushort Keys::shift(const ushort uni) {
1123 1123
1124 if (shiftMap[uni]) { 1124 if (shiftMap[uni]) {
1125 1125
1126 return shiftMap[uni]; 1126 return shiftMap[uni];
1127 } 1127 }
1128 else 1128 else
1129 return 0; 1129 return 0;
1130 1130
1131} 1131}
1132 1132
1133bool *Keys::pressedPtr(const int row, const int col) { 1133bool *Keys::pressedPtr(const int row, const int col) {
1134 1134
1135 return keys[row].at(col)->pressed; 1135 return keys[row].at(col)->pressed;
1136} 1136}