-rw-r--r-- | inputmethods/multikey/keyboard.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp index 1c17172..89937cf 100644 --- a/inputmethods/multikey/keyboard.cpp +++ b/inputmethods/multikey/keyboard.cpp | |||
@@ -1,1260 +1,1262 @@ | |||
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 | /* Keyboard::Keyboard {{{1 */ | 42 | /* Keyboard::Keyboard {{{1 */ |
43 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : | 43 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : |
44 | QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0), meta(0), | 44 | QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0), meta(0), |
45 | useLargeKeys(TRUE), usePicks(0), useRepeat(0), pressedKeyRow(-1), pressedKeyCol(-1), | 45 | useLargeKeys(TRUE), usePicks(0), useRepeat(0), pressedKeyRow(-1), pressedKeyCol(-1), |
46 | unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), | 46 | unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), |
47 | configdlg(0) | 47 | configdlg(0) |
48 | 48 | ||
49 | { | 49 | { |
50 | 50 | ||
51 | // get the default font | 51 | // get the default font |
52 | Config *config = new Config( "qpe" ); | 52 | Config *config = new Config( "qpe" ); |
53 | config->setGroup( "Appearance" ); | 53 | config->setGroup( "Appearance" ); |
54 | QString familyStr = config->readEntry( "FontFamily", "fixed" ); | 54 | QString familyStr = config->readEntry( "FontFamily", "fixed" ); |
55 | delete config; | 55 | delete config; |
56 | 56 | ||
57 | config = new Config("multikey"); | 57 | config = new Config("multikey"); |
58 | config->setGroup ("general"); | 58 | config->setGroup ("general"); |
59 | usePicks = config->readBoolEntry ("usePickboard", "0"); // default closed | 59 | usePicks = config->readBoolEntry ("usePickboard", "0"); // default closed |
60 | useRepeat = config->readBoolEntry ("useRepeat", "1"); | 60 | useRepeat = config->readBoolEntry ("useRepeat", "1"); |
61 | delete config; | 61 | delete config; |
62 | 62 | ||
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 | ||
85 | Keyboard::~Keyboard() { | 85 | Keyboard::~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 */ |
95 | void Keyboard::resizeEvent(QResizeEvent*) | 95 | void 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 */ |
113 | void KeyboardPicks::initialise() | 113 | void 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 */ |
122 | QSize KeyboardPicks::sizeHint() const | 122 | QSize 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 */ |
129 | void KeyboardConfig::generateText(const QString &s) | 129 | void 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 */ |
150 | void Keyboard::paintEvent(QPaintEvent* e) | 150 | void 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 | ||
161 | void Keyboard::drawKeyboard(QPainter &p, int row, int col) | 161 | void 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 | if (shift || lock) | 186 | if (shift || lock) |
187 | c = keys->shift(c); | 187 | c = keys->shift(c); |
188 | if (meta) { | 188 | if (meta) { |
189 | 189 | ||
190 | c = keys->meta(c); | 190 | c = keys->meta(c); |
191 | } | 191 | } |
192 | p.drawText(x, y, | 192 | p.drawText(x, y, |
193 | defaultKeyWidth * keyWidth + 3, keyHeight, | 193 | defaultKeyWidth * keyWidth + 3, keyHeight, |
194 | AlignCenter, (QChar)c); | 194 | AlignCenter, (QChar)c); |
195 | } | 195 | } |
196 | else | 196 | else |
197 | // center the image in the middle of the key | 197 | // center the image in the middle of the key |
198 | p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, | 198 | p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, |
199 | y + (keyHeight - pix->height())/2 + 1, | 199 | y + (keyHeight - pix->height())/2 + 1, |
200 | *pix ); | 200 | *pix ); |
201 | 201 | ||
202 | // this fixes the problem that the very right end of the board's vertical line | 202 | // this fixes the problem that the very right end of the board's vertical line |
203 | // gets painted over, because it's one pixel shorter than all other keys | 203 | // gets painted over, because it's one pixel shorter than all other keys |
204 | p.setPen(keycolor_lines); | 204 | p.setPen(keycolor_lines); |
205 | p.drawLine(width() - 1, 0, width() - 1, height()); | 205 | p.drawLine(width() - 1, 0, width() - 1, height()); |
206 | 206 | ||
207 | } else { | 207 | } else { |
208 | 208 | ||
209 | 209 | ||
210 | p.fillRect(0, 0, width(), height(), keycolor); | 210 | p.fillRect(0, 0, width(), height(), keycolor); |
211 | 211 | ||
212 | for (row = 1; row <= 5; row++) { | 212 | for (row = 1; row <= 5; row++) { |
213 | 213 | ||
214 | int x = 0; | 214 | int x = 0; |
215 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 215 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
216 | 216 | ||
217 | p.setPen(keycolor_lines); | 217 | p.setPen(keycolor_lines); |
218 | p.drawLine(x, y, x + width(), y); | 218 | p.drawLine(x, y, x + width(), y); |
219 | 219 | ||
220 | for (int col = 0; col < keys->numKeys(row); col++) { | 220 | for (int col = 0; col < keys->numKeys(row); col++) { |
221 | 221 | ||
222 | QPixmap *pix = keys->pix(row, col); | 222 | QPixmap *pix = keys->pix(row, col); |
223 | int keyWidth = keys->width(row, col); | 223 | int keyWidth = keys->width(row, col); |
224 | 224 | ||
225 | 225 | ||
226 | int keyWidthPix = defaultKeyWidth * keyWidth; | 226 | int keyWidthPix = defaultKeyWidth * keyWidth; |
227 | 227 | ||
228 | if (keys->pressed(row, col)) | 228 | if (keys->pressed(row, col)) |
229 | p.fillRect(x+1, y+1, keyWidthPix - 1, | 229 | p.fillRect(x+1, y+1, keyWidthPix - 1, |
230 | keyHeight - 1, keycolor_pressed); | 230 | keyHeight - 1, keycolor_pressed); |
231 | 231 | ||
232 | ushort c = keys->uni(row, col); | 232 | ushort c = keys->uni(row, col); |
233 | 233 | ||
234 | if (!pix) { | 234 | if (!pix) { |
235 | if ((shift || lock) && keys->shift(c)) | 235 | if ((shift || lock) && keys->shift(c)) |
236 | c = keys->shift(c); | 236 | c = keys->shift(c); |
237 | else if (meta && keys->meta(c)) | 237 | else if (meta && keys->meta(c)) |
238 | c = keys->meta(c); | 238 | c = keys->meta(c); |
239 | 239 | ||
240 | p.drawText(x, y, | 240 | p.drawText(x, y, |
241 | defaultKeyWidth * keyWidth + 3, keyHeight, | 241 | defaultKeyWidth * keyWidth + 3, keyHeight, |
242 | AlignCenter, (QChar)c); | 242 | AlignCenter, (QChar)c); |
243 | } | 243 | } |
244 | else { | 244 | else { |
245 | // center the image in the middle of the key | 245 | // center the image in the middle of the key |
246 | p.drawPixmap( x + (keyWidthPix - pix->width())/2, | 246 | p.drawPixmap( x + (keyWidthPix - pix->width())/2, |
247 | y + (keyHeight - pix->height())/2 + 1, | 247 | y + (keyHeight - pix->height())/2 + 1, |
248 | QPixmap(*pix) ); | 248 | QPixmap(*pix) ); |
249 | } | 249 | } |
250 | 250 | ||
251 | p.setPen(keycolor_lines); | 251 | p.setPen(keycolor_lines); |
252 | p.drawLine(x, y, x, y + keyHeight); | 252 | p.drawLine(x, y, x, y + keyHeight); |
253 | 253 | ||
254 | x += keyWidthPix; | 254 | x += keyWidthPix; |
255 | } | 255 | } |
256 | 256 | ||
257 | 257 | ||
258 | } | 258 | } |
259 | p.drawLine(0, height() - 1, width(), height() - 1); | 259 | p.drawLine(0, height() - 1, width(), height() - 1); |
260 | p.drawLine(width() - 1, 0, width() - 1, height()); | 260 | p.drawLine(width() - 1, 0, width() - 1, height()); |
261 | } | 261 | } |
262 | 262 | ||
263 | } | 263 | } |
264 | 264 | ||
265 | 265 | ||
266 | /* Keyboard::mousePressEvent {{{1 */ | 266 | /* Keyboard::mousePressEvent {{{1 */ |
267 | void Keyboard::mousePressEvent(QMouseEvent *e) | 267 | void Keyboard::mousePressEvent(QMouseEvent *e) |
268 | { | 268 | { |
269 | int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; | 269 | int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; |
270 | if (row > 5) row = 5; | 270 | if (row > 5) row = 5; |
271 | 271 | ||
272 | // figure out the column | 272 | // figure out the column |
273 | int col = 0; | 273 | int col = 0; |
274 | for (int w = 0; e->x() >= w; col++) | 274 | for (int w = 0; e->x() >= w; col++) |
275 | if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys | 275 | if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys |
276 | w += keys->width(row,col) * defaultKeyWidth; | 276 | w += keys->width(row,col) * defaultKeyWidth; |
277 | else break; | 277 | else break; |
278 | 278 | ||
279 | if (col <= 0) return; | 279 | if (col <= 0) return; |
280 | 280 | ||
281 | col --; // rewind one... | 281 | col --; // rewind one... |
282 | 282 | ||
283 | qkeycode = keys->qcode(row, col); | 283 | qkeycode = keys->qcode(row, col); |
284 | unicode = keys->uni(row, col); | 284 | unicode = keys->uni(row, col); |
285 | 285 | ||
286 | // might need to repaint if two or more of the same keys. | 286 | // might need to repaint if two or more of the same keys. |
287 | // should be faster if just paint one key even though multiple keys exist. | 287 | // should be faster if just paint one key even though multiple keys exist. |
288 | bool need_repaint = FALSE; | 288 | bool need_repaint = FALSE; |
289 | 289 | ||
290 | if (unicode == 0) { // either Qt char, or nothing | 290 | if (unicode == 0) { // either Qt char, or nothing |
291 | 291 | ||
292 | if (qkeycode == Qt::Key_F1) { // toggle the pickboard | 292 | if (qkeycode == Qt::Key_F1) { // toggle the pickboard |
293 | 293 | ||
294 | if ( configdlg ) { | 294 | if ( configdlg ) { |
295 | delete (ConfigDlg *) configdlg; | 295 | delete (ConfigDlg *) configdlg; |
296 | configdlg = 0; | 296 | configdlg = 0; |
297 | } | 297 | } |
298 | else { | 298 | else { |
299 | configdlg = new ConfigDlg (); | 299 | configdlg = new ConfigDlg (); |
300 | connect(configdlg, SIGNAL(setMapToDefault()), | 300 | connect(configdlg, SIGNAL(setMapToDefault()), |
301 | this, SLOT(setMapToDefault())); | 301 | this, SLOT(setMapToDefault())); |
302 | connect(configdlg, SIGNAL(setMapToFile(QString)), | 302 | connect(configdlg, SIGNAL(setMapToFile(QString)), |
303 | this, SLOT(setMapToFile(QString))); | 303 | this, SLOT(setMapToFile(QString))); |
304 | connect(configdlg, SIGNAL(pickboardToggled(bool)), | 304 | connect(configdlg, SIGNAL(pickboardToggled(bool)), |
305 | this, SLOT(togglePickboard(bool))); | 305 | this, SLOT(togglePickboard(bool))); |
306 | connect(configdlg, SIGNAL(repeatToggled(bool)), | 306 | connect(configdlg, SIGNAL(repeatToggled(bool)), |
307 | this, SLOT(toggleRepeat(bool))); | 307 | this, SLOT(toggleRepeat(bool))); |
308 | connect(configdlg, SIGNAL(reloadKeyboard()), | 308 | connect(configdlg, SIGNAL(reloadKeyboard()), |
309 | this, SLOT(reloadKeyboard())); | 309 | this, SLOT(reloadKeyboard())); |
310 | configdlg->showMaximized(); | 310 | configdlg->showMaximized(); |
311 | configdlg->show(); | 311 | configdlg->show(); |
312 | configdlg->raise(); | 312 | configdlg->raise(); |
313 | } | 313 | } |
314 | 314 | ||
315 | } else if (qkeycode == Qt::Key_Control) { | 315 | } else if (qkeycode == Qt::Key_Control) { |
316 | need_repaint = TRUE; | ||
316 | 317 | ||
317 | if (ctrl) { | 318 | if (ctrl) { |
318 | 319 | ||
319 | *ctrl = 0; | 320 | *ctrl = 0; |
320 | ctrl = 0; | 321 | ctrl = 0; |
321 | 322 | ||
322 | } else { | 323 | } else { |
323 | 324 | ||
324 | ctrl = keys->pressedPtr(row, col); | 325 | ctrl = keys->pressedPtr(row, col); |
325 | need_repaint = TRUE; | 326 | need_repaint = TRUE; |
326 | *ctrl = !keys->pressed(row, col); | 327 | *ctrl = !keys->pressed(row, col); |
327 | 328 | ||
328 | } | 329 | } |
329 | 330 | ||
330 | } else if (qkeycode == Qt::Key_Alt) { | 331 | } else if (qkeycode == Qt::Key_Alt) { |
332 | need_repaint = TRUE; | ||
331 | 333 | ||
332 | if (alt) { | 334 | if (alt) { |
333 | *alt = 0; | 335 | *alt = 0; |
334 | alt = 0; | 336 | alt = 0; |
335 | 337 | ||
336 | } else { | 338 | } else { |
337 | 339 | ||
338 | alt = keys->pressedPtr(row, col); | 340 | alt = keys->pressedPtr(row, col); |
339 | need_repaint = TRUE; | 341 | need_repaint = TRUE; |
340 | *alt = !keys->pressed(row, col); | 342 | *alt = !keys->pressed(row, col); |
341 | } | 343 | } |
342 | 344 | ||
343 | } else if (qkeycode == Qt::Key_Shift) { | 345 | } else if (qkeycode == Qt::Key_Shift) { |
344 | need_repaint = TRUE; | 346 | need_repaint = TRUE; |
345 | 347 | ||
346 | if (shift) { | 348 | if (shift) { |
347 | *shift = 0; | 349 | *shift = 0; |
348 | shift = 0; | 350 | shift = 0; |
349 | } | 351 | } |
350 | else { | 352 | else { |
351 | shift = keys->pressedPtr(row, col); | 353 | shift = keys->pressedPtr(row, col); |
352 | *shift = 1; | 354 | *shift = 1; |
353 | if (lock) { | 355 | if (lock) { |
354 | *lock = 0; | 356 | *lock = 0; |
355 | lock = 0; | 357 | lock = 0; |
356 | } | 358 | } |
357 | } | 359 | } |
358 | if (meta) { | 360 | if (meta) { |
359 | 361 | ||
360 | *meta = 0; | 362 | *meta = 0; |
361 | meta = 0; | 363 | meta = 0; |
362 | } | 364 | } |
363 | 365 | ||
364 | } else if (qkeycode == Qt::Key_CapsLock) { | 366 | } else if (qkeycode == Qt::Key_CapsLock) { |
365 | need_repaint = TRUE; | 367 | need_repaint = TRUE; |
366 | 368 | ||
367 | if (lock) { | 369 | if (lock) { |
368 | *lock = 0; | 370 | *lock = 0; |
369 | lock = 0; | 371 | lock = 0; |
370 | } | 372 | } |
371 | else { | 373 | else { |
372 | lock = keys->pressedPtr(row, col);; | 374 | lock = keys->pressedPtr(row, col);; |
373 | *lock = 1; | 375 | *lock = 1; |
374 | if (shift) { | 376 | if (shift) { |
375 | *shift = 0; | 377 | *shift = 0; |
376 | shift = 0; | 378 | shift = 0; |
377 | } | 379 | } |
378 | } | 380 | } |
379 | if (meta) { | 381 | if (meta) { |
380 | 382 | ||
381 | *meta = 0; | 383 | *meta = 0; |
382 | meta = 0; | 384 | meta = 0; |
383 | } | 385 | } |
384 | 386 | ||
385 | } else if (qkeycode == Qt::Key_Meta) { | 387 | } else if (qkeycode == Qt::Key_Meta) { |
386 | need_repaint = TRUE; | 388 | need_repaint = TRUE; |
387 | 389 | ||
388 | if (meta) { | 390 | if (meta) { |
389 | *meta = 0; | 391 | *meta = 0; |
390 | meta = 0; | 392 | meta = 0; |
391 | 393 | ||
392 | } else { | 394 | } else { |
393 | 395 | ||
394 | meta = keys->pressedPtr(row, col); | 396 | meta = keys->pressedPtr(row, col); |
395 | need_repaint = TRUE; | 397 | need_repaint = TRUE; |
396 | *meta = !keys->pressed(row, col); | 398 | *meta = !keys->pressed(row, col); |
397 | } | 399 | } |
398 | 400 | ||
399 | if (shift) { | 401 | if (shift) { |
400 | 402 | ||
401 | *shift = 0; | 403 | *shift = 0; |
402 | shift = 0; | 404 | shift = 0; |
403 | 405 | ||
404 | } | 406 | } |
405 | if (lock) { | 407 | if (lock) { |
406 | 408 | ||
407 | *lock = 0; | 409 | *lock = 0; |
408 | lock = 0; | 410 | lock = 0; |
409 | 411 | ||
410 | } | 412 | } |
411 | 413 | ||
412 | // dont need to emit this key... acts same as alt | 414 | // dont need to emit this key... acts same as alt |
413 | qkeycode = 0; | 415 | qkeycode = 0; |
414 | } | 416 | } |
415 | 417 | ||
416 | } | 418 | } |
417 | else { // normal char | 419 | else { // normal char |
418 | if ((shift || lock) && keys->shift(unicode)) { | 420 | if ((shift || lock) && keys->shift(unicode)) { |
419 | unicode = keys->shift(unicode); | 421 | unicode = keys->shift(unicode); |
420 | } | 422 | } |
421 | if (meta && keys->meta(unicode)) { | 423 | if (meta && keys->meta(unicode)) { |
422 | unicode = keys->meta(unicode); | 424 | unicode = keys->meta(unicode); |
423 | } | 425 | } |
424 | } | 426 | } |
425 | 427 | ||
426 | // korean parsing | 428 | // korean parsing |
427 | if (keys->lang == "ko") { | 429 | if (keys->lang == "ko") { |
428 | 430 | ||
429 | unicode = parseKoreanInput(unicode); | 431 | unicode = parseKoreanInput(unicode); |
430 | } | 432 | } |
431 | 433 | ||
432 | modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); | 434 | modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); |
433 | 435 | ||
434 | if ('A' <= unicode && unicode <= 'z' && modifiers) { | 436 | if ('A' <= unicode && unicode <= 'z' && modifiers) { |
435 | 437 | ||
436 | qkeycode = QChar(unicode).upper(); | 438 | qkeycode = QChar(unicode).upper(); |
437 | unicode = qkeycode - '@'; | 439 | unicode = qkeycode - '@'; |
438 | } | 440 | } |
439 | 441 | ||
440 | QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); | 442 | QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); |
441 | 443 | ||
442 | // pickboard stuff | 444 | // pickboard stuff |
443 | if (usePicks) { | 445 | if (usePicks) { |
444 | 446 | ||
445 | KeyboardConfig *dc = picks->dc; | 447 | KeyboardConfig *dc = picks->dc; |
446 | 448 | ||
447 | if (dc) { | 449 | if (dc) { |
448 | if (qkeycode == Qt::Key_Backspace) { | 450 | if (qkeycode == Qt::Key_Backspace) { |
449 | dc->input.remove(dc->input.last()); // remove last input | 451 | dc->input.remove(dc->input.last()); // remove last input |
450 | dc->decBackspaces(); | 452 | dc->decBackspaces(); |
451 | } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { | 453 | } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { |
452 | dc->input.clear(); | 454 | dc->input.clear(); |
453 | dc->resetBackspaces(); | 455 | dc->resetBackspaces(); |
454 | } else { | 456 | } else { |
455 | dc->add(QString(QChar(unicode))); | 457 | dc->add(QString(QChar(unicode))); |
456 | dc->incBackspaces(); | 458 | dc->incBackspaces(); |
457 | } | 459 | } |
458 | } | 460 | } |
459 | picks->repaint(); | 461 | picks->repaint(); |
460 | } | 462 | } |
461 | 463 | ||
462 | 464 | ||
463 | // painting | 465 | // painting |
464 | pressed = TRUE; | 466 | pressed = TRUE; |
465 | 467 | ||
466 | pressedKeyRow = row; | 468 | pressedKeyRow = row; |
467 | pressedKeyCol = col; | 469 | pressedKeyCol = col; |
468 | 470 | ||
469 | if (need_repaint) repaint(FALSE); | 471 | if (need_repaint) repaint(FALSE); |
470 | else { // just paint the one key pressed | 472 | else { // just paint the one key pressed |
471 | 473 | ||
472 | 474 | ||
473 | 475 | ||
474 | QPainter p(this); | 476 | QPainter p(this); |
475 | drawKeyboard(p, row, col); | 477 | drawKeyboard(p, row, col); |
476 | 478 | ||
477 | } | 479 | } |
478 | 480 | ||
479 | if (useRepeat) repeatTimer->start( 800 ); | 481 | if (useRepeat) repeatTimer->start( 800 ); |
480 | //pressTid = startTimer(80); | 482 | //pressTid = startTimer(80); |
481 | 483 | ||
482 | } | 484 | } |
483 | 485 | ||
484 | 486 | ||
485 | /* Keyboard::mouseReleaseEvent {{{1 */ | 487 | /* Keyboard::mouseReleaseEvent {{{1 */ |
486 | void Keyboard::mouseReleaseEvent(QMouseEvent*) | 488 | void Keyboard::mouseReleaseEvent(QMouseEvent*) |
487 | { | 489 | { |
488 | pressed = FALSE; | 490 | pressed = FALSE; |
489 | //if ( pressTid == 0 ) | 491 | //if ( pressTid == 0 ) |
490 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 492 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
491 | if ( unicode != -1 ) { | 493 | if ( unicode != -1 ) { |
492 | emit key( unicode, qkeycode, modifiers, false, false ); | 494 | emit key( unicode, qkeycode, modifiers, false, false ); |
493 | repeatTimer->stop(); | 495 | repeatTimer->stop(); |
494 | } | 496 | } |
495 | #endif | 497 | #endif |
496 | if (shift && unicode != 0) { | 498 | if (shift && unicode != 0) { |
497 | 499 | ||
498 | 500 | ||
499 | *shift = 0; // unpress shift key | 501 | *shift = 0; // unpress shift key |
500 | shift = 0; // reset the shift pointer | 502 | shift = 0; // reset the shift pointer |
501 | repaint(FALSE); | 503 | repaint(FALSE); |
502 | 504 | ||
503 | } else if (meta && unicode != 0) { | 505 | } else if (meta && unicode != 0) { |
504 | 506 | ||
505 | *meta = 0; | 507 | *meta = 0; |
506 | meta = 0; | 508 | meta = 0; |
507 | repaint(FALSE); | 509 | repaint(FALSE); |
508 | } | 510 | } |
509 | else | 511 | else |
510 | 512 | ||
511 | clearHighlight(); | 513 | clearHighlight(); |
512 | } | 514 | } |
513 | 515 | ||
514 | /* Keyboard::timerEvent {{{1 */ | 516 | /* Keyboard::timerEvent {{{1 */ |
515 | 517 | ||
516 | /* dont know what this does, but i think it is here so that if your screen | 518 | /* dont know what this does, but i think it is here so that if your screen |
517 | * sticks (like on an ipaq) then it will stop repeating if you click another | 519 | * sticks (like on an ipaq) then it will stop repeating if you click another |
518 | * key... but who knows what anything does in this thing anyway? | 520 | * key... but who knows what anything does in this thing anyway? |
519 | 521 | ||
520 | void Keyboard::timerEvent(QTimerEvent* e) | 522 | void Keyboard::timerEvent(QTimerEvent* e) |
521 | { | 523 | { |
522 | if ( e->timerId() == pressTid ) { | 524 | if ( e->timerId() == pressTid ) { |
523 | killTimer(pressTid); | 525 | killTimer(pressTid); |
524 | pressTid = 0; | 526 | pressTid = 0; |
525 | if ( !pressed ) | 527 | if ( !pressed ) |
526 | cout << "calling clearHighlight from timerEvent\n"; | 528 | cout << "calling clearHighlight from timerEvent\n"; |
527 | //clearHighlight(); | 529 | //clearHighlight(); |
528 | } | 530 | } |
529 | } | 531 | } |
530 | */ | 532 | */ |
531 | 533 | ||
532 | void Keyboard::repeat() | 534 | void Keyboard::repeat() |
533 | { | 535 | { |
534 | 536 | ||
535 | repeatTimer->start( 200 ); | 537 | repeatTimer->start( 200 ); |
536 | emit key( unicode, qkeycode, modifiers, true, true ); | 538 | emit key( unicode, qkeycode, modifiers, true, true ); |
537 | } | 539 | } |
538 | 540 | ||
539 | void Keyboard::clearHighlight() | 541 | void Keyboard::clearHighlight() |
540 | { | 542 | { |
541 | if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { | 543 | if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { |
542 | int tmpRow = pressedKeyRow; | 544 | int tmpRow = pressedKeyRow; |
543 | int tmpCol = pressedKeyCol; | 545 | int tmpCol = pressedKeyCol; |
544 | 546 | ||
545 | pressedKeyRow = -1; | 547 | pressedKeyRow = -1; |
546 | pressedKeyCol = -1; | 548 | pressedKeyCol = -1; |
547 | 549 | ||
548 | QPainter p(this); | 550 | QPainter p(this); |
549 | drawKeyboard(p, tmpRow, tmpCol); | 551 | drawKeyboard(p, tmpRow, tmpCol); |
550 | } | 552 | } |
551 | } | 553 | } |
552 | 554 | ||
553 | 555 | ||
554 | /* Keyboard::sizeHint {{{1 */ | 556 | /* Keyboard::sizeHint {{{1 */ |
555 | QSize Keyboard::sizeHint() const | 557 | QSize Keyboard::sizeHint() const |
556 | { | 558 | { |
557 | QFontMetrics fm=fontMetrics(); | 559 | QFontMetrics fm=fontMetrics(); |
558 | int keyHeight = fm.lineSpacing() + 2; | 560 | int keyHeight = fm.lineSpacing() + 2; |
559 | 561 | ||
560 | return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1); | 562 | return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1); |
561 | } | 563 | } |
562 | 564 | ||
563 | 565 | ||
564 | void Keyboard::resetState() | 566 | void Keyboard::resetState() |
565 | { | 567 | { |
566 | schar = mchar = echar = 0; | 568 | schar = mchar = echar = 0; |
567 | picks->resetState(); | 569 | picks->resetState(); |
568 | } | 570 | } |
569 | 571 | ||
570 | /* Keyboard::togglePickboard {{{1 */ | 572 | /* Keyboard::togglePickboard {{{1 */ |
571 | void Keyboard::togglePickboard(bool on_off) | 573 | void Keyboard::togglePickboard(bool on_off) |
572 | { | 574 | { |
573 | usePicks = on_off; | 575 | usePicks = on_off; |
574 | if (usePicks) { | 576 | if (usePicks) { |
575 | picks->show(); | 577 | picks->show(); |
576 | //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send | 578 | //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send |
577 | //adjustSize(); | 579 | //adjustSize(); |
578 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 580 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
579 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 581 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
580 | } else { | 582 | } else { |
581 | 583 | ||
582 | picks->hide(); | 584 | picks->hide(); |
583 | picks->resetState(); | 585 | picks->resetState(); |
584 | //move(x(), y() + picks->height()); | 586 | //move(x(), y() + picks->height()); |
585 | //adjustSize(); | 587 | //adjustSize(); |
586 | QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 588 | QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
587 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 589 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
588 | 590 | ||
589 | } | 591 | } |
590 | /* | 592 | /* |
591 | * this closes && opens the input method | 593 | * this closes && opens the input method |
592 | */ | 594 | */ |
593 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); | 595 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); |
594 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); | 596 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); |
595 | } | 597 | } |
596 | 598 | ||
597 | void Keyboard::toggleRepeat(bool on) { | 599 | void Keyboard::toggleRepeat(bool on) { |
598 | 600 | ||
599 | useRepeat = on; | 601 | useRepeat = on; |
600 | cout << "setting useRepeat to: " << useRepeat << "\n"; | 602 | cout << "setting useRepeat to: " << useRepeat << "\n"; |
601 | } | 603 | } |
602 | 604 | ||
603 | /* Keyboard::setMapTo ... {{{1 */ | 605 | /* Keyboard::setMapTo ... {{{1 */ |
604 | void Keyboard::setMapToDefault() { | 606 | void Keyboard::setMapToDefault() { |
605 | 607 | ||
606 | 608 | ||
607 | /* load current locale language map */ | 609 | /* load current locale language map */ |
608 | Config *config = new Config("locale"); | 610 | Config *config = new Config("locale"); |
609 | config->setGroup( "Language" ); | 611 | config->setGroup( "Language" ); |
610 | QString l = config->readEntry( "Language" , "en" ); | 612 | QString l = config->readEntry( "Language" , "en" ); |
611 | delete config; | 613 | delete config; |
612 | 614 | ||
613 | QString key_map = QPEApplication::qpeDir() + "/share/multikey/" | 615 | QString key_map = QPEApplication::qpeDir() + "/share/multikey/" |
614 | + l + ".keymap"; | 616 | + l + ".keymap"; |
615 | 617 | ||
616 | /* save change to multikey config file */ | 618 | /* save change to multikey config file */ |
617 | config = new Config("multikey"); | 619 | config = new Config("multikey"); |
618 | config->setGroup ("keymaps"); | 620 | config->setGroup ("keymaps"); |
619 | config->writeEntry ("current", key_map); // default closed | 621 | config->writeEntry ("current", key_map); // default closed |
620 | delete config; | 622 | delete config; |
621 | 623 | ||
622 | delete keys; | 624 | delete keys; |
623 | keys = new Keys(key_map); | 625 | keys = new Keys(key_map); |
624 | 626 | ||
625 | // have to repaint the keyboard | 627 | // have to repaint the keyboard |
626 | repaint(FALSE); | 628 | repaint(FALSE); |
627 | } | 629 | } |
628 | 630 | ||
629 | void Keyboard::setMapToFile(QString map) { | 631 | void Keyboard::setMapToFile(QString map) { |
630 | 632 | ||
631 | /* save change to multikey config file */ | 633 | /* save change to multikey config file */ |
632 | Config *config = new Config("multikey"); | 634 | Config *config = new Config("multikey"); |
633 | config->setGroup ("keymaps"); | 635 | config->setGroup ("keymaps"); |
634 | config->writeEntry ("current", map); // default closed | 636 | config->writeEntry ("current", map); // default closed |
635 | 637 | ||
636 | delete config; | 638 | delete config; |
637 | 639 | ||
638 | delete keys; | 640 | delete keys; |
639 | if (QFile(map).exists()) | 641 | if (QFile(map).exists()) |
640 | keys = new Keys(map); | 642 | keys = new Keys(map); |
641 | else | 643 | else |
642 | keys = new Keys(); | 644 | keys = new Keys(); |
643 | 645 | ||
644 | repaint(FALSE); | 646 | repaint(FALSE); |
645 | 647 | ||
646 | } | 648 | } |
647 | 649 | ||
648 | /* Keybaord::reloadKeyboard {{{1 */ | 650 | /* Keybaord::reloadKeyboard {{{1 */ |
649 | void Keyboard::reloadKeyboard() { | 651 | void Keyboard::reloadKeyboard() { |
650 | 652 | ||
651 | // reload colors and redraw | 653 | // reload colors and redraw |
652 | loadKeyboardColors(); | 654 | loadKeyboardColors(); |
653 | repaint(); | 655 | repaint(); |
654 | 656 | ||
655 | } | 657 | } |
656 | 658 | ||
657 | void Keyboard::loadKeyboardColors() { | 659 | void Keyboard::loadKeyboardColors() { |
658 | 660 | ||
659 | Config config ("multikey"); | 661 | Config config ("multikey"); |
660 | config.setGroup("colors"); | 662 | config.setGroup("colors"); |
661 | 663 | ||
662 | QStringList color; | 664 | QStringList color; |
663 | color = config.readListEntry("keycolor", QChar(',')); | 665 | color = config.readListEntry("keycolor", QChar(',')); |
664 | if (color.isEmpty()) { | 666 | if (color.isEmpty()) { |
665 | color = QStringList::split(",", "240,240,240"); | 667 | color = QStringList::split(",", "240,240,240"); |
666 | config.writeEntry("keycolor", color.join(",")); | 668 | config.writeEntry("keycolor", color.join(",")); |
667 | 669 | ||
668 | } | 670 | } |
669 | keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 671 | keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
670 | 672 | ||
671 | color = config.readListEntry("keycolor_pressed", QChar(',')); | 673 | color = config.readListEntry("keycolor_pressed", QChar(',')); |
672 | if (color.isEmpty()) { | 674 | if (color.isEmpty()) { |
673 | color = QStringList::split(",", "171,183,198"); | 675 | color = QStringList::split(",", "171,183,198"); |
674 | config.writeEntry("keycolor_pressed", color.join(",")); | 676 | config.writeEntry("keycolor_pressed", color.join(",")); |
675 | 677 | ||
676 | } | 678 | } |
677 | keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 679 | keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
678 | 680 | ||
679 | color = config.readListEntry("keycolor_lines", QChar(',')); | 681 | color = config.readListEntry("keycolor_lines", QChar(',')); |
680 | if (color.isEmpty()) { | 682 | if (color.isEmpty()) { |
681 | color = QStringList::split(",", "138,148,160"); | 683 | color = QStringList::split(",", "138,148,160"); |
682 | config.writeEntry("keycolor_lines", color.join(",")); | 684 | config.writeEntry("keycolor_lines", color.join(",")); |
683 | 685 | ||
684 | } | 686 | } |
685 | keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 687 | keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
686 | 688 | ||
687 | color = config.readListEntry("textcolor", QChar(',')); | 689 | color = config.readListEntry("textcolor", QChar(',')); |
688 | if (color.isEmpty()) { | 690 | if (color.isEmpty()) { |
689 | color = QStringList::split(",", "43,54,68"); | 691 | color = QStringList::split(",", "43,54,68"); |
690 | config.writeEntry("textcolor", color.join(",")); | 692 | config.writeEntry("textcolor", color.join(",")); |
691 | 693 | ||
692 | } | 694 | } |
693 | textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 695 | textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
694 | 696 | ||
695 | } | 697 | } |
696 | 698 | ||
697 | /* korean input functions {{{1 | 699 | /* korean input functions {{{1 |
698 | * | 700 | * |
699 | * TODO | 701 | * TODO |
700 | * one major problem with this implementation is that you can't move the | 702 | * one major problem with this implementation is that you can't move the |
701 | * cursor after inputing korean chars, otherwise it will eat up and replace | 703 | * cursor after inputing korean chars, otherwise it will eat up and replace |
702 | * the char before the cursor you move to. fix that | 704 | * the char before the cursor you move to. fix that |
703 | * | 705 | * |
704 | * make backspace delete one single char, not the whole thing if still | 706 | * make backspace delete one single char, not the whole thing if still |
705 | * editing. | 707 | * editing. |
706 | * | 708 | * |
707 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 709 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
708 | * | 710 | * |
709 | * how korean input works | 711 | * how korean input works |
710 | * | 712 | * |
711 | * all following chars means unicode char value and are in hex | 713 | * all following chars means unicode char value and are in hex |
712 | * | 714 | * |
713 | * ÃÊÀ½ = schar (start char) | 715 | * ÃÊÀ½ = schar (start char) |
714 | * ÁßÀ½ = mchar (middle char) | 716 | * ÁßÀ½ = mchar (middle char) |
715 | * ³¡À½ = echar (end char) | 717 | * ³¡À½ = echar (end char) |
716 | * | 718 | * |
717 | * there are 19 schars. unicode position is at 1100 - 1112 | 719 | * there are 19 schars. unicode position is at 1100 - 1112 |
718 | * there are 21 mchars. unicode position is at 1161 - 1175 | 720 | * there are 21 mchars. unicode position is at 1161 - 1175 |
719 | * there are 27 echars. unicode position is at 11a8 - 11c2 | 721 | * there are 27 echars. unicode position is at 11a8 - 11c2 |
720 | * | 722 | * |
721 | * the map with everything combined is at ac00 - d7a3 | 723 | * the map with everything combined is at ac00 - d7a3 |
722 | * | 724 | * |
723 | */ | 725 | */ |
724 | 726 | ||
725 | ushort Keyboard::parseKoreanInput (ushort c) { | 727 | ushort Keyboard::parseKoreanInput (ushort c) { |
726 | 728 | ||
727 | if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) | 729 | if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) |
728 | || | 730 | || |
729 | (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode | 731 | (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode |
730 | && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { | 732 | && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { |
731 | 733 | ||
732 | schar = 0, mchar = 0, echar = 0; | 734 | schar = 0, mchar = 0, echar = 0; |
733 | return c; | 735 | return c; |
734 | } | 736 | } |
735 | 737 | ||
736 | if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input | 738 | if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input |
737 | 739 | ||
738 | if (schar == 0 || (schar != 0 && mchar == 0)) { | 740 | if (schar == 0 || (schar != 0 && mchar == 0)) { |
739 | schar = c; mchar = 0; echar = 0; | 741 | schar = c; mchar = 0; echar = 0; |
740 | return c; | 742 | return c; |
741 | } | 743 | } |
742 | else if (mchar != 0) { | 744 | else if (mchar != 0) { |
743 | 745 | ||
744 | if (echar == 0) { | 746 | if (echar == 0) { |
745 | 747 | ||
746 | if (!(echar = constoe(c))) { | 748 | if (!(echar = constoe(c))) { |
747 | 749 | ||
748 | schar = c; mchar = 0; echar = 0; | 750 | schar = c; mchar = 0; echar = 0; |
749 | return c; | 751 | return c; |
750 | } | 752 | } |
751 | 753 | ||
752 | } | 754 | } |
753 | else { // must figure out what the echar is | 755 | else { // must figure out what the echar is |
754 | 756 | ||
755 | if (echar == 0x11a8) { // ¤¡ | 757 | if (echar == 0x11a8) { // ¤¡ |
756 | 758 | ||
757 | if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡ | 759 | if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡ |
758 | else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ | 760 | else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ |
759 | else { | 761 | else { |
760 | schar = c; mchar = 0; echar = 0; | 762 | schar = c; mchar = 0; echar = 0; |
761 | return c; | 763 | return c; |
762 | } | 764 | } |
763 | 765 | ||
764 | } else if (echar == 0x11ab) { // ¤¤ | 766 | } else if (echar == 0x11ab) { // ¤¤ |
765 | 767 | ||
766 | if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸ | 768 | if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸ |
767 | else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾ | 769 | else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾ |
768 | else { | 770 | else { |
769 | schar = c; mchar = 0; echar = 0; | 771 | schar = c; mchar = 0; echar = 0; |
770 | return c; | 772 | return c; |
771 | } | 773 | } |
772 | 774 | ||
773 | } else if (echar == 0x11af) { // ¤© | 775 | } else if (echar == 0x11af) { // ¤© |
774 | 776 | ||
775 | if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡ | 777 | if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡ |
776 | else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤± | 778 | else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤± |
777 | else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤² | 779 | else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤² |
778 | else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ | 780 | else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ |
779 | else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼ | 781 | else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼ |
780 | else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½ | 782 | else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½ |
781 | else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾ | 783 | else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾ |
782 | else { | 784 | else { |
783 | schar = c; mchar = 0; echar = 0; | 785 | schar = c; mchar = 0; echar = 0; |
784 | return c; | 786 | return c; |
785 | } | 787 | } |
786 | 788 | ||
787 | } else if (echar == 0x11b8) { // ¤² | 789 | } else if (echar == 0x11b8) { // ¤² |
788 | 790 | ||
789 | if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ | 791 | if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ |
790 | else { | 792 | else { |
791 | schar = c; mchar = 0; echar = 0; | 793 | schar = c; mchar = 0; echar = 0; |
792 | return c; | 794 | return c; |
793 | } | 795 | } |
794 | 796 | ||
795 | } else if (echar == 0x11ba) { // ¤µ | 797 | } else if (echar == 0x11ba) { // ¤µ |
796 | 798 | ||
797 | if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ | 799 | if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ |
798 | else { | 800 | else { |
799 | schar = c; mchar = 0; echar = 0; | 801 | schar = c; mchar = 0; echar = 0; |
800 | return c; | 802 | return c; |
801 | } | 803 | } |
802 | 804 | ||
803 | } else { // if any other char, cannot combine chars | 805 | } else { // if any other char, cannot combine chars |
804 | 806 | ||
805 | schar = c; mchar = 0; echar = 0; | 807 | schar = c; mchar = 0; echar = 0; |
806 | return c; | 808 | return c; |
807 | } | 809 | } |
808 | 810 | ||
809 | unicode = echar; | 811 | unicode = echar; |
810 | } | 812 | } |
811 | } | 813 | } |
812 | 814 | ||
813 | } | 815 | } |
814 | else if (0x1161 <= c && c <= 0x1175) { // mchar was input | 816 | else if (0x1161 <= c && c <= 0x1175) { // mchar was input |
815 | 817 | ||
816 | if (schar != 0 && mchar == 0) { mchar = c; } | 818 | if (schar != 0 && mchar == 0) { mchar = c; } |
817 | 819 | ||
818 | else if (schar != 0 && mchar != 0 && echar == 0) { | 820 | else if (schar != 0 && mchar != 0 && echar == 0) { |
819 | 821 | ||
820 | switch (mchar) { | 822 | switch (mchar) { |
821 | case 0x1169: | 823 | case 0x1169: |
822 | if (c == 0x1161) mchar = 0x116a; | 824 | if (c == 0x1161) mchar = 0x116a; |
823 | else if (c == 0x1162) mchar = 0x116b; | 825 | else if (c == 0x1162) mchar = 0x116b; |
824 | else if (c == 0x1175) mchar = 0x116c; | 826 | else if (c == 0x1175) mchar = 0x116c; |
825 | else { | 827 | else { |
826 | schar = 0; mchar = 0; echar = 0; | 828 | schar = 0; mchar = 0; echar = 0; |
827 | return c; | 829 | return c; |
828 | } | 830 | } |
829 | break; | 831 | break; |
830 | case 0x116e: | 832 | case 0x116e: |
831 | if (c == 0x1165) mchar = 0x116f; | 833 | if (c == 0x1165) mchar = 0x116f; |
832 | else if (c == 0x1166) mchar = 0x1170; | 834 | else if (c == 0x1166) mchar = 0x1170; |
833 | else if (c == 0x1175) mchar = 0x1171; | 835 | else if (c == 0x1175) mchar = 0x1171; |
834 | else { | 836 | else { |
835 | schar = 0; mchar = 0; echar = 0; | 837 | schar = 0; mchar = 0; echar = 0; |
836 | return c; | 838 | return c; |
837 | } | 839 | } |
838 | break; | 840 | break; |
839 | case 0x1173: | 841 | case 0x1173: |
840 | if (c == 0x1175) mchar = 0x1174; | 842 | if (c == 0x1175) mchar = 0x1174; |
841 | else { | 843 | else { |
842 | schar = 0; mchar = 0; echar = 0; | 844 | schar = 0; mchar = 0; echar = 0; |
843 | return c; | 845 | return c; |
844 | } | 846 | } |
845 | break; | 847 | break; |
846 | default: | 848 | default: |
847 | schar = 0; mchar = 0; echar = 0; | 849 | schar = 0; mchar = 0; echar = 0; |
848 | return c; | 850 | return c; |
849 | } | 851 | } |
850 | } | 852 | } |
851 | else if (schar != 0 && mchar != 0 && echar != 0) { | 853 | else if (schar != 0 && mchar != 0 && echar != 0) { |
852 | 854 | ||
853 | emit key( 8, Qt::Key_Backspace, 0, true, false ); | 855 | emit key( 8, Qt::Key_Backspace, 0, true, false ); |
854 | 856 | ||
855 | ushort prev = 0; | 857 | ushort prev = 0; |
856 | switch (echar) { | 858 | switch (echar) { |
857 | /* | 859 | /* |
858 | case 0x11a9: | 860 | case 0x11a9: |
859 | prev = combineKoreanChars(schar, mchar, 0x11a8); | 861 | prev = combineKoreanChars(schar, mchar, 0x11a8); |
860 | schar = 0x1100; | 862 | schar = 0x1100; |
861 | break; | 863 | break; |
862 | */ | 864 | */ |
863 | case 0x11aa: | 865 | case 0x11aa: |
864 | prev = combineKoreanChars(schar, mchar, 0x11a8); | 866 | prev = combineKoreanChars(schar, mchar, 0x11a8); |
865 | schar = 0x1109; | 867 | schar = 0x1109; |
866 | break; | 868 | break; |
867 | case 0x11ac: | 869 | case 0x11ac: |
868 | prev = combineKoreanChars(schar, mchar, 0x11ab); | 870 | prev = combineKoreanChars(schar, mchar, 0x11ab); |
869 | schar = 0x110c; | 871 | schar = 0x110c; |
870 | break; | 872 | break; |
871 | case 0x11ad: | 873 | case 0x11ad: |
872 | prev = combineKoreanChars(schar, mchar, 0x11ab); | 874 | prev = combineKoreanChars(schar, mchar, 0x11ab); |
873 | schar = 0x1112; | 875 | schar = 0x1112; |
874 | break; | 876 | break; |
875 | case 0x11b0: | 877 | case 0x11b0: |
876 | prev = combineKoreanChars(schar, mchar, 0x11af); | 878 | prev = combineKoreanChars(schar, mchar, 0x11af); |
877 | schar = 0x1100; | 879 | schar = 0x1100; |
878 | break; | 880 | break; |
879 | case 0x11b1: | 881 | case 0x11b1: |
880 | prev = combineKoreanChars(schar, mchar, 0x11af); | 882 | prev = combineKoreanChars(schar, mchar, 0x11af); |
881 | schar = 0x1106; | 883 | schar = 0x1106; |
882 | break; | 884 | break; |
883 | case 0x11b2: | 885 | case 0x11b2: |
884 | prev = combineKoreanChars(schar, mchar, 0x11af); | 886 | prev = combineKoreanChars(schar, mchar, 0x11af); |
885 | schar = 0x1107; | 887 | schar = 0x1107; |
886 | break; | 888 | break; |
887 | case 0x11b3: | 889 | case 0x11b3: |
888 | prev = combineKoreanChars(schar, mchar, 0x11af); | 890 | prev = combineKoreanChars(schar, mchar, 0x11af); |
889 | schar = 0x1109; | 891 | schar = 0x1109; |
890 | break; | 892 | break; |
891 | case 0x11b4: | 893 | case 0x11b4: |
892 | prev = combineKoreanChars(schar, mchar, 0x11af); | 894 | prev = combineKoreanChars(schar, mchar, 0x11af); |
893 | schar = 0x1110; | 895 | schar = 0x1110; |
894 | break; | 896 | break; |
895 | case 0x11b9: | 897 | case 0x11b9: |
896 | prev = combineKoreanChars(schar, mchar, 0x11b8); | 898 | prev = combineKoreanChars(schar, mchar, 0x11b8); |
897 | schar = 0x1109; | 899 | schar = 0x1109; |
898 | break; | 900 | break; |
899 | /* | 901 | /* |
900 | case 0x11bb: | 902 | case 0x11bb: |
901 | prev = combineKoreanChars(schar, mchar, 0x11ba); | 903 | prev = combineKoreanChars(schar, mchar, 0x11ba); |
902 | schar = 0x1109; | 904 | schar = 0x1109; |
903 | break; | 905 | break; |
904 | */ | 906 | */ |
905 | default: | 907 | default: |
906 | 908 | ||
907 | if (constoe(echar)) { | 909 | if (constoe(echar)) { |
908 | 910 | ||
909 | prev = combineKoreanChars(schar, mchar, 0); | 911 | prev = combineKoreanChars(schar, mchar, 0); |
910 | schar = constoe(echar); | 912 | schar = constoe(echar); |
911 | } | 913 | } |
912 | break; | 914 | break; |
913 | } | 915 | } |
914 | 916 | ||
915 | emit key( prev, prev, 0, true, false ); | 917 | emit key( prev, prev, 0, true, false ); |
916 | 918 | ||
917 | mchar = c; echar = 0; | 919 | mchar = c; echar = 0; |
918 | 920 | ||
919 | return combineKoreanChars(schar, mchar, 0); | 921 | return combineKoreanChars(schar, mchar, 0); |
920 | 922 | ||
921 | } | 923 | } |
922 | else { | 924 | else { |
923 | schar = 0; mchar = 0; echar = 0; | 925 | schar = 0; mchar = 0; echar = 0; |
924 | return c; | 926 | return c; |
925 | } | 927 | } |
926 | 928 | ||
927 | } | 929 | } |
928 | else /*if (c == ' ')*/ return c; | 930 | else /*if (c == ' ')*/ return c; |
929 | 931 | ||
930 | 932 | ||
931 | // and now... finally delete previous char, and return new char | 933 | // and now... finally delete previous char, and return new char |
932 | emit key( 8, Qt::Key_Backspace, 0, true, false ); | 934 | emit key( 8, Qt::Key_Backspace, 0, true, false ); |
933 | 935 | ||
934 | 936 | ||
935 | return combineKoreanChars( schar, mchar, echar); | 937 | return combineKoreanChars( schar, mchar, echar); |
936 | 938 | ||
937 | } | 939 | } |
938 | 940 | ||
939 | ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { | 941 | ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { |
940 | 942 | ||
941 | return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; | 943 | return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; |
942 | 944 | ||
943 | } | 945 | } |
944 | 946 | ||
945 | ushort Keyboard::constoe(const ushort c) { | 947 | ushort Keyboard::constoe(const ushort c) { |
946 | 948 | ||
947 | // converts schars to echars if possible | 949 | // converts schars to echars if possible |
948 | 950 | ||
949 | if (0x1100 <= c && c <= 0x1112) { // schar to echar | 951 | if (0x1100 <= c && c <= 0x1112) { // schar to echar |
950 | 952 | ||
951 | switch (c) { | 953 | switch (c) { |
952 | case 0x1100: return 0x11a8; | 954 | case 0x1100: return 0x11a8; |
953 | case 0x1101: return 0x11a9; | 955 | case 0x1101: return 0x11a9; |
954 | case 0x1102: return 0x11ab; | 956 | case 0x1102: return 0x11ab; |
955 | case 0x1103: return 0x11ae; | 957 | case 0x1103: return 0x11ae; |
956 | case 0x1105: return 0x11af; | 958 | case 0x1105: return 0x11af; |
957 | case 0x1106: return 0x11b7; | 959 | case 0x1106: return 0x11b7; |
958 | case 0x1107: return 0x11b8; | 960 | case 0x1107: return 0x11b8; |
959 | case 0x1109: return 0x11ba; | 961 | case 0x1109: return 0x11ba; |
960 | case 0x110a: return 0x11bb; | 962 | case 0x110a: return 0x11bb; |
961 | case 0x110b: return 0x11bc; | 963 | case 0x110b: return 0x11bc; |
962 | case 0x110c: return 0x11bd; | 964 | case 0x110c: return 0x11bd; |
963 | case 0x110e: return 0x11be; | 965 | case 0x110e: return 0x11be; |
964 | case 0x110f: return 0x11bf; | 966 | case 0x110f: return 0x11bf; |
965 | case 0x1110: return 0x11c0; | 967 | case 0x1110: return 0x11c0; |
966 | case 0x1111: return 0x11c1; | 968 | case 0x1111: return 0x11c1; |
967 | case 0x1112: return 0x11c2; | 969 | case 0x1112: return 0x11c2; |
968 | default: return 0; | 970 | default: return 0; |
969 | 971 | ||
970 | } | 972 | } |
971 | 973 | ||
972 | } else { //echar to schar | 974 | } else { //echar to schar |
973 | 975 | ||
974 | switch (c) { | 976 | switch (c) { |
975 | case 0x11a8: return 0x1100; | 977 | case 0x11a8: return 0x1100; |
976 | case 0x11a9: return 0x1101; | 978 | case 0x11a9: return 0x1101; |
977 | case 0x11ab: return 0x1102; | 979 | case 0x11ab: return 0x1102; |
978 | case 0x11ae: return 0x1103; | 980 | case 0x11ae: return 0x1103; |
979 | case 0x11af: return 0x1105; | 981 | case 0x11af: return 0x1105; |
980 | case 0x11b7: return 0x1106; | 982 | case 0x11b7: return 0x1106; |
981 | case 0x11b8: return 0x1107; | 983 | case 0x11b8: return 0x1107; |
982 | case 0x11ba: return 0x1109; | 984 | case 0x11ba: return 0x1109; |
983 | case 0x11bb: return 0x110a; | 985 | case 0x11bb: return 0x110a; |
984 | case 0x11bc: return 0x110b; | 986 | case 0x11bc: return 0x110b; |
985 | case 0x11bd: return 0x110c; | 987 | case 0x11bd: return 0x110c; |
986 | case 0x11be: return 0x110e; | 988 | case 0x11be: return 0x110e; |
987 | case 0x11bf: return 0x110f; | 989 | case 0x11bf: return 0x110f; |
988 | case 0x11c0: return 0x1110; | 990 | case 0x11c0: return 0x1110; |
989 | case 0x11c1: return 0x1111; | 991 | case 0x11c1: return 0x1111; |
990 | case 0x11c2: return 0x1112; | 992 | case 0x11c2: return 0x1112; |
991 | default: return 0; | 993 | default: return 0; |
992 | 994 | ||
993 | } | 995 | } |
994 | 996 | ||
995 | } | 997 | } |
996 | } | 998 | } |
997 | 999 | ||
998 | 1000 | ||
999 | // Keys::Keys {{{1 | 1001 | // Keys::Keys {{{1 |
1000 | 1002 | ||
1001 | Keys::Keys() { | 1003 | Keys::Keys() { |
1002 | 1004 | ||
1003 | Config *config = new Config ("multikey"); | 1005 | Config *config = new Config ("multikey"); |
1004 | config->setGroup( "keymaps" ); | 1006 | config->setGroup( "keymaps" ); |
1005 | QString map = config->readEntry( "current" ); | 1007 | QString map = config->readEntry( "current" ); |
1006 | delete config; | 1008 | delete config; |
1007 | 1009 | ||
1008 | if (map.isNull() || !(QFile(map).exists())) { | 1010 | if (map.isNull() || !(QFile(map).exists())) { |
1009 | 1011 | ||
1010 | Config *config = new Config("locale"); | 1012 | Config *config = new Config("locale"); |
1011 | config->setGroup( "Language" ); | 1013 | config->setGroup( "Language" ); |
1012 | QString l = config->readEntry( "Language" , "en" ); | 1014 | QString l = config->readEntry( "Language" , "en" ); |
1013 | delete config; | 1015 | delete config; |
1014 | 1016 | ||
1015 | map = QPEApplication::qpeDir() + "/share/multikey/" | 1017 | map = QPEApplication::qpeDir() + "/share/multikey/" |
1016 | + l + ".keymap"; | 1018 | + l + ".keymap"; |
1017 | 1019 | ||
1018 | } | 1020 | } |
1019 | 1021 | ||
1020 | setKeysFromFile(map); | 1022 | setKeysFromFile(map); |
1021 | } | 1023 | } |
1022 | 1024 | ||
1023 | Keys::Keys(const char * filename) { | 1025 | Keys::Keys(const char * filename) { |
1024 | 1026 | ||
1025 | setKeysFromFile(filename); | 1027 | setKeysFromFile(filename); |
1026 | } | 1028 | } |
1027 | 1029 | ||
1028 | // Keys::setKeysFromFile {{{2 | 1030 | // Keys::setKeysFromFile {{{2 |
1029 | void Keys::setKeysFromFile(const char * filename) { | 1031 | void Keys::setKeysFromFile(const char * filename) { |
1030 | 1032 | ||
1031 | QFile f(filename); | 1033 | QFile f(filename); |
1032 | 1034 | ||
1033 | if (f.open(IO_ReadOnly)) { | 1035 | if (f.open(IO_ReadOnly)) { |
1034 | 1036 | ||
1035 | QTextStream t(&f); | 1037 | QTextStream t(&f); |
1036 | int row; | 1038 | int row; |
1037 | int qcode; | 1039 | int qcode; |
1038 | ushort unicode; | 1040 | ushort unicode; |
1039 | int width; | 1041 | int width; |
1040 | QString buf; | 1042 | QString buf; |
1041 | QString comment; | 1043 | QString comment; |
1042 | char * xpm[256]; //couldnt be larger than that... could it? | 1044 | char * xpm[256]; //couldnt be larger than that... could it? |
1043 | QPixmap *xpm2pix = 0; | 1045 | QPixmap *xpm2pix = 0; |
1044 | 1046 | ||
1045 | buf = t.readLine(); | 1047 | buf = t.readLine(); |
1046 | while (buf) { | 1048 | while (buf) { |
1047 | 1049 | ||
1048 | // get rid of comments | 1050 | // get rid of comments |
1049 | buf.replace(QRegExp("#.*$", FALSE, FALSE), ""); | 1051 | buf.replace(QRegExp("#.*$", FALSE, FALSE), ""); |
1050 | 1052 | ||
1051 | // key definition | 1053 | // key definition |
1052 | if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { | 1054 | if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { |
1053 | // no $1 type referencing!!! this implementation of regexp sucks | 1055 | // no $1 type referencing!!! this implementation of regexp sucks |
1054 | 1056 | ||
1055 | // dont know of any sscanf() type funcs in Qt lib | 1057 | // dont know of any sscanf() type funcs in Qt lib |
1056 | QTextStream tmp (buf, IO_ReadOnly); | 1058 | QTextStream tmp (buf, IO_ReadOnly); |
1057 | tmp >> row >> qcode >> unicode >> width >> comment; | 1059 | tmp >> row >> qcode >> unicode >> width >> comment; |
1058 | 1060 | ||
1059 | buf = t.readLine(); | 1061 | buf = t.readLine(); |
1060 | int xpmLineCount = 0; | 1062 | int xpmLineCount = 0; |
1061 | xpm2pix = 0; | 1063 | xpm2pix = 0; |
1062 | 1064 | ||
1063 | // erase blank space | 1065 | // erase blank space |
1064 | while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); | 1066 | while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); |
1065 | 1067 | ||
1066 | while (buf.contains(QRegExp("^\\s*\".*\""))) { | 1068 | while (buf.contains(QRegExp("^\\s*\".*\""))) { |
1067 | 1069 | ||
1068 | QString xpmBuf = buf.stripWhiteSpace(); | 1070 | QString xpmBuf = buf.stripWhiteSpace(); |
1069 | 1071 | ||
1070 | xpm[xpmLineCount] = new char [xpmBuf.length()]; | 1072 | xpm[xpmLineCount] = new char [xpmBuf.length()]; |
1071 | 1073 | ||
1072 | int j = 0; | 1074 | int j = 0; |
1073 | for (ushort i = 0; i < xpmBuf.length(); i++) { | 1075 | for (ushort i = 0; i < xpmBuf.length(); i++) { |
1074 | if (xpmBuf[i].latin1() != '"') { | 1076 | if (xpmBuf[i].latin1() != '"') { |
1075 | 1077 | ||
1076 | ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); | 1078 | ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); |
1077 | j++; | 1079 | j++; |
1078 | } | 1080 | } |
1079 | 1081 | ||
1080 | } | 1082 | } |
1081 | // have to close that facker up | 1083 | // have to close that facker up |
1082 | ((char *)xpm[xpmLineCount])[j] = '\0'; | 1084 | ((char *)xpm[xpmLineCount])[j] = '\0'; |
1083 | 1085 | ||
1084 | xpmLineCount++; | 1086 | xpmLineCount++; |
1085 | buf = t.readLine(); | 1087 | buf = t.readLine(); |
1086 | } | 1088 | } |
1087 | if (xpmLineCount) { | 1089 | if (xpmLineCount) { |
1088 | 1090 | ||
1089 | xpm2pix = new QPixmap((const char **)xpm); | 1091 | xpm2pix = new QPixmap((const char **)xpm); |
1090 | for (int i = 0; i < xpmLineCount; i++) | 1092 | for (int i = 0; i < xpmLineCount; i++) |
1091 | 1093 | ||
1092 | delete [] (xpm[i]); | 1094 | delete [] (xpm[i]); |
1093 | 1095 | ||
1094 | } | 1096 | } |
1095 | setKey(row, qcode, unicode, width, xpm2pix); | 1097 | setKey(row, qcode, unicode, width, xpm2pix); |
1096 | } | 1098 | } |
1097 | 1099 | ||
1098 | // shift map | 1100 | // shift map |
1099 | else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { | 1101 | else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { |
1100 | 1102 | ||
1101 | QTextStream tmp (buf, IO_ReadOnly); | 1103 | QTextStream tmp (buf, IO_ReadOnly); |
1102 | ushort lower, shift; | 1104 | ushort lower, shift; |
1103 | tmp >> lower >> shift; | 1105 | tmp >> lower >> shift; |
1104 | 1106 | ||
1105 | shiftMap.insert(lower, shift); | 1107 | shiftMap.insert(lower, shift); |
1106 | 1108 | ||
1107 | buf = t.readLine(); | 1109 | buf = t.readLine(); |
1108 | } | 1110 | } |
1109 | 1111 | ||
1110 | // meta key map | 1112 | // meta key map |
1111 | else if (buf.contains(QRegExp("^\\s*m\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { | 1113 | else if (buf.contains(QRegExp("^\\s*m\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { |
1112 | 1114 | ||
1113 | QTextStream tmp (buf, IO_ReadOnly); | 1115 | QTextStream tmp (buf, IO_ReadOnly); |
1114 | ushort lower, shift; | 1116 | ushort lower, shift; |
1115 | QChar m; | 1117 | QChar m; |
1116 | tmp >> m >> lower >> shift; | 1118 | tmp >> m >> lower >> shift; |
1117 | 1119 | ||
1118 | metaMap.insert(lower, shift); | 1120 | metaMap.insert(lower, shift); |
1119 | 1121 | ||
1120 | buf = t.readLine(); | 1122 | buf = t.readLine(); |
1121 | } | 1123 | } |
1122 | 1124 | ||
1123 | // other variables like lang & title | 1125 | // other variables like lang & title |
1124 | else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { | 1126 | else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { |
1125 | 1127 | ||
1126 | QTextStream tmp (buf, IO_ReadOnly); | 1128 | QTextStream tmp (buf, IO_ReadOnly); |
1127 | QString name, equals, value; | 1129 | QString name, equals, value; |
1128 | 1130 | ||
1129 | tmp >> name >> equals >> value; | 1131 | tmp >> name >> equals >> value; |
1130 | 1132 | ||
1131 | if (name == "lang") { | 1133 | if (name == "lang") { |
1132 | 1134 | ||
1133 | lang = value; | 1135 | lang = value; |
1134 | 1136 | ||
1135 | } | 1137 | } |
1136 | 1138 | ||
1137 | buf = t.readLine(); | 1139 | buf = t.readLine(); |
1138 | } | 1140 | } |
1139 | // comments | 1141 | // comments |
1140 | else if (buf.contains(QRegExp("^\\s*#"))) { | 1142 | else if (buf.contains(QRegExp("^\\s*#"))) { |
1141 | 1143 | ||
1142 | buf = t.readLine(); | 1144 | buf = t.readLine(); |
1143 | 1145 | ||
1144 | } else { // blank line, or garbage | 1146 | } else { // blank line, or garbage |
1145 | 1147 | ||
1146 | buf = t.readLine(); | 1148 | buf = t.readLine(); |
1147 | 1149 | ||
1148 | } | 1150 | } |
1149 | 1151 | ||
1150 | } | 1152 | } |
1151 | f.close(); | 1153 | f.close(); |
1152 | } | 1154 | } |
1153 | 1155 | ||
1154 | } | 1156 | } |
1155 | 1157 | ||
1156 | // Keys::setKey {{{2 | 1158 | // Keys::setKey {{{2 |
1157 | void Keys::setKey(const int row, const int qcode, const ushort unicode, | 1159 | void Keys::setKey(const int row, const int qcode, const ushort unicode, |
1158 | const int width, QPixmap *pix) { | 1160 | const int width, QPixmap *pix) { |
1159 | 1161 | ||
1160 | Key * key; | 1162 | Key * key; |
1161 | key = new Key; | 1163 | key = new Key; |
1162 | key->qcode = qcode; | 1164 | key->qcode = qcode; |
1163 | key->unicode = unicode; | 1165 | key->unicode = unicode; |
1164 | key->width = width; | 1166 | key->width = width; |
1165 | 1167 | ||
1166 | // share key->pressed between same keys | 1168 | // share key->pressed between same keys |
1167 | bool found = 0; | 1169 | bool found = 0; |
1168 | for (int i = 1; i <= 5; i++) { | 1170 | for (int i = 1; i <= 5; i++) { |
1169 | for (unsigned int j = 0; j < keys[i].count(); j++) | 1171 | for (unsigned int j = 0; j < keys[i].count(); j++) |
1170 | if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { | 1172 | if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { |
1171 | 1173 | ||
1172 | key->pressed = keys[i].at(j)->pressed; | 1174 | key->pressed = keys[i].at(j)->pressed; |
1173 | found = 1; | 1175 | found = 1; |
1174 | } | 1176 | } |
1175 | 1177 | ||
1176 | } | 1178 | } |
1177 | if (!found) { | 1179 | if (!found) { |
1178 | 1180 | ||
1179 | key->pressed = new bool; | 1181 | key->pressed = new bool; |
1180 | *(key->pressed) = 0; | 1182 | *(key->pressed) = 0; |
1181 | } | 1183 | } |
1182 | 1184 | ||
1183 | key->pix = pix; | 1185 | key->pix = pix; |
1184 | 1186 | ||
1185 | 1187 | ||
1186 | keys[row].append(key); | 1188 | keys[row].append(key); |
1187 | } | 1189 | } |
1188 | 1190 | ||
1189 | // Keys::~Keys {{{2 | 1191 | // Keys::~Keys {{{2 |
1190 | Keys::~Keys() { | 1192 | Keys::~Keys() { |
1191 | 1193 | ||
1192 | for (int i = 1; i <= 5; i++) | 1194 | for (int i = 1; i <= 5; i++) |
1193 | for (unsigned int j = 0; j < keys[i].count(); j++) | 1195 | for (unsigned int j = 0; j < keys[i].count(); j++) |
1194 | delete keys[i].at(j); | 1196 | delete keys[i].at(j); |
1195 | 1197 | ||
1196 | } | 1198 | } |
1197 | 1199 | ||
1198 | // Keys:: other functions {{{2 | 1200 | // Keys:: other functions {{{2 |
1199 | int Keys::width(const int row, const int col) { | 1201 | int Keys::width(const int row, const int col) { |
1200 | 1202 | ||
1201 | return keys[row].at(col)->width; | 1203 | return keys[row].at(col)->width; |
1202 | 1204 | ||
1203 | } | 1205 | } |
1204 | ushort Keys::uni(const int row, const int col) { | 1206 | ushort Keys::uni(const int row, const int col) { |
1205 | 1207 | ||
1206 | return keys[row].at(col)->unicode; | 1208 | return keys[row].at(col)->unicode; |
1207 | 1209 | ||
1208 | } | 1210 | } |
1209 | 1211 | ||
1210 | int Keys::qcode(const int row, const int col) { | 1212 | int Keys::qcode(const int row, const int col) { |
1211 | 1213 | ||
1212 | return keys[row].at(col)->qcode; | 1214 | return keys[row].at(col)->qcode; |
1213 | } | 1215 | } |
1214 | 1216 | ||
1215 | QPixmap *Keys::pix(const int row, const int col) { | 1217 | QPixmap *Keys::pix(const int row, const int col) { |
1216 | 1218 | ||
1217 | return keys[row].at(col)->pix; | 1219 | return keys[row].at(col)->pix; |
1218 | 1220 | ||
1219 | } | 1221 | } |
1220 | bool Keys::pressed(const int row, const int col) { | 1222 | bool Keys::pressed(const int row, const int col) { |
1221 | 1223 | ||
1222 | return *(keys[row].at(col)->pressed); | 1224 | return *(keys[row].at(col)->pressed); |
1223 | } | 1225 | } |
1224 | 1226 | ||
1225 | int Keys::numKeys(const int row) { | 1227 | int Keys::numKeys(const int row) { |
1226 | 1228 | ||
1227 | return keys[row].count(); | 1229 | return keys[row].count(); |
1228 | } | 1230 | } |
1229 | 1231 | ||
1230 | void Keys::setPressed(const int row, const int col, const bool pressed) { | 1232 | void Keys::setPressed(const int row, const int col, const bool pressed) { |
1231 | 1233 | ||
1232 | *(keys[row].at(col)->pressed) = pressed; | 1234 | *(keys[row].at(col)->pressed) = pressed; |
1233 | } | 1235 | } |
1234 | 1236 | ||
1235 | ushort Keys::shift(const ushort uni) { | 1237 | ushort Keys::shift(const ushort uni) { |
1236 | 1238 | ||
1237 | if (shiftMap[uni]) { | 1239 | if (shiftMap[uni]) { |
1238 | 1240 | ||
1239 | return shiftMap[uni]; | 1241 | return shiftMap[uni]; |
1240 | } | 1242 | } |
1241 | else | 1243 | else |
1242 | return 0; | 1244 | return 0; |
1243 | 1245 | ||
1244 | } | 1246 | } |
1245 | 1247 | ||
1246 | ushort Keys::meta(const ushort uni) { | 1248 | ushort Keys::meta(const ushort uni) { |
1247 | 1249 | ||
1248 | if (metaMap[uni]) { | 1250 | if (metaMap[uni]) { |
1249 | 1251 | ||
1250 | return metaMap[uni]; | 1252 | return metaMap[uni]; |
1251 | } | 1253 | } |
1252 | else | 1254 | else |
1253 | return 0; | 1255 | return 0; |
1254 | 1256 | ||
1255 | } | 1257 | } |
1256 | 1258 | ||
1257 | bool *Keys::pressedPtr(const int row, const int col) { | 1259 | bool *Keys::pressedPtr(const int row, const int col) { |
1258 | 1260 | ||
1259 | return keys[row].at(col)->pressed; | 1261 | return keys[row].at(col)->pressed; |
1260 | } | 1262 | } |