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