-rw-r--r-- | inputmethods/multikey/keyboard.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp index c22fbb1..bded447 100644 --- a/inputmethods/multikey/keyboard.cpp +++ b/inputmethods/multikey/keyboard.cpp | |||
@@ -1,1592 +1,1592 @@ | |||
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 | 37 | ||
38 | #include <sys/utsname.h> | 38 | #include <sys/utsname.h> |
39 | 39 | ||
40 | using namespace MultiKey; | 40 | using namespace MultiKey; |
41 | 41 | ||
42 | /* Keyboard::Keyboard {{{1 */ | 42 | /* Keyboard::Keyboard {{{1 */ |
43 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : | 43 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : |
44 | QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0), | 44 | QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0), |
45 | meta(0), circumflex(0), diaeresis(0), baccent(0), accent(0), | 45 | meta(0), circumflex(0), diaeresis(0), baccent(0), accent(0), |
46 | useLargeKeys(TRUE), usePicks(0), useRepeat(0), | 46 | useLargeKeys(TRUE), usePicks(0), useRepeat(0), |
47 | pressedKeyRow(-1), pressedKeyCol(-1), | 47 | pressedKeyRow(-1), pressedKeyCol(-1), |
48 | unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), | 48 | unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), |
49 | configdlg(0) | 49 | configdlg(0) |
50 | 50 | ||
51 | { | 51 | { |
52 | 52 | ||
53 | // get the default font | 53 | // get the default font |
54 | Config *config = new Config( "qpe" ); | 54 | Config *config = new Config( "qpe" ); |
55 | config->setGroup( "Appearance" ); | 55 | config->setGroup( "Appearance" ); |
56 | QString familyStr = config->readEntry( "FontFamily", "fixed" ); | 56 | QString familyStr = config->readEntry( "FontFamily", "smallsmooth" ); |
57 | delete config; | 57 | delete config; |
58 | 58 | ||
59 | config = new Config("multikey"); | 59 | config = new Config("multikey"); |
60 | config->setGroup ("general"); | 60 | config->setGroup ("general"); |
61 | usePicks = config->readBoolEntry ("usePickboard", 0); // default closed | 61 | usePicks = config->readBoolEntry ("usePickboard", 0); // default closed |
62 | useRepeat = config->readBoolEntry ("useRepeat", 1); | 62 | useRepeat = config->readBoolEntry ("useRepeat", 1); |
63 | delete config; | 63 | delete config; |
64 | 64 | ||
65 | 65 | ||
66 | setFont( QFont( familyStr, 10 ) ); | 66 | setFont( QFont( familyStr, 10 ) ); |
67 | 67 | ||
68 | picks = new KeyboardPicks( this ); | 68 | picks = new KeyboardPicks( this ); |
69 | picks->setFont( QFont( familyStr, 10 ) ); | 69 | picks->setFont( QFont( familyStr, 10 ) ); |
70 | picks->initialise(); | 70 | picks->initialise(); |
71 | if (usePicks) { | 71 | if (usePicks) { |
72 | 72 | ||
73 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 73 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
74 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 74 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
75 | 75 | ||
76 | } else picks->hide(); | 76 | } else picks->hide(); |
77 | 77 | ||
78 | loadKeyboardColors(); | 78 | loadKeyboardColors(); |
79 | 79 | ||
80 | keys = new Keys(); | 80 | keys = new Keys(); |
81 | 81 | ||
82 | repeatTimer = new QTimer( this ); | 82 | repeatTimer = new QTimer( this ); |
83 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); | 83 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); |
84 | 84 | ||
85 | } | 85 | } |
86 | 86 | ||
87 | Keyboard::~Keyboard() { | 87 | Keyboard::~Keyboard() { |
88 | 88 | ||
89 | if ( configdlg ) { | 89 | if ( configdlg ) { |
90 | delete (ConfigDlg *) configdlg; | 90 | delete (ConfigDlg *) configdlg; |
91 | configdlg = 0; | 91 | configdlg = 0; |
92 | } | 92 | } |
93 | 93 | ||
94 | } | 94 | } |
95 | 95 | ||
96 | /* Keyboard::resizeEvent {{{1 */ | 96 | /* Keyboard::resizeEvent {{{1 */ |
97 | void Keyboard::resizeEvent(QResizeEvent*) | 97 | void Keyboard::resizeEvent(QResizeEvent*) |
98 | { | 98 | { |
99 | int ph = picks->sizeHint().height(); | 99 | int ph = picks->sizeHint().height(); |
100 | picks->setGeometry( 0, 0, width(), ph ); | 100 | picks->setGeometry( 0, 0, width(), ph ); |
101 | keyHeight = (height()-(usePicks ? ph : 0))/(keys->rows()?keys->rows():1); | 101 | keyHeight = (height()-(usePicks ? ph : 0))/(keys->rows()?keys->rows():1); |
102 | 102 | ||
103 | int nk; // number of keys? | 103 | int nk; // number of keys? |
104 | if ( useLargeKeys ) { | 104 | if ( useLargeKeys ) { |
105 | nk = 15; | 105 | nk = 15; |
106 | } else { | 106 | } else { |
107 | nk = 19; | 107 | nk = 19; |
108 | } | 108 | } |
109 | defaultKeyWidth = (width()/nk)/2; | 109 | defaultKeyWidth = (width()/nk)/2; |
110 | xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? | 110 | xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? |
111 | 111 | ||
112 | } | 112 | } |
113 | 113 | ||
114 | /* KeyboardPicks::initialize {{{1 */ | 114 | /* KeyboardPicks::initialize {{{1 */ |
115 | void KeyboardPicks::initialise() | 115 | void KeyboardPicks::initialise() |
116 | { | 116 | { |
117 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); | 117 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); |
118 | mode = 0; | 118 | mode = 0; |
119 | dc = new KeyboardConfig(this); | 119 | dc = new KeyboardConfig(this); |
120 | configs.append(dc); | 120 | configs.append(dc); |
121 | } | 121 | } |
122 | 122 | ||
123 | /* KeyboardPicks::sizeHint {{{1 */ | 123 | /* KeyboardPicks::sizeHint {{{1 */ |
124 | QSize KeyboardPicks::sizeHint() const | 124 | QSize KeyboardPicks::sizeHint() const |
125 | { | 125 | { |
126 | return QSize(240,fontMetrics().lineSpacing()); | 126 | return QSize(240,fontMetrics().lineSpacing()); |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | /* KeyboardConfig::generateText {{{1 */ | 130 | /* KeyboardConfig::generateText {{{1 */ |
131 | void KeyboardConfig::generateText(const QString &s) | 131 | void KeyboardConfig::generateText(const QString &s) |
132 | { | 132 | { |
133 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 133 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
134 | for (int i=0; i<(int)backspaces; i++) { | 134 | for (int i=0; i<(int)backspaces; i++) { |
135 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); | 135 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); |
136 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); | 136 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); |
137 | } | 137 | } |
138 | for (int i=0; i<(int)s.length(); i++) { | 138 | for (int i=0; i<(int)s.length(); i++) { |
139 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); | 139 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); |
140 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); | 140 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); |
141 | } | 141 | } |
142 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); | 142 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); |
143 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); | 143 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); |
144 | backspaces = 0; | 144 | backspaces = 0; |
145 | #endif | 145 | #endif |
146 | } | 146 | } |
147 | 147 | ||
148 | 148 | ||
149 | 149 | ||
150 | 150 | ||
151 | /* Keyboard::paintEvent {{{1 */ | 151 | /* Keyboard::paintEvent {{{1 */ |
152 | void Keyboard::paintEvent(QPaintEvent* e) | 152 | void Keyboard::paintEvent(QPaintEvent* e) |
153 | { | 153 | { |
154 | QPainter painter(this); | 154 | QPainter painter(this); |
155 | painter.setClipRect(e->rect()); | 155 | painter.setClipRect(e->rect()); |
156 | drawKeyboard( painter ); | 156 | drawKeyboard( painter ); |
157 | picks->dc->draw( &painter ); | 157 | picks->dc->draw( &painter ); |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | /* Keyboard::drawKeyboard {{{1 */ | 161 | /* Keyboard::drawKeyboard {{{1 */ |
162 | 162 | ||
163 | void Keyboard::drawKeyboard(QPainter &p, int row, int col) | 163 | void Keyboard::drawKeyboard(QPainter &p, int row, int col) |
164 | { | 164 | { |
165 | 165 | ||
166 | 166 | ||
167 | if (row != -1 && col != -1) { //just redraw one key | 167 | if (row != -1 && col != -1) { //just redraw one key |
168 | 168 | ||
169 | int x = 0; | 169 | int x = 0; |
170 | for (int i = 0; i < col; i++) { | 170 | for (int i = 0; i < col; i++) { |
171 | 171 | ||
172 | x += keys->width(row, i) * defaultKeyWidth; | 172 | x += keys->width(row, i) * defaultKeyWidth; |
173 | } | 173 | } |
174 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 174 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
175 | 175 | ||
176 | int keyWidth = keys->width(row, col); | 176 | int keyWidth = keys->width(row, col); |
177 | 177 | ||
178 | p.fillRect(x + 1, y + 1, | 178 | p.fillRect(x + 1, y + 1, |
179 | keyWidth * defaultKeyWidth - 1, keyHeight - 1, | 179 | keyWidth * defaultKeyWidth - 1, keyHeight - 1, |
180 | pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); | 180 | pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); |
181 | 181 | ||
182 | QImage *pix = keys->pix(row,col); | 182 | QImage *pix = keys->pix(row,col); |
183 | 183 | ||
184 | ushort c = keys->uni(row, col); | 184 | ushort c = keys->uni(row, col); |
185 | 185 | ||
186 | p.setPen(textcolor); | 186 | p.setPen(textcolor); |
187 | if (!pix) { | 187 | if (!pix) { |
188 | if ((shift || lock) && keys->shift(c)) | 188 | if ((shift || lock) && keys->shift(c)) |
189 | 189 | ||
190 | if (circumflex && keys->circumflex(keys->shift(c))) | 190 | if (circumflex && keys->circumflex(keys->shift(c))) |
191 | c = keys->circumflex(keys->shift(c)); | 191 | c = keys->circumflex(keys->shift(c)); |
192 | else if (diaeresis && keys->diaeresis(keys->shift(c))) | 192 | else if (diaeresis && keys->diaeresis(keys->shift(c))) |
193 | c = keys->diaeresis(keys->shift(c)); | 193 | c = keys->diaeresis(keys->shift(c)); |
194 | else if (baccent && keys->baccent(keys->shift(c))) | 194 | else if (baccent && keys->baccent(keys->shift(c))) |
195 | c = keys->baccent(keys->shift(c)); | 195 | c = keys->baccent(keys->shift(c)); |
196 | else if (accent && keys->accent(keys->shift(c))) | 196 | else if (accent && keys->accent(keys->shift(c))) |
197 | c = keys->accent(keys->shift(c)); | 197 | c = keys->accent(keys->shift(c)); |
198 | else if (meta && keys->meta(keys->shift(c))) | 198 | else if (meta && keys->meta(keys->shift(c))) |
199 | c = keys->meta(keys->shift(c)); | 199 | c = keys->meta(keys->shift(c)); |
200 | else | 200 | else |
201 | c = keys->shift(c); | 201 | c = keys->shift(c); |
202 | 202 | ||
203 | else if (meta && keys->meta(c)) | 203 | else if (meta && keys->meta(c)) |
204 | c = keys->meta(c); | 204 | c = keys->meta(c); |
205 | else if (circumflex && keys->circumflex(c)) | 205 | else if (circumflex && keys->circumflex(c)) |
206 | c = keys->circumflex(c); | 206 | c = keys->circumflex(c); |
207 | else if (baccent && keys->baccent(c)) | 207 | else if (baccent && keys->baccent(c)) |
208 | c = keys->baccent(c); | 208 | c = keys->baccent(c); |
209 | else if (accent && keys->accent(c)) | 209 | else if (accent && keys->accent(c)) |
210 | c = keys->accent(c); | 210 | c = keys->accent(c); |
211 | else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { | 211 | else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { |
212 | 212 | ||
213 | // the diaeresis key itself has to be in the diaeresisMap, | 213 | // the diaeresis key itself has to be in the diaeresisMap, |
214 | // or just do this to make it display the diaeresis char. | 214 | // or just do this to make it display the diaeresis char. |
215 | 215 | ||
216 | if (c == 0x2c6) | 216 | if (c == 0x2c6) |
217 | c = 0xa8; | 217 | c = 0xa8; |
218 | else | 218 | else |
219 | c = keys->diaeresis(c); | 219 | c = keys->diaeresis(c); |
220 | } | 220 | } |
221 | 221 | ||
222 | p.drawText(x, y, | 222 | p.drawText(x, y, |
223 | defaultKeyWidth * keyWidth + 3, keyHeight, | 223 | defaultKeyWidth * keyWidth + 3, keyHeight, |
224 | AlignCenter, (QChar)c); | 224 | AlignCenter, (QChar)c); |
225 | } | 225 | } |
226 | else | 226 | else |
227 | // center the image in the middle of the key | 227 | // center the image in the middle of the key |
228 | p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2 + 1, | 228 | p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2 + 1, |
229 | y + (keyHeight - pix->height())/2 + 1, | 229 | y + (keyHeight - pix->height())/2 + 1, |
230 | *pix ); | 230 | *pix ); |
231 | 231 | ||
232 | // this fixes the problem that the very right end of the board's vertical line | 232 | // this fixes the problem that the very right end of the board's vertical line |
233 | // gets painted over, because it's one pixel shorter than all other keys | 233 | // gets painted over, because it's one pixel shorter than all other keys |
234 | p.setPen(keycolor_lines); | 234 | p.setPen(keycolor_lines); |
235 | p.drawLine(width() - 1, 0, width() - 1, height()); | 235 | p.drawLine(width() - 1, 0, width() - 1, height()); |
236 | 236 | ||
237 | } else { | 237 | } else { |
238 | 238 | ||
239 | 239 | ||
240 | p.fillRect(0, 0, width(), height(), keycolor); | 240 | p.fillRect(0, 0, width(), height(), keycolor); |
241 | 241 | ||
242 | for (row = 1; row <= keys->rows(); row++) { | 242 | for (row = 1; row <= keys->rows(); row++) { |
243 | 243 | ||
244 | int x = 0; | 244 | int x = 0; |
245 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 245 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
246 | 246 | ||
247 | p.setPen(keycolor_lines); | 247 | p.setPen(keycolor_lines); |
248 | p.drawLine(x, y, x + width(), y); | 248 | p.drawLine(x, y, x + width(), y); |
249 | 249 | ||
250 | for (int col = 0; col < keys->numKeys(row); col++) { | 250 | for (int col = 0; col < keys->numKeys(row); col++) { |
251 | 251 | ||
252 | QImage *pix = keys->pix(row, col); | 252 | QImage *pix = keys->pix(row, col); |
253 | int keyWidth = keys->width(row, col); | 253 | int keyWidth = keys->width(row, col); |
254 | 254 | ||
255 | 255 | ||
256 | int keyWidthPix = defaultKeyWidth * keyWidth; | 256 | int keyWidthPix = defaultKeyWidth * keyWidth; |
257 | 257 | ||
258 | if (keys->pressed(row, col)) | 258 | if (keys->pressed(row, col)) |
259 | p.fillRect(x+1, y+1, keyWidthPix - 1, | 259 | p.fillRect(x+1, y+1, keyWidthPix - 1, |
260 | keyHeight - 1, keycolor_pressed); | 260 | keyHeight - 1, keycolor_pressed); |
261 | 261 | ||
262 | ushort c = keys->uni(row, col); | 262 | ushort c = keys->uni(row, col); |
263 | 263 | ||
264 | p.setPen(textcolor); | 264 | p.setPen(textcolor); |
265 | if (!pix) { | 265 | if (!pix) { |
266 | if ((shift || lock) && keys->shift(c)) | 266 | if ((shift || lock) && keys->shift(c)) |
267 | 267 | ||
268 | if (circumflex && keys->circumflex(keys->shift(c))) | 268 | if (circumflex && keys->circumflex(keys->shift(c))) |
269 | c = keys->circumflex(keys->shift(c)); | 269 | c = keys->circumflex(keys->shift(c)); |
270 | else if (diaeresis && keys->diaeresis(keys->shift(c))) | 270 | else if (diaeresis && keys->diaeresis(keys->shift(c))) |
271 | c = keys->diaeresis(keys->shift(c)); | 271 | c = keys->diaeresis(keys->shift(c)); |
272 | else if (baccent && keys->baccent(keys->shift(c))) | 272 | else if (baccent && keys->baccent(keys->shift(c))) |
273 | c = keys->baccent(keys->shift(c)); | 273 | c = keys->baccent(keys->shift(c)); |
274 | else if (accent && keys->accent(keys->shift(c))) | 274 | else if (accent && keys->accent(keys->shift(c))) |
275 | c = keys->accent(keys->shift(c)); | 275 | c = keys->accent(keys->shift(c)); |
276 | else if (meta && keys->meta(keys->shift(c))) | 276 | else if (meta && keys->meta(keys->shift(c))) |
277 | c = keys->meta(keys->shift(c)); | 277 | c = keys->meta(keys->shift(c)); |
278 | else | 278 | else |
279 | c = keys->shift(c); | 279 | c = keys->shift(c); |
280 | 280 | ||
281 | else if (meta && keys->meta(c)) | 281 | else if (meta && keys->meta(c)) |
282 | c = keys->meta(c); | 282 | c = keys->meta(c); |
283 | else if (circumflex && keys->circumflex(c)) | 283 | else if (circumflex && keys->circumflex(c)) |
284 | c = keys->circumflex(c); | 284 | c = keys->circumflex(c); |
285 | else if (baccent && keys->baccent(c)) | 285 | else if (baccent && keys->baccent(c)) |
286 | c = keys->baccent(c); | 286 | c = keys->baccent(c); |
287 | else if (accent && keys->accent(c)) | 287 | else if (accent && keys->accent(c)) |
288 | c = keys->accent(c); | 288 | c = keys->accent(c); |
289 | else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { | 289 | else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { |
290 | 290 | ||
291 | if (c == 0x2c6) | 291 | if (c == 0x2c6) |
292 | c = 0xa8; | 292 | c = 0xa8; |
293 | else | 293 | else |
294 | c = keys->diaeresis(c); | 294 | c = keys->diaeresis(c); |
295 | } | 295 | } |
296 | 296 | ||
297 | p.drawText(x, y, | 297 | p.drawText(x, y, |
298 | keyWidthPix + 3, keyHeight, | 298 | keyWidthPix + 3, keyHeight, |
299 | AlignCenter, (QChar)c); | 299 | AlignCenter, (QChar)c); |
300 | } | 300 | } |
301 | else { | 301 | else { |
302 | // center the image in the middle of the key | 302 | // center the image in the middle of the key |
303 | pix->setColor(1, textcolor.rgb()); | 303 | pix->setColor(1, textcolor.rgb()); |
304 | p.drawImage( x + (keyWidthPix - pix->width())/2 + 1, | 304 | p.drawImage( x + (keyWidthPix - pix->width())/2 + 1, |
305 | y + (keyHeight - pix->height())/2 + 1, | 305 | y + (keyHeight - pix->height())/2 + 1, |
306 | QImage(*pix) ); | 306 | QImage(*pix) ); |
307 | } | 307 | } |
308 | 308 | ||
309 | p.setPen(keycolor_lines); | 309 | p.setPen(keycolor_lines); |
310 | p.drawLine(x, y, x, y + keyHeight); | 310 | p.drawLine(x, y, x, y + keyHeight); |
311 | 311 | ||
312 | x += keyWidthPix; | 312 | x += keyWidthPix; |
313 | } | 313 | } |
314 | 314 | ||
315 | 315 | ||
316 | } | 316 | } |
317 | p.setPen(keycolor_lines); | 317 | p.setPen(keycolor_lines); |
318 | p.drawLine(0, height() - 1, width(), height() - 1); | 318 | p.drawLine(0, height() - 1, width(), height() - 1); |
319 | p.drawLine(width() - 1, 0, width() - 1, height()); | 319 | p.drawLine(width() - 1, 0, width() - 1, height()); |
320 | } | 320 | } |
321 | 321 | ||
322 | } | 322 | } |
323 | 323 | ||
324 | 324 | ||
325 | /* Keyboard::mousePressEvent {{{1 */ | 325 | /* Keyboard::mousePressEvent {{{1 */ |
326 | void Keyboard::mousePressEvent(QMouseEvent *e) | 326 | void Keyboard::mousePressEvent(QMouseEvent *e) |
327 | { | 327 | { |
328 | int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; | 328 | int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; |
329 | if (row > 5) row = 5; | 329 | if (row > 5) row = 5; |
330 | 330 | ||
331 | // figure out the column | 331 | // figure out the column |
332 | int col = 0; | 332 | int col = 0; |
333 | for (int w = 0; e->x() >= w; col++) | 333 | for (int w = 0; e->x() >= w; col++) |
334 | if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys | 334 | if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys |
335 | w += keys->width(row,col) * defaultKeyWidth; | 335 | w += keys->width(row,col) * defaultKeyWidth; |
336 | else break; | 336 | else break; |
337 | 337 | ||
338 | if (col <= 0) return; | 338 | if (col <= 0) return; |
339 | 339 | ||
340 | col --; // rewind one... | 340 | col --; // rewind one... |
341 | 341 | ||
342 | qkeycode = keys->qcode(row, col); | 342 | qkeycode = keys->qcode(row, col); |
343 | unicode = keys->uni(row, col); | 343 | unicode = keys->uni(row, col); |
344 | 344 | ||
345 | // might need to repaint if two or more of the same keys. | 345 | // might need to repaint if two or more of the same keys. |
346 | // should be faster if just paint one key even though multiple keys exist. | 346 | // should be faster if just paint one key even though multiple keys exist. |
347 | bool need_repaint = FALSE; | 347 | bool need_repaint = FALSE; |
348 | 348 | ||
349 | // circumflex and diaeresis support | 349 | // circumflex and diaeresis support |
350 | // messy to have this here, but too hard to implement any other method | 350 | // messy to have this here, but too hard to implement any other method |
351 | if (unicode == 0x2c6) { | 351 | if (unicode == 0x2c6) { |
352 | 352 | ||
353 | unicode = 0; | 353 | unicode = 0; |
354 | if (shift || lock) { | 354 | if (shift || lock) { |
355 | 355 | ||
356 | // diaeresis | 356 | // diaeresis |
357 | qkeycode = 0x2001; | 357 | qkeycode = 0x2001; |
358 | } | 358 | } |
359 | else { | 359 | else { |
360 | 360 | ||
361 | // circumflex | 361 | // circumflex |
362 | qkeycode = 0x2000; | 362 | qkeycode = 0x2000; |
363 | } | 363 | } |
364 | } | 364 | } |
365 | 365 | ||
366 | // Back accent character support | 366 | // Back accent character support |
367 | 367 | ||
368 | // the keys from 2c6 ~ 2cf should be used instead of the ascii one | 368 | // the keys from 2c6 ~ 2cf should be used instead of the ascii one |
369 | if (unicode == 0x2cb) { | 369 | if (unicode == 0x2cb) { |
370 | 370 | ||
371 | unicode = 0; | 371 | unicode = 0; |
372 | if (shift || lock) { | 372 | if (shift || lock) { |
373 | 373 | ||
374 | // circumblex | 374 | // circumblex |
375 | qkeycode = 0x2000; | 375 | qkeycode = 0x2000; |
376 | } | 376 | } |
377 | else { | 377 | else { |
378 | 378 | ||
379 | // back accent | 379 | // back accent |
380 | qkeycode = 0x2002; | 380 | qkeycode = 0x2002; |
381 | } | 381 | } |
382 | } | 382 | } |
383 | 383 | ||
384 | // Accent character support | 384 | // Accent character support |
385 | 385 | ||
386 | if (unicode == 0x2ca) { | 386 | if (unicode == 0x2ca) { |
387 | 387 | ||
388 | unicode = 0; | 388 | unicode = 0; |
389 | if (shift || lock) { | 389 | if (shift || lock) { |
390 | 390 | ||
391 | // diaeresis | 391 | // diaeresis |
392 | qkeycode = 0x2001; | 392 | qkeycode = 0x2001; |
393 | } | 393 | } |
394 | else { | 394 | else { |
395 | 395 | ||
396 | // accent | 396 | // accent |
397 | qkeycode = 0x2003; | 397 | qkeycode = 0x2003; |
398 | } | 398 | } |
399 | } | 399 | } |
400 | 400 | ||
401 | 401 | ||
402 | if (unicode == 0) { // either Qt char, or nothing | 402 | if (unicode == 0) { // either Qt char, or nothing |
403 | 403 | ||
404 | if (qkeycode == Qt::Key_F1) { // toggle the pickboard | 404 | if (qkeycode == Qt::Key_F1) { // toggle the pickboard |
405 | 405 | ||
406 | if ( configdlg ) { | 406 | if ( configdlg ) { |
407 | 407 | ||
408 | delete (ConfigDlg *) configdlg; | 408 | delete (ConfigDlg *) configdlg; |
409 | configdlg = 0; | 409 | configdlg = 0; |
410 | } | 410 | } |
411 | else { | 411 | else { |
412 | configdlg = new ConfigDlg (); | 412 | configdlg = new ConfigDlg (); |
413 | connect(configdlg, SIGNAL(setMapToDefault()), | 413 | connect(configdlg, SIGNAL(setMapToDefault()), |
414 | this, SLOT(setMapToDefault())); | 414 | this, SLOT(setMapToDefault())); |
415 | connect(configdlg, SIGNAL(setMapToFile(QString)), | 415 | connect(configdlg, SIGNAL(setMapToFile(QString)), |
416 | this, SLOT(setMapToFile(QString))); | 416 | this, SLOT(setMapToFile(QString))); |
417 | connect(configdlg, SIGNAL(pickboardToggled(bool)), | 417 | connect(configdlg, SIGNAL(pickboardToggled(bool)), |
418 | this, SLOT(togglePickboard(bool))); | 418 | this, SLOT(togglePickboard(bool))); |
419 | connect(configdlg, SIGNAL(repeatToggled(bool)), | 419 | connect(configdlg, SIGNAL(repeatToggled(bool)), |
420 | this, SLOT(toggleRepeat(bool))); | 420 | this, SLOT(toggleRepeat(bool))); |
421 | connect(configdlg, SIGNAL(reloadKeyboard()), | 421 | connect(configdlg, SIGNAL(reloadKeyboard()), |
422 | this, SLOT(reloadKeyboard())); | 422 | this, SLOT(reloadKeyboard())); |
423 | connect(configdlg, SIGNAL(configDlgClosed()), | 423 | connect(configdlg, SIGNAL(configDlgClosed()), |
424 | this, SLOT(cleanupConfigDlg())); | 424 | this, SLOT(cleanupConfigDlg())); |
425 | configdlg->showMaximized(); | 425 | configdlg->showMaximized(); |
426 | configdlg->show(); | 426 | configdlg->show(); |
427 | configdlg->raise(); | 427 | configdlg->raise(); |
428 | } | 428 | } |
429 | 429 | ||
430 | } else if (qkeycode == Qt::Key_Control) { | 430 | } else if (qkeycode == Qt::Key_Control) { |
431 | need_repaint = TRUE; | 431 | need_repaint = TRUE; |
432 | 432 | ||
433 | if (ctrl) { | 433 | if (ctrl) { |
434 | 434 | ||
435 | *ctrl = 0; | 435 | *ctrl = 0; |
436 | ctrl = 0; | 436 | ctrl = 0; |
437 | 437 | ||
438 | } else { | 438 | } else { |
439 | 439 | ||
440 | ctrl = keys->pressedPtr(row, col); | 440 | ctrl = keys->pressedPtr(row, col); |
441 | need_repaint = TRUE; | 441 | need_repaint = TRUE; |
442 | *ctrl = !keys->pressed(row, col); | 442 | *ctrl = !keys->pressed(row, col); |
443 | 443 | ||
444 | } | 444 | } |
445 | 445 | ||
446 | } else if (qkeycode == Qt::Key_Alt) { | 446 | } else if (qkeycode == Qt::Key_Alt) { |
447 | need_repaint = TRUE; | 447 | need_repaint = TRUE; |
448 | 448 | ||
449 | if (alt) { | 449 | if (alt) { |
450 | *alt = 0; | 450 | *alt = 0; |
451 | alt = 0; | 451 | alt = 0; |
452 | 452 | ||
453 | } else { | 453 | } else { |
454 | 454 | ||
455 | alt = keys->pressedPtr(row, col); | 455 | alt = keys->pressedPtr(row, col); |
456 | need_repaint = TRUE; | 456 | need_repaint = TRUE; |
457 | *alt = !keys->pressed(row, col); | 457 | *alt = !keys->pressed(row, col); |
458 | } | 458 | } |
459 | 459 | ||
460 | } else if (qkeycode == Qt::Key_Shift) { | 460 | } else if (qkeycode == Qt::Key_Shift) { |
461 | need_repaint = TRUE; | 461 | need_repaint = TRUE; |
462 | 462 | ||
463 | if (shift) { | 463 | if (shift) { |
464 | *shift = 0; | 464 | *shift = 0; |
465 | shift = 0; | 465 | shift = 0; |
466 | } | 466 | } |
467 | else { | 467 | else { |
468 | shift = keys->pressedPtr(row, col); | 468 | shift = keys->pressedPtr(row, col); |
469 | *shift = 1; | 469 | *shift = 1; |
470 | if (lock) { | 470 | if (lock) { |
471 | *lock = 0; | 471 | *lock = 0; |
472 | lock = 0; | 472 | lock = 0; |
473 | } | 473 | } |
474 | } | 474 | } |
475 | 475 | ||
476 | 476 | ||
477 | /* | 477 | /* |
478 | * want to be able to hit circumflex/diaeresis -> shift | 478 | * want to be able to hit circumflex/diaeresis -> shift |
479 | * to type in shifted circumflex/diaeresis chars. | 479 | * to type in shifted circumflex/diaeresis chars. |
480 | * same thing with meta | 480 | * same thing with meta |
481 | 481 | ||
482 | if (meta) { *meta = 0; meta = 0; } | 482 | if (meta) { *meta = 0; meta = 0; } |
483 | if (circumflex) { *circumflex = 0; circumflex = 0; } | 483 | if (circumflex) { *circumflex = 0; circumflex = 0; } |
484 | if (diaeresis) { *diaeresis = 0; diaeresis = 0; } | 484 | if (diaeresis) { *diaeresis = 0; diaeresis = 0; } |
485 | 485 | ||
486 | */ | 486 | */ |
487 | 487 | ||
488 | } else if (qkeycode == Qt::Key_CapsLock) { | 488 | } else if (qkeycode == Qt::Key_CapsLock) { |
489 | need_repaint = TRUE; | 489 | need_repaint = TRUE; |
490 | 490 | ||
491 | if (lock) { | 491 | if (lock) { |
492 | *lock = 0; | 492 | *lock = 0; |
493 | lock = 0; | 493 | lock = 0; |
494 | } | 494 | } |
495 | else { | 495 | else { |
496 | lock = keys->pressedPtr(row, col);; | 496 | lock = keys->pressedPtr(row, col);; |
497 | *lock = true;; | 497 | *lock = true;; |
498 | if (shift) { | 498 | if (shift) { |
499 | *shift = 0; | 499 | *shift = 0; |
500 | shift = 0; | 500 | shift = 0; |
501 | } | 501 | } |
502 | } | 502 | } |
503 | 503 | ||
504 | /* | 504 | /* |
505 | if (meta) { *meta = 0; meta = 0; } | 505 | if (meta) { *meta = 0; meta = 0; } |
506 | if (circumflex) { *circumflex = 0; circumflex = 0; } | 506 | if (circumflex) { *circumflex = 0; circumflex = 0; } |
507 | if (diaeresis) { *diaeresis = 0; diaeresis = 0; } | 507 | if (diaeresis) { *diaeresis = 0; diaeresis = 0; } |
508 | */ | 508 | */ |
509 | 509 | ||
510 | } else if (qkeycode == Qt::Key_Meta) { | 510 | } else if (qkeycode == Qt::Key_Meta) { |
511 | need_repaint = TRUE; | 511 | need_repaint = TRUE; |
512 | 512 | ||
513 | if (meta) { | 513 | if (meta) { |
514 | *meta = 0; | 514 | *meta = 0; |
515 | meta = 0; | 515 | meta = 0; |
516 | 516 | ||
517 | } else { | 517 | } else { |
518 | 518 | ||
519 | meta = keys->pressedPtr(row, col); | 519 | meta = keys->pressedPtr(row, col); |
520 | *meta = true; | 520 | *meta = true; |
521 | } | 521 | } |
522 | 522 | ||
523 | // reset all the other keys | 523 | // reset all the other keys |
524 | if (shift) { *shift = 0; shift = 0; } | 524 | if (shift) { *shift = 0; shift = 0; } |
525 | if (lock) { *lock = 0; lock = 0; } | 525 | if (lock) { *lock = 0; lock = 0; } |
526 | if (circumflex) { *circumflex = 0; circumflex = 0; } | 526 | if (circumflex) { *circumflex = 0; circumflex = 0; } |
527 | if (diaeresis) { *diaeresis = 0; diaeresis = 0; } | 527 | if (diaeresis) { *diaeresis = 0; diaeresis = 0; } |
528 | if (baccent) { *baccent = 0; baccent = 0; } | 528 | if (baccent) { *baccent = 0; baccent = 0; } |
529 | if (accent) { *accent = 0; accent = 0; } | 529 | if (accent) { *accent = 0; accent = 0; } |
530 | 530 | ||
531 | // dont need to emit this key... acts same as alt | 531 | // dont need to emit this key... acts same as alt |
532 | qkeycode = 0; | 532 | qkeycode = 0; |
533 | 533 | ||
534 | // circumflex | 534 | // circumflex |
535 | } else if (qkeycode == 0x2000) { | 535 | } else if (qkeycode == 0x2000) { |
536 | need_repaint = TRUE; | 536 | need_repaint = TRUE; |
537 | 537 | ||
538 | if (circumflex) { | 538 | if (circumflex) { |
539 | 539 | ||
540 | *circumflex = 0; | 540 | *circumflex = 0; |
541 | circumflex = 0; | 541 | circumflex = 0; |
542 | 542 | ||
543 | } else { | 543 | } else { |
544 | 544 | ||
545 | circumflex = keys->pressedPtr(row, col); | 545 | circumflex = keys->pressedPtr(row, col); |
546 | *circumflex = true; | 546 | *circumflex = true; |
547 | } | 547 | } |
548 | 548 | ||
549 | /* no need to turn off shift or lock if circumflex | 549 | /* no need to turn off shift or lock if circumflex |
550 | * keys are pressed | 550 | * keys are pressed |
551 | 551 | ||
552 | if (shift) { *shift = 0; shift = 0; } | 552 | if (shift) { *shift = 0; shift = 0; } |
553 | if (lock) { *lock = 0; lock = 0; } | 553 | if (lock) { *lock = 0; lock = 0; } |
554 | 554 | ||
555 | */ | 555 | */ |
556 | 556 | ||
557 | // have to reset all the other keys | 557 | // have to reset all the other keys |
558 | if (meta) { *meta = 0; meta = 0; } | 558 | if (meta) { *meta = 0; meta = 0; } |
559 | if (diaeresis) { | 559 | if (diaeresis) { |
560 | 560 | ||
561 | // *diaeresis and *circumflex point to the same thing | 561 | // *diaeresis and *circumflex point to the same thing |
562 | // when diaeresis is enabled and you hit the circumflex | 562 | // when diaeresis is enabled and you hit the circumflex |
563 | // since they are the same key, it should turn off the | 563 | // since they are the same key, it should turn off the |
564 | // key | 564 | // key |
565 | 565 | ||
566 | *diaeresis = 0; | 566 | *diaeresis = 0; |
567 | diaeresis = 0; | 567 | diaeresis = 0; |
568 | circumflex = 0; | 568 | circumflex = 0; |
569 | } | 569 | } |
570 | 570 | ||
571 | qkeycode = 0; | 571 | qkeycode = 0; |
572 | 572 | ||
573 | // diaeresis | 573 | // diaeresis |
574 | } else if (qkeycode == 0x2001) { | 574 | } else if (qkeycode == 0x2001) { |
575 | need_repaint = TRUE; | 575 | need_repaint = TRUE; |
576 | 576 | ||
577 | if (diaeresis) { | 577 | if (diaeresis) { |
578 | 578 | ||
579 | *diaeresis = 0; | 579 | *diaeresis = 0; |
580 | diaeresis = 0; | 580 | diaeresis = 0; |
581 | 581 | ||
582 | } else { | 582 | } else { |
583 | 583 | ||
584 | diaeresis = keys->pressedPtr(row, col); | 584 | diaeresis = keys->pressedPtr(row, col); |
585 | *diaeresis = true; | 585 | *diaeresis = true; |
586 | } | 586 | } |
587 | 587 | ||
588 | 588 | ||
589 | if (shift) { *shift = 0; shift = 0; } | 589 | if (shift) { *shift = 0; shift = 0; } |
590 | 590 | ||
591 | /* | 591 | /* |
592 | * | 592 | * |
593 | if (lock) { *lock = 0; lock = 0; } | 593 | if (lock) { *lock = 0; lock = 0; } |
594 | * | 594 | * |
595 | */ | 595 | */ |
596 | 596 | ||
597 | if (meta) { *meta = 0; meta = 0; } | 597 | if (meta) { *meta = 0; meta = 0; } |
598 | if (circumflex) { | 598 | if (circumflex) { |
599 | 599 | ||
600 | // *circumflex = 0; | 600 | // *circumflex = 0; |
601 | // | 601 | // |
602 | // same thing the diaeresis pointer points too | 602 | // same thing the diaeresis pointer points too |
603 | 603 | ||
604 | circumflex = 0; | 604 | circumflex = 0; |
605 | } | 605 | } |
606 | 606 | ||
607 | 607 | ||
608 | qkeycode = 0; | 608 | qkeycode = 0; |
609 | 609 | ||
610 | // Back accent | 610 | // Back accent |
611 | } else if (qkeycode == 0x2002) { | 611 | } else if (qkeycode == 0x2002) { |
612 | need_repaint = TRUE; | 612 | need_repaint = TRUE; |
613 | 613 | ||
614 | if (baccent) { | 614 | if (baccent) { |
615 | 615 | ||
616 | *baccent = 0; | 616 | *baccent = 0; |
617 | baccent = 0; | 617 | baccent = 0; |
618 | 618 | ||
619 | } else { | 619 | } else { |
620 | 620 | ||
621 | baccent = keys->pressedPtr(row, col); | 621 | baccent = keys->pressedPtr(row, col); |
622 | *baccent = true; | 622 | *baccent = true; |
623 | } | 623 | } |
624 | 624 | ||
625 | 625 | ||
626 | if (shift) { *shift = 0; shift = 0; } | 626 | if (shift) { *shift = 0; shift = 0; } |
627 | if (meta) { *meta = 0; meta = 0; } | 627 | if (meta) { *meta = 0; meta = 0; } |
628 | if (accent) { *accent = 0; accent = 0; } | 628 | if (accent) { *accent = 0; accent = 0; } |
629 | 629 | ||
630 | qkeycode = 0; | 630 | qkeycode = 0; |
631 | 631 | ||
632 | // Accent | 632 | // Accent |
633 | } else if (qkeycode == 0x2003) { | 633 | } else if (qkeycode == 0x2003) { |
634 | need_repaint = TRUE; | 634 | need_repaint = TRUE; |
635 | 635 | ||
636 | if (accent) { | 636 | if (accent) { |
637 | 637 | ||
638 | *accent = 0; | 638 | *accent = 0; |
639 | accent = 0; | 639 | accent = 0; |
640 | 640 | ||
641 | } else { | 641 | } else { |
642 | 642 | ||
643 | accent = keys->pressedPtr(row, col); | 643 | accent = keys->pressedPtr(row, col); |
644 | *accent = true; | 644 | *accent = true; |
645 | } | 645 | } |
646 | 646 | ||
647 | 647 | ||
648 | if (shift) { *shift = 0; shift = 0; } | 648 | if (shift) { *shift = 0; shift = 0; } |
649 | if (meta) { *meta = 0; meta = 0; } | 649 | if (meta) { *meta = 0; meta = 0; } |
650 | if (baccent) { *baccent = 0; } | 650 | if (baccent) { *baccent = 0; } |
651 | 651 | ||
652 | qkeycode = 0; | 652 | qkeycode = 0; |
653 | } | 653 | } |
654 | 654 | ||
655 | } | 655 | } |
656 | else { // normal char | 656 | else { // normal char |
657 | if ((shift || lock) && keys->shift(unicode)) { | 657 | if ((shift || lock) && keys->shift(unicode)) { |
658 | 658 | ||
659 | // make diaeresis/circumflex -> shift input shifted | 659 | // make diaeresis/circumflex -> shift input shifted |
660 | // diaeresis/circumflex chars | 660 | // diaeresis/circumflex chars |
661 | 661 | ||
662 | if (circumflex && keys->circumflex(keys->shift(unicode))) | 662 | if (circumflex && keys->circumflex(keys->shift(unicode))) |
663 | unicode = keys->circumflex(keys->shift(unicode)); | 663 | unicode = keys->circumflex(keys->shift(unicode)); |
664 | else if (diaeresis && keys->diaeresis(keys->shift(unicode))) | 664 | else if (diaeresis && keys->diaeresis(keys->shift(unicode))) |
665 | unicode = keys->diaeresis(keys->shift(unicode)); | 665 | unicode = keys->diaeresis(keys->shift(unicode)); |
666 | else if (baccent && keys->baccent(keys->shift(unicode))) | 666 | else if (baccent && keys->baccent(keys->shift(unicode))) |
667 | unicode = keys->baccent(keys->shift(unicode)); | 667 | unicode = keys->baccent(keys->shift(unicode)); |
668 | else if (accent && keys->accent(keys->shift(unicode))) | 668 | else if (accent && keys->accent(keys->shift(unicode))) |
669 | unicode = keys->accent(keys->shift(unicode)); | 669 | unicode = keys->accent(keys->shift(unicode)); |
670 | else if (meta && keys->meta(keys->shift(unicode))) | 670 | else if (meta && keys->meta(keys->shift(unicode))) |
671 | unicode = keys->meta(keys->shift(unicode)); | 671 | unicode = keys->meta(keys->shift(unicode)); |
672 | else | 672 | else |
673 | unicode = keys->shift(unicode); | 673 | unicode = keys->shift(unicode); |
674 | } | 674 | } |
675 | else if (meta && keys->meta(unicode)) { | 675 | else if (meta && keys->meta(unicode)) { |
676 | unicode = keys->meta(unicode); | 676 | unicode = keys->meta(unicode); |
677 | } | 677 | } |
678 | else if (circumflex && keys->circumflex(unicode)) { | 678 | else if (circumflex && keys->circumflex(unicode)) { |
679 | unicode = keys->circumflex(unicode); | 679 | unicode = keys->circumflex(unicode); |
680 | } | 680 | } |
681 | else if (diaeresis && keys->diaeresis(unicode)) { | 681 | else if (diaeresis && keys->diaeresis(unicode)) { |
682 | 682 | ||
683 | unicode = keys->diaeresis(unicode); | 683 | unicode = keys->diaeresis(unicode); |
684 | } | 684 | } |
685 | else if (baccent && keys->baccent(unicode)) { | 685 | else if (baccent && keys->baccent(unicode)) { |
686 | unicode = keys->baccent(unicode); | 686 | unicode = keys->baccent(unicode); |
687 | } | 687 | } |
688 | else if (accent && keys->accent(unicode)) { | 688 | else if (accent && keys->accent(unicode)) { |
689 | unicode = keys->accent(unicode); | 689 | unicode = keys->accent(unicode); |
690 | } | 690 | } |
691 | } | 691 | } |
692 | 692 | ||
693 | // korean parsing | 693 | // korean parsing |
694 | if (keys->lang == "ko") { | 694 | if (keys->lang == "ko") { |
695 | 695 | ||
696 | unicode = parseKoreanInput(unicode); | 696 | unicode = parseKoreanInput(unicode); |
697 | } | 697 | } |
698 | 698 | ||
699 | modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); | 699 | modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0); |
700 | 700 | ||
701 | if ('A' <= unicode && unicode <= 'z' && modifiers) { | 701 | if ('A' <= unicode && unicode <= 'z' && modifiers) { |
702 | 702 | ||
703 | qkeycode = QChar(unicode).upper(); | 703 | qkeycode = QChar(unicode).upper(); |
704 | unicode = qkeycode - '@'; | 704 | unicode = qkeycode - '@'; |
705 | } | 705 | } |
706 | 706 | ||
707 | QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); | 707 | QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false); |
708 | 708 | ||
709 | // pickboard stuff | 709 | // pickboard stuff |
710 | if (usePicks) { | 710 | if (usePicks) { |
711 | 711 | ||
712 | KeyboardConfig *dc = picks->dc; | 712 | KeyboardConfig *dc = picks->dc; |
713 | 713 | ||
714 | if (dc) { | 714 | if (dc) { |
715 | if (qkeycode == Qt::Key_Backspace) { | 715 | if (qkeycode == Qt::Key_Backspace) { |
716 | dc->input.remove(dc->input.last()); // remove last input | 716 | dc->input.remove(dc->input.last()); // remove last input |
717 | dc->decBackspaces(); | 717 | dc->decBackspaces(); |
718 | } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { | 718 | } else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) { |
719 | dc->input.clear(); | 719 | dc->input.clear(); |
720 | dc->resetBackspaces(); | 720 | dc->resetBackspaces(); |
721 | } else { | 721 | } else { |
722 | dc->add(QString(QChar(unicode))); | 722 | dc->add(QString(QChar(unicode))); |
723 | dc->incBackspaces(); | 723 | dc->incBackspaces(); |
724 | } | 724 | } |
725 | } | 725 | } |
726 | picks->repaint(); | 726 | picks->repaint(); |
727 | } | 727 | } |
728 | 728 | ||
729 | 729 | ||
730 | // painting | 730 | // painting |
731 | pressed = TRUE; | 731 | pressed = TRUE; |
732 | 732 | ||
733 | pressedKeyRow = row; | 733 | pressedKeyRow = row; |
734 | pressedKeyCol = col; | 734 | pressedKeyCol = col; |
735 | 735 | ||
736 | if (need_repaint) repaint(FALSE); | 736 | if (need_repaint) repaint(FALSE); |
737 | else { // just paint the one key pressed | 737 | else { // just paint the one key pressed |
738 | 738 | ||
739 | 739 | ||
740 | 740 | ||
741 | QPainter p(this); | 741 | QPainter p(this); |
742 | drawKeyboard(p, row, col); | 742 | drawKeyboard(p, row, col); |
743 | 743 | ||
744 | } | 744 | } |
745 | 745 | ||
746 | if (useRepeat) repeatTimer->start( 800 ); | 746 | if (useRepeat) repeatTimer->start( 800 ); |
747 | //pressTid = startTimer(80); | 747 | //pressTid = startTimer(80); |
748 | 748 | ||
749 | } | 749 | } |
750 | 750 | ||
751 | 751 | ||
752 | /* Keyboard::mouseReleaseEvent {{{1 */ | 752 | /* Keyboard::mouseReleaseEvent {{{1 */ |
753 | void Keyboard::mouseReleaseEvent(QMouseEvent*) | 753 | void Keyboard::mouseReleaseEvent(QMouseEvent*) |
754 | { | 754 | { |
755 | pressed = FALSE; | 755 | pressed = FALSE; |
756 | //if ( pressTid == 0 ) | 756 | //if ( pressTid == 0 ) |
757 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 757 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
758 | if ( unicode != -1 ) { | 758 | if ( unicode != -1 ) { |
759 | emit key( unicode, qkeycode, modifiers, false, false ); | 759 | emit key( unicode, qkeycode, modifiers, false, false ); |
760 | repeatTimer->stop(); | 760 | repeatTimer->stop(); |
761 | } | 761 | } |
762 | #endif | 762 | #endif |
763 | if (shift && unicode != 0) { | 763 | if (shift && unicode != 0) { |
764 | 764 | ||
765 | 765 | ||
766 | *shift = 0; // unpress shift key | 766 | *shift = 0; // unpress shift key |
767 | shift = 0; // reset the shift pointer | 767 | shift = 0; // reset the shift pointer |
768 | repaint(FALSE); | 768 | repaint(FALSE); |
769 | 769 | ||
770 | } | 770 | } |
771 | if (ctrl && unicode != 0) { | 771 | if (ctrl && unicode != 0) { |
772 | 772 | ||
773 | *ctrl = 0; | 773 | *ctrl = 0; |
774 | ctrl = 0; | 774 | ctrl = 0; |
775 | repaint(FALSE); | 775 | repaint(FALSE); |
776 | 776 | ||
777 | } | 777 | } |
778 | if (alt && alt != 0) { | 778 | if (alt && alt != 0) { |
779 | 779 | ||
780 | *alt = 0; | 780 | *alt = 0; |
781 | alt = 0; | 781 | alt = 0; |
782 | repaint(FALSE); | 782 | repaint(FALSE); |
783 | 783 | ||
784 | } | 784 | } |
785 | 785 | ||
786 | /* | 786 | /* |
787 | * do not make the meta key release after being pressed | 787 | * do not make the meta key release after being pressed |
788 | * | 788 | * |
789 | 789 | ||
790 | else if (meta && unicode != 0) { | 790 | else if (meta && unicode != 0) { |
791 | 791 | ||
792 | *meta = 0; | 792 | *meta = 0; |
793 | meta = 0; | 793 | meta = 0; |
794 | repaint(FALSE); | 794 | repaint(FALSE); |
795 | } | 795 | } |
796 | 796 | ||
797 | */ | 797 | */ |
798 | 798 | ||
799 | else clearHighlight(); | 799 | else clearHighlight(); |
800 | } | 800 | } |
801 | 801 | ||
802 | /* Keyboard::timerEvent {{{1 */ | 802 | /* Keyboard::timerEvent {{{1 */ |
803 | 803 | ||
804 | /* dont know what this does, but i think it is here so that if your screen | 804 | /* dont know what this does, but i think it is here so that if your screen |
805 | * sticks (like on an ipaq) then it will stop repeating if you click another | 805 | * sticks (like on an ipaq) then it will stop repeating if you click another |
806 | * key... but who knows what anything does in this thing anyway? | 806 | * key... but who knows what anything does in this thing anyway? |
807 | 807 | ||
808 | void Keyboard::timerEvent(QTimerEvent* e) | 808 | void Keyboard::timerEvent(QTimerEvent* e) |
809 | { | 809 | { |
810 | if ( e->timerId() == pressTid ) { | 810 | if ( e->timerId() == pressTid ) { |
811 | killTimer(pressTid); | 811 | killTimer(pressTid); |
812 | pressTid = 0; | 812 | pressTid = 0; |
813 | if ( !pressed ) | 813 | if ( !pressed ) |
814 | cout << "calling clearHighlight from timerEvent\n"; | 814 | cout << "calling clearHighlight from timerEvent\n"; |
815 | //clearHighlight(); | 815 | //clearHighlight(); |
816 | } | 816 | } |
817 | } | 817 | } |
818 | */ | 818 | */ |
819 | 819 | ||
820 | void Keyboard::repeat() | 820 | void Keyboard::repeat() |
821 | { | 821 | { |
822 | 822 | ||
823 | repeatTimer->start( 200 ); | 823 | repeatTimer->start( 200 ); |
824 | emit key( unicode, qkeycode, modifiers, true, true ); | 824 | emit key( unicode, qkeycode, modifiers, true, true ); |
825 | } | 825 | } |
826 | 826 | ||
827 | void Keyboard::clearHighlight() | 827 | void Keyboard::clearHighlight() |
828 | { | 828 | { |
829 | if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { | 829 | if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) { |
830 | int tmpRow = pressedKeyRow; | 830 | int tmpRow = pressedKeyRow; |
831 | int tmpCol = pressedKeyCol; | 831 | int tmpCol = pressedKeyCol; |
832 | 832 | ||
833 | pressedKeyRow = -1; | 833 | pressedKeyRow = -1; |
834 | pressedKeyCol = -1; | 834 | pressedKeyCol = -1; |
835 | 835 | ||
836 | QPainter p(this); | 836 | QPainter p(this); |
837 | drawKeyboard(p, tmpRow, tmpCol); | 837 | drawKeyboard(p, tmpRow, tmpCol); |
838 | } | 838 | } |
839 | } | 839 | } |
840 | 840 | ||
841 | 841 | ||
842 | /* Keyboard::sizeHint {{{1 */ | 842 | /* Keyboard::sizeHint {{{1 */ |
843 | QSize Keyboard::sizeHint() const | 843 | QSize Keyboard::sizeHint() const |
844 | { | 844 | { |
845 | QFontMetrics fm=fontMetrics(); | 845 | QFontMetrics fm=fontMetrics(); |
846 | int keyHeight = fm.lineSpacing() + 2; | 846 | int keyHeight = fm.lineSpacing() + 2; |
847 | 847 | ||
848 | return QSize( 240, keyHeight * keys->rows() + (usePicks ? picks->sizeHint().height() : 0) + 1); | 848 | return QSize( 240, keyHeight * keys->rows() + (usePicks ? picks->sizeHint().height() : 0) + 1); |
849 | } | 849 | } |
850 | 850 | ||
851 | 851 | ||
852 | void Keyboard::resetState() | 852 | void Keyboard::resetState() |
853 | { | 853 | { |
854 | if (shift) { *shift = 0; shift = 0; } | 854 | if (shift) { *shift = 0; shift = 0; } |
855 | if (lock) {*lock = 0; lock = 0; } | 855 | if (lock) {*lock = 0; lock = 0; } |
856 | if (meta) { *meta = 0; meta = 0; } | 856 | if (meta) { *meta = 0; meta = 0; } |
857 | if (circumflex) { *circumflex = 0; circumflex = 0; } | 857 | if (circumflex) { *circumflex = 0; circumflex = 0; } |
858 | if (diaeresis) { *diaeresis = 0; diaeresis = 0; } | 858 | if (diaeresis) { *diaeresis = 0; diaeresis = 0; } |
859 | if (baccent) { *baccent = 0; baccent = 0; } | 859 | if (baccent) { *baccent = 0; baccent = 0; } |
860 | if (accent) { *accent = 0; accent = 0; } | 860 | if (accent) { *accent = 0; accent = 0; } |
861 | 861 | ||
862 | schar = mchar = echar = 0; | 862 | schar = mchar = echar = 0; |
863 | picks->resetState(); | 863 | picks->resetState(); |
864 | } | 864 | } |
865 | 865 | ||
866 | /* Keyboard::togglePickboard {{{1 */ | 866 | /* Keyboard::togglePickboard {{{1 */ |
867 | void Keyboard::togglePickboard(bool on_off) | 867 | void Keyboard::togglePickboard(bool on_off) |
868 | { | 868 | { |
869 | usePicks = on_off; | 869 | usePicks = on_off; |
870 | if (usePicks) { | 870 | if (usePicks) { |
871 | picks->show(); | 871 | picks->show(); |
872 | //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send | 872 | //move(x(), y() - picks->height()); // not required anymore because QCopChannel::send |
873 | //adjustSize(); | 873 | //adjustSize(); |
874 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 874 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
875 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 875 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
876 | } else { | 876 | } else { |
877 | 877 | ||
878 | picks->hide(); | 878 | picks->hide(); |
879 | picks->resetState(); | 879 | picks->resetState(); |
880 | //move(x(), y() + picks->height()); | 880 | //move(x(), y() + picks->height()); |
881 | //adjustSize(); | 881 | //adjustSize(); |
882 | QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 882 | QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
883 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 883 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
884 | 884 | ||
885 | } | 885 | } |
886 | /* | 886 | /* |
887 | * this closes && opens the input method | 887 | * this closes && opens the input method |
888 | */ | 888 | */ |
889 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); | 889 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); |
890 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); | 890 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); |
891 | } | 891 | } |
892 | 892 | ||
893 | void Keyboard::toggleRepeat(bool on) { | 893 | void Keyboard::toggleRepeat(bool on) { |
894 | 894 | ||
895 | useRepeat = on; | 895 | useRepeat = on; |
896 | //cout << "setting useRepeat to: " << useRepeat << "\n"; | 896 | //cout << "setting useRepeat to: " << useRepeat << "\n"; |
897 | } | 897 | } |
898 | 898 | ||
899 | void Keyboard::cleanupConfigDlg() { | 899 | void Keyboard::cleanupConfigDlg() { |
900 | 900 | ||
901 | if ( configdlg ) { | 901 | if ( configdlg ) { |
902 | delete (ConfigDlg *) configdlg; | 902 | delete (ConfigDlg *) configdlg; |
903 | configdlg = 0; | 903 | configdlg = 0; |
904 | } | 904 | } |
905 | } | 905 | } |
906 | 906 | ||
907 | /* Keyboard::setMapTo ... {{{1 */ | 907 | /* Keyboard::setMapTo ... {{{1 */ |
908 | void Keyboard::setMapToDefault() { | 908 | void Keyboard::setMapToDefault() { |
909 | 909 | ||
910 | 910 | ||
911 | /* load current locale language map */ | 911 | /* load current locale language map */ |
912 | Config *config = new Config("locale"); | 912 | Config *config = new Config("locale"); |
913 | config->setGroup( "Language" ); | 913 | config->setGroup( "Language" ); |
914 | QString l = config->readEntry( "Language" , "en" ); | 914 | QString l = config->readEntry( "Language" , "en" ); |
915 | delete config; | 915 | delete config; |
916 | 916 | ||
917 | QString key_map = QPEApplication::qpeDir() + "share/multikey/" | 917 | QString key_map = QPEApplication::qpeDir() + "share/multikey/" |
918 | + l + ".keymap"; | 918 | + l + ".keymap"; |
919 | 919 | ||
920 | /* save change to multikey config file */ | 920 | /* save change to multikey config file */ |
921 | config = new Config("multikey"); | 921 | config = new Config("multikey"); |
922 | config->setGroup ("keymaps"); | 922 | config->setGroup ("keymaps"); |
923 | config->writeEntry ("current", key_map); // default closed | 923 | config->writeEntry ("current", key_map); // default closed |
924 | delete config; | 924 | delete config; |
925 | 925 | ||
926 | int prevRows = keys->rows(); | 926 | int prevRows = keys->rows(); |
927 | 927 | ||
928 | delete keys; | 928 | delete keys; |
929 | keys = new Keys(key_map); | 929 | keys = new Keys(key_map); |
930 | 930 | ||
931 | // have to repaint the keyboard | 931 | // have to repaint the keyboard |
932 | if (prevRows != keys->rows()) { | 932 | if (prevRows != keys->rows()) { |
933 | 933 | ||
934 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); | 934 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); |
935 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); | 935 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); |
936 | 936 | ||
937 | } else repaint(FALSE); | 937 | } else repaint(FALSE); |
938 | 938 | ||
939 | resetState(); | 939 | resetState(); |
940 | } | 940 | } |
941 | 941 | ||
942 | void Keyboard::setMapToFile(QString map) { | 942 | void Keyboard::setMapToFile(QString map) { |
943 | 943 | ||
944 | /* save change to multikey config file */ | 944 | /* save change to multikey config file */ |
945 | Config *config = new Config("multikey"); | 945 | Config *config = new Config("multikey"); |
946 | config->setGroup ("keymaps"); | 946 | config->setGroup ("keymaps"); |
947 | config->writeEntry ("current", map); // default closed | 947 | config->writeEntry ("current", map); // default closed |
948 | 948 | ||
949 | delete config; | 949 | delete config; |
950 | 950 | ||
951 | int prevRows = keys->rows(); | 951 | int prevRows = keys->rows(); |
952 | 952 | ||
953 | delete keys; | 953 | delete keys; |
954 | if (QFile(map).exists()) | 954 | if (QFile(map).exists()) |
955 | keys = new Keys(map); | 955 | keys = new Keys(map); |
956 | else | 956 | else |
957 | keys = new Keys(); | 957 | keys = new Keys(); |
958 | 958 | ||
959 | if (keys->rows() != prevRows) { | 959 | if (keys->rows() != prevRows) { |
960 | 960 | ||
961 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); | 961 | QCopChannel::send ("QPE/TaskBar", "hideInputMethod()"); |
962 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); | 962 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); |
963 | } | 963 | } |
964 | else repaint(FALSE); | 964 | else repaint(FALSE); |
965 | 965 | ||
966 | resetState(); | 966 | resetState(); |
967 | } | 967 | } |
968 | 968 | ||
969 | /* Keybaord::reloadKeyboard {{{1 */ | 969 | /* Keybaord::reloadKeyboard {{{1 */ |
970 | void Keyboard::reloadKeyboard() { | 970 | void Keyboard::reloadKeyboard() { |
971 | 971 | ||
972 | // reload colors and redraw | 972 | // reload colors and redraw |
973 | loadKeyboardColors(); | 973 | loadKeyboardColors(); |
974 | repaint(); | 974 | repaint(); |
975 | 975 | ||
976 | } | 976 | } |
977 | 977 | ||
978 | void Keyboard::loadKeyboardColors() { | 978 | void Keyboard::loadKeyboardColors() { |
979 | 979 | ||
980 | Config config ("multikey"); | 980 | Config config ("multikey"); |
981 | config.setGroup("colors"); | 981 | config.setGroup("colors"); |
982 | 982 | ||
983 | QStringList color; | 983 | QStringList color; |
984 | color = config.readListEntry("keycolor", QChar(',')); | 984 | color = config.readListEntry("keycolor", QChar(',')); |
985 | if (color.isEmpty()) { | 985 | if (color.isEmpty()) { |
986 | color = QStringList::split(",", "240,240,240"); | 986 | color = QStringList::split(",", "240,240,240"); |
987 | config.writeEntry("keycolor", color.join(",")); | 987 | config.writeEntry("keycolor", color.join(",")); |
988 | 988 | ||
989 | } | 989 | } |
990 | keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 990 | keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
991 | 991 | ||
992 | color = config.readListEntry("keycolor_pressed", QChar(',')); | 992 | color = config.readListEntry("keycolor_pressed", QChar(',')); |
993 | if (color.isEmpty()) { | 993 | if (color.isEmpty()) { |
994 | color = QStringList::split(",", "171,183,198"); | 994 | color = QStringList::split(",", "171,183,198"); |
995 | config.writeEntry("keycolor_pressed", color.join(",")); | 995 | config.writeEntry("keycolor_pressed", color.join(",")); |
996 | 996 | ||
997 | } | 997 | } |
998 | keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 998 | keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
999 | 999 | ||
1000 | color = config.readListEntry("keycolor_lines", QChar(',')); | 1000 | color = config.readListEntry("keycolor_lines", QChar(',')); |
1001 | if (color.isEmpty()) { | 1001 | if (color.isEmpty()) { |
1002 | color = QStringList::split(",", "138,148,160"); | 1002 | color = QStringList::split(",", "138,148,160"); |
1003 | config.writeEntry("keycolor_lines", color.join(",")); | 1003 | config.writeEntry("keycolor_lines", color.join(",")); |
1004 | 1004 | ||
1005 | } | 1005 | } |
1006 | keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 1006 | keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
1007 | 1007 | ||
1008 | color = config.readListEntry("textcolor", QChar(',')); | 1008 | color = config.readListEntry("textcolor", QChar(',')); |
1009 | if (color.isEmpty()) { | 1009 | if (color.isEmpty()) { |
1010 | color = QStringList::split(",", "43,54,68"); | 1010 | color = QStringList::split(",", "43,54,68"); |
1011 | config.writeEntry("textcolor", color.join(",")); | 1011 | config.writeEntry("textcolor", color.join(",")); |
1012 | 1012 | ||
1013 | } | 1013 | } |
1014 | textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | 1014 | textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); |
1015 | 1015 | ||
1016 | } | 1016 | } |
1017 | 1017 | ||
1018 | /* korean input functions {{{1 | 1018 | /* korean input functions {{{1 |
1019 | * | 1019 | * |
1020 | * TODO | 1020 | * TODO |
1021 | * one major problem with this implementation is that you can't move the | 1021 | * one major problem with this implementation is that you can't move the |
1022 | * cursor after inputing korean chars, otherwise it will eat up and replace | 1022 | * cursor after inputing korean chars, otherwise it will eat up and replace |
1023 | * the char before the cursor you move to. fix that | 1023 | * the char before the cursor you move to. fix that |
1024 | * | 1024 | * |
1025 | * make backspace delete one single char, not the whole thing if still | 1025 | * make backspace delete one single char, not the whole thing if still |
1026 | * editing. | 1026 | * editing. |
1027 | * | 1027 | * |
1028 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 1028 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
1029 | * | 1029 | * |
1030 | * how korean input works | 1030 | * how korean input works |
1031 | * | 1031 | * |
1032 | * all following chars means unicode char value and are in hex | 1032 | * all following chars means unicode char value and are in hex |
1033 | * | 1033 | * |
1034 | * 초음 = schar (start char) | 1034 | * 초음 = schar (start char) |
1035 | * 중음 = mchar (middle char) | 1035 | * 중음 = mchar (middle char) |
1036 | * 끝음 = echar (end char) | 1036 | * 끝음 = echar (end char) |
1037 | * | 1037 | * |
1038 | * there are 19 schars. unicode position is at 1100 - 1112 | 1038 | * there are 19 schars. unicode position is at 1100 - 1112 |
1039 | * there are 21 mchars. unicode position is at 1161 - 1175 | 1039 | * there are 21 mchars. unicode position is at 1161 - 1175 |
1040 | * there are 27 echars. unicode position is at 11a8 - 11c2 | 1040 | * there are 27 echars. unicode position is at 11a8 - 11c2 |
1041 | * | 1041 | * |
1042 | * the map with everything combined is at ac00 - d7a3 | 1042 | * the map with everything combined is at ac00 - d7a3 |
1043 | * | 1043 | * |
1044 | */ | 1044 | */ |
1045 | 1045 | ||
1046 | ushort Keyboard::parseKoreanInput (ushort c) { | 1046 | ushort Keyboard::parseKoreanInput (ushort c) { |
1047 | 1047 | ||
1048 | if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) | 1048 | if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) |
1049 | || | 1049 | || |
1050 | (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode | 1050 | (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode |
1051 | && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { | 1051 | && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { |
1052 | 1052 | ||
1053 | schar = 0, mchar = 0, echar = 0; | 1053 | schar = 0, mchar = 0, echar = 0; |
1054 | return c; | 1054 | return c; |
1055 | } | 1055 | } |
1056 | 1056 | ||
1057 | if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input | 1057 | if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input |
1058 | 1058 | ||
1059 | if (schar == 0 || (schar != 0 && mchar == 0)) { | 1059 | if (schar == 0 || (schar != 0 && mchar == 0)) { |
1060 | schar = c; mchar = 0; echar = 0; | 1060 | schar = c; mchar = 0; echar = 0; |
1061 | return c; | 1061 | return c; |
1062 | } | 1062 | } |
1063 | else if (mchar != 0) { | 1063 | else if (mchar != 0) { |
1064 | 1064 | ||
1065 | if (echar == 0) { | 1065 | if (echar == 0) { |
1066 | 1066 | ||
1067 | if (!(echar = constoe(c))) { | 1067 | if (!(echar = constoe(c))) { |
1068 | 1068 | ||
1069 | schar = c; mchar = 0; echar = 0; | 1069 | schar = c; mchar = 0; echar = 0; |
1070 | return c; | 1070 | return c; |
1071 | } | 1071 | } |
1072 | 1072 | ||
1073 | } | 1073 | } |
1074 | else { // must figure out what the echar is | 1074 | else { // must figure out what the echar is |
1075 | 1075 | ||
1076 | if (echar == 0x11a8) { // ㄱ | 1076 | if (echar == 0x11a8) { // ㄱ |
1077 | 1077 | ||
1078 | if (c == 0x1100) echar = 0x11a9; // ㄱ + ㄱ | 1078 | if (c == 0x1100) echar = 0x11a9; // ㄱ + ㄱ |
1079 | else if (c == 0x1109) echar = 0x11aa; // ㄱ + ㅅ | 1079 | else if (c == 0x1109) echar = 0x11aa; // ㄱ + ㅅ |
1080 | else { | 1080 | else { |
1081 | schar = c; mchar = 0; echar = 0; | 1081 | schar = c; mchar = 0; echar = 0; |
1082 | return c; | 1082 | return c; |
1083 | } | 1083 | } |
1084 | 1084 | ||
1085 | } else if (echar == 0x11ab) { // ㄴ | 1085 | } else if (echar == 0x11ab) { // ㄴ |
1086 | 1086 | ||
1087 | if (c == 0x110c) echar = 0x11ac; // ㄴ + ㅈ | 1087 | if (c == 0x110c) echar = 0x11ac; // ㄴ + ㅈ |
1088 | else if (c == 0x1112) echar = 0x11ad; // ㄴ + ㅎ | 1088 | else if (c == 0x1112) echar = 0x11ad; // ㄴ + ㅎ |
1089 | else { | 1089 | else { |
1090 | schar = c; mchar = 0; echar = 0; | 1090 | schar = c; mchar = 0; echar = 0; |
1091 | return c; | 1091 | return c; |
1092 | } | 1092 | } |
1093 | 1093 | ||
1094 | } else if (echar == 0x11af) { // ㄹ | 1094 | } else if (echar == 0x11af) { // ㄹ |
1095 | 1095 | ||
1096 | if (c == 0x1100) echar = 0x11b0; // ㄹ + ㄱ | 1096 | if (c == 0x1100) echar = 0x11b0; // ㄹ + ㄱ |
1097 | else if (c == 0x1106) echar = 0x11b1; // ㄹ + ㅁ | 1097 | else if (c == 0x1106) echar = 0x11b1; // ㄹ + ㅁ |
1098 | else if (c == 0x1107) echar = 0x11b2; // ㄹ + ㅂ | 1098 | else if (c == 0x1107) echar = 0x11b2; // ㄹ + ㅂ |
1099 | else if (c == 0x1109) echar = 0x11b3; // ㄹ + ㅅ | 1099 | else if (c == 0x1109) echar = 0x11b3; // ㄹ + ㅅ |
1100 | else if (c == 0x1110) echar = 0x11b4; // ㄹ + ㅌ | 1100 | else if (c == 0x1110) echar = 0x11b4; // ㄹ + ㅌ |
1101 | else if (c == 0x1111) echar = 0x11b5; // ㄹ + ㅍ | 1101 | else if (c == 0x1111) echar = 0x11b5; // ㄹ + ㅍ |
1102 | else if (c == 0x1112) echar = 0x11b6; // ㄹ + ㅎ | 1102 | else if (c == 0x1112) echar = 0x11b6; // ㄹ + ㅎ |
1103 | else { | 1103 | else { |
1104 | schar = c; mchar = 0; echar = 0; | 1104 | schar = c; mchar = 0; echar = 0; |
1105 | return c; | 1105 | return c; |
1106 | } | 1106 | } |
1107 | 1107 | ||
1108 | } else if (echar == 0x11b8) { // ㅂ | 1108 | } else if (echar == 0x11b8) { // ㅂ |
1109 | 1109 | ||
1110 | if (c == 0x1109) echar = 0x11b9; // ㅂ + ㅅ | 1110 | if (c == 0x1109) echar = 0x11b9; // ㅂ + ㅅ |
1111 | else { | 1111 | else { |
1112 | schar = c; mchar = 0; echar = 0; | 1112 | schar = c; mchar = 0; echar = 0; |
1113 | return c; | 1113 | return c; |
1114 | } | 1114 | } |
1115 | 1115 | ||
1116 | } else if (echar == 0x11ba) { // ㅅ | 1116 | } else if (echar == 0x11ba) { // ㅅ |
1117 | 1117 | ||
1118 | if (c == 0x1109) echar = 0x11bb; // ㅅ + ㅅ | 1118 | if (c == 0x1109) echar = 0x11bb; // ㅅ + ㅅ |
1119 | else { | 1119 | else { |
1120 | schar = c; mchar = 0; echar = 0; | 1120 | schar = c; mchar = 0; echar = 0; |
1121 | return c; | 1121 | return c; |
1122 | } | 1122 | } |
1123 | 1123 | ||
1124 | } else { // if any other char, cannot combine chars | 1124 | } else { // if any other char, cannot combine chars |
1125 | 1125 | ||
1126 | schar = c; mchar = 0; echar = 0; | 1126 | schar = c; mchar = 0; echar = 0; |
1127 | return c; | 1127 | return c; |
1128 | } | 1128 | } |
1129 | 1129 | ||
1130 | unicode = echar; | 1130 | unicode = echar; |
1131 | } | 1131 | } |
1132 | } | 1132 | } |
1133 | 1133 | ||
1134 | } | 1134 | } |
1135 | else if (0x1161 <= c && c <= 0x1175) { // mchar was input | 1135 | else if (0x1161 <= c && c <= 0x1175) { // mchar was input |
1136 | 1136 | ||
1137 | if (schar != 0 && mchar == 0) { mchar = c; } | 1137 | if (schar != 0 && mchar == 0) { mchar = c; } |
1138 | 1138 | ||
1139 | else if (schar != 0 && mchar != 0 && echar == 0) { | 1139 | else if (schar != 0 && mchar != 0 && echar == 0) { |
1140 | 1140 | ||
1141 | switch (mchar) { | 1141 | switch (mchar) { |
1142 | case 0x1169: | 1142 | case 0x1169: |
1143 | if (c == 0x1161) mchar = 0x116a; | 1143 | if (c == 0x1161) mchar = 0x116a; |
1144 | else if (c == 0x1162) mchar = 0x116b; | 1144 | else if (c == 0x1162) mchar = 0x116b; |
1145 | else if (c == 0x1175) mchar = 0x116c; | 1145 | else if (c == 0x1175) mchar = 0x116c; |
1146 | else { | 1146 | else { |
1147 | schar = 0; mchar = 0; echar = 0; | 1147 | schar = 0; mchar = 0; echar = 0; |
1148 | return c; | 1148 | return c; |
1149 | } | 1149 | } |
1150 | break; | 1150 | break; |
1151 | case 0x116e: | 1151 | case 0x116e: |
1152 | if (c == 0x1165) mchar = 0x116f; | 1152 | if (c == 0x1165) mchar = 0x116f; |
1153 | else if (c == 0x1166) mchar = 0x1170; | 1153 | else if (c == 0x1166) mchar = 0x1170; |
1154 | else if (c == 0x1175) mchar = 0x1171; | 1154 | else if (c == 0x1175) mchar = 0x1171; |
1155 | else { | 1155 | else { |
1156 | schar = 0; mchar = 0; echar = 0; | 1156 | schar = 0; mchar = 0; echar = 0; |
1157 | return c; | 1157 | return c; |
1158 | } | 1158 | } |
1159 | break; | 1159 | break; |
1160 | case 0x1173: | 1160 | case 0x1173: |
1161 | if (c == 0x1175) mchar = 0x1174; | 1161 | if (c == 0x1175) mchar = 0x1174; |
1162 | else { | 1162 | else { |
1163 | schar = 0; mchar = 0; echar = 0; | 1163 | schar = 0; mchar = 0; echar = 0; |
1164 | return c; | 1164 | return c; |
1165 | } | 1165 | } |
1166 | break; | 1166 | break; |
1167 | default: | 1167 | default: |
1168 | schar = 0; mchar = 0; echar = 0; | 1168 | schar = 0; mchar = 0; echar = 0; |
1169 | return c; | 1169 | return c; |
1170 | } | 1170 | } |
1171 | } | 1171 | } |
1172 | else if (schar != 0 && mchar != 0 && echar != 0) { | 1172 | else if (schar != 0 && mchar != 0 && echar != 0) { |
1173 | 1173 | ||
1174 | emit key( 8, Qt::Key_Backspace, 0, true, false ); | 1174 | emit key( 8, Qt::Key_Backspace, 0, true, false ); |
1175 | 1175 | ||
1176 | ushort prev = 0; | 1176 | ushort prev = 0; |
1177 | switch (echar) { | 1177 | switch (echar) { |
1178 | /* | 1178 | /* |
1179 | case 0x11a9: | 1179 | case 0x11a9: |
1180 | prev = combineKoreanChars(schar, mchar, 0x11a8); | 1180 | prev = combineKoreanChars(schar, mchar, 0x11a8); |
1181 | schar = 0x1100; | 1181 | schar = 0x1100; |
1182 | break; | 1182 | break; |
1183 | */ | 1183 | */ |
1184 | case 0x11aa: | 1184 | case 0x11aa: |
1185 | prev = combineKoreanChars(schar, mchar, 0x11a8); | 1185 | prev = combineKoreanChars(schar, mchar, 0x11a8); |
1186 | schar = 0x1109; | 1186 | schar = 0x1109; |
1187 | break; | 1187 | break; |
1188 | case 0x11ac: | 1188 | case 0x11ac: |
1189 | prev = combineKoreanChars(schar, mchar, 0x11ab); | 1189 | prev = combineKoreanChars(schar, mchar, 0x11ab); |
1190 | schar = 0x110c; | 1190 | schar = 0x110c; |
1191 | break; | 1191 | break; |
1192 | case 0x11ad: | 1192 | case 0x11ad: |
1193 | prev = combineKoreanChars(schar, mchar, 0x11ab); | 1193 | prev = combineKoreanChars(schar, mchar, 0x11ab); |
1194 | schar = 0x1112; | 1194 | schar = 0x1112; |
1195 | break; | 1195 | break; |
1196 | case 0x11b0: | 1196 | case 0x11b0: |
1197 | prev = combineKoreanChars(schar, mchar, 0x11af); | 1197 | prev = combineKoreanChars(schar, mchar, 0x11af); |
1198 | schar = 0x1100; | 1198 | schar = 0x1100; |
1199 | break; | 1199 | break; |
1200 | case 0x11b1: | 1200 | case 0x11b1: |
1201 | prev = combineKoreanChars(schar, mchar, 0x11af); | 1201 | prev = combineKoreanChars(schar, mchar, 0x11af); |
1202 | schar = 0x1106; | 1202 | schar = 0x1106; |
1203 | break; | 1203 | break; |
1204 | case 0x11b2: | 1204 | case 0x11b2: |
1205 | prev = combineKoreanChars(schar, mchar, 0x11af); | 1205 | prev = combineKoreanChars(schar, mchar, 0x11af); |
1206 | schar = 0x1107; | 1206 | schar = 0x1107; |
1207 | break; | 1207 | break; |
1208 | case 0x11b3: | 1208 | case 0x11b3: |
1209 | prev = combineKoreanChars(schar, mchar, 0x11af); | 1209 | prev = combineKoreanChars(schar, mchar, 0x11af); |
1210 | schar = 0x1109; | 1210 | schar = 0x1109; |
1211 | break; | 1211 | break; |
1212 | case 0x11b4: | 1212 | case 0x11b4: |
1213 | prev = combineKoreanChars(schar, mchar, 0x11af); | 1213 | prev = combineKoreanChars(schar, mchar, 0x11af); |
1214 | schar = 0x1110; | 1214 | schar = 0x1110; |
1215 | break; | 1215 | break; |
1216 | case 0x11b9: | 1216 | case 0x11b9: |
1217 | prev = combineKoreanChars(schar, mchar, 0x11b8); | 1217 | prev = combineKoreanChars(schar, mchar, 0x11b8); |
1218 | schar = 0x1109; | 1218 | schar = 0x1109; |
1219 | break; | 1219 | break; |
1220 | /* | 1220 | /* |
1221 | case 0x11bb: | 1221 | case 0x11bb: |
1222 | prev = combineKoreanChars(schar, mchar, 0x11ba); | 1222 | prev = combineKoreanChars(schar, mchar, 0x11ba); |
1223 | schar = 0x1109; | 1223 | schar = 0x1109; |
1224 | break; | 1224 | break; |
1225 | */ | 1225 | */ |
1226 | default: | 1226 | default: |
1227 | 1227 | ||
1228 | if (constoe(echar)) { | 1228 | if (constoe(echar)) { |
1229 | 1229 | ||
1230 | prev = combineKoreanChars(schar, mchar, 0); | 1230 | prev = combineKoreanChars(schar, mchar, 0); |
1231 | schar = constoe(echar); | 1231 | schar = constoe(echar); |
1232 | } | 1232 | } |
1233 | break; | 1233 | break; |
1234 | } | 1234 | } |
1235 | 1235 | ||
1236 | emit key( prev, prev, 0, true, false ); | 1236 | emit key( prev, prev, 0, true, false ); |
1237 | 1237 | ||
1238 | mchar = c; echar = 0; | 1238 | mchar = c; echar = 0; |
1239 | 1239 | ||
1240 | return combineKoreanChars(schar, mchar, 0); | 1240 | return combineKoreanChars(schar, mchar, 0); |
1241 | 1241 | ||
1242 | } | 1242 | } |
1243 | else { | 1243 | else { |
1244 | schar = 0; mchar = 0; echar = 0; | 1244 | schar = 0; mchar = 0; echar = 0; |
1245 | return c; | 1245 | return c; |
1246 | } | 1246 | } |
1247 | 1247 | ||
1248 | } | 1248 | } |
1249 | else /*if (c == ' ')*/ return c; | 1249 | else /*if (c == ' ')*/ return c; |
1250 | 1250 | ||
1251 | 1251 | ||
1252 | // and now... finally delete previous char, and return new char | 1252 | // and now... finally delete previous char, and return new char |
1253 | emit key( 8, Qt::Key_Backspace, 0, true, false ); | 1253 | emit key( 8, Qt::Key_Backspace, 0, true, false ); |
1254 | 1254 | ||
1255 | 1255 | ||
1256 | return combineKoreanChars( schar, mchar, echar); | 1256 | return combineKoreanChars( schar, mchar, echar); |
1257 | 1257 | ||
1258 | } | 1258 | } |
1259 | 1259 | ||
1260 | ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { | 1260 | ushort Keyboard::combineKoreanChars(const ushort s, const ushort m, const ushort e) { |
1261 | 1261 | ||
1262 | return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; | 1262 | return ((s - 0x1100) * 588) + ((m - 0x1161) * 28) + (e ? e - 0x11a7 : 0) + 0xac00; |
1263 | 1263 | ||
1264 | } | 1264 | } |
1265 | 1265 | ||
1266 | ushort Keyboard::constoe(const ushort c) { | 1266 | ushort Keyboard::constoe(const ushort c) { |
1267 | 1267 | ||
1268 | // converts schars to echars if possible | 1268 | // converts schars to echars if possible |
1269 | 1269 | ||
1270 | if (0x1100 <= c && c <= 0x1112) { // schar to echar | 1270 | if (0x1100 <= c && c <= 0x1112) { // schar to echar |
1271 | 1271 | ||
1272 | switch (c) { | 1272 | switch (c) { |
1273 | case 0x1100: return 0x11a8; | 1273 | case 0x1100: return 0x11a8; |
1274 | case 0x1101: return 0x11a9; | 1274 | case 0x1101: return 0x11a9; |
1275 | case 0x1102: return 0x11ab; | 1275 | case 0x1102: return 0x11ab; |
1276 | case 0x1103: return 0x11ae; | 1276 | case 0x1103: return 0x11ae; |
1277 | case 0x1105: return 0x11af; | 1277 | case 0x1105: return 0x11af; |
1278 | case 0x1106: return 0x11b7; | 1278 | case 0x1106: return 0x11b7; |
1279 | case 0x1107: return 0x11b8; | 1279 | case 0x1107: return 0x11b8; |
1280 | case 0x1109: return 0x11ba; | 1280 | case 0x1109: return 0x11ba; |
1281 | case 0x110a: return 0x11bb; | 1281 | case 0x110a: return 0x11bb; |
1282 | case 0x110b: return 0x11bc; | 1282 | case 0x110b: return 0x11bc; |
1283 | case 0x110c: return 0x11bd; | 1283 | case 0x110c: return 0x11bd; |
1284 | case 0x110e: return 0x11be; | 1284 | case 0x110e: return 0x11be; |
1285 | case 0x110f: return 0x11bf; | 1285 | case 0x110f: return 0x11bf; |
1286 | case 0x1110: return 0x11c0; | 1286 | case 0x1110: return 0x11c0; |
1287 | case 0x1111: return 0x11c1; | 1287 | case 0x1111: return 0x11c1; |
1288 | case 0x1112: return 0x11c2; | 1288 | case 0x1112: return 0x11c2; |
1289 | default: return 0; | 1289 | default: return 0; |
1290 | 1290 | ||
1291 | } | 1291 | } |
1292 | 1292 | ||
1293 | } else { //echar to schar | 1293 | } else { //echar to schar |
1294 | 1294 | ||
1295 | switch (c) { | 1295 | switch (c) { |
1296 | case 0x11a8: return 0x1100; | 1296 | case 0x11a8: return 0x1100; |
1297 | case 0x11a9: return 0x1101; | 1297 | case 0x11a9: return 0x1101; |
1298 | case 0x11ab: return 0x1102; | 1298 | case 0x11ab: return 0x1102; |
1299 | case 0x11ae: return 0x1103; | 1299 | case 0x11ae: return 0x1103; |
1300 | case 0x11af: return 0x1105; | 1300 | case 0x11af: return 0x1105; |
1301 | case 0x11b7: return 0x1106; | 1301 | case 0x11b7: return 0x1106; |
1302 | case 0x11b8: return 0x1107; | 1302 | case 0x11b8: return 0x1107; |
1303 | case 0x11ba: return 0x1109; | 1303 | case 0x11ba: return 0x1109; |
1304 | case 0x11bb: return 0x110a; | 1304 | case 0x11bb: return 0x110a; |
1305 | case 0x11bc: return 0x110b; | 1305 | case 0x11bc: return 0x110b; |
1306 | case 0x11bd: return 0x110c; | 1306 | case 0x11bd: return 0x110c; |
1307 | case 0x11be: return 0x110e; | 1307 | case 0x11be: return 0x110e; |
1308 | case 0x11bf: return 0x110f; | 1308 | case 0x11bf: return 0x110f; |
1309 | case 0x11c0: return 0x1110; | 1309 | case 0x11c0: return 0x1110; |
1310 | case 0x11c1: return 0x1111; | 1310 | case 0x11c1: return 0x1111; |
1311 | case 0x11c2: return 0x1112; | 1311 | case 0x11c2: return 0x1112; |
1312 | default: return 0; | 1312 | default: return 0; |
1313 | 1313 | ||
1314 | } | 1314 | } |
1315 | 1315 | ||
1316 | } | 1316 | } |
1317 | } | 1317 | } |
1318 | 1318 | ||
1319 | 1319 | ||
1320 | // Keys::Keys {{{1 | 1320 | // Keys::Keys {{{1 |
1321 | 1321 | ||
1322 | Keys::Keys() { | 1322 | Keys::Keys() { |
1323 | 1323 | ||
1324 | Config *config = new Config ("multikey"); | 1324 | Config *config = new Config ("multikey"); |
1325 | config->setGroup( "keymaps" ); | 1325 | config->setGroup( "keymaps" ); |
1326 | QString map = config->readEntry( "current" ); | 1326 | QString map = config->readEntry( "current" ); |
1327 | delete config; | 1327 | delete config; |
1328 | 1328 | ||
1329 | if (map.isNull() || !(QFile(map).exists())) { | 1329 | if (map.isNull() || !(QFile(map).exists())) { |
1330 | 1330 | ||
1331 | Config *config = new Config("locale"); | 1331 | Config *config = new Config("locale"); |
1332 | config->setGroup( "Language" ); | 1332 | config->setGroup( "Language" ); |
1333 | QString l = config->readEntry( "Language" , "en" ); | 1333 | QString l = config->readEntry( "Language" , "en" ); |
1334 | delete config; | 1334 | delete config; |
1335 | 1335 | ||
1336 | map = QPEApplication::qpeDir() + "/share/multikey/" | 1336 | map = QPEApplication::qpeDir() + "/share/multikey/" |
1337 | + l + ".keymap"; | 1337 | + l + ".keymap"; |
1338 | 1338 | ||
1339 | } | 1339 | } |
1340 | if (map.isNull() || !(QFile(map).exists())) { | 1340 | if (map.isNull() || !(QFile(map).exists())) { |
1341 | map = QPEApplication::qpeDir() + "/share/multikey/en.keymap"; | 1341 | map = QPEApplication::qpeDir() + "/share/multikey/en.keymap"; |
1342 | } | 1342 | } |
1343 | 1343 | ||
1344 | setKeysFromFile(map); | 1344 | setKeysFromFile(map); |
1345 | } | 1345 | } |
1346 | 1346 | ||
1347 | Keys::Keys(const char * filename) { | 1347 | Keys::Keys(const char * filename) { |
1348 | 1348 | ||
1349 | setKeysFromFile(filename); | 1349 | setKeysFromFile(filename); |
1350 | } | 1350 | } |
1351 | 1351 | ||
1352 | // Keys::setKeysFromFile {{{2 | 1352 | // Keys::setKeysFromFile {{{2 |
1353 | void Keys::setKeysFromFile(const char * filename) { | 1353 | void Keys::setKeysFromFile(const char * filename) { |
1354 | 1354 | ||
1355 | QFile f(filename); | 1355 | QFile f(filename); |
1356 | 1356 | ||
1357 | if (f.open(IO_ReadOnly)) { | 1357 | if (f.open(IO_ReadOnly)) { |
1358 | 1358 | ||
1359 | QTextStream t(&f); | 1359 | QTextStream t(&f); |
1360 | int row; | 1360 | int row; |
1361 | int qcode; | 1361 | int qcode; |
1362 | ushort unicode; | 1362 | ushort unicode; |
1363 | int width; | 1363 | int width; |
1364 | QString buf; | 1364 | QString buf; |
1365 | QString comment; | 1365 | QString comment; |
1366 | char * xpm[256]; //couldnt be larger than that... could it? | 1366 | char * xpm[256]; //couldnt be larger than that... could it? |
1367 | QImage *xpm2pix = 0; | 1367 | QImage *xpm2pix = 0; |
1368 | 1368 | ||
1369 | buf = t.readLine(); | 1369 | buf = t.readLine(); |
1370 | while (buf) { | 1370 | while (buf) { |
1371 | 1371 | ||
1372 | // get rid of comments | 1372 | // get rid of comments |
1373 | buf.replace(QRegExp("#.*$", FALSE, FALSE), ""); | 1373 | buf.replace(QRegExp("#.*$", FALSE, FALSE), ""); |
1374 | 1374 | ||
1375 | // key definition | 1375 | // key definition |
1376 | if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { | 1376 | if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { |
1377 | // no $1 type referencing!!! this implementation of regexp sucks | 1377 | // no $1 type referencing!!! this implementation of regexp sucks |
1378 | 1378 | ||
1379 | // dont know of any sscanf() type funcs in Qt lib | 1379 | // dont know of any sscanf() type funcs in Qt lib |
1380 | QTextStream tmp (buf, IO_ReadOnly); | 1380 | QTextStream tmp (buf, IO_ReadOnly); |
1381 | tmp >> row >> qcode >> unicode >> width >> comment; | 1381 | tmp >> row >> qcode >> unicode >> width >> comment; |
1382 | 1382 | ||
1383 | buf = t.readLine(); | 1383 | buf = t.readLine(); |
1384 | int xpmLineCount = 0; | 1384 | int xpmLineCount = 0; |
1385 | xpm2pix = 0; | 1385 | xpm2pix = 0; |
1386 | 1386 | ||
1387 | // erase blank space | 1387 | // erase blank space |
1388 | while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); | 1388 | while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); |
1389 | 1389 | ||
1390 | while (buf.contains(QRegExp("^\\s*\".*\""))) { | 1390 | while (buf.contains(QRegExp("^\\s*\".*\""))) { |
1391 | 1391 | ||
1392 | QString xpmBuf = buf.stripWhiteSpace(); | 1392 | QString xpmBuf = buf.stripWhiteSpace(); |
1393 | 1393 | ||
1394 | xpm[xpmLineCount] = new char [xpmBuf.length()]; | 1394 | xpm[xpmLineCount] = new char [xpmBuf.length()]; |
1395 | 1395 | ||
1396 | int j = 0; | 1396 | int j = 0; |
1397 | for (ushort i = 0; i < xpmBuf.length(); i++) { | 1397 | for (ushort i = 0; i < xpmBuf.length(); i++) { |
1398 | if (xpmBuf[i].latin1() != '"') { | 1398 | if (xpmBuf[i].latin1() != '"') { |
1399 | 1399 | ||
1400 | ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); | 1400 | ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); |
1401 | j++; | 1401 | j++; |
1402 | } | 1402 | } |
1403 | 1403 | ||
1404 | } | 1404 | } |
1405 | // have to close that facker up | 1405 | // have to close that facker up |
1406 | ((char *)xpm[xpmLineCount])[j] = '\0'; | 1406 | ((char *)xpm[xpmLineCount])[j] = '\0'; |
1407 | 1407 | ||
1408 | xpmLineCount++; | 1408 | xpmLineCount++; |
1409 | buf = t.readLine(); | 1409 | buf = t.readLine(); |
1410 | } | 1410 | } |
1411 | if (xpmLineCount) { | 1411 | if (xpmLineCount) { |
1412 | 1412 | ||
1413 | xpm2pix = new QImage((const char **)xpm); | 1413 | xpm2pix = new QImage((const char **)xpm); |
1414 | for (int i = 0; i < xpmLineCount; i++) | 1414 | for (int i = 0; i < xpmLineCount; i++) |
1415 | 1415 | ||
1416 | delete [] (xpm[i]); | 1416 | delete [] (xpm[i]); |
1417 | 1417 | ||
1418 | } | 1418 | } |
1419 | setKey(row, qcode, unicode, width, xpm2pix); | 1419 | setKey(row, qcode, unicode, width, xpm2pix); |
1420 | } | 1420 | } |
1421 | 1421 | ||
1422 | // shift map | 1422 | // shift map |
1423 | else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { | 1423 | else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { |
1424 | 1424 | ||
1425 | QTextStream tmp (buf, IO_ReadOnly); | 1425 | QTextStream tmp (buf, IO_ReadOnly); |
1426 | ushort lower, shift; | 1426 | ushort lower, shift; |
1427 | tmp >> lower >> shift; | 1427 | tmp >> lower >> shift; |
1428 | 1428 | ||
1429 | shiftMap.insert(lower, shift); | 1429 | shiftMap.insert(lower, shift); |
1430 | 1430 | ||
1431 | buf = t.readLine(); | 1431 | buf = t.readLine(); |
1432 | } | 1432 | } |
1433 | 1433 | ||
1434 | // meta key map | 1434 | // meta key map |
1435 | else if (buf.contains(QRegExp("^\\s*m\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { | 1435 | else if (buf.contains(QRegExp("^\\s*m\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { |
1436 | 1436 | ||
1437 | QTextStream tmp (buf, IO_ReadOnly); | 1437 | QTextStream tmp (buf, IO_ReadOnly); |
1438 | ushort lower, shift; | 1438 | ushort lower, shift; |
1439 | QChar m; | 1439 | QChar m; |
1440 | tmp >> m >> lower >> shift; | 1440 | tmp >> m >> lower >> shift; |
1441 | 1441 | ||
1442 | metaMap.insert(lower, shift); | 1442 | metaMap.insert(lower, shift); |
1443 | 1443 | ||
1444 | buf = t.readLine(); | 1444 | buf = t.readLine(); |
1445 | } | 1445 | } |
1446 | 1446 | ||
1447 | // circumflex | 1447 | // circumflex |
1448 | else if (buf.contains(QRegExp("^\\s*c\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { | 1448 | else if (buf.contains(QRegExp("^\\s*c\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { |
1449 | 1449 | ||
1450 | QTextStream tmp (buf, IO_ReadOnly); | 1450 | QTextStream tmp (buf, IO_ReadOnly); |
1451 | ushort lower, shift; | 1451 | ushort lower, shift; |
1452 | QChar c; | 1452 | QChar c; |
1453 | tmp >> c >> lower >> shift; | 1453 | tmp >> c >> lower >> shift; |
1454 | 1454 | ||
1455 | circumflexMap.insert(lower, shift); | 1455 | circumflexMap.insert(lower, shift); |
1456 | 1456 | ||
1457 | buf = t.readLine(); | 1457 | buf = t.readLine(); |
1458 | } | 1458 | } |
1459 | // diaeresis | 1459 | // diaeresis |
1460 | else if (buf.contains(QRegExp("^\\s*d\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { | 1460 | else if (buf.contains(QRegExp("^\\s*d\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { |
1461 | 1461 | ||
1462 | QTextStream tmp (buf, IO_ReadOnly); | 1462 | QTextStream tmp (buf, IO_ReadOnly); |
1463 | ushort lower, shift; | 1463 | ushort lower, shift; |
1464 | QChar d; | 1464 | QChar d; |
1465 | tmp >> d >> lower >> shift; | 1465 | tmp >> d >> lower >> shift; |
1466 | 1466 | ||
1467 | diaeresisMap.insert(lower, shift); | 1467 | diaeresisMap.insert(lower, shift); |
1468 | 1468 | ||
1469 | buf = t.readLine(); | 1469 | buf = t.readLine(); |
1470 | } | 1470 | } |
1471 | // back accent | 1471 | // back accent |
1472 | else if (buf.contains(QRegExp("^\\s*b\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { | 1472 | else if (buf.contains(QRegExp("^\\s*b\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { |
1473 | 1473 | ||
1474 | QTextStream tmp (buf, IO_ReadOnly); | 1474 | QTextStream tmp (buf, IO_ReadOnly); |
1475 | ushort lower, shift; | 1475 | ushort lower, shift; |
1476 | QChar d; | 1476 | QChar d; |
1477 | tmp >> d >> lower >> shift; | 1477 | tmp >> d >> lower >> shift; |
1478 | 1478 | ||
1479 | baccentMap.insert(lower, shift); | 1479 | baccentMap.insert(lower, shift); |
1480 | 1480 | ||
1481 | qDebug ("Estoy aadiendo %i con %i", lower, shift); | 1481 | qDebug ("Estoy aadiendo %i con %i", lower, shift); |
1482 | buf = t.readLine(); | 1482 | buf = t.readLine(); |
1483 | } | 1483 | } |
1484 | // accent | 1484 | // accent |
1485 | else if (buf.contains(QRegExp("^\\s*a\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { | 1485 | else if (buf.contains(QRegExp("^\\s*a\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { |
1486 | 1486 | ||
1487 | QTextStream tmp (buf, IO_ReadOnly); | 1487 | QTextStream tmp (buf, IO_ReadOnly); |
1488 | ushort lower, shift; | 1488 | ushort lower, shift; |
1489 | QChar d; | 1489 | QChar d; |
1490 | tmp >> d >> lower >> shift; | 1490 | tmp >> d >> lower >> shift; |
1491 | 1491 | ||
1492 | accentMap.insert(lower, shift); | 1492 | accentMap.insert(lower, shift); |
1493 | 1493 | ||
1494 | buf = t.readLine(); | 1494 | buf = t.readLine(); |
1495 | } | 1495 | } |
1496 | 1496 | ||
1497 | // other variables like lang & title | 1497 | // other variables like lang & title |
1498 | else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { | 1498 | else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { |
1499 | 1499 | ||
1500 | QTextStream tmp (buf, IO_ReadOnly); | 1500 | QTextStream tmp (buf, IO_ReadOnly); |
1501 | QString name, equals, value; | 1501 | QString name, equals, value; |
1502 | 1502 | ||
1503 | tmp >> name >> equals >> value; | 1503 | tmp >> name >> equals >> value; |
1504 | 1504 | ||
1505 | if (name == "lang") { | 1505 | if (name == "lang") { |
1506 | 1506 | ||
1507 | lang = value; | 1507 | lang = value; |
1508 | 1508 | ||
1509 | } | 1509 | } |
1510 | 1510 | ||
1511 | buf = t.readLine(); | 1511 | buf = t.readLine(); |
1512 | } | 1512 | } |
1513 | // comments | 1513 | // comments |
1514 | else if (buf.contains(QRegExp("^\\s*#"))) { | 1514 | else if (buf.contains(QRegExp("^\\s*#"))) { |
1515 | 1515 | ||
1516 | buf = t.readLine(); | 1516 | buf = t.readLine(); |
1517 | 1517 | ||
1518 | } else { // blank line, or garbage | 1518 | } else { // blank line, or garbage |
1519 | 1519 | ||
1520 | buf = t.readLine(); | 1520 | buf = t.readLine(); |
1521 | 1521 | ||
1522 | } | 1522 | } |
1523 | 1523 | ||
1524 | } | 1524 | } |
1525 | f.close(); | 1525 | f.close(); |
1526 | } | 1526 | } |
1527 | 1527 | ||
1528 | } | 1528 | } |
1529 | 1529 | ||
1530 | // Keys::setKey {{{2 | 1530 | // Keys::setKey {{{2 |
1531 | void Keys::setKey(const int row, const int qcode, const ushort unicode, | 1531 | void Keys::setKey(const int row, const int qcode, const ushort unicode, |
1532 | const int width, QImage *pix) { | 1532 | const int width, QImage *pix) { |
1533 | 1533 | ||
1534 | Key * key; | 1534 | Key * key; |
1535 | key = new Key; | 1535 | key = new Key; |
1536 | key->qcode = qcode; | 1536 | key->qcode = qcode; |
1537 | key->unicode = unicode; | 1537 | key->unicode = unicode; |
1538 | key->width = width; | 1538 | key->width = width; |
1539 | 1539 | ||
1540 | // share key->pressed between same keys | 1540 | // share key->pressed between same keys |
1541 | bool found = 0; | 1541 | bool found = 0; |
1542 | for (int i = 1; i <= 5; i++) { | 1542 | for (int i = 1; i <= 5; i++) { |
1543 | for (unsigned int j = 0; j < keys[i].count(); j++) | 1543 | for (unsigned int j = 0; j < keys[i].count(); j++) |
1544 | if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { | 1544 | if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { |
1545 | 1545 | ||
1546 | key->pressed = keys[i].at(j)->pressed; | 1546 | key->pressed = keys[i].at(j)->pressed; |
1547 | found = 1; | 1547 | found = 1; |
1548 | } | 1548 | } |
1549 | 1549 | ||
1550 | } | 1550 | } |
1551 | if (!found) { | 1551 | if (!found) { |
1552 | 1552 | ||
1553 | key->pressed = new bool; | 1553 | key->pressed = new bool; |
1554 | *(key->pressed) = 0; | 1554 | *(key->pressed) = 0; |
1555 | } | 1555 | } |
1556 | 1556 | ||
1557 | key->pix = pix; | 1557 | key->pix = pix; |
1558 | 1558 | ||
1559 | 1559 | ||
1560 | keys[row].append(key); | 1560 | keys[row].append(key); |
1561 | } | 1561 | } |
1562 | 1562 | ||
1563 | // Keys::~Keys {{{2 | 1563 | // Keys::~Keys {{{2 |
1564 | Keys::~Keys() { | 1564 | Keys::~Keys() { |
1565 | 1565 | ||
1566 | for (int i = 1; i <= 5; i++) | 1566 | for (int i = 1; i <= 5; i++) |
1567 | for (unsigned int j = 0; j < keys[i].count(); j++) | 1567 | for (unsigned int j = 0; j < keys[i].count(); j++) |
1568 | delete keys[i].at(j); | 1568 | delete keys[i].at(j); |
1569 | 1569 | ||
1570 | } | 1570 | } |
1571 | 1571 | ||
1572 | // Keys:: other functions {{{2 | 1572 | // Keys:: other functions {{{2 |
1573 | int Keys::width(const int row, const int col) { | 1573 | int Keys::width(const int row, const int col) { |
1574 | 1574 | ||
1575 | return keys[row].at(col)->width; | 1575 | return keys[row].at(col)->width; |
1576 | 1576 | ||
1577 | } | 1577 | } |
1578 | 1578 | ||
1579 | int Keys::rows() { | 1579 | int Keys::rows() { |
1580 | 1580 | ||
1581 | for (int i = 1; i <= 5; i++) { | 1581 | for (int i = 1; i <= 5; i++) { |
1582 | 1582 | ||
1583 | if (keys[i].count() == 0) | 1583 | if (keys[i].count() == 0) |
1584 | return i - 1; | 1584 | return i - 1; |
1585 | 1585 | ||
1586 | } | 1586 | } |
1587 | return 5; | 1587 | return 5; |
1588 | } | 1588 | } |
1589 | 1589 | ||
1590 | ushort Keys::uni(const int row, const int col) { | 1590 | ushort Keys::uni(const int row, const int col) { |
1591 | 1591 | ||
1592 | return keys[row].at(col)->unicode; | 1592 | return keys[row].at(col)->unicode; |