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,824 +1,842 @@ | |||
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: |