summaryrefslogtreecommitdiff
path: root/inputmethods/keyboard
Unidiff
Diffstat (limited to 'inputmethods/keyboard') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/keyboard/keyboard.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/inputmethods/keyboard/keyboard.cpp b/inputmethods/keyboard/keyboard.cpp
index fb88f2a..39d44cd 100644
--- a/inputmethods/keyboard/keyboard.cpp
+++ b/inputmethods/keyboard/keyboard.cpp
@@ -1,305 +1,312 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "keyboard.h" 21#include "keyboard.h"
22 22
23#include <qpe/global.h> 23#include <qpe/global.h>
24 24#include <qpe/config.h>
25#include <qwindowsystem_qws.h> 25#include <qwindowsystem_qws.h>
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qfontmetrics.h> 27#include <qfontmetrics.h>
28#include <qtimer.h> 28#include <qtimer.h>
29#include <ctype.h> 29#include <ctype.h>
30 30
31#include <sys/utsname.h> 31#include <sys/utsname.h>
32 32
33using namespace KeyboardInput; 33using namespace KeyboardInput;
34 34
35#define USE_SMALL_BACKSPACE 35#define USE_SMALL_BACKSPACE
36 36
37Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : 37Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) :
38 QFrame(parent, _name, f), shift(FALSE), lock(FALSE), ctrl(FALSE), 38 QFrame(parent, _name, f), shift(FALSE), lock(FALSE), ctrl(FALSE),
39 alt(FALSE), useLargeKeys(TRUE), useOptiKeys(0), pressedKey(-1), 39 alt(FALSE), useLargeKeys(TRUE), useOptiKeys(0), pressedKey(-1),
40 unicode(-1), qkeycode(0), modifiers(0) 40 unicode(-1), qkeycode(0), modifiers(0)
41{ 41{
42 // setPalette(QPalette(QColor(240,240,230))); // Beige! 42 // setPalette(QPalette(QColor(240,240,230))); // Beige!
43 // setFont( QFont( "Helvetica", 8 ) ); 43 // setFont( QFont( "Helvetica", 8 ) );
44// setPalette(QPalette(QColor(200,200,200))); // Gray 44// setPalette(QPalette(QColor(200,200,200))); // Gray
45 setPalette(QPalette(QColor(220,220,220))); // Gray 45 setPalette(QPalette(QColor(220,220,220))); // Gray
46 46
47 // get the default font
48 Config *config = new Config( "qpe" );
49 config->setGroup( "Appearance" );
50 QString familyStr = config->readEntry( "FontFamily", "smallsmooth" );
51 int fontSize = config->readNumEntry( "FontSize", 10 );
52 delete config;
53
47 picks = new KeyboardPicks( this ); 54 picks = new KeyboardPicks( this );
48 picks->setFont( QFont( "smallsmooth", 9 ) ); 55 picks->setFont( QFont( familyStr, fontSize ) );
49 setFont( QFont( "smallsmooth", 9 ) ); 56 setFont( QFont( familyStr, fontSize ) );
50 picks->initialise(); 57 picks->initialise();
51 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 58 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
52 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 59 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
53 60
54 repeatTimer = new QTimer( this ); 61 repeatTimer = new QTimer( this );
55 62
56 // temporary quick and dirty fix for the "sticky keyboard bug" 63 // temporary quick and dirty fix for the "sticky keyboard bug"
57 // on ipaq. 64 // on ipaq.
58// struct utsname name; 65// struct utsname name;
59// if (uname(&name) != -1) 66// if (uname(&name) != -1)
60 // { 67 // {
61 //QString release=name.release; 68 //QString release=name.release;
62 //qWarning("System release: %s\n", name.release); 69 //qWarning("System release: %s\n", name.release);
63 //if(release.find("embedix",0,TRUE) !=-1) 70 //if(release.find("embedix",0,TRUE) !=-1)
64 // { 71 // {
65 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); 72 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) );
66 // } 73 // }
67 // } 74 // }
68} 75}
69 76
70void Keyboard::resizeEvent(QResizeEvent*) 77void Keyboard::resizeEvent(QResizeEvent*)
71{ 78{
72 int ph = picks->sizeHint().height(); 79 int ph = picks->sizeHint().height();
73 picks->setGeometry( 0, 0, width(), ph ); 80 picks->setGeometry( 0, 0, width(), ph );
74 keyHeight = (height()-ph)/5; 81 keyHeight = (height()-ph)/5;
75 int nk; 82 int nk;
76 if ( useOptiKeys ) { 83 if ( useOptiKeys ) {
77 nk = 15; 84 nk = 15;
78 } else if ( useLargeKeys ) { 85 } else if ( useLargeKeys ) {
79 nk = 15; 86 nk = 15;
80 } else { 87 } else {
81 nk = 19; 88 nk = 19;
82 } 89 }
83 defaultKeyWidth = width()/nk; 90 defaultKeyWidth = width()/nk;
84 xoffs = (width()-defaultKeyWidth*nk)/2; 91 xoffs = (width()-defaultKeyWidth*nk)/2;
85} 92}
86 93
87void KeyboardPicks::initialise() 94void KeyboardPicks::initialise()
88{ 95{
89 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); 96 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
90 mode = 0; 97 mode = 0;
91 dc = new KeyboardConfig(this); 98 dc = new KeyboardConfig(this);
92 configs.append(dc); 99 configs.append(dc);
93} 100}
94 101
95QSize KeyboardPicks::sizeHint() const 102QSize KeyboardPicks::sizeHint() const
96{ 103{
97 return QSize(240,fontMetrics().lineSpacing()); 104 return QSize(240,fontMetrics().lineSpacing());
98} 105}
99 106
100 107
101void KeyboardConfig::generateText(const QString &s) 108void KeyboardConfig::generateText(const QString &s)
102{ 109{
103#if defined(Q_WS_QWS) || defined(_WS_QWS_) 110#if defined(Q_WS_QWS) || defined(_WS_QWS_)
104 for (int i=0; i<(int)backspaces; i++) { 111 for (int i=0; i<(int)backspaces; i++) {
105 parent->emitKey( 0, ::Qt::Key_Backspace, 0, true, false ); 112 parent->emitKey( 0, ::Qt::Key_Backspace, 0, true, false );
106 parent->emitKey( 0, ::Qt::Key_Backspace, 0, false, false ); 113 parent->emitKey( 0, ::Qt::Key_Backspace, 0, false, false );
107 } 114 }
108 for (int i=0; i<(int)s.length(); i++) { 115 for (int i=0; i<(int)s.length(); i++) {
109 parent->emitKey( s[i].unicode(), 0, 0, true, false ); 116 parent->emitKey( s[i].unicode(), 0, 0, true, false );
110 parent->emitKey( s[i].unicode(), 0, 0, false, false ); 117 parent->emitKey( s[i].unicode(), 0, 0, false, false );
111 } 118 }
112 parent->emitKey( 0, ::Qt::Key_Space, 0, true, false ); 119 parent->emitKey( 0, ::Qt::Key_Space, 0, true, false );
113 parent->emitKey( 0, ::Qt::Key_Space, 0, false, false ); 120 parent->emitKey( 0, ::Qt::Key_Space, 0, false, false );
114 backspaces = 0; 121 backspaces = 0;
115#endif 122#endif
116} 123}
117 124
118 125
119//PC keyboard layout and scancodes 126//PC keyboard layout and scancodes
120 127
121/* 128/*
122 Format: length, code, length, code, ..., 0 129 Format: length, code, length, code, ..., 0
123 130
124 length is measured in half the width of a standard key. 131 length is measured in half the width of a standard key.
125 If code < 0x80 we have length/2 consecutive standard keys, 132 If code < 0x80 we have length/2 consecutive standard keys,
126 starting with scancode code. 133 starting with scancode code.
127 134
128 Special keys are hardcoded, one at a time, with length of key 135 Special keys are hardcoded, one at a time, with length of key
129 and code >= 0x80, these are NOT standard PC scancodes, but are looked 136 and code >= 0x80, these are NOT standard PC scancodes, but are looked
130 up in specialM[]. (The special keys are not keymappable.) 137 up in specialM[]. (The special keys are not keymappable.)
131 138
132 */ 139 */
133 140
134static const uchar * const keyboard_opti[5] = { 141static const uchar * const keyboard_opti[5] = {
135 (const uchar *const) "\001\223\003\240\002\20\002\41\002\26\002\62\002\56\002\45\002\54\003\200\001\223\002\226\002\235\002\234\002\236", 142 (const uchar *const) "\001\223\003\240\002\20\002\41\002\26\002\62\002\56\002\45\002\54\003\200\001\223\002\226\002\235\002\234\002\236",
136 (const uchar *const) "\001\223\003\201\004\207\002\30\002\24\002\43\004\207\003\203\001\223\006\002\002\065", 143 (const uchar *const) "\001\223\003\201\004\207\002\30\002\24\002\43\004\207\003\203\001\223\006\002\002\065",
137 (const uchar *const) "\001\223\003\202\002\60\002\37\002\23\002\22\002\36\002\21\002\55\003\203\001\223\006\005\002\055", 144 (const uchar *const) "\001\223\003\202\002\60\002\37\002\23\002\22\002\36\002\21\002\55\003\203\001\223\006\005\002\055",
138 (const uchar *const) "\001\223\003\205\004\207\002\27\002\61\002\40\004\207\003\204\001\223\006\010\002\014", 145 (const uchar *const) "\001\223\003\205\004\207\002\27\002\61\002\40\004\207\003\204\001\223\006\010\002\014",
139 (const uchar *const) "\001\223\003\206\002\44\002\31\002\57\002\42\002\46\002\25\002\207\003\204\001\223\002\013\002\064\002\015\002\230" 146 (const uchar *const) "\001\223\003\206\002\44\002\31\002\57\002\42\002\46\002\25\002\207\003\204\001\223\002\013\002\064\002\015\002\230"
140}; 147};
141 148
142 149
143static const uchar * const keyboard_standard[5] = { 150static const uchar * const keyboard_standard[5] = {
144 151
145#ifdef USE_SMALL_BACKSPACE 152#ifdef USE_SMALL_BACKSPACE
146 (const uchar *const)"\002\240\002`\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\002\200\002\223\002\215\002\216\002\217", 153 (const uchar *const)"\002\240\002`\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\002\200\002\223\002\215\002\216\002\217",
147#else 154#else
148 (const uchar *const)"\002\051\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\004\200\002\223\002\215\002\216\002\217", 155 (const uchar *const)"\002\051\0021\0022\0023\0024\0025\0026\0027\0028\0029\0020\002-\002=\004\200\002\223\002\215\002\216\002\217",
149#endif 156#endif
150 //~ + 123...+ BACKSPACE //+ INSERT + HOME + PGUP 157 //~ + 123...+ BACKSPACE //+ INSERT + HOME + PGUP
151 158
152 (const uchar *const)"\003\201\002q\002w\002e\002r\002t\002y\002u\002i\002o\002p\002[\002]\002\\\001\224\002\223\002\221\002\220\002\222", 159 (const uchar *const)"\003\201\002q\002w\002e\002r\002t\002y\002u\002i\002o\002p\002[\002]\002\\\001\224\002\223\002\221\002\220\002\222",
153 //TAB + qwerty.. + backslash //+ DEL + END + PGDN 160 //TAB + qwerty.. + backslash //+ DEL + END + PGDN
154 161
155 (const uchar *const)"\004\202\002a\002s\002d\002f\002g\002h\002j\002k\002l\002;\002'\004\203", 162 (const uchar *const)"\004\202\002a\002s\002d\002f\002g\002h\002j\002k\002l\002;\002'\004\203",
156 //CAPS + asdf.. + RETURN 163 //CAPS + asdf.. + RETURN
157 164
158 (const uchar *const)"\005\204\002z\002x\002c\002v\002b\002n\002m\002,\002.\002/\005\204\002\223\002\223\002\211", 165 (const uchar *const)"\005\204\002z\002x\002c\002v\002b\002n\002m\002,\002.\002/\005\204\002\223\002\223\002\211",
159 //SHIFT + zxcv... //+ UP 166 //SHIFT + zxcv... //+ UP
160 167
161 (const uchar *const)"\003\205\003\206\022\207\003\206\003\205\002\223\002\212\002\213\002\214" 168 (const uchar *const)"\003\205\003\206\022\207\003\206\003\205\002\223\002\212\002\213\002\214"
162 //CTRL + ALT + SPACE //+ LEFT + DOWN + RIGHT 169 //CTRL + ALT + SPACE //+ LEFT + DOWN + RIGHT
163 170
164}; 171};
165 172
166 173
167struct ShiftMap { 174struct ShiftMap {
168 char normal; 175 char normal;
169 char shifted; 176 char shifted;
170}; 177};
171 178
172 179
173static const ShiftMap shiftMap[] = { 180static const ShiftMap shiftMap[] = {
174 { '`', '~' }, 181 { '`', '~' },
175 { '1', '!' }, 182 { '1', '!' },
176 { '2', '@' }, 183 { '2', '@' },
177 { '3', '#' }, 184 { '3', '#' },
178 { '4', '$' }, 185 { '4', '$' },
179 { '5', '%' }, 186 { '5', '%' },
180 { '6', '^' }, 187 { '6', '^' },
181 { '7', '&' }, 188 { '7', '&' },
182 { '8', '*' }, 189 { '8', '*' },
183 { '9', '(' }, 190 { '9', '(' },
184 { '0', ')' }, 191 { '0', ')' },
185 { '-', '_' }, 192 { '-', '_' },
186 { '=', '+' }, 193 { '=', '+' },
187 { '\\', '|' }, 194 { '\\', '|' },
188 { '[', '{' }, 195 { '[', '{' },
189 { ']', '}' }, 196 { ']', '}' },
190 { ';', ':' }, 197 { ';', ':' },
191 { '\'', '"' }, 198 { '\'', '"' },
192 { ',', '<' }, 199 { ',', '<' },
193 { '.', '>' }, 200 { '.', '>' },
194 { '/', '?' } 201 { '/', '?' }
195}; 202};
196 203
197 204
198/* XPM */ 205/* XPM */
199static const char * const uparrow_xpm[]={ 206static const char * const uparrow_xpm[]={
200"9 9 2 1", 207"9 9 2 1",
201"a c #000000", 208"a c #000000",
202". c None", 209". c None",
203".........", 210".........",
204"....a....", 211"....a....",
205"...aaa...", 212"...aaa...",
206"..aaaaa..", 213"..aaaaa..",
207"....a....", 214"....a....",
208"....a....", 215"....a....",
209"....a....", 216"....a....",
210"....a....", 217"....a....",
211"........."}; 218"........."};
212/* XPM */ 219/* XPM */
213static const char * const leftarrow_xpm[]={ 220static const char * const leftarrow_xpm[]={
214"9 9 2 1", 221"9 9 2 1",
215"a c #000000", 222"a c #000000",
216". c None", 223". c None",
217".........", 224".........",
218".........", 225".........",
219"...a.....", 226"...a.....",
220"..aa.....", 227"..aa.....",
221".aaaaaaa.", 228".aaaaaaa.",
222"..aa.....", 229"..aa.....",
223"...a.....", 230"...a.....",
224".........", 231".........",
225"........."}; 232"........."};
226/* XPM */ 233/* XPM */
227static const char * const downarrow_xpm[]={ 234static const char * const downarrow_xpm[]={
228"9 9 2 1", 235"9 9 2 1",
229"a c #000000", 236"a c #000000",
230". c None", 237". c None",
231".........", 238".........",
232"....a....", 239"....a....",
233"....a....", 240"....a....",
234"....a....", 241"....a....",
235"....a....", 242"....a....",
236"..aaaaa..", 243"..aaaaa..",
237"...aaa...", 244"...aaa...",
238"....a....", 245"....a....",
239"........."}; 246"........."};
240/* XPM */ 247/* XPM */
241static const char * const rightarrow_xpm[]={ 248static const char * const rightarrow_xpm[]={
242"9 9 2 1", 249"9 9 2 1",
243"a c #000000", 250"a c #000000",
244". c None", 251". c None",
245".........", 252".........",
246".........", 253".........",
247".....a...", 254".....a...",
248".....aa..", 255".....aa..",
249".aaaaaaa.", 256".aaaaaaa.",
250".....aa..", 257".....aa..",
251".....a...", 258".....a...",
252".........", 259".........",
253"........."}; 260"........."};
254/* XPM */ 261/* XPM */
255static const char * const insert_xpm[]={ 262static const char * const insert_xpm[]={
256"9 9 2 1", 263"9 9 2 1",
257"a c #000000", 264"a c #000000",
258". c None", 265". c None",
259".........", 266".........",
260"a........", 267"a........",
261"a.aaa.aaa", 268"a.aaa.aaa",
262"a.a.a.a..", 269"a.a.a.a..",
263"a.a.a..a.", 270"a.a.a..a.",
264"a.a.a...a", 271"a.a.a...a",
265"a.a.a.aaa", 272"a.a.a.aaa",
266".........", 273".........",
267"........."}; 274"........."};
268/* XPM */ 275/* XPM */
269static const char * const delete_xpm[]={ 276static const char * const delete_xpm[]={
270"9 9 2 1", 277"9 9 2 1",
271"a c #000000", 278"a c #000000",
272". c None", 279". c None",
273".........", 280".........",
274"aa......a", 281"aa......a",
275"a.a.aaa.a", 282"a.a.aaa.a",
276"a.a.a.a.a", 283"a.a.a.a.a",
277"a.a.aaa.a.", 284"a.a.aaa.a.",
278"a.a.a...a", 285"a.a.a...a",
279"aaa.aaa.a", 286"aaa.aaa.a",
280".........", 287".........",
281"........."}; 288"........."};
282/* XPM */ 289/* XPM */
283static const char * const home_xpm[]={ 290static const char * const home_xpm[]={
284"9 9 2 1", 291"9 9 2 1",
285"a c #000000", 292"a c #000000",
286". c None", 293". c None",
287"....a....", 294"....a....",
288"...a.a...", 295"...a.a...",
289"..a...a..", 296"..a...a..",
290".a.....a.", 297".a.....a.",
291"aa.aaa.aa", 298"aa.aaa.aa",
292".a.a.a.a.", 299".a.a.a.a.",
293".a.a.a.a.", 300".a.a.a.a.",
294".aaaaaaa.", 301".aaaaaaa.",
295"........."}; 302"........."};
296/* XPM */ 303/* XPM */
297static const char * const end_xpm[]={ 304static const char * const end_xpm[]={
298"10 9 2 1", 305"10 9 2 1",
299"a c #000000", 306"a c #000000",
300". c None", 307". c None",
301"..........", 308"..........",
302"aa.......a", 309"aa.......a",
303"a..aaa.aaa", 310"a..aaa.aaa",
304"aa.a.a.a.a", 311"aa.a.a.a.a",
305"a..a.a.a.a", 312"a..a.a.a.a",