-rw-r--r-- | inputmethods/multikey/keyboard.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp index c22fbb1..bded447 100644 --- a/inputmethods/multikey/keyboard.cpp +++ b/inputmethods/multikey/keyboard.cpp | |||
@@ -1,248 +1,248 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "keyboard.h" | 21 | #include "keyboard.h" |
22 | #include "configdlg.h" | 22 | #include "configdlg.h" |
23 | 23 | ||
24 | #include <qpe/global.h> | 24 | #include <qpe/global.h> |
25 | #include <qpe/qcopenvelope_qws.h> | 25 | #include <qpe/qcopenvelope_qws.h> |
26 | 26 | ||
27 | #include <qwindowsystem_qws.h> | 27 | #include <qwindowsystem_qws.h> |
28 | #include <qpainter.h> | 28 | #include <qpainter.h> |
29 | #include <qfontmetrics.h> | 29 | #include <qfontmetrics.h> |
30 | #include <qtimer.h> | 30 | #include <qtimer.h> |
31 | #include <qpe/qpeapplication.h> | 31 | #include <qpe/qpeapplication.h> |
32 | #include <qpe/config.h> | 32 | #include <qpe/config.h> |
33 | #include <ctype.h> | 33 | #include <ctype.h> |
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qtextstream.h> | 35 | #include <qtextstream.h> |
36 | #include <qstringlist.h> | 36 | #include <qstringlist.h> |
37 | 37 | ||
38 | #include <sys/utsname.h> | 38 | #include <sys/utsname.h> |
39 | 39 | ||
40 | using namespace MultiKey; | 40 | using namespace MultiKey; |
41 | 41 | ||
42 | /* Keyboard::Keyboard {{{1 */ | 42 | /* Keyboard::Keyboard {{{1 */ |
43 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : | 43 | Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : |
44 | QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0), | 44 | QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0), |
45 | meta(0), circumflex(0), diaeresis(0), baccent(0), accent(0), | 45 | meta(0), circumflex(0), diaeresis(0), baccent(0), accent(0), |
46 | useLargeKeys(TRUE), usePicks(0), useRepeat(0), | 46 | useLargeKeys(TRUE), usePicks(0), useRepeat(0), |
47 | pressedKeyRow(-1), pressedKeyCol(-1), | 47 | pressedKeyRow(-1), pressedKeyCol(-1), |
48 | unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), | 48 | unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), |
49 | configdlg(0) | 49 | configdlg(0) |
50 | 50 | ||
51 | { | 51 | { |
52 | 52 | ||
53 | // get the default font | 53 | // get the default font |
54 | Config *config = new Config( "qpe" ); | 54 | Config *config = new Config( "qpe" ); |
55 | config->setGroup( "Appearance" ); | 55 | config->setGroup( "Appearance" ); |
56 | QString familyStr = config->readEntry( "FontFamily", "fixed" ); | 56 | QString familyStr = config->readEntry( "FontFamily", "smallsmooth" ); |
57 | delete config; | 57 | delete config; |
58 | 58 | ||
59 | config = new Config("multikey"); | 59 | config = new Config("multikey"); |
60 | config->setGroup ("general"); | 60 | config->setGroup ("general"); |
61 | usePicks = config->readBoolEntry ("usePickboard", 0); // default closed | 61 | usePicks = config->readBoolEntry ("usePickboard", 0); // default closed |
62 | useRepeat = config->readBoolEntry ("useRepeat", 1); | 62 | useRepeat = config->readBoolEntry ("useRepeat", 1); |
63 | delete config; | 63 | delete config; |
64 | 64 | ||
65 | 65 | ||
66 | setFont( QFont( familyStr, 10 ) ); | 66 | setFont( QFont( familyStr, 10 ) ); |
67 | 67 | ||
68 | picks = new KeyboardPicks( this ); | 68 | picks = new KeyboardPicks( this ); |
69 | picks->setFont( QFont( familyStr, 10 ) ); | 69 | picks->setFont( QFont( familyStr, 10 ) ); |
70 | picks->initialise(); | 70 | picks->initialise(); |
71 | if (usePicks) { | 71 | if (usePicks) { |
72 | 72 | ||
73 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), | 73 | QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), |
74 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); | 74 | this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); |
75 | 75 | ||
76 | } else picks->hide(); | 76 | } else picks->hide(); |
77 | 77 | ||
78 | loadKeyboardColors(); | 78 | loadKeyboardColors(); |
79 | 79 | ||
80 | keys = new Keys(); | 80 | keys = new Keys(); |
81 | 81 | ||
82 | repeatTimer = new QTimer( this ); | 82 | repeatTimer = new QTimer( this ); |
83 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); | 83 | connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); |
84 | 84 | ||
85 | } | 85 | } |
86 | 86 | ||
87 | Keyboard::~Keyboard() { | 87 | Keyboard::~Keyboard() { |
88 | 88 | ||
89 | if ( configdlg ) { | 89 | if ( configdlg ) { |
90 | delete (ConfigDlg *) configdlg; | 90 | delete (ConfigDlg *) configdlg; |
91 | configdlg = 0; | 91 | configdlg = 0; |
92 | } | 92 | } |
93 | 93 | ||
94 | } | 94 | } |
95 | 95 | ||
96 | /* Keyboard::resizeEvent {{{1 */ | 96 | /* Keyboard::resizeEvent {{{1 */ |
97 | void Keyboard::resizeEvent(QResizeEvent*) | 97 | void Keyboard::resizeEvent(QResizeEvent*) |
98 | { | 98 | { |
99 | int ph = picks->sizeHint().height(); | 99 | int ph = picks->sizeHint().height(); |
100 | picks->setGeometry( 0, 0, width(), ph ); | 100 | picks->setGeometry( 0, 0, width(), ph ); |
101 | keyHeight = (height()-(usePicks ? ph : 0))/(keys->rows()?keys->rows():1); | 101 | keyHeight = (height()-(usePicks ? ph : 0))/(keys->rows()?keys->rows():1); |
102 | 102 | ||
103 | int nk; // number of keys? | 103 | int nk; // number of keys? |
104 | if ( useLargeKeys ) { | 104 | if ( useLargeKeys ) { |
105 | nk = 15; | 105 | nk = 15; |
106 | } else { | 106 | } else { |
107 | nk = 19; | 107 | nk = 19; |
108 | } | 108 | } |
109 | defaultKeyWidth = (width()/nk)/2; | 109 | defaultKeyWidth = (width()/nk)/2; |
110 | xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? | 110 | xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? |
111 | 111 | ||
112 | } | 112 | } |
113 | 113 | ||
114 | /* KeyboardPicks::initialize {{{1 */ | 114 | /* KeyboardPicks::initialize {{{1 */ |
115 | void KeyboardPicks::initialise() | 115 | void KeyboardPicks::initialise() |
116 | { | 116 | { |
117 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); | 117 | setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); |
118 | mode = 0; | 118 | mode = 0; |
119 | dc = new KeyboardConfig(this); | 119 | dc = new KeyboardConfig(this); |
120 | configs.append(dc); | 120 | configs.append(dc); |
121 | } | 121 | } |
122 | 122 | ||
123 | /* KeyboardPicks::sizeHint {{{1 */ | 123 | /* KeyboardPicks::sizeHint {{{1 */ |
124 | QSize KeyboardPicks::sizeHint() const | 124 | QSize KeyboardPicks::sizeHint() const |
125 | { | 125 | { |
126 | return QSize(240,fontMetrics().lineSpacing()); | 126 | return QSize(240,fontMetrics().lineSpacing()); |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | /* KeyboardConfig::generateText {{{1 */ | 130 | /* KeyboardConfig::generateText {{{1 */ |
131 | void KeyboardConfig::generateText(const QString &s) | 131 | void KeyboardConfig::generateText(const QString &s) |
132 | { | 132 | { |
133 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) | 133 | #if defined(Q_WS_QWS) || defined(_WS_QWS_) |
134 | for (int i=0; i<(int)backspaces; i++) { | 134 | for (int i=0; i<(int)backspaces; i++) { |
135 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); | 135 | parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); |
136 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); | 136 | parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); |
137 | } | 137 | } |
138 | for (int i=0; i<(int)s.length(); i++) { | 138 | for (int i=0; i<(int)s.length(); i++) { |
139 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); | 139 | parent->emitKey( s[i].unicode(), 0, 0, true, false ); |
140 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); | 140 | parent->emitKey( s[i].unicode(), 0, 0, false, false ); |
141 | } | 141 | } |
142 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); | 142 | parent->emitKey( 0, Qt::Key_Space, 0, true, false ); |
143 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); | 143 | parent->emitKey( 0, Qt::Key_Space, 0, false, false ); |
144 | backspaces = 0; | 144 | backspaces = 0; |
145 | #endif | 145 | #endif |
146 | } | 146 | } |
147 | 147 | ||
148 | 148 | ||
149 | 149 | ||
150 | 150 | ||
151 | /* Keyboard::paintEvent {{{1 */ | 151 | /* Keyboard::paintEvent {{{1 */ |
152 | void Keyboard::paintEvent(QPaintEvent* e) | 152 | void Keyboard::paintEvent(QPaintEvent* e) |
153 | { | 153 | { |
154 | QPainter painter(this); | 154 | QPainter painter(this); |
155 | painter.setClipRect(e->rect()); | 155 | painter.setClipRect(e->rect()); |
156 | drawKeyboard( painter ); | 156 | drawKeyboard( painter ); |
157 | picks->dc->draw( &painter ); | 157 | picks->dc->draw( &painter ); |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | /* Keyboard::drawKeyboard {{{1 */ | 161 | /* Keyboard::drawKeyboard {{{1 */ |
162 | 162 | ||
163 | void Keyboard::drawKeyboard(QPainter &p, int row, int col) | 163 | void Keyboard::drawKeyboard(QPainter &p, int row, int col) |
164 | { | 164 | { |
165 | 165 | ||
166 | 166 | ||
167 | if (row != -1 && col != -1) { //just redraw one key | 167 | if (row != -1 && col != -1) { //just redraw one key |
168 | 168 | ||
169 | int x = 0; | 169 | int x = 0; |
170 | for (int i = 0; i < col; i++) { | 170 | for (int i = 0; i < col; i++) { |
171 | 171 | ||
172 | x += keys->width(row, i) * defaultKeyWidth; | 172 | x += keys->width(row, i) * defaultKeyWidth; |
173 | } | 173 | } |
174 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 174 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
175 | 175 | ||
176 | int keyWidth = keys->width(row, col); | 176 | int keyWidth = keys->width(row, col); |
177 | 177 | ||
178 | p.fillRect(x + 1, y + 1, | 178 | p.fillRect(x + 1, y + 1, |
179 | keyWidth * defaultKeyWidth - 1, keyHeight - 1, | 179 | keyWidth * defaultKeyWidth - 1, keyHeight - 1, |
180 | pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); | 180 | pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); |
181 | 181 | ||
182 | QImage *pix = keys->pix(row,col); | 182 | QImage *pix = keys->pix(row,col); |
183 | 183 | ||
184 | ushort c = keys->uni(row, col); | 184 | ushort c = keys->uni(row, col); |
185 | 185 | ||
186 | p.setPen(textcolor); | 186 | p.setPen(textcolor); |
187 | if (!pix) { | 187 | if (!pix) { |
188 | if ((shift || lock) && keys->shift(c)) | 188 | if ((shift || lock) && keys->shift(c)) |
189 | 189 | ||
190 | if (circumflex && keys->circumflex(keys->shift(c))) | 190 | if (circumflex && keys->circumflex(keys->shift(c))) |
191 | c = keys->circumflex(keys->shift(c)); | 191 | c = keys->circumflex(keys->shift(c)); |
192 | else if (diaeresis && keys->diaeresis(keys->shift(c))) | 192 | else if (diaeresis && keys->diaeresis(keys->shift(c))) |
193 | c = keys->diaeresis(keys->shift(c)); | 193 | c = keys->diaeresis(keys->shift(c)); |
194 | else if (baccent && keys->baccent(keys->shift(c))) | 194 | else if (baccent && keys->baccent(keys->shift(c))) |
195 | c = keys->baccent(keys->shift(c)); | 195 | c = keys->baccent(keys->shift(c)); |
196 | else if (accent && keys->accent(keys->shift(c))) | 196 | else if (accent && keys->accent(keys->shift(c))) |
197 | c = keys->accent(keys->shift(c)); | 197 | c = keys->accent(keys->shift(c)); |
198 | else if (meta && keys->meta(keys->shift(c))) | 198 | else if (meta && keys->meta(keys->shift(c))) |
199 | c = keys->meta(keys->shift(c)); | 199 | c = keys->meta(keys->shift(c)); |
200 | else | 200 | else |
201 | c = keys->shift(c); | 201 | c = keys->shift(c); |
202 | 202 | ||
203 | else if (meta && keys->meta(c)) | 203 | else if (meta && keys->meta(c)) |
204 | c = keys->meta(c); | 204 | c = keys->meta(c); |
205 | else if (circumflex && keys->circumflex(c)) | 205 | else if (circumflex && keys->circumflex(c)) |
206 | c = keys->circumflex(c); | 206 | c = keys->circumflex(c); |
207 | else if (baccent && keys->baccent(c)) | 207 | else if (baccent && keys->baccent(c)) |
208 | c = keys->baccent(c); | 208 | c = keys->baccent(c); |
209 | else if (accent && keys->accent(c)) | 209 | else if (accent && keys->accent(c)) |
210 | c = keys->accent(c); | 210 | c = keys->accent(c); |
211 | else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { | 211 | else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { |
212 | 212 | ||
213 | // the diaeresis key itself has to be in the diaeresisMap, | 213 | // the diaeresis key itself has to be in the diaeresisMap, |
214 | // or just do this to make it display the diaeresis char. | 214 | // or just do this to make it display the diaeresis char. |
215 | 215 | ||
216 | if (c == 0x2c6) | 216 | if (c == 0x2c6) |
217 | c = 0xa8; | 217 | c = 0xa8; |
218 | else | 218 | else |
219 | c = keys->diaeresis(c); | 219 | c = keys->diaeresis(c); |
220 | } | 220 | } |
221 | 221 | ||
222 | p.drawText(x, y, | 222 | p.drawText(x, y, |
223 | defaultKeyWidth * keyWidth + 3, keyHeight, | 223 | defaultKeyWidth * keyWidth + 3, keyHeight, |
224 | AlignCenter, (QChar)c); | 224 | AlignCenter, (QChar)c); |
225 | } | 225 | } |
226 | else | 226 | else |
227 | // center the image in the middle of the key | 227 | // center the image in the middle of the key |
228 | p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2 + 1, | 228 | p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2 + 1, |
229 | y + (keyHeight - pix->height())/2 + 1, | 229 | y + (keyHeight - pix->height())/2 + 1, |
230 | *pix ); | 230 | *pix ); |
231 | 231 | ||
232 | // this fixes the problem that the very right end of the board's vertical line | 232 | // this fixes the problem that the very right end of the board's vertical line |
233 | // gets painted over, because it's one pixel shorter than all other keys | 233 | // gets painted over, because it's one pixel shorter than all other keys |
234 | p.setPen(keycolor_lines); | 234 | p.setPen(keycolor_lines); |
235 | p.drawLine(width() - 1, 0, width() - 1, height()); | 235 | p.drawLine(width() - 1, 0, width() - 1, height()); |
236 | 236 | ||
237 | } else { | 237 | } else { |
238 | 238 | ||
239 | 239 | ||
240 | p.fillRect(0, 0, width(), height(), keycolor); | 240 | p.fillRect(0, 0, width(), height(), keycolor); |
241 | 241 | ||
242 | for (row = 1; row <= keys->rows(); row++) { | 242 | for (row = 1; row <= keys->rows(); row++) { |
243 | 243 | ||
244 | int x = 0; | 244 | int x = 0; |
245 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); | 245 | int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); |
246 | 246 | ||
247 | p.setPen(keycolor_lines); | 247 | p.setPen(keycolor_lines); |
248 | p.drawLine(x, y, x + width(), y); | 248 | p.drawLine(x, y, x + width(), y); |