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