-rw-r--r-- | inputmethods/multikey/keyboard.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp index 92da8ca..3e43978 100644 --- a/inputmethods/multikey/keyboard.cpp +++ b/inputmethods/multikey/keyboard.cpp | |||
@@ -1,955 +1,962 @@ | |||
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 | 22 | ||
23 | #include <qpe/global.h> | 23 | #include <qpe/global.h> |
24 | 24 | ||
25 | #include <qwindowsystem_qws.h> | 25 | #include <qwindowsystem_qws.h> |
26 | #include <qpainter.h> | 26 | #include <qpainter.h> |
27 | #include <qfontmetrics.h> | 27 | #include <qfontmetrics.h> |
28 | #include <qtimer.h> | 28 | #include <qtimer.h> |
29 | #include <qpe/qpeapplication.h> | 29 | #include <qpe/qpeapplication.h> |
30 | #include <qpe/config.h> | 30 | #include <qpe/config.h> |
31 | #include <ctype.h> | 31 | #include <ctype.h> |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qtextstream.h> | 33 | #include <qtextstream.h> |
34 | 34 | ||
35 | #include <sys/utsname.h> | 35 | #include <sys/utsname.h> |
36 | 36 | ||
37 | 37 | ||
38 | #define USE_SMALL_BACKSPACE | 38 | #define USE_SMALL_BACKSPACE |
39 | 39 | ||
40 | /* Keyboard::Keyboard {{{1 */ | 40 | /* Keyboard::Keyboard {{{1 */ |
41 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : | 41 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : |
42 | QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), | 42 | QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), |
43 | alt(0), useLargeKeys(TRUE), usePicks(0), pressedKeyRow(-1), pressedKeyCol(-1), | 43 | alt(0), useLargeKeys(TRUE), usePicks(0), pressedKeyRow(-1), pressedKeyCol(-1), |
44 | unicode(-1), qkeycode(0), modifiers(0), LANG("ko"), schar(0), mchar(0), echar(0) | 44 | unicode(-1), qkeycode(0), modifiers(0), LANG("ko"), schar(0), mchar(0), echar(0) |
45 | { | 45 | { |
46 | // get the default font | ||
47 | Config qpeConfig( "qpe" ); | ||
48 | qpeConfig.setGroup( "Appearance" ); | ||
49 | QString familyStr = qpeConfig.readEntry( "FontFamily", "fixed" ); | ||
50 | |||
51 | setFont( QFont( familyStr, 8 ) ); | ||
46 | 52 | ||
47 | picks = new KeyboardPicks( this ); | 53 | picks = new KeyboardPicks( this ); |
48 | picks->setFont( QFont( "helvetica", 8 ) ); | 54 | picks->setFont( QFont( familyStr, 8 ) ); |
49 | setFont( QFont( "helvetica", 8 ) ); | ||
50 | picks->initialise(); | 55 | picks->initialise(); |
51 | if (usePicks) { | 56 | if (usePicks) { |
52 | 57 | ||
53 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 58 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
54 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 59 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
55 | 60 | ||
56 | } else picks->hide(); | 61 | } else picks->hide(); |
57 | 62 | ||
58 | Config config("locale"); | 63 | Config config("locale"); |
59 | config.setGroup( "Language" ); | 64 | config.setGroup( "Language" ); |
60 | LANG = config.readEntry( "Language" ); | 65 | //LANG = config.readEntry( "Language", "en" ); |
61 | if(LANG.isEmpty()) LANG = "en"; | 66 | LANG = "ko"; |
62 | 67 | ||
63 | repeatTimer = new QTimer( this ); | 68 | repeatTimer = new QTimer( this ); |
64 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); | 69 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); |
65 | 70 | ||
66 | } | 71 | } |
67 | 72 | ||
68 | /* Keyboard::resizeEvent {{{1 */ | 73 | /* Keyboard::resizeEvent {{{1 */ |
69 | void Keyboard::resizeEvent(QResizeEvent*) | 74 | void Keyboard::resizeEvent(QResizeEvent*) |
70 | { | 75 | { |
71 | int ph = picks->sizeHint().height(); | 76 | int ph = picks->sizeHint().height(); |
72 | picks->setGeometry( 0, 0, width(), ph ); | 77 | picks->setGeometry( 0, 0, width(), ph ); |
73 | keyHeight = (height()-(usePicks ? ph : 0))/5; | 78 | keyHeight = (height()-(usePicks ? ph : 0))/5; |
74 | 79 | ||
75 | int nk; // number of keys? | 80 | int nk; // number of keys? |
76 | if ( useLargeKeys ) { | 81 | if ( useLargeKeys ) { |
77 | nk = 15; | 82 | nk = 15; |
78 | } else { | 83 | } else { |
79 | nk = 19; | 84 | nk = 19; |
80 | } | 85 | } |
81 | defaultKeyWidth = (width()/nk)/2; | 86 | defaultKeyWidth = (width()/nk)/2; |
82 | xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? | 87 | xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? |
83 | 88 | ||
84 | } | 89 | } |
85 | 90 | ||
86 | /* KeyboardPicks::initialize {{{1 */ | 91 | /* KeyboardPicks::initialize {{{1 */ |
87 | void KeyboardPicks::initialise() | 92 | void KeyboardPicks::initialise() |
88 | { | 93 | { |
89 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); | 94 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); |
90 | mode = 0; | 95 | mode = 0; |
91 | dc = new KeyboardConfig(this); | 96 | dc = new KeyboardConfig(this); |
92 | configs.append(dc); | 97 | configs.append(dc); |
93 | } | 98 | } |
94 | 99 | ||
95 | /* KeyboardPicks::sizeHint {{{1 */ | 100 | /* KeyboardPicks::sizeHint {{{1 */ |
96 | QSize KeyboardPicks::sizeHint() const | 101 | QSize KeyboardPicks::sizeHint() const |
97 | { | 102 | { |
98 | return QSize(240,fontMetrics().lineSpacing()); | 103 | return QSize(240,fontMetrics().lineSpacing()); |
99 | } | 104 | } |
100 | 105 | ||
101 | 106 | ||
102 | /* KeyboardConfig::generateText {{{1 */ | 107 | /* KeyboardConfig::generateText {{{1 */ |
103 | void KeyboardConfig::generateText(const QString &s) | 108 | void KeyboardConfig::generateText(const QString &s) |
104 | { | 109 | { |
105 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 110 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
106 | for (int i=0; i<(int)backspaces; i++) { | 111 | for (int i=0; i<(int)backspaces; i++) { |
107 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); | 112 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); |
108 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); | 113 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); |
109 | } | 114 | } |
110 | for (int i=0; i<(int)s.length(); i++) { | 115 | for (int i=0; i<(int)s.length(); i++) { |
111 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); | 116 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); |
112 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); | 117 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); |
113 | } | 118 | } |
114 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); | 119 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); |
115 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); | 120 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); |
116 | backspaces = 0; | 121 | backspaces = 0; |
117 | #endif | 122 | #endif |
118 | } | 123 | } |
119 | 124 | ||
120 | 125 | ||
121 | 126 | ||
122 | 127 | ||
123 | /* Keyboard::paintEvent {{{1 */ | 128 | /* Keyboard::paintEvent {{{1 */ |
124 | void Keyboard::paintEvent(QPaintEvent* e) | 129 | void Keyboard::paintEvent(QPaintEvent* e) |
125 | { | 130 | { |
126 | QPainter painter(this); | 131 | QPainter painter(this); |
127 | painter.setClipRect(e->rect()); | 132 | painter.setClipRect(e->rect()); |
128 | drawKeyboard( painter ); | 133 | drawKeyboard( painter ); |
129 | picks->dc->draw( &painter ); | 134 | picks->dc->draw( &painter ); |
130 | } | 135 | } |
131 | 136 | ||
132 | 137 | ||
133 | /* Keyboard::drawKeyboard {{{1 */ | 138 | /* Keyboard::drawKeyboard {{{1 */ |
134 | 139 | ||
135 | void Keyboard::drawKeyboard(QPainter &p, int row, int col) | 140 | void Keyboard::drawKeyboard(QPainter &p, int row, int col) |
136 | { | 141 | { |
137 | QColor keycolor = | 142 | QColor keycolor = |
138 | QColor(240,240,240); | 143 | QColor(240,240,240); |
139 | QColor keycolor_pressed = QColor(171,183,198); | 144 | QColor keycolor_pressed = QColor(171,183,198); |
140 | QColor keycolor_lines = QColor(138,148,160); | 145 | QColor keycolor_lines = QColor(138,148,160); |
141 | QColor textcolor = QColor(43,54,68); | 146 | QColor textcolor = QColor(43,54,68); |
142 | 147 | ||
143 | 148 | ||
144 | if (row != -1 && col != -1) { //just redraw one key | 149 | if (row != -1 && col != -1) { //just redraw one key |
145 | 150 | ||
146 | int x = 0; | 151 | int x = 0; |
147 | for (int i = 0; i < col; i++) { | 152 | for (int i = 0; i < col; i++) { |
148 | 153 | ||
149 | x += keys.width(row, i) * defaultKeyWidth; | 154 | x += keys.width(row, i) * defaultKeyWidth; |
150 | } | 155 | } |
151 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 156 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
152 | 157 | ||
153 | int keyWidth = keys.width(row, col); | 158 | int keyWidth = keys.width(row, col); |
154 | 159 | ||
155 | p.fillRect(x + 1, y + 1, | 160 | p.fillRect(x + 1, y + 1, |
156 | keyWidth * defaultKeyWidth - 1, keyHeight - 1, | 161 | keyWidth * defaultKeyWidth - 1, keyHeight - 1, |
157 | pressed || keys.pressed(row, col) ? keycolor_pressed : keycolor); | 162 | pressed || keys.pressed(row, col) ? keycolor_pressed : keycolor); |
158 | 163 | ||
159 | QPixmap *pix = keys.pix(row,col); | 164 | QPixmap *pix = keys.pix(row,col); |
160 | 165 | ||
161 | ushort c = keys.uni(row, col); | 166 | ushort c = keys.uni(row, col); |
162 | 167 | ||
163 | if (!pix) { | 168 | if (!pix) { |
164 | p.setPen(textcolor); | 169 | p.setPen(textcolor); |
165 | p.drawText(x, y, | 170 | p.drawText(x, y, |
166 | defaultKeyWidth * keyWidth, keyHeight, | 171 | defaultKeyWidth * keyWidth, keyHeight, |
167 | AlignCenter, ((shift || lock) && keys.shift(c)) ? (QChar)keys.shift(c) : (QChar)c); | 172 | AlignCenter, ((shift || lock) && keys.shift(c)) ? (QChar)keys.shift(c) : (QChar)c); |
168 | } | 173 | } |
169 | else | 174 | else |
170 | // center the image in the middle of the key | 175 | // center the image in the middle of the key |
171 | p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, | 176 | p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, |
172 | y + (keyHeight - pix->height())/2 + 1, | 177 | y + (keyHeight - pix->height())/2 + 1, |
173 | *pix ); | 178 | *pix ); |
174 | 179 | ||
175 | // this fixes the problem that the very right end of the board's vertical line | 180 | // this fixes the problem that the very right end of the board's vertical line |
176 | // gets painted over, because it's one pixel shorter than all other keys | 181 | // gets painted over, because it's one pixel shorter than all other keys |
177 | p.setPen(keycolor_lines); | 182 | p.setPen(keycolor_lines); |
178 | p.drawLine(width() - 1, 0, width() - 1, height()); | 183 | p.drawLine(width() - 1, 0, width() - 1, height()); |
179 | 184 | ||
180 | } else { | 185 | } else { |
181 | 186 | ||
182 | 187 | ||
183 | p.fillRect(0, 0, width(), height(), keycolor); | 188 | p.fillRect(0, 0, width(), height(), keycolor); |
184 | 189 | ||
185 | for (row = 1; row <= 5; row++) { | 190 | for (row = 1; row <= 5; row++) { |
186 | 191 | ||
187 | int x = 0; | 192 | int x = 0; |
188 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 193 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
189 | 194 | ||
190 | p.setPen(keycolor_lines); | 195 | p.setPen(keycolor_lines); |
191 | p.drawLine(x, y, x + width(), y); | 196 | p.drawLine(x, y, x + width(), y); |
192 | 197 | ||
193 | for (int col = 0; col < keys.numKeys(row); col++) { | 198 | for (int col = 0; col < keys.numKeys(row); col++) { |
194 | 199 | ||
195 | QPixmap *pix = keys.pix(row, col); | 200 | QPixmap *pix = keys.pix(row, col); |
196 | int keyWidth = keys.width(row, col); | 201 | int keyWidth = keys.width(row, col); |
197 | 202 | ||
198 | 203 | ||
199 | int keyWidthPix = defaultKeyWidth * keyWidth; | 204 | int keyWidthPix = defaultKeyWidth * keyWidth; |
200 | 205 | ||
201 | if (keys.pressed(row, col)) | 206 | if (keys.pressed(row, col)) |
202 | p.fillRect(x+1, y+1, keyWidthPix - 1, | 207 | p.fillRect(x+1, y+1, keyWidthPix - 1, |
203 | keyHeight - 1, keycolor_pressed); | 208 | keyHeight - 1, keycolor_pressed); |
204 | 209 | ||
205 | ushort c = keys.uni(row, col); | 210 | ushort c = keys.uni(row, col); |
206 | 211 | ||
207 | if (!pix) { | 212 | if (!pix) { |
208 | p.setPen(textcolor); | 213 | p.setPen(textcolor); |
209 | p.drawText(x, y, | 214 | p.drawText(x, y, |
210 | keyWidthPix, keyHeight, | 215 | keyWidthPix, keyHeight, |
211 | AlignCenter, ((shift || lock) && keys.shift(c)) ? (QChar)keys.shift(c) : (QChar)c); | 216 | AlignCenter, ((shift || lock) && keys.shift(c)) ? (QChar)keys.shift(c) : (QChar)c); |
212 | } | 217 | } |
213 | else { | 218 | else { |
214 | // center the image in the middle of the key | 219 | // center the image in the middle of the key |
215 | p.drawPixmap( x + (keyWidthPix - pix->width())/2, | 220 | p.drawPixmap( x + (keyWidthPix - pix->width())/2, |
216 | y + (keyHeight - pix->height())/2 + 1, | 221 | y + (keyHeight - pix->height())/2 + 1, |
217 | QPixmap(*pix) ); | 222 | QPixmap(*pix) ); |
218 | } | 223 | } |
219 | 224 | ||
220 | p.setPen(keycolor_lines); | 225 | p.setPen(keycolor_lines); |
221 | p.drawLine(x, y, x, y + keyHeight); | 226 | p.drawLine(x, y, x, y + keyHeight); |
222 | 227 | ||
223 | x += keyWidthPix; | 228 | x += keyWidthPix; |
224 | } | 229 | } |
225 | 230 | ||
226 | 231 | ||
227 | } | 232 | } |
228 | p.drawLine(0, height() - 1, width(), height() - 1); | 233 | p.drawLine(0, height() - 1, width(), height() - 1); |
229 | p.drawLine(width() - 1, 0, width() - 1, height()); | 234 | p.drawLine(width() - 1, 0, width() - 1, height()); |
230 | } | 235 | } |
231 | 236 | ||
232 | } | 237 | } |
233 | 238 | ||
234 | 239 | ||
235 | /* Keyboard::mousePressEvent {{{1 */ | 240 | /* Keyboard::mousePressEvent {{{1 */ |
236 | void Keyboard::mousePressEvent(QMouseEvent *e) | 241 | void Keyboard::mousePressEvent(QMouseEvent *e) |
237 | { | 242 | { |
238 | int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; | 243 | int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; |
239 | if (row > 5) row = 5; | 244 | if (row > 5) row = 5; |
240 | 245 | ||
241 | // figure out the column | 246 | // figure out the column |
242 | int col = 0; | 247 | int col = 0; |
243 | for (int w = 0; e->x() >= w; col++) | 248 | for (int w = 0; e->x() >= w; col++) |
244 | if (col < keys.numKeys(row)) // it segfaults if it trys to read past numKeys | 249 | if (col < keys.numKeys(row)) // it segfaults if it trys to read past numKeys |
245 | w += keys.width(row,col) * defaultKeyWidth; | 250 | w += keys.width(row,col) * defaultKeyWidth; |
246 | else break; | 251 | else break; |
247 | 252 | ||
248 | col --; // rewind one... | 253 | col --; // rewind one... |
249 | 254 | ||
250 | qkeycode = keys.qcode(row, col); | 255 | qkeycode = keys.qcode(row, col); |
251 | unicode = keys.uni(row, col); | 256 | unicode = keys.uni(row, col); |
252 | 257 | ||
253 | // might need to repaint if two or more of the same keys. | 258 | // might need to repaint if two or more of the same keys. |
254 | // should be faster if just paint one key even though multiple keys exist. | 259 | // should be faster if just paint one key even though multiple keys exist. |
255 | bool need_repaint = FALSE; | 260 | bool need_repaint = FALSE; |
256 | 261 | ||
257 | if (unicode == 0) { // either Qt char, or nothing | 262 | if (unicode == 0) { // either Qt char, or nothing |
258 | 263 | ||
259 | if (qkeycode == Qt::Key_F1) { // toggle the pickboard | 264 | if (qkeycode == Qt::Key_F1) { // toggle the pickboard |
260 | 265 | ||
261 | usePicks = !usePicks; | 266 | usePicks = !usePicks; |
262 | if (usePicks) { | 267 | if (usePicks) { |
263 | picks->show(); | 268 | picks->show(); |
264 | move(x(), y() - picks->height()); | 269 | move(x(), y() - picks->height()); |
265 | adjustSize(); | 270 | adjustSize(); |
266 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 271 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
267 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 272 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
268 | } else { | 273 | } else { |
269 | 274 | ||
270 | picks->hide(); | 275 | picks->hide(); |
271 | picks->resetState(); | 276 | picks->resetState(); |
272 | move(x(), y() + picks->height()); | 277 | move(x(), y() + picks->height()); |
273 | adjustSize(); | 278 | adjustSize(); |
274 | QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 279 | QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
275 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 280 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
276 | 281 | ||
277 | } | 282 | } |
278 | 283 | ||
279 | keys.setPressed(row, col, usePicks); | 284 | keys.setPressed(row, col, usePicks); |
280 | need_repaint = TRUE; | 285 | need_repaint = TRUE; |
281 | qkeycode = 0; // don't need to emit Key_F1 | 286 | qkeycode = 0; // don't need to emit Key_F1 |
282 | } else if (qkeycode == Qt::Key_Control) { | 287 | } else if (qkeycode == Qt::Key_Control) { |
283 | ctrl = keys.pressedPtr(row, col); | 288 | ctrl = keys.pressedPtr(row, col); |
284 | need_repaint = TRUE; | 289 | need_repaint = TRUE; |
285 | *ctrl = !keys.pressed(row, col); | 290 | *ctrl = !keys.pressed(row, col); |
286 | 291 | ||
287 | } else if (qkeycode == Qt::Key_Alt) { | 292 | } else if (qkeycode == Qt::Key_Alt) { |
288 | alt = keys.pressedPtr(row, col); | 293 | alt = keys.pressedPtr(row, col); |
289 | need_repaint = TRUE; | 294 | need_repaint = TRUE; |
290 | *alt = !keys.pressed(row, col); | 295 | *alt = !keys.pressed(row, col); |
291 | 296 | ||
292 | } else if (qkeycode == Qt::Key_Shift) { | 297 | } else if (qkeycode == Qt::Key_Shift) { |
293 | need_repaint = TRUE; | 298 | need_repaint = TRUE; |
294 | 299 | ||
295 | if (shift) { | 300 | if (shift) { |
296 | *shift = 0; | 301 | *shift = 0; |
297 | shift = 0; | 302 | shift = 0; |
298 | } | 303 | } |
299 | else { | 304 | else { |
300 | shift = keys.pressedPtr(row, col); | 305 | shift = keys.pressedPtr(row, col); |
301 | *shift = 1; | 306 | *shift = 1; |
302 | if (lock) { | 307 | if (lock) { |
303 | *lock = 0; | 308 | *lock = 0; |
304 | lock = 0; | 309 | lock = 0; |
305 | } | 310 | } |
306 | } | 311 | } |
307 | 312 | ||
308 | } else if (qkeycode == Qt::Key_CapsLock) { | 313 | } else if (qkeycode == Qt::Key_CapsLock) { |
309 | need_repaint = TRUE; | 314 | need_repaint = TRUE; |
310 | 315 | ||
311 | if (lock) { | 316 | if (lock) { |
312 | *lock = 0; | 317 | *lock = 0; |
313 | lock = 0; | 318 | lock = 0; |
314 | } | 319 | } |
315 | else { | 320 | else { |
316 | lock = keys.pressedPtr(row, col);; | 321 | lock = keys.pressedPtr(row, col);; |
317 | *lock = 1; | 322 | *lock = 1; |
318 | if (shift) { | 323 | if (shift) { |
319 | *shift = 0; | 324 | *shift = 0; |
320 | shift = 0; | 325 | shift = 0; |
321 | } | 326 | } |
322 | } | 327 | } |
323 | 328 | ||
324 | } | 329 | } |
325 | 330 | ||
326 | } | 331 | } |
327 | else { // normal char | 332 | else { // normal char |
328 | if ((shift || lock) && keys.shift(unicode)) { | 333 | if ((shift || lock) && keys.shift(unicode)) { |
329 | unicode = keys.shift(unicode); | 334 | unicode = keys.shift(unicode); |
330 | } | 335 | } |
331 | } | 336 | } |
332 | 337 | ||
333 | // korean parsing | 338 | // korean parsing |
334 | if (LANG == "ko") { | 339 | if (LANG == "ko") { |
335 | 340 | ||
336 | unicode = parseKoreanInput(unicode); | 341 | unicode = parseKoreanInput(unicode); |
337 | } | 342 | } |
338 | 343 | ||
339 | modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); | 344 | modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); |
340 | 345 | ||
341 | emit key(unicode, qkeycode, modifiers, true, false); | 346 | emit key(unicode, qkeycode, modifiers, true, false); |
342 | 347 | ||
343 | // pickboard stuff | 348 | // pickboard stuff |
344 | if (usePicks) { | 349 | if (usePicks) { |
345 | 350 | ||
346 | KeyboardConfig *dc = picks->dc; | 351 | KeyboardConfig *dc = picks->dc; |
347 | 352 | ||
348 | if (dc) { | 353 | if (dc) { |
349 | if (qkeycode == Qt::Key_Backspace) { | 354 | if (qkeycode == Qt::Key_Backspace) { |
350 | dc->input.remove(dc->input.last()); // remove last input | 355 | dc->input.remove(dc->input.last()); // remove last input |
351 | dc->decBackspaces(); | 356 | dc->decBackspaces(); |
352 | } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { | 357 | } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { |
353 | dc->input.clear(); | 358 | dc->input.clear(); |
354 | dc->resetBackspaces(); | 359 | dc->resetBackspaces(); |
355 | } else { | 360 | } else { |
356 | dc->add(QString(QChar(unicode))); | 361 | dc->add(QString(QChar(unicode))); |
357 | dc->incBackspaces(); | 362 | dc->incBackspaces(); |
358 | } | 363 | } |
359 | } | 364 | } |
360 | picks->repaint(); | 365 | picks->repaint(); |
361 | } | 366 | } |
362 | 367 | ||
363 | 368 | ||
364 | // painting | 369 | // painting |
365 | pressed = TRUE; | 370 | pressed = TRUE; |
366 | 371 | ||
367 | pressedKeyRow = row; | 372 | pressedKeyRow = row; |
368 | pressedKeyCol = col; | 373 | pressedKeyCol = col; |
369 | 374 | ||
370 | if (need_repaint) repaint(FALSE); | 375 | if (need_repaint) repaint(FALSE); |
371 | else { // just paint the one key pressed | 376 | else { // just paint the one key pressed |
372 | 377 | ||
373 | 378 | ||
374 | 379 | ||
375 | QPainter p(this); | 380 | QPainter p(this); |
376 | drawKeyboard(p, row, col); | 381 | drawKeyboard(p, row, col); |
377 | 382 | ||
378 | } | 383 | } |
379 | 384 | ||
380 | pressTid = startTimer(80); | 385 | pressTid = startTimer(80); |
381 | 386 | ||
382 | } | 387 | } |
383 | 388 | ||
384 | 389 | ||
385 | /* Keyboard::mouseReleaseEvent {{{1 */ | 390 | /* Keyboard::mouseReleaseEvent {{{1 */ |
386 | void Keyboard::mouseReleaseEvent(QMouseEvent*) | 391 | void Keyboard::mouseReleaseEvent(QMouseEvent*) |
387 | { | 392 | { |
388 | pressed = FALSE; | 393 | pressed = FALSE; |
389 | if ( pressTid == 0 ) | 394 | if ( pressTid == 0 ) |
390 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 395 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
391 | if ( unicode != -1 ) { | 396 | if ( unicode != -1 ) { |
392 | emit key( unicode, qkeycode, modifiers, false, false ); | 397 | emit key( unicode, qkeycode, modifiers, false, false ); |
393 | repeatTimer->stop(); | 398 | repeatTimer->stop(); |
394 | } | 399 | } |
395 | #endif | 400 | #endif |
396 | if (shift && unicode != 0) { | 401 | if (shift && unicode != 0) { |
397 | 402 | ||
398 | 403 | ||
399 | *shift = 0; // unpress shift key | 404 | *shift = 0; // unpress shift key |
400 | shift = 0; // reset the shift pointer | 405 | shift = 0; // reset the shift pointer |
401 | repaint(FALSE); | 406 | repaint(FALSE); |
402 | 407 | ||
403 | } | 408 | } |
404 | else | 409 | else |
405 | 410 | ||
406 | clearHighlight(); | 411 | clearHighlight(); |
407 | } | 412 | } |
408 | 413 | ||
409 | /* Keyboard::timerEvent {{{1 */ | 414 | /* Keyboard::timerEvent {{{1 */ |
410 | /* | 415 | /* |
411 | void Keyboard::timerEvent(QTimerEvent* e) | 416 | void Keyboard::timerEvent(QTimerEvent* e) |
412 | { | 417 | { |
413 | if ( e->timerId() == pressTid ) { | 418 | if ( e->timerId() == pressTid ) { |
414 | killTimer(pressTid); | 419 | killTimer(pressTid); |
415 | pressTid = 0; | 420 | pressTid = 0; |
416 | if ( !pressed ) | 421 | if ( !pressed ) |
417 | cout << "calling clearHighlight from timerEvent\n"; | 422 | cout << "calling clearHighlight from timerEvent\n"; |
418 | clearHighlight(); | 423 | clearHighlight(); |
419 | } | 424 | } |
420 | } | 425 | } |
421 | */ | 426 | */ |
422 | 427 | ||
423 | void Keyboard::repeat() | 428 | void Keyboard::repeat() |
424 | { | 429 | { |
425 | 430 | ||
426 | repeatTimer->start( 200 ); | 431 | repeatTimer->start( 200 ); |
427 | emit key( unicode, 0, modifiers, true, true ); | 432 | emit key( unicode, 0, modifiers, true, true ); |
428 | } | 433 | } |
429 | 434 | ||
430 | void Keyboard::clearHighlight() | 435 | void Keyboard::clearHighlight() |
431 | { | 436 | { |
432 | if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { | 437 | if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { |
433 | int tmpRow = pressedKeyRow; | 438 | int tmpRow = pressedKeyRow; |
434 | int tmpCol = pressedKeyCol; | 439 | int tmpCol = pressedKeyCol; |
435 | 440 | ||
436 | pressedKeyRow = -1; | 441 | pressedKeyRow = -1; |
437 | pressedKeyCol = -1; | 442 | pressedKeyCol = -1; |
438 | 443 | ||
439 | QPainter p(this); | 444 | QPainter p(this); |
440 | drawKeyboard(p, tmpRow, tmpCol); | 445 | drawKeyboard(p, tmpRow, tmpCol); |
441 | } | 446 | } |
442 | } | 447 | } |
443 | 448 | ||
444 | 449 | ||
445 | /* Keyboard::sizeHint {{{1 */ | 450 | /* Keyboard::sizeHint {{{1 */ |
446 | QSize Keyboard::sizeHint() const | 451 | QSize Keyboard::sizeHint() const |
447 | { | 452 | { |
448 | QFontMetrics fm=fontMetrics(); | 453 | QFontMetrics fm=fontMetrics(); |
449 | int keyHeight = fm.lineSpacing()+2; | 454 | int keyHeight = fm.lineSpacing(); |
450 | 455 | ||
451 | return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1); | 456 | return QSize( 240, keyHeight * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1); |
452 | } | 457 | } |
453 | 458 | ||
454 | 459 | ||
455 | void Keyboard::resetState() | 460 | void Keyboard::resetState() |
456 | { | 461 | { |
457 | schar = mchar = echar = 0; | 462 | schar = mchar = echar = 0; |
458 | picks->resetState(); | 463 | picks->resetState(); |
459 | } | 464 | } |
460 | 465 | ||
461 | /* korean input functions {{{1 | 466 | /* korean input functions {{{1 |
462 | * | 467 | * |
463 | * TODO | 468 | * TODO |
464 | * one major problem with this implementation is that you can't move the | 469 | * one major problem with this implementation is that you can't move the |
465 | * cursor after inputing korean chars, otherwise it will eat up and replace | 470 | * cursor after inputing korean chars, otherwise it will eat up and replace |
466 | * the char before the cursor you move to. fix that | 471 | * the char before the cursor you move to. fix that |
467 | * | 472 | * |
468 | * make a kor/eng swaping key | 473 | * make a kor/eng swaping key |
469 | * | 474 | * |
470 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 475 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
471 | * | 476 | * |
472 | * how korean input works | 477 | * how korean input works |
473 | * | 478 | * |
474 | * all following chars means unicode char value and are in hex | 479 | * all following chars means unicode char value and are in hex |
475 | * | 480 | * |
476 | * ÃÊÀ½ = schar (start char) | 481 | * ÃÊÀ½ = schar (start char) |
477 | * ÁßÀ½ = mchar (middle char) | 482 | * ÁßÀ½ = mchar (middle char) |
478 | * ³¡À½ = echar (end char) | 483 | * ³¡À½ = echar (end char) |
479 | * | 484 | * |
480 | * there are 19 schars. unicode position is at 1100 - 1112 | 485 | * there are 19 schars. unicode position is at 1100 - 1112 |
481 | * there are 21 mchars. unicode position is at 1161 - 1175 | 486 | * there are 21 mchars. unicode position is at 1161 - 1175 |
482 | * there are 27 echars. unicode position is at 11a8 - 11c2 | 487 | * there are 27 echars. unicode position is at 11a8 - 11c2 |
483 | * | 488 | * |
484 | * the map with everything combined is at ac00 - d7a3 | 489 | * the map with everything combined is at ac00 - d7a3 |
485 | * | 490 | * |
486 | */ | 491 | */ |
487 | 492 | ||
488 | ushort Keyboard::parseKoreanInput (ushort c) { | 493 | ushort Keyboard::parseKoreanInput (ushort c) { |
489 | 494 | ||
490 | if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) | 495 | if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) |
491 | || | 496 | || |
492 | (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode | 497 | (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode |
493 | && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { | 498 | && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { |
494 | 499 | ||
495 | schar = 0, mchar = 0, echar = 0; | 500 | schar = 0, mchar = 0, echar = 0; |
496 | return c; | 501 | return c; |
497 | } | 502 | } |
498 | 503 | ||
499 | if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input | 504 | if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input |
500 | 505 | ||
501 | if (schar == 0 || (schar != 0 && mchar == 0)) { | 506 | if (schar == 0 || (schar != 0 && mchar == 0)) { |
502 | schar = c; mchar = 0; echar = 0; | 507 | schar = c; mchar = 0; echar = 0; |
503 | return c; | 508 | return c; |
504 | } | 509 | } |
505 | else if (mchar != 0) { | 510 | else if (mchar != 0) { |
506 | 511 | ||
507 | if (echar == 0) { | 512 | if (echar == 0) { |
508 | 513 | ||
509 | if (!(echar = constoe(c))) { | 514 | if (!(echar = constoe(c))) { |
510 | 515 | ||
511 | schar = c; mchar = 0; echar = 0; | 516 | schar = c; mchar = 0; echar = 0; |
512 | return c; | 517 | return c; |
513 | } | 518 | } |
514 | 519 | ||
515 | } | 520 | } |
516 | else { // must figure out what the echar is | 521 | else { // must figure out what the echar is |
517 | 522 | ||
518 | if (echar == 0x11a8) { // ¤¡ | 523 | if (echar == 0x11a8) { // ¤¡ |
519 | 524 | ||
520 | if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡ | 525 | if (c == 0x1100) echar = 0x11a9; // ¤¡ + ¤¡ |
521 | else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ | 526 | else if (c == 0x1109) echar = 0x11aa; // ¤¡ + ¤µ |
522 | else { | 527 | else { |
523 | schar = c; mchar = 0; echar = 0; | 528 | schar = c; mchar = 0; echar = 0; |
524 | return c; | 529 | return c; |
525 | } | 530 | } |
526 | 531 | ||
527 | } else if (echar == 0x11ab) { // ¤¤ | 532 | } else if (echar == 0x11ab) { // ¤¤ |
528 | 533 | ||
529 | if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸ | 534 | if (c == 0x110c) echar = 0x11ac; // ¤¤ + ¤¸ |
530 | else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾ | 535 | else if (c == 0x1112) echar = 0x11ad; // ¤¤ + ¤¾ |
531 | else { | 536 | else { |
532 | schar = c; mchar = 0; echar = 0; | 537 | schar = c; mchar = 0; echar = 0; |
533 | return c; | 538 | return c; |
534 | } | 539 | } |
535 | 540 | ||
536 | } else if (echar == 0x11af) { // ¤© | 541 | } else if (echar == 0x11af) { // ¤© |
537 | 542 | ||
538 | if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡ | 543 | if (c == 0x1100) echar = 0x11b0; // ¤© + ¤¡ |
539 | else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤± | 544 | else if (c == 0x1106) echar = 0x11b1; // ¤© + ¤± |
540 | else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤² | 545 | else if (c == 0x1107) echar = 0x11b2; // ¤© + ¤² |
541 | else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ | 546 | else if (c == 0x1109) echar = 0x11b3; // ¤© + ¤µ |
542 | else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼ | 547 | else if (c == 0x1110) echar = 0x11b4; // ¤© + ¤¼ |
543 | else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½ | 548 | else if (c == 0x1111) echar = 0x11b5; // ¤© + ¤½ |
544 | else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾ | 549 | else if (c == 0x1112) echar = 0x11b6; // ¤© + ¤¾ |
545 | else { | 550 | else { |
546 | schar = c; mchar = 0; echar = 0; | 551 | schar = c; mchar = 0; echar = 0; |
547 | return c; | 552 | return c; |
548 | } | 553 | } |
549 | 554 | ||
550 | } else if (echar == 0x11b8) { // ¤² | 555 | } else if (echar == 0x11b8) { // ¤² |
551 | 556 | ||
552 | if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ | 557 | if (c == 0x1109) echar = 0x11b9; // ¤² + ¤µ |
553 | else { | 558 | else { |
554 | schar = c; mchar = 0; echar = 0; | 559 | schar = c; mchar = 0; echar = 0; |
555 | return c; | 560 | return c; |
556 | } | 561 | } |
557 | 562 | ||
558 | } else if (echar == 0x11ba) { // ¤µ | 563 | } else if (echar == 0x11ba) { // ¤µ |
559 | 564 | ||
560 | if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ | 565 | if (c == 0x1109) echar = 0x11bb; // ¤µ + ¤µ |
561 | else { | 566 | else { |
562 | schar = c; mchar = 0; echar = 0; | 567 | schar = c; mchar = 0; echar = 0; |
563 | return c; | 568 | return c; |
564 | } | 569 | } |
565 | 570 | ||
566 | } else { // if any other char, cannot combine chars | 571 | } else { // if any other char, cannot combine chars |
567 | 572 | ||
568 | schar = c; mchar = 0; echar = 0; | 573 | schar = c; mchar = 0; echar = 0; |
569 | return c; | 574 | return c; |
570 | } | 575 | } |
571 | 576 | ||
572 | unicode = echar; | 577 | unicode = echar; |
573 | } | 578 | } |
574 | } | 579 | } |
575 | 580 | ||
576 | } | 581 | } |
577 | else if (0x1161 <= c && c <= 0x1175) { // mchar was input | 582 | else if (0x1161 <= c && c <= 0x1175) { // mchar was input |
578 | 583 | ||
579 | if (schar != 0 && mchar == 0) { mchar = c; } | 584 | if (schar != 0 && mchar == 0) { mchar = c; } |
580 | 585 | ||
581 | else if (schar != 0 && mchar != 0 && echar == 0) { | 586 | else if (schar != 0 && mchar != 0 && echar == 0) { |
582 | 587 | ||
583 | switch (mchar) { | 588 | switch (mchar) { |
584 | case 0x1169: | 589 | case 0x1169: |
585 | if (c == 0x1161) mchar = 0x116a; | 590 | if (c == 0x1161) mchar = 0x116a; |
586 | else if (c == 0x1162) mchar = 0x116b; | 591 | else if (c == 0x1162) mchar = 0x116b; |
587 | else if (c == 0x1175) mchar = 0x116c; | 592 | else if (c == 0x1175) mchar = 0x116c; |
588 | else { | 593 | else { |
589 | schar = 0; mchar = 0; echar = 0; | 594 | schar = 0; mchar = 0; echar = 0; |
590 | return c; | 595 | return c; |
591 | } | 596 | } |
592 | break; | 597 | break; |
593 | case 0x116e: | 598 | case 0x116e: |
594 | if (c == 0x1165) mchar = 0x116f; | 599 | if (c == 0x1165) mchar = 0x116f; |
595 | else if (c == 0x1166) mchar = 0x1170; | 600 | else if (c == 0x1166) mchar = 0x1170; |
596 | else if (c == 0x1175) mchar = 0x1171; | 601 | else if (c == 0x1175) mchar = 0x1171; |
597 | else { | 602 | else { |
598 | schar = 0; mchar = 0; echar = 0; | 603 | schar = 0; mchar = 0; echar = 0; |
599 | return c; | 604 | return c; |
600 | } | 605 | } |
601 | break; | 606 | break; |
602 | case 0x1173: | 607 | case 0x1173: |
603 | if (c == 0x1175) mchar = 0x1174; | 608 | if (c == 0x1175) mchar = 0x1174; |
604 | else { | 609 | else { |
605 | schar = 0; mchar = 0; echar = 0; | 610 | schar = 0; mchar = 0; echar = 0; |
606 | return c; | 611 | return c; |
607 | } | 612 | } |
608 | break; | 613 | break; |
609 | default: | 614 | default: |
610 | schar = 0; mchar = 0; echar = 0; | 615 | schar = 0; mchar = 0; echar = 0; |
611 | return c; | 616 | return c; |
612 | } | 617 | } |
613 | } | 618 | } |
614 | else if (schar != 0 && mchar != 0 && echar != 0) { | 619 | else if (schar != 0 && mchar != 0 && echar != 0) { |
615 | 620 | ||
616 | emit key( 8, Qt::Key_Backspace, 0, true, false ); | 621 | emit key( 8, Qt::Key_Backspace, 0, true, false ); |
617 | 622 | ||
618 | ushort prev = 0; | 623 | ushort prev = 0; |
619 | switch (echar) { | 624 | switch (echar) { |
620 | /* | 625 | /* |
621 | case 0x11a9: | 626 | case 0x11a9: |
622 | prev = combineKoreanChars(schar, mchar, 0x11a8); | 627 | prev = combineKoreanChars(schar, mchar, 0x11a8); |
623 | schar = 0x1100; | 628 | schar = 0x1100; |
624 | break; | 629 | break; |
625 | */ | 630 | */ |
626 | case 0x11aa: | 631 | case 0x11aa: |
627 | prev = combineKoreanChars(schar, mchar, 0x11a8); | 632 | prev = combineKoreanChars(schar, mchar, 0x11a8); |
628 | schar = 0x1109; | 633 | schar = 0x1109; |
629 | break; | 634 | break; |
630 | case 0x11ac: | 635 | case 0x11ac: |
631 | prev = combineKoreanChars(schar, mchar, 0x11ab); | 636 | prev = combineKoreanChars(schar, mchar, 0x11ab); |
632 | schar = 0x110c; | 637 | schar = 0x110c; |
633 | break; | 638 | break; |
634 | case 0x11ad: | 639 | case 0x11ad: |
635 | prev = combineKoreanChars(schar, mchar, 0x11ab); | 640 | prev = combineKoreanChars(schar, mchar, 0x11ab); |
636 | schar = 0x1112; | 641 | schar = 0x1112; |
637 | break; | 642 | break; |
638 | case 0x11b0: | 643 | case 0x11b0: |
639 | prev = combineKoreanChars(schar, mchar, 0x11af); | 644 | prev = combineKoreanChars(schar, mchar, 0x11af); |
640 | schar = 0x1100; | 645 | schar = 0x1100; |
641 | break; | 646 | break; |
642 | case 0x11b1: | 647 | case 0x11b1: |
643 | prev = combineKoreanChars(schar, mchar, 0x11af); | 648 | prev = combineKoreanChars(schar, mchar, 0x11af); |
644 | schar = 0x1106; | 649 | schar = 0x1106; |
645 | break; | 650 | break; |
646 | case 0x11b2: | 651 | case 0x11b2: |
647 | prev = combineKoreanChars(schar, mchar, 0x11af); | 652 | prev = combineKoreanChars(schar, mchar, 0x11af); |
648 | schar = 0x1107; | 653 | schar = 0x1107; |
649 | break; | 654 | break; |
650 | case 0x11b3: | 655 | case 0x11b3: |
651 | prev = combineKoreanChars(schar, mchar, 0x11af); | 656 | prev = combineKoreanChars(schar, mchar, 0x11af); |
652 | schar = 0x1109; | 657 | schar = 0x1109; |
653 | break; | 658 | break; |
654 | case 0x11b4: | 659 | case 0x11b4: |
655 | prev = combineKoreanChars(schar, mchar, 0x11af); | 660 | prev = combineKoreanChars(schar, mchar, 0x11af); |
656 | schar = 0x1110; | 661 | schar = 0x1110; |
657 | break; | 662 | break; |
658 | case 0x11b9: | 663 | case 0x11b9: |
659 | prev = combineKoreanChars(schar, mchar, 0x11b8); | 664 | prev = combineKoreanChars(schar, mchar, 0x11b8); |
660 | schar = 0x1109; | 665 | schar = 0x1109; |
661 | break; | 666 | break; |
662 | /* | 667 | /* |
663 | case 0x11bb: | 668 | case 0x11bb: |
664 | prev = combineKoreanChars(schar, mchar, 0x11ba); | 669 | prev = combineKoreanChars(schar, mchar, 0x11ba); |
665 | schar = 0x1109; | 670 | schar = 0x1109; |
666 | break; | 671 | break; |
667 | */ | 672 | */ |
668 | default: | 673 | default: |
669 | 674 | ||
670 | if (constoe(echar)) { | 675 | if (constoe(echar)) { |
671 | 676 | ||
672 | prev = combineKoreanChars(schar, mchar, 0); | 677 | prev = combineKoreanChars(schar, mchar, 0); |
673 | schar = constoe(echar); | 678 | schar = constoe(echar); |
674 | } | 679 | } |
675 | break; | 680 | break; |
676 | } | 681 | } |
677 | 682 | ||
678 | emit key( prev, prev, 0, true, false ); | 683 | emit key( prev, prev, 0, true, false ); |
679 | 684 | ||
680 | mchar = c; echar = 0; | 685 | mchar = c; echar = 0; |
681 | 686 | ||
682 | return combineKoreanChars(schar, mchar, 0); | 687 | return combineKoreanChars(schar, mchar, 0); |
683 | 688 | ||
684 | } | 689 | } |
685 | else { | 690 | else { |
686 | schar = 0; mchar = 0; echar = 0; | 691 | schar = 0; mchar = 0; echar = 0; |
687 | return c; | 692 | return c; |
688 | } | 693 | } |
689 | 694 | ||
690 | } | 695 | } |
691 | else /*if (c == ' ')*/ return c; | 696 | else /*if (c == ' ')*/ return c; |
692 | 697 | ||
693 | 698 | ||
694 | // and now... finally delete previous char, and return new char | 699 | // and now... finally delete previous char, and return new char |
695 | emit key( 8, Qt::Key_Backspace, 0, true, false ); | 700 | emit key( 8, Qt::Key_Backspace, 0, true, false ); |
696 | 701 | ||
697 | 702 | ||
698 | return combineKoreanChars( schar, mchar, echar); | 703 | return combineKoreanChars( schar, mchar, echar); |
699 | 704 | ||
700 | } | 705 | } |
701 | 706 | ||
702 | ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { | 707 | ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { |
703 | 708 | ||
704 | return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; | 709 | return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; |
705 | 710 | ||
706 | } | 711 | } |
707 | 712 | ||
708 | ushort Keyboard::constoe(const ushort c) { | 713 | ushort Keyboard::constoe(const ushort c) { |
709 | 714 | ||
710 | // converts schars to echars if possible | 715 | // converts schars to echars if possible |
711 | 716 | ||
712 | if (0x1100 <= c && c <= 0x1112) { // schar to echar | 717 | if (0x1100 <= c && c <= 0x1112) { // schar to echar |
713 | 718 | ||
714 | switch (c) { | 719 | switch (c) { |
715 | case 0x1100: return 0x11a8; | 720 | case 0x1100: return 0x11a8; |
716 | case 0x1101: return 0x11a9; | 721 | case 0x1101: return 0x11a9; |
717 | case 0x1102: return 0x11ab; | 722 | case 0x1102: return 0x11ab; |
718 | case 0x1103: return 0x11ae; | 723 | case 0x1103: return 0x11ae; |
719 | case 0x1105: return 0x11af; | 724 | case 0x1105: return 0x11af; |
720 | case 0x1106: return 0x11b7; | 725 | case 0x1106: return 0x11b7; |
721 | case 0x1107: return 0x11b8; | 726 | case 0x1107: return 0x11b8; |
722 | case 0x1109: return 0x11ba; | 727 | case 0x1109: return 0x11ba; |
723 | case 0x110a: return 0x11bb; | 728 | case 0x110a: return 0x11bb; |
724 | case 0x110b: return 0x11bc; | 729 | case 0x110b: return 0x11bc; |
725 | case 0x110c: return 0x11bd; | 730 | case 0x110c: return 0x11bd; |
726 | case 0x110e: return 0x11be; | 731 | case 0x110e: return 0x11be; |
727 | case 0x110f: return 0x11bf; | 732 | case 0x110f: return 0x11bf; |
728 | case 0x1110: return 0x11c0; | 733 | case 0x1110: return 0x11c0; |
729 | case 0x1111: return 0x11c1; | 734 | case 0x1111: return 0x11c1; |
730 | case 0x1112: return 0x11c2; | 735 | case 0x1112: return 0x11c2; |
731 | default: return 0; | 736 | default: return 0; |
732 | 737 | ||
733 | } | 738 | } |
734 | 739 | ||
735 | } else { //echar to schar | 740 | } else { //echar to schar |
736 | 741 | ||
737 | switch (c) { | 742 | switch (c) { |
738 | case 0x11a8: return 0x1100; | 743 | case 0x11a8: return 0x1100; |
739 | case 0x11a9: return 0x1101; | 744 | case 0x11a9: return 0x1101; |
740 | case 0x11ab: return 0x1102; | 745 | case 0x11ab: return 0x1102; |
741 | case 0x11ae: return 0x1103; | 746 | case 0x11ae: return 0x1103; |
742 | case 0x11af: return 0x1105; | 747 | case 0x11af: return 0x1105; |
743 | case 0x11b7: return 0x1106; | 748 | case 0x11b7: return 0x1106; |
744 | case 0x11b8: return 0x1107; | 749 | case 0x11b8: return 0x1107; |
745 | case 0x11ba: return 0x1109; | 750 | case 0x11ba: return 0x1109; |
746 | case 0x11bb: return 0x110a; | 751 | case 0x11bb: return 0x110a; |
747 | case 0x11bc: return 0x110b; | 752 | case 0x11bc: return 0x110b; |
748 | case 0x11bd: return 0x110c; | 753 | case 0x11bd: return 0x110c; |
749 | case 0x11be: return 0x110e; | 754 | case 0x11be: return 0x110e; |
750 | case 0x11bf: return 0x110f; | 755 | case 0x11bf: return 0x110f; |
751 | case 0x11c0: return 0x1110; | 756 | case 0x11c0: return 0x1110; |
752 | case 0x11c1: return 0x1111; | 757 | case 0x11c1: return 0x1111; |
753 | case 0x11c2: return 0x1112; | 758 | case 0x11c2: return 0x1112; |
754 | default: return 0; | 759 | default: return 0; |
755 | 760 | ||
756 | } | 761 | } |
757 | 762 | ||
758 | } | 763 | } |
759 | } | 764 | } |
760 | 765 | ||
761 | 766 | ||
762 | // Keys::Keys {{{1 | 767 | // Keys::Keys {{{1 |
763 | 768 | ||
764 | Keys::Keys() { | 769 | Keys::Keys() { |
765 | 770 | ||
766 | Config config("locale"); | 771 | Config config("locale"); |
767 | config.setGroup( "Language" ); | 772 | config.setGroup( "Language" ); |
768 | QString l = config.readEntry( "Language" ); | 773 | QString l = config.readEntry( "Language" ); |
769 | if(l.isEmpty()) l = "en"; | 774 | if(l.isEmpty()) l = "en"; |
770 | 775 | ||
771 | QString key_map = QPEApplication::qpeDir() + "/i18n/" + l + "/keyboard"; | 776 | QString key_map = QPEApplication::qpeDir() + "/share/multikey/" |
777 | + /* l // testing korean for now */ | ||
778 | + "ko.keymap"; | ||
772 | 779 | ||
773 | setKeysFromFile(key_map); | 780 | setKeysFromFile(key_map); |
774 | } | 781 | } |
775 | 782 | ||
776 | Keys::Keys(const char * filename) { | 783 | Keys::Keys(const char * filename) { |
777 | 784 | ||
778 | setKeysFromFile(filename); | 785 | setKeysFromFile(filename); |
779 | } | 786 | } |
780 | 787 | ||
781 | // Keys::setKeysFromFile {{{2 | 788 | // Keys::setKeysFromFile {{{2 |
782 | void Keys::setKeysFromFile(const char * filename) { | 789 | void Keys::setKeysFromFile(const char * filename) { |
783 | 790 | ||
784 | QFile f(filename); | 791 | QFile f(filename); |
785 | 792 | ||
786 | if (f.open(IO_ReadOnly)) { | 793 | if (f.open(IO_ReadOnly)) { |
787 | 794 | ||
788 | QTextStream t(&f); | 795 | QTextStream t(&f); |
789 | int row; | 796 | int row; |
790 | int qcode; | 797 | int qcode; |
791 | ushort unicode; | 798 | ushort unicode; |
792 | int width; | 799 | int width; |
793 | QString buf; | 800 | QString buf; |
794 | QString comment; | 801 | QString comment; |
795 | char * xpm[256]; //couldnt be larger than that... could it? | 802 | char * xpm[256]; //couldnt be larger than that... could it? |
796 | QPixmap *xpm2pix = 0; | 803 | QPixmap *xpm2pix = 0; |
797 | 804 | ||
798 | buf = t.readLine(); | 805 | buf = t.readLine(); |
799 | while (buf) { | 806 | while (buf) { |
800 | 807 | ||
801 | if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { | 808 | if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { |
802 | // no $1 type referencing!!! this implementation of regexp sucks | 809 | // no $1 type referencing!!! this implementation of regexp sucks |
803 | 810 | ||
804 | // dont know of any sscanf() type funcs in Qt lib | 811 | // dont know of any sscanf() type funcs in Qt lib |
805 | QTextStream tmp (buf, IO_ReadOnly); | 812 | QTextStream tmp (buf, IO_ReadOnly); |
806 | tmp >> row >> qcode >> unicode >> width >> comment; | 813 | tmp >> row >> qcode >> unicode >> width >> comment; |
807 | 814 | ||
808 | buf = t.readLine(); | 815 | buf = t.readLine(); |
809 | int xpmLineCount = 0; | 816 | int xpmLineCount = 0; |
810 | xpm2pix = 0; | 817 | xpm2pix = 0; |
811 | 818 | ||
812 | // erase blank space | 819 | // erase blank space |
813 | while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); | 820 | while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); |
814 | 821 | ||
815 | while (buf.contains(QRegExp("^\\s*\".*\""))) { | 822 | while (buf.contains(QRegExp("^\\s*\".*\""))) { |
816 | 823 | ||
817 | QString xpmBuf = buf.stripWhiteSpace(); | 824 | QString xpmBuf = buf.stripWhiteSpace(); |
818 | 825 | ||
819 | xpm[xpmLineCount] = new char [xpmBuf.length()]; | 826 | xpm[xpmLineCount] = new char [xpmBuf.length()]; |
820 | 827 | ||
821 | int j = 0; | 828 | int j = 0; |
822 | for (ushort i = 0; i < xpmBuf.length(); i++) { | 829 | for (ushort i = 0; i < xpmBuf.length(); i++) { |
823 | if (xpmBuf[i].latin1() != '"') { | 830 | if (xpmBuf[i].latin1() != '"') { |
824 | 831 | ||
825 | ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); | 832 | ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); |
826 | j++; | 833 | j++; |
827 | } | 834 | } |
828 | 835 | ||
829 | } | 836 | } |
830 | // have to close that facker up | 837 | // have to close that facker up |
831 | ((char *)xpm[xpmLineCount])[j] = '\0'; | 838 | ((char *)xpm[xpmLineCount])[j] = '\0'; |
832 | 839 | ||
833 | xpmLineCount++; | 840 | xpmLineCount++; |
834 | buf = t.readLine(); | 841 | buf = t.readLine(); |
835 | } | 842 | } |
836 | if (xpmLineCount) { | 843 | if (xpmLineCount) { |
837 | 844 | ||
838 | xpm2pix = new QPixmap((const char **)xpm); | 845 | xpm2pix = new QPixmap((const char **)xpm); |
839 | for (int i = 0; i < xpmLineCount; i++) | 846 | for (int i = 0; i < xpmLineCount; i++) |
840 | 847 | ||
841 | delete [] (xpm[i]); | 848 | delete [] (xpm[i]); |
842 | 849 | ||
843 | } | 850 | } |
844 | setKey(row, qcode, unicode, width, xpm2pix); | 851 | setKey(row, qcode, unicode, width, xpm2pix); |
845 | } | 852 | } |
846 | else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { | 853 | else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { |
847 | 854 | ||
848 | QTextStream tmp (buf, IO_ReadOnly); | 855 | QTextStream tmp (buf, IO_ReadOnly); |
849 | ushort lower, shift; | 856 | ushort lower, shift; |
850 | tmp >> lower >> shift; | 857 | tmp >> lower >> shift; |
851 | 858 | ||
852 | shiftMap.insert(lower, shift); | 859 | shiftMap.insert(lower, shift); |
853 | 860 | ||
854 | buf = t.readLine(); | 861 | buf = t.readLine(); |
855 | } | 862 | } |
856 | else if (buf.contains(QRegExp("^\\s*#"))) { | 863 | else if (buf.contains(QRegExp("^\\s*#"))) { |
857 | 864 | ||
858 | buf = t.readLine(); | 865 | buf = t.readLine(); |
859 | 866 | ||
860 | } else { // blank line, or garbage | 867 | } else { // blank line, or garbage |
861 | 868 | ||
862 | buf = t.readLine(); | 869 | buf = t.readLine(); |
863 | 870 | ||
864 | } | 871 | } |
865 | 872 | ||
866 | } | 873 | } |
867 | f.close(); | 874 | f.close(); |
868 | } | 875 | } |
869 | 876 | ||
870 | } | 877 | } |
871 | 878 | ||
872 | // Keys::setKey {{{2 | 879 | // Keys::setKey {{{2 |
873 | void Keys::setKey(const int row, const int qcode, const ushort unicode, | 880 | void Keys::setKey(const int row, const int qcode, const ushort unicode, |
874 | const int width, QPixmap *pix) { | 881 | const int width, QPixmap *pix) { |
875 | 882 | ||
876 | Key * key; | 883 | Key * key; |
877 | key = new Key; | 884 | key = new Key; |
878 | key->qcode = qcode; | 885 | key->qcode = qcode; |
879 | key->unicode = unicode; | 886 | key->unicode = unicode; |
880 | key->width = width; | 887 | key->width = width; |
881 | 888 | ||
882 | // share key->pressed between same keys | 889 | // share key->pressed between same keys |
883 | bool found = 0; | 890 | bool found = 0; |
884 | for (int i = 1; i <= 5; i++) { | 891 | for (int i = 1; i <= 5; i++) { |
885 | for (unsigned int j = 0; j < keys[i].count(); j++) | 892 | for (unsigned int j = 0; j < keys[i].count(); j++) |
886 | if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { | 893 | if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { |
887 | 894 | ||
888 | key->pressed = keys[i].at(j)->pressed; | 895 | key->pressed = keys[i].at(j)->pressed; |
889 | found = 1; | 896 | found = 1; |
890 | } | 897 | } |
891 | 898 | ||
892 | } | 899 | } |
893 | if (!found) { | 900 | if (!found) { |
894 | 901 | ||
895 | key->pressed = new bool; | 902 | key->pressed = new bool; |
896 | *(key->pressed) = 0; | 903 | *(key->pressed) = 0; |
897 | } | 904 | } |
898 | 905 | ||
899 | key->pix = pix; | 906 | key->pix = pix; |
900 | 907 | ||
901 | 908 | ||
902 | keys[row].append(key); | 909 | keys[row].append(key); |
903 | } | 910 | } |
904 | // Keys:: other functions {{{2 | 911 | // Keys:: other functions {{{2 |
905 | int Keys::width(const int row, const int col) { | 912 | int Keys::width(const int row, const int col) { |
906 | 913 | ||
907 | return keys[row].at(col)->width; | 914 | return keys[row].at(col)->width; |
908 | 915 | ||
909 | } | 916 | } |
910 | ushort Keys::uni(const int row, const int col) { | 917 | ushort Keys::uni(const int row, const int col) { |
911 | 918 | ||
912 | return keys[row].at(col)->unicode; | 919 | return keys[row].at(col)->unicode; |
913 | 920 | ||
914 | } | 921 | } |
915 | 922 | ||
916 | int Keys::qcode(const int row, const int col) { | 923 | int Keys::qcode(const int row, const int col) { |
917 | 924 | ||
918 | return keys[row].at(col)->qcode; | 925 | return keys[row].at(col)->qcode; |
919 | } | 926 | } |
920 | 927 | ||
921 | QPixmap *Keys::pix(const int row, const int col) { | 928 | QPixmap *Keys::pix(const int row, const int col) { |
922 | 929 | ||
923 | return keys[row].at(col)->pix; | 930 | return keys[row].at(col)->pix; |
924 | 931 | ||
925 | } | 932 | } |
926 | bool Keys::pressed(const int row, const int col) { | 933 | bool Keys::pressed(const int row, const int col) { |
927 | 934 | ||
928 | return *(keys[row].at(col)->pressed); | 935 | return *(keys[row].at(col)->pressed); |
929 | } | 936 | } |
930 | 937 | ||
931 | int Keys::numKeys(const int row) { | 938 | int Keys::numKeys(const int row) { |
932 | 939 | ||
933 | return keys[row].count(); | 940 | return keys[row].count(); |
934 | } | 941 | } |
935 | 942 | ||
936 | void Keys::setPressed(const int row, const int col, const bool pressed) { | 943 | void Keys::setPressed(const int row, const int col, const bool pressed) { |
937 | 944 | ||
938 | *(keys[row].at(col)->pressed) = pressed; | 945 | *(keys[row].at(col)->pressed) = pressed; |
939 | } | 946 | } |
940 | 947 | ||
941 | ushort Keys::shift(const ushort uni) { | 948 | ushort Keys::shift(const ushort uni) { |
942 | 949 | ||
943 | if (shiftMap[uni]) { | 950 | if (shiftMap[uni]) { |
944 | 951 | ||
945 | return shiftMap[uni]; | 952 | return shiftMap[uni]; |
946 | } | 953 | } |
947 | else | 954 | else |
948 | return 0; | 955 | return 0; |
949 | 956 | ||
950 | } | 957 | } |
951 | 958 | ||
952 | bool *Keys::pressedPtr(const int row, const int col) { | 959 | bool *Keys::pressedPtr(const int row, const int col) { |
953 | 960 | ||
954 | return keys[row].at(col)->pressed; | 961 | return keys[row].at(col)->pressed; |
955 | } | 962 | } |