Diffstat (limited to 'inputmethods/multikey/keyboard.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | inputmethods/multikey/keyboard.cpp | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp index ac3d9be..68918a6 100644 --- a/inputmethods/multikey/keyboard.cpp +++ b/inputmethods/multikey/keyboard.cpp | |||
@@ -4,235 +4,233 @@ | |||
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 | #define USE_SMALL_BACKSPACE | 42 | #define USE_SMALL_BACKSPACE |
43 | 43 | ||
44 | /* Keyboard::Keyboard {{{1 */ | 44 | /* Keyboard::Keyboard {{{1 */ |
45 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : | 45 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : |
46 | QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), | 46 | QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), |
47 | alt(0), useLargeKeys(TRUE), usePicks(0), pressedKeyRow(-1), pressedKeyCol(-1), | 47 | alt(0), useLargeKeys(TRUE), usePicks(0), 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 | // get the default font | 53 | // get the default font |
53 | Config *config = new Config( "qpe" ); | 54 | Config *config = new Config( "qpe" ); |
54 | config->setGroup( "Appearance" ); | 55 | config->setGroup( "Appearance" ); |
55 | QString familyStr = config->readEntry( "FontFamily", "fixed" ); | 56 | QString familyStr = config->readEntry( "FontFamily", "fixed" ); |
56 | delete config; | 57 | delete config; |
57 | 58 | ||
58 | config = new Config("multikey"); | 59 | config = new Config("multikey"); |
59 | config->setGroup ("pickboard"); | 60 | config->setGroup ("pickboard"); |
60 | usePicks = config->readBoolEntry ("open", "0"); // default closed | 61 | usePicks = config->readBoolEntry ("open", "0"); // default closed |
61 | delete config; | 62 | delete config; |
62 | 63 | ||
63 | setFont( QFont( familyStr, 10 ) ); | 64 | setFont( QFont( familyStr, 10 ) ); |
64 | 65 | ||
65 | picks = new KeyboardPicks( this ); | 66 | picks = new KeyboardPicks( this ); |
66 | picks->setFont( QFont( familyStr, 10 ) ); | 67 | picks->setFont( QFont( familyStr, 10 ) ); |
67 | picks->initialise(); | 68 | picks->initialise(); |
68 | if (usePicks) { | 69 | if (usePicks) { |
69 | 70 | ||
70 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 71 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
71 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 72 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
72 | 73 | ||
73 | } else picks->hide(); | 74 | } else picks->hide(); |
74 | 75 | ||
76 | loadKeyboardColors(); | ||
77 | |||
75 | keys = new Keys(); | 78 | keys = new Keys(); |
76 | 79 | ||
77 | repeatTimer = new QTimer( this ); | 80 | repeatTimer = new QTimer( this ); |
78 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); | 81 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); |
79 | 82 | ||
80 | } | 83 | } |
84 | |||
81 | Keyboard::~Keyboard() { | 85 | Keyboard::~Keyboard() { |
82 | 86 | ||
83 | if ( configdlg ) { | 87 | if ( configdlg ) { |
84 | delete (ConfigDlg *) configdlg; | 88 | delete (ConfigDlg *) configdlg; |
85 | configdlg = 0; | 89 | configdlg = 0; |
86 | } | 90 | } |
87 | 91 | ||
88 | } | 92 | } |
89 | 93 | ||
90 | /* Keyboard::resizeEvent {{{1 */ | 94 | /* Keyboard::resizeEvent {{{1 */ |
91 | void Keyboard::resizeEvent(QResizeEvent*) | 95 | void Keyboard::resizeEvent(QResizeEvent*) |
92 | { | 96 | { |
93 | int ph = picks->sizeHint().height(); | 97 | int ph = picks->sizeHint().height(); |
94 | picks->setGeometry( 0, 0, width(), ph ); | 98 | picks->setGeometry( 0, 0, width(), ph ); |
95 | keyHeight = (height()-(usePicks ? ph : 0))/5; | 99 | keyHeight = (height()-(usePicks ? ph : 0))/5; |
96 | 100 | ||
97 | int nk; // number of keys? | 101 | int nk; // number of keys? |
98 | if ( useLargeKeys ) { | 102 | if ( useLargeKeys ) { |
99 | nk = 15; | 103 | nk = 15; |
100 | } else { | 104 | } else { |
101 | nk = 19; | 105 | nk = 19; |
102 | } | 106 | } |
103 | defaultKeyWidth = (width()/nk)/2; | 107 | defaultKeyWidth = (width()/nk)/2; |
104 | xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? | 108 | xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? |
105 | 109 | ||
106 | } | 110 | } |
107 | 111 | ||
108 | /* KeyboardPicks::initialize {{{1 */ | 112 | /* KeyboardPicks::initialize {{{1 */ |
109 | void KeyboardPicks::initialise() | 113 | void KeyboardPicks::initialise() |
110 | { | 114 | { |
111 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); | 115 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); |
112 | mode = 0; | 116 | mode = 0; |
113 | dc = new KeyboardConfig(this); | 117 | dc = new KeyboardConfig(this); |
114 | configs.append(dc); | 118 | configs.append(dc); |
115 | } | 119 | } |
116 | 120 | ||
117 | /* KeyboardPicks::sizeHint {{{1 */ | 121 | /* KeyboardPicks::sizeHint {{{1 */ |
118 | QSize KeyboardPicks::sizeHint() const | 122 | QSize KeyboardPicks::sizeHint() const |
119 | { | 123 | { |
120 | return QSize(240,fontMetrics().lineSpacing()); | 124 | return QSize(240,fontMetrics().lineSpacing()); |
121 | } | 125 | } |
122 | 126 | ||
123 | 127 | ||
124 | /* KeyboardConfig::generateText {{{1 */ | 128 | /* KeyboardConfig::generateText {{{1 */ |
125 | void KeyboardConfig::generateText(const QString &s) | 129 | void KeyboardConfig::generateText(const QString &s) |
126 | { | 130 | { |
127 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 131 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
128 | for (int i=0; i<(int)backspaces; i++) { | 132 | for (int i=0; i<(int)backspaces; i++) { |
129 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); | 133 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); |
130 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); | 134 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); |
131 | } | 135 | } |
132 | for (int i=0; i<(int)s.length(); i++) { | 136 | for (int i=0; i<(int)s.length(); i++) { |
133 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); | 137 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); |
134 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); | 138 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); |
135 | } | 139 | } |
136 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); | 140 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); |
137 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); | 141 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); |
138 | backspaces = 0; | 142 | backspaces = 0; |
139 | #endif | 143 | #endif |
140 | } | 144 | } |
141 | 145 | ||
142 | 146 | ||
143 | 147 | ||
144 | 148 | ||
145 | /* Keyboard::paintEvent {{{1 */ | 149 | /* Keyboard::paintEvent {{{1 */ |
146 | void Keyboard::paintEvent(QPaintEvent* e) | 150 | void Keyboard::paintEvent(QPaintEvent* e) |
147 | { | 151 | { |
148 | QPainter painter(this); | 152 | QPainter painter(this); |
149 | painter.setClipRect(e->rect()); | 153 | painter.setClipRect(e->rect()); |
150 | drawKeyboard( painter ); | 154 | drawKeyboard( painter ); |
151 | picks->dc->draw( &painter ); | 155 | picks->dc->draw( &painter ); |
152 | } | 156 | } |
153 | 157 | ||
154 | 158 | ||
155 | /* Keyboard::drawKeyboard {{{1 */ | 159 | /* Keyboard::drawKeyboard {{{1 */ |
156 | 160 | ||
157 | void Keyboard::drawKeyboard(QPainter &p, int row, int col) | 161 | void Keyboard::drawKeyboard(QPainter &p, int row, int col) |
158 | { | 162 | { |
159 | QColor keycolor = | ||
160 | QColor(240,240,240); | ||
161 | QColor keycolor_pressed = QColor(171,183,198); | ||
162 | QColor keycolor_lines = QColor(138,148,160); | ||
163 | QColor textcolor = QColor(43,54,68); | ||
164 | 163 | ||
165 | 164 | ||
166 | if (row != -1 && col != -1) { //just redraw one key | 165 | if (row != -1 && col != -1) { //just redraw one key |
167 | 166 | ||
168 | int x = 0; | 167 | int x = 0; |
169 | for (int i = 0; i < col; i++) { | 168 | for (int i = 0; i < col; i++) { |
170 | 169 | ||
171 | x += keys->width(row, i) * defaultKeyWidth; | 170 | x += keys->width(row, i) * defaultKeyWidth; |
172 | } | 171 | } |
173 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 172 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
174 | 173 | ||
175 | int keyWidth = keys->width(row, col); | 174 | int keyWidth = keys->width(row, col); |
176 | 175 | ||
177 | p.fillRect(x + 1, y + 1, | 176 | p.fillRect(x + 1, y + 1, |
178 | keyWidth * defaultKeyWidth - 1, keyHeight - 1, | 177 | keyWidth * defaultKeyWidth - 1, keyHeight - 1, |
179 | pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); | 178 | pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); |
180 | 179 | ||
181 | QPixmap *pix = keys->pix(row,col); | 180 | QPixmap *pix = keys->pix(row,col); |
182 | 181 | ||
183 | ushort c = keys->uni(row, col); | 182 | ushort c = keys->uni(row, col); |
184 | 183 | ||
185 | if (!pix) { | ||
186 | p.setPen(textcolor); | 184 | p.setPen(textcolor); |
185 | if (!pix) | ||
187 | p.drawText(x, y, | 186 | p.drawText(x, y, |
188 | defaultKeyWidth * keyWidth, keyHeight, | 187 | defaultKeyWidth * keyWidth, keyHeight, |
189 | 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); |
190 | } | ||
191 | else | 189 | else |
192 | // center the image in the middle of the key | 190 | // center the image in the middle of the key |
193 | p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, | 191 | p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, |
194 | y + (keyHeight - pix->height())/2 + 1, | 192 | y + (keyHeight - pix->height())/2 + 1, |
195 | *pix ); | 193 | *pix ); |
196 | 194 | ||
197 | // 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 |
198 | // 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 |
199 | p.setPen(keycolor_lines); | 197 | p.setPen(keycolor_lines); |
200 | p.drawLine(width() - 1, 0, width() - 1, height()); | 198 | p.drawLine(width() - 1, 0, width() - 1, height()); |
201 | 199 | ||
202 | } else { | 200 | } else { |
203 | 201 | ||
204 | 202 | ||
205 | p.fillRect(0, 0, width(), height(), keycolor); | 203 | p.fillRect(0, 0, width(), height(), keycolor); |
206 | 204 | ||
207 | for (row = 1; row <= 5; row++) { | 205 | for (row = 1; row <= 5; row++) { |
208 | 206 | ||
209 | int x = 0; | 207 | int x = 0; |
210 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 208 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
211 | 209 | ||
212 | p.setPen(keycolor_lines); | 210 | p.setPen(keycolor_lines); |
213 | p.drawLine(x, y, x + width(), y); | 211 | p.drawLine(x, y, x + width(), y); |
214 | 212 | ||
215 | for (int col = 0; col < keys->numKeys(row); col++) { | 213 | for (int col = 0; col < keys->numKeys(row); col++) { |
216 | 214 | ||
217 | QPixmap *pix = keys->pix(row, col); | 215 | QPixmap *pix = keys->pix(row, col); |
218 | int keyWidth = keys->width(row, col); | 216 | int keyWidth = keys->width(row, col); |
219 | 217 | ||
220 | 218 | ||
221 | int keyWidthPix = defaultKeyWidth * keyWidth; | 219 | int keyWidthPix = defaultKeyWidth * keyWidth; |
222 | 220 | ||
223 | if (keys->pressed(row, col)) | 221 | if (keys->pressed(row, col)) |
224 | p.fillRect(x+1, y+1, keyWidthPix - 1, | 222 | p.fillRect(x+1, y+1, keyWidthPix - 1, |
225 | keyHeight - 1, keycolor_pressed); | 223 | keyHeight - 1, keycolor_pressed); |
226 | 224 | ||
227 | ushort c = keys->uni(row, col); | 225 | ushort c = keys->uni(row, col); |
228 | 226 | ||
229 | if (!pix) { | 227 | if (!pix) { |
230 | p.setPen(textcolor); | 228 | p.setPen(textcolor); |
231 | p.drawText(x, y, | 229 | p.drawText(x, y, |
232 | keyWidthPix, keyHeight, | 230 | keyWidthPix, keyHeight, |
233 | 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); |
234 | } | 232 | } |
235 | else { | 233 | else { |
236 | // center the image in the middle of the key | 234 | // center the image in the middle of the key |
237 | p.drawPixmap( x + (keyWidthPix - pix->width())/2, | 235 | p.drawPixmap( x + (keyWidthPix - pix->width())/2, |
238 | y + (keyHeight - pix->height())/2 + 1, | 236 | y + (keyHeight - pix->height())/2 + 1, |
@@ -247,96 +245,98 @@ void Keyboard::drawKeyboard(QPainter &p, int row, int col) | |||
247 | 245 | ||
248 | 246 | ||
249 | } | 247 | } |
250 | p.drawLine(0, height() - 1, width(), height() - 1); | 248 | p.drawLine(0, height() - 1, width(), height() - 1); |
251 | p.drawLine(width() - 1, 0, width() - 1, height()); | 249 | p.drawLine(width() - 1, 0, width() - 1, height()); |
252 | } | 250 | } |
253 | 251 | ||
254 | } | 252 | } |
255 | 253 | ||
256 | 254 | ||
257 | /* Keyboard::mousePressEvent {{{1 */ | 255 | /* Keyboard::mousePressEvent {{{1 */ |
258 | void Keyboard::mousePressEvent(QMouseEvent *e) | 256 | void Keyboard::mousePressEvent(QMouseEvent *e) |
259 | { | 257 | { |
260 | int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; | 258 | int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1; |
261 | if (row > 5) row = 5; | 259 | if (row > 5) row = 5; |
262 | 260 | ||
263 | // figure out the column | 261 | // figure out the column |
264 | int col = 0; | 262 | int col = 0; |
265 | for (int w = 0; e->x() >= w; col++) | 263 | for (int w = 0; e->x() >= w; col++) |
266 | 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 |
267 | w += keys->width(row,col) * defaultKeyWidth; | 265 | w += keys->width(row,col) * defaultKeyWidth; |
268 | else break; | 266 | else break; |
269 | 267 | ||
270 | col --; // rewind one... | 268 | col --; // rewind one... |
271 | 269 | ||
272 | qkeycode = keys->qcode(row, col); | 270 | qkeycode = keys->qcode(row, col); |
273 | unicode = keys->uni(row, col); | 271 | unicode = keys->uni(row, col); |
274 | 272 | ||
275 | // might need to repaint if two or more of the same keys. | 273 | // might need to repaint if two or more of the same keys. |
276 | // should be faster if just paint one key even though multiple keys exist. | 274 | // should be faster if just paint one key even though multiple keys exist. |
277 | bool need_repaint = FALSE; | 275 | bool need_repaint = FALSE; |
278 | 276 | ||
279 | if (unicode == 0) { // either Qt char, or nothing | 277 | if (unicode == 0) { // either Qt char, or nothing |
280 | 278 | ||
281 | if (qkeycode == Qt::Key_F1) { // toggle the pickboard | 279 | if (qkeycode == Qt::Key_F1) { // toggle the pickboard |
282 | 280 | ||
283 | if ( configdlg ) { | 281 | if ( configdlg ) { |
284 | delete (ConfigDlg *) configdlg; | 282 | delete (ConfigDlg *) configdlg; |
285 | configdlg = 0; | 283 | configdlg = 0; |
286 | } | 284 | } |
287 | else { | 285 | else { |
288 | configdlg = new ConfigDlg (); | 286 | configdlg = new ConfigDlg (); |
289 | connect(configdlg, SIGNAL(pickboardToggled(bool)), | 287 | connect(configdlg, SIGNAL(pickboardToggled(bool)), |
290 | this, SLOT(togglePickboard(bool))); | 288 | this, SLOT(togglePickboard(bool))); |
291 | connect(configdlg, SIGNAL(setMapToDefault()), | 289 | connect(configdlg, SIGNAL(setMapToDefault()), |
292 | this, SLOT(setMapToDefault())); | 290 | this, SLOT(setMapToDefault())); |
293 | connect(configdlg, SIGNAL(setMapToFile(QString)), | 291 | connect(configdlg, SIGNAL(setMapToFile(QString)), |
294 | this, SLOT(setMapToFile(QString))); | 292 | this, SLOT(setMapToFile(QString))); |
293 | connect(configdlg, SIGNAL(reloadKeyboard()), | ||
294 | this, SLOT(reloadKeyboard())); | ||
295 | configdlg->showMaximized(); | 295 | configdlg->showMaximized(); |
296 | configdlg->show(); | 296 | configdlg->show(); |
297 | configdlg->raise(); | 297 | configdlg->raise(); |
298 | } | 298 | } |
299 | 299 | ||
300 | } else if (qkeycode == Qt::Key_Control) { | 300 | } else if (qkeycode == Qt::Key_Control) { |
301 | ctrl = keys->pressedPtr(row, col); | 301 | ctrl = keys->pressedPtr(row, col); |
302 | need_repaint = TRUE; | 302 | need_repaint = TRUE; |
303 | *ctrl = !keys->pressed(row, col); | 303 | *ctrl = !keys->pressed(row, col); |
304 | 304 | ||
305 | } else if (qkeycode == Qt::Key_Alt) { | 305 | } else if (qkeycode == Qt::Key_Alt) { |
306 | alt = keys->pressedPtr(row, col); | 306 | alt = keys->pressedPtr(row, col); |
307 | need_repaint = TRUE; | 307 | need_repaint = TRUE; |
308 | *alt = !keys->pressed(row, col); | 308 | *alt = !keys->pressed(row, col); |
309 | 309 | ||
310 | } else if (qkeycode == Qt::Key_Shift) { | 310 | } else if (qkeycode == Qt::Key_Shift) { |
311 | need_repaint = TRUE; | 311 | need_repaint = TRUE; |
312 | 312 | ||
313 | if (shift) { | 313 | if (shift) { |
314 | *shift = 0; | 314 | *shift = 0; |
315 | shift = 0; | 315 | shift = 0; |
316 | } | 316 | } |
317 | else { | 317 | else { |
318 | shift = keys->pressedPtr(row, col); | 318 | shift = keys->pressedPtr(row, col); |
319 | *shift = 1; | 319 | *shift = 1; |
320 | if (lock) { | 320 | if (lock) { |
321 | *lock = 0; | 321 | *lock = 0; |
322 | lock = 0; | 322 | lock = 0; |
323 | } | 323 | } |
324 | } | 324 | } |
325 | 325 | ||
326 | } else if (qkeycode == Qt::Key_CapsLock) { | 326 | } else if (qkeycode == Qt::Key_CapsLock) { |
327 | need_repaint = TRUE; | 327 | need_repaint = TRUE; |
328 | 328 | ||
329 | if (lock) { | 329 | if (lock) { |
330 | *lock = 0; | 330 | *lock = 0; |
331 | lock = 0; | 331 | lock = 0; |
332 | } | 332 | } |
333 | else { | 333 | else { |
334 | lock = keys->pressedPtr(row, col);; | 334 | lock = keys->pressedPtr(row, col);; |
335 | *lock = 1; | 335 | *lock = 1; |
336 | if (shift) { | 336 | if (shift) { |
337 | *shift = 0; | 337 | *shift = 0; |
338 | shift = 0; | 338 | shift = 0; |
339 | } | 339 | } |
340 | } | 340 | } |
341 | 341 | ||
342 | } | 342 | } |
@@ -503,96 +503,145 @@ void Keyboard::togglePickboard(bool on_off) | |||
503 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); | 503 | QCopChannel::send ("QPE/TaskBar", "showInputMethod()"); |
504 | } | 504 | } |
505 | 505 | ||
506 | /* Keyboard::setMapTo ... {{{1 */ | 506 | /* Keyboard::setMapTo ... {{{1 */ |
507 | void Keyboard::setMapToDefault() { | 507 | void Keyboard::setMapToDefault() { |
508 | 508 | ||
509 | 509 | ||
510 | /* load current locale language map */ | 510 | /* load current locale language map */ |
511 | Config *config = new Config("locale"); | 511 | Config *config = new Config("locale"); |
512 | config->setGroup( "Language" ); | 512 | config->setGroup( "Language" ); |
513 | QString l = config->readEntry( "Language" , "en" ); | 513 | QString l = config->readEntry( "Language" , "en" ); |
514 | delete config; | 514 | delete config; |
515 | 515 | ||
516 | QString key_map = QPEApplication::qpeDir() + "/share/multikey/" | 516 | QString key_map = QPEApplication::qpeDir() + "/share/multikey/" |
517 | + l + ".keymap"; | 517 | + l + ".keymap"; |
518 | 518 | ||
519 | /* save change to multikey config file */ | 519 | /* save change to multikey config file */ |
520 | config = new Config("multikey"); | 520 | config = new Config("multikey"); |
521 | config->setGroup ("keymaps"); | 521 | config->setGroup ("keymaps"); |
522 | config->writeEntry ("current", key_map); // default closed | 522 | config->writeEntry ("current", key_map); // default closed |
523 | delete config; | 523 | delete config; |
524 | 524 | ||
525 | delete keys; | 525 | delete keys; |
526 | keys = new Keys(key_map); | 526 | keys = new Keys(key_map); |
527 | 527 | ||
528 | // have to repaint the keyboard | 528 | // have to repaint the keyboard |
529 | repaint(FALSE); | 529 | repaint(FALSE); |
530 | } | 530 | } |
531 | 531 | ||
532 | void Keyboard::setMapToFile(QString map) { | 532 | void Keyboard::setMapToFile(QString map) { |
533 | 533 | ||
534 | /* save change to multikey config file */ | 534 | /* save change to multikey config file */ |
535 | Config *config = new Config("multikey"); | 535 | Config *config = new Config("multikey"); |
536 | config->setGroup ("keymaps"); | 536 | config->setGroup ("keymaps"); |
537 | config->writeEntry ("current", map); // default closed | 537 | config->writeEntry ("current", map); // default closed |
538 | 538 | ||
539 | delete config; | 539 | delete config; |
540 | 540 | ||
541 | delete keys; | 541 | delete keys; |
542 | if (QFile(map).exists()) | 542 | if (QFile(map).exists()) |
543 | keys = new Keys(map); | 543 | keys = new Keys(map); |
544 | else | 544 | else |
545 | keys = new Keys(); | 545 | keys = new Keys(); |
546 | 546 | ||
547 | repaint(FALSE); | 547 | repaint(FALSE); |
548 | 548 | ||
549 | } | 549 | } |
550 | 550 | ||
551 | /* Keybaord::setColor {{{1 */ | ||
552 | void Keyboard::reloadKeyboard() { | ||
553 | |||
554 | // reload colors and redraw | ||
555 | loadKeyboardColors(); | ||
556 | repaint(); | ||
557 | |||
558 | } | ||
559 | |||
560 | void Keyboard::loadKeyboardColors() { | ||
561 | |||
562 | Config config ("multikey"); | ||
563 | config.setGroup("colors"); | ||
564 | |||
565 | QStringList color; | ||
566 | color = config.readListEntry("keycolor", QChar(',')); | ||
567 | if (color.isEmpty()) { | ||
568 | color = QStringList::split(",", "240,240,240"); | ||
569 | config.writeEntry("keycolor", color.join(",")); | ||
570 | |||
571 | } | ||
572 | keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | ||
573 | |||
574 | color = config.readListEntry("keycolor_pressed", QChar(',')); | ||
575 | if (color.isEmpty()) { | ||
576 | color = QStringList::split(",", "171,183,198"); | ||
577 | config.writeEntry("keycolor_pressed", color.join(",")); | ||
578 | |||
579 | } | ||
580 | keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | ||
581 | |||
582 | color = config.readListEntry("keycolor_lines", QChar(',')); | ||
583 | if (color.isEmpty()) { | ||
584 | color = QStringList::split(",", "138,148,160"); | ||
585 | config.writeEntry("keycolor_lines", color.join(",")); | ||
586 | |||
587 | } | ||
588 | keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | ||
589 | |||
590 | color = config.readListEntry("textcolor", QChar(',')); | ||
591 | if (color.isEmpty()) { | ||
592 | color = QStringList::split(",", "43,54,68"); | ||
593 | config.writeEntry("textcolor", color.join(",")); | ||
594 | |||
595 | } | ||
596 | textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()); | ||
597 | |||
598 | } | ||
599 | |||
551 | /* korean input functions {{{1 | 600 | /* korean input functions {{{1 |
552 | * | 601 | * |
553 | * TODO | 602 | * TODO |
554 | * one major problem with this implementation is that you can't move the | 603 | * one major problem with this implementation is that you can't move the |
555 | * cursor after inputing korean chars, otherwise it will eat up and replace | 604 | * cursor after inputing korean chars, otherwise it will eat up and replace |
556 | * the char before the cursor you move to. fix that | 605 | * the char before the cursor you move to. fix that |
557 | * | 606 | * |
558 | * make backspace delete one single char, not the whole thing if still | 607 | * make backspace delete one single char, not the whole thing if still |
559 | * editing. | 608 | * editing. |
560 | * | 609 | * |
561 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 610 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
562 | * | 611 | * |
563 | * how korean input works | 612 | * how korean input works |
564 | * | 613 | * |
565 | * all following chars means unicode char value and are in hex | 614 | * all following chars means unicode char value and are in hex |
566 | * | 615 | * |
567 | * ÃÊÀ½ = schar (start char) | 616 | * ÃÊÀ½ = schar (start char) |
568 | * ÁßÀ½ = mchar (middle char) | 617 | * ÁßÀ½ = mchar (middle char) |
569 | * ³¡À½ = echar (end char) | 618 | * ³¡À½ = echar (end char) |
570 | * | 619 | * |
571 | * there are 19 schars. unicode position is at 1100 - 1112 | 620 | * there are 19 schars. unicode position is at 1100 - 1112 |
572 | * there are 21 mchars. unicode position is at 1161 - 1175 | 621 | * there are 21 mchars. unicode position is at 1161 - 1175 |
573 | * there are 27 echars. unicode position is at 11a8 - 11c2 | 622 | * there are 27 echars. unicode position is at 11a8 - 11c2 |
574 | * | 623 | * |
575 | * the map with everything combined is at ac00 - d7a3 | 624 | * the map with everything combined is at ac00 - d7a3 |
576 | * | 625 | * |
577 | */ | 626 | */ |
578 | 627 | ||
579 | ushort Keyboard::parseKoreanInput (ushort c) { | 628 | ushort Keyboard::parseKoreanInput (ushort c) { |
580 | 629 | ||
581 | if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) | 630 | if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c)) |
582 | || | 631 | || |
583 | (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode | 632 | (c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode |
584 | && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { | 633 | && qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) { |
585 | 634 | ||
586 | schar = 0, mchar = 0, echar = 0; | 635 | schar = 0, mchar = 0, echar = 0; |
587 | return c; | 636 | return c; |
588 | } | 637 | } |
589 | 638 | ||
590 | if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input | 639 | if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input |
591 | 640 | ||
592 | if (schar == 0 || (schar != 0 && mchar == 0)) { | 641 | if (schar == 0 || (schar != 0 && mchar == 0)) { |
593 | schar = c; mchar = 0; echar = 0; | 642 | schar = c; mchar = 0; echar = 0; |
594 | return c; | 643 | return c; |
595 | } | 644 | } |
596 | else if (mchar != 0) { | 645 | else if (mchar != 0) { |
597 | 646 | ||
598 | if (echar == 0) { | 647 | if (echar == 0) { |