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 | |||
@@ -12,512 +12,514 @@ | |||
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 | } |