summaryrefslogtreecommitdiff
authortreke <treke>2003-07-19 16:38:27 (UTC)
committer treke <treke>2003-07-19 16:38:27 (UTC)
commit67b69b7aede83ccb0d933dec9bd959f01eb6ea06 (patch) (unidiff)
tree6e404164453172adc58d088f72c58e6f38e4b4c3
parentcf3921fe77f87e94ff821df65bb80b02487a9f9b (diff)
downloadopie-67b69b7aede83ccb0d933dec9bd959f01eb6ea06.zip
opie-67b69b7aede83ccb0d933dec9bd959f01eb6ea06.tar.gz
opie-67b69b7aede83ccb0d933dec9bd959f01eb6ea06.tar.bz2
* Adds a keyboard layout with a configure button to multikey when it is
unable to load the selected layout. Fixes (#920)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/keyboard.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index bded447..2ce6dd3 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -1,233 +1,245 @@
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
40using namespace MultiKey; 40using namespace MultiKey;
41 41
42static const char * const kb_config_xpm[] = {
43"13 7 2 1",
44" c None",
45". c #000000",
46" ",
47" . ",
48" ... ",
49" ..... ",
50" . ",
51" . ",
52" "};
53
42/* Keyboard::Keyboard {{{1 */ 54/* Keyboard::Keyboard {{{1 */
43Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) : 55Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) :
44 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0), 56 QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0),
45 meta(0), circumflex(0), diaeresis(0), baccent(0), accent(0), 57 meta(0), circumflex(0), diaeresis(0), baccent(0), accent(0),
46 useLargeKeys(TRUE), usePicks(0), useRepeat(0), 58 useLargeKeys(TRUE), usePicks(0), useRepeat(0),
47 pressedKeyRow(-1), pressedKeyCol(-1), 59 pressedKeyRow(-1), pressedKeyCol(-1),
48 unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0), 60 unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0),
49 configdlg(0) 61 configdlg(0)
50 62
51{ 63{
52 64
53 // get the default font 65 // get the default font
54 Config *config = new Config( "qpe" ); 66 Config *config = new Config( "qpe" );
55 config->setGroup( "Appearance" ); 67 config->setGroup( "Appearance" );
56 QString familyStr = config->readEntry( "FontFamily", "smallsmooth" ); 68 QString familyStr = config->readEntry( "FontFamily", "smallsmooth" );
57 delete config; 69 delete config;
58 70
59 config = new Config("multikey"); 71 config = new Config("multikey");
60 config->setGroup ("general"); 72 config->setGroup ("general");
61 usePicks = config->readBoolEntry ("usePickboard", 0); // default closed 73 usePicks = config->readBoolEntry ("usePickboard", 0); // default closed
62 useRepeat = config->readBoolEntry ("useRepeat", 1); 74 useRepeat = config->readBoolEntry ("useRepeat", 1);
63 delete config; 75 delete config;
64 76
65 77
66 setFont( QFont( familyStr, 10 ) ); 78 setFont( QFont( familyStr, 10 ) );
67 79
68 picks = new KeyboardPicks( this ); 80 picks = new KeyboardPicks( this );
69 picks->setFont( QFont( familyStr, 10 ) ); 81 picks->setFont( QFont( familyStr, 10 ) );
70 picks->initialise(); 82 picks->initialise();
71 if (usePicks) { 83 if (usePicks) {
72 84
73 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ), 85 QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
74 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) ); 86 this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
75 87
76 } else picks->hide(); 88 } else picks->hide();
77 89
78 loadKeyboardColors(); 90 loadKeyboardColors();
79 91
80 keys = new Keys(); 92 keys = new Keys();
81 93
82 repeatTimer = new QTimer( this ); 94 repeatTimer = new QTimer( this );
83 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) ); 95 connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) );
84 96
85} 97}
86 98
87Keyboard::~Keyboard() { 99Keyboard::~Keyboard() {
88 100
89 if ( configdlg ) { 101 if ( configdlg ) {
90 delete (ConfigDlg *) configdlg; 102 delete (ConfigDlg *) configdlg;
91 configdlg = 0; 103 configdlg = 0;
92 } 104 }
93 105
94} 106}
95 107
96/* Keyboard::resizeEvent {{{1 */ 108/* Keyboard::resizeEvent {{{1 */
97void Keyboard::resizeEvent(QResizeEvent*) 109void Keyboard::resizeEvent(QResizeEvent*)
98{ 110{
99 int ph = picks->sizeHint().height(); 111 int ph = picks->sizeHint().height();
100 picks->setGeometry( 0, 0, width(), ph ); 112 picks->setGeometry( 0, 0, width(), ph );
101 keyHeight = (height()-(usePicks ? ph : 0))/(keys->rows()?keys->rows():1); 113 keyHeight = (height()-(usePicks ? ph : 0))/(keys->rows()?keys->rows():1);
102 114
103 int nk; // number of keys? 115 int nk; // number of keys?
104 if ( useLargeKeys ) { 116 if ( useLargeKeys ) {
105 nk = 15; 117 nk = 15;
106 } else { 118 } else {
107 nk = 19; 119 nk = 19;
108 } 120 }
109 defaultKeyWidth = (width()/nk)/2; 121 defaultKeyWidth = (width()/nk)/2;
110 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces? 122 xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces?
111 123
112} 124}
113 125
114/* KeyboardPicks::initialize {{{1 */ 126/* KeyboardPicks::initialize {{{1 */
115void KeyboardPicks::initialise() 127void KeyboardPicks::initialise()
116{ 128{
117 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); 129 setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
118 mode = 0; 130 mode = 0;
119 dc = new KeyboardConfig(this); 131 dc = new KeyboardConfig(this);
120 configs.append(dc); 132 configs.append(dc);
121} 133}
122 134
123/* KeyboardPicks::sizeHint {{{1 */ 135/* KeyboardPicks::sizeHint {{{1 */
124QSize KeyboardPicks::sizeHint() const 136QSize KeyboardPicks::sizeHint() const
125{ 137{
126 return QSize(240,fontMetrics().lineSpacing()); 138 return QSize(240,fontMetrics().lineSpacing());
127} 139}
128 140
129 141
130/* KeyboardConfig::generateText {{{1 */ 142/* KeyboardConfig::generateText {{{1 */
131void KeyboardConfig::generateText(const QString &s) 143void KeyboardConfig::generateText(const QString &s)
132{ 144{
133#if defined(Q_WS_QWS) || defined(_WS_QWS_) 145#if defined(Q_WS_QWS) || defined(_WS_QWS_)
134 for (int i=0; i<(int)backspaces; i++) { 146 for (int i=0; i<(int)backspaces; i++) {
135 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false ); 147 parent->emitKey( 0, Qt::Key_Backspace, 0, true, false );
136 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false ); 148 parent->emitKey( 0, Qt::Key_Backspace, 0, false, false );
137 } 149 }
138 for (int i=0; i<(int)s.length(); i++) { 150 for (int i=0; i<(int)s.length(); i++) {
139 parent->emitKey( s[i].unicode(), 0, 0, true, false ); 151 parent->emitKey( s[i].unicode(), 0, 0, true, false );
140 parent->emitKey( s[i].unicode(), 0, 0, false, false ); 152 parent->emitKey( s[i].unicode(), 0, 0, false, false );
141 } 153 }
142 parent->emitKey( 0, Qt::Key_Space, 0, true, false ); 154 parent->emitKey( 0, Qt::Key_Space, 0, true, false );
143 parent->emitKey( 0, Qt::Key_Space, 0, false, false ); 155 parent->emitKey( 0, Qt::Key_Space, 0, false, false );
144 backspaces = 0; 156 backspaces = 0;
145#endif 157#endif
146} 158}
147 159
148 160
149 161
150 162
151/* Keyboard::paintEvent {{{1 */ 163/* Keyboard::paintEvent {{{1 */
152void Keyboard::paintEvent(QPaintEvent* e) 164void Keyboard::paintEvent(QPaintEvent* e)
153{ 165{
154 QPainter painter(this); 166 QPainter painter(this);
155 painter.setClipRect(e->rect()); 167 painter.setClipRect(e->rect());
156 drawKeyboard( painter ); 168 drawKeyboard( painter );
157 picks->dc->draw( &painter ); 169 picks->dc->draw( &painter );
158} 170}
159 171
160 172
161/* Keyboard::drawKeyboard {{{1 */ 173/* Keyboard::drawKeyboard {{{1 */
162 174
163void Keyboard::drawKeyboard(QPainter &p, int row, int col) 175void Keyboard::drawKeyboard(QPainter &p, int row, int col)
164{ 176{
165 177
166 178
167 if (row != -1 && col != -1) { //just redraw one key 179 if (row != -1 && col != -1) { //just redraw one key
168 180
169 int x = 0; 181 int x = 0;
170 for (int i = 0; i < col; i++) { 182 for (int i = 0; i < col; i++) {
171 183
172 x += keys->width(row, i) * defaultKeyWidth; 184 x += keys->width(row, i) * defaultKeyWidth;
173 } 185 }
174 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); 186 int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0);
175 187
176 int keyWidth = keys->width(row, col); 188 int keyWidth = keys->width(row, col);
177 189
178 p.fillRect(x + 1, y + 1, 190 p.fillRect(x + 1, y + 1,
179 keyWidth * defaultKeyWidth - 1, keyHeight - 1, 191 keyWidth * defaultKeyWidth - 1, keyHeight - 1,
180 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); 192 pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor);
181 193
182 QImage *pix = keys->pix(row,col); 194 QImage *pix = keys->pix(row,col);
183 195
184 ushort c = keys->uni(row, col); 196 ushort c = keys->uni(row, col);
185 197
186 p.setPen(textcolor); 198 p.setPen(textcolor);
187 if (!pix) { 199 if (!pix) {
188 if ((shift || lock) && keys->shift(c)) 200 if ((shift || lock) && keys->shift(c))
189 201
190 if (circumflex && keys->circumflex(keys->shift(c))) 202 if (circumflex && keys->circumflex(keys->shift(c)))
191 c = keys->circumflex(keys->shift(c)); 203 c = keys->circumflex(keys->shift(c));
192 else if (diaeresis && keys->diaeresis(keys->shift(c))) 204 else if (diaeresis && keys->diaeresis(keys->shift(c)))
193 c = keys->diaeresis(keys->shift(c)); 205 c = keys->diaeresis(keys->shift(c));
194 else if (baccent && keys->baccent(keys->shift(c))) 206 else if (baccent && keys->baccent(keys->shift(c)))
195 c = keys->baccent(keys->shift(c)); 207 c = keys->baccent(keys->shift(c));
196 else if (accent && keys->accent(keys->shift(c))) 208 else if (accent && keys->accent(keys->shift(c)))
197 c = keys->accent(keys->shift(c)); 209 c = keys->accent(keys->shift(c));
198 else if (meta && keys->meta(keys->shift(c))) 210 else if (meta && keys->meta(keys->shift(c)))
199 c = keys->meta(keys->shift(c)); 211 c = keys->meta(keys->shift(c));
200 else 212 else
201 c = keys->shift(c); 213 c = keys->shift(c);
202 214
203 else if (meta && keys->meta(c)) 215 else if (meta && keys->meta(c))
204 c = keys->meta(c); 216 c = keys->meta(c);
205 else if (circumflex && keys->circumflex(c)) 217 else if (circumflex && keys->circumflex(c))
206 c = keys->circumflex(c); 218 c = keys->circumflex(c);
207 else if (baccent && keys->baccent(c)) 219 else if (baccent && keys->baccent(c))
208 c = keys->baccent(c); 220 c = keys->baccent(c);
209 else if (accent && keys->accent(c)) 221 else if (accent && keys->accent(c))
210 c = keys->accent(c); 222 c = keys->accent(c);
211 else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) { 223 else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) {
212 224
213 // the diaeresis key itself has to be in the diaeresisMap, 225 // the diaeresis key itself has to be in the diaeresisMap,
214 // or just do this to make it display the diaeresis char. 226 // or just do this to make it display the diaeresis char.
215 227
216 if (c == 0x2c6) 228 if (c == 0x2c6)
217 c = 0xa8; 229 c = 0xa8;
218 else 230 else
219 c = keys->diaeresis(c); 231 c = keys->diaeresis(c);
220 } 232 }
221 233
222 p.drawText(x, y, 234 p.drawText(x, y,
223 defaultKeyWidth * keyWidth + 3, keyHeight, 235 defaultKeyWidth * keyWidth + 3, keyHeight,
224 AlignCenter, (QChar)c); 236 AlignCenter, (QChar)c);
225 } 237 }
226 else 238 else
227 // center the image in the middle of the key 239 // center the image in the middle of the key
228 p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2 + 1, 240 p.drawImage( x + (defaultKeyWidth * keyWidth - pix->width())/2 + 1,
229 y + (keyHeight - pix->height())/2 + 1, 241 y + (keyHeight - pix->height())/2 + 1,
230 *pix ); 242 *pix );
231 243
232 // this fixes the problem that the very right end of the board's vertical line 244 // 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 245 // gets painted over, because it's one pixel shorter than all other keys
@@ -1333,328 +1345,334 @@ Keys::Keys() {
1333 QString l = config->readEntry( "Language" , "en" ); 1345 QString l = config->readEntry( "Language" , "en" );
1334 delete config; 1346 delete config;
1335 1347
1336 map = QPEApplication::qpeDir() + "/share/multikey/" 1348 map = QPEApplication::qpeDir() + "/share/multikey/"
1337 + l + ".keymap"; 1349 + l + ".keymap";
1338 1350
1339 } 1351 }
1340 if (map.isNull() || !(QFile(map).exists())) { 1352 if (map.isNull() || !(QFile(map).exists())) {
1341 map = QPEApplication::qpeDir() + "/share/multikey/en.keymap"; 1353 map = QPEApplication::qpeDir() + "/share/multikey/en.keymap";
1342 } 1354 }
1343 1355
1344 setKeysFromFile(map); 1356 setKeysFromFile(map);
1345} 1357}
1346 1358
1347Keys::Keys(const char * filename) { 1359Keys::Keys(const char * filename) {
1348 1360
1349 setKeysFromFile(filename); 1361 setKeysFromFile(filename);
1350} 1362}
1351 1363
1352// Keys::setKeysFromFile {{{2 1364// Keys::setKeysFromFile {{{2
1353void Keys::setKeysFromFile(const char * filename) { 1365void Keys::setKeysFromFile(const char * filename) {
1354 1366
1355 QFile f(filename); 1367 QFile f(filename);
1356 1368
1357 if (f.open(IO_ReadOnly)) { 1369 if (f.open(IO_ReadOnly)) {
1358 1370
1359 QTextStream t(&f); 1371 QTextStream t(&f);
1360 int row; 1372 int row;
1361 int qcode; 1373 int qcode;
1362 ushort unicode; 1374 ushort unicode;
1363 int width; 1375 int width;
1364 QString buf; 1376 QString buf;
1365 QString comment; 1377 QString comment;
1366 char * xpm[256]; //couldnt be larger than that... could it? 1378 char * xpm[256]; //couldnt be larger than that... could it?
1367 QImage *xpm2pix = 0; 1379 QImage *xpm2pix = 0;
1368 1380
1369 buf = t.readLine(); 1381 buf = t.readLine();
1370 while (buf) { 1382 while (buf) {
1371 1383
1372 // get rid of comments 1384 // get rid of comments
1373 buf.replace(QRegExp("#.*$", FALSE, FALSE), ""); 1385 buf.replace(QRegExp("#.*$", FALSE, FALSE), "");
1374 1386
1375 // key definition 1387 // key definition
1376 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) { 1388 if (buf.contains(QRegExp("^\\d+\\s+[0-1a-fx]+", FALSE, FALSE))) {
1377 // no $1 type referencing!!! this implementation of regexp sucks 1389 // no $1 type referencing!!! this implementation of regexp sucks
1378 1390
1379 // dont know of any sscanf() type funcs in Qt lib 1391 // dont know of any sscanf() type funcs in Qt lib
1380 QTextStream tmp (buf, IO_ReadOnly); 1392 QTextStream tmp (buf, IO_ReadOnly);
1381 tmp >> row >> qcode >> unicode >> width >> comment; 1393 tmp >> row >> qcode >> unicode >> width >> comment;
1382 1394
1383 buf = t.readLine(); 1395 buf = t.readLine();
1384 int xpmLineCount = 0; 1396 int xpmLineCount = 0;
1385 xpm2pix = 0; 1397 xpm2pix = 0;
1386 1398
1387 // erase blank space 1399 // erase blank space
1388 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine(); 1400 while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine();
1389 1401
1390 while (buf.contains(QRegExp("^\\s*\".*\""))) { 1402 while (buf.contains(QRegExp("^\\s*\".*\""))) {
1391 1403
1392 QString xpmBuf = buf.stripWhiteSpace(); 1404 QString xpmBuf = buf.stripWhiteSpace();
1393 1405
1394 xpm[xpmLineCount] = new char [xpmBuf.length()]; 1406 xpm[xpmLineCount] = new char [xpmBuf.length()];
1395 1407
1396 int j = 0; 1408 int j = 0;
1397 for (ushort i = 0; i < xpmBuf.length(); i++) { 1409 for (ushort i = 0; i < xpmBuf.length(); i++) {
1398 if (xpmBuf[i].latin1() != '"') { 1410 if (xpmBuf[i].latin1() != '"') {
1399 1411
1400 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1(); 1412 ((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1();
1401 j++; 1413 j++;
1402 } 1414 }
1403 1415
1404 } 1416 }
1405 // have to close that facker up 1417 // have to close that facker up
1406 ((char *)xpm[xpmLineCount])[j] = '\0'; 1418 ((char *)xpm[xpmLineCount])[j] = '\0';
1407 1419
1408 xpmLineCount++; 1420 xpmLineCount++;
1409 buf = t.readLine(); 1421 buf = t.readLine();
1410 } 1422 }
1411 if (xpmLineCount) { 1423 if (xpmLineCount) {
1412 1424
1413 xpm2pix = new QImage((const char **)xpm); 1425 xpm2pix = new QImage((const char **)xpm);
1414 for (int i = 0; i < xpmLineCount; i++) 1426 for (int i = 0; i < xpmLineCount; i++)
1415 1427
1416 delete [] (xpm[i]); 1428 delete [] (xpm[i]);
1417 1429
1418 } 1430 }
1419 setKey(row, qcode, unicode, width, xpm2pix); 1431 setKey(row, qcode, unicode, width, xpm2pix);
1420 } 1432 }
1421 1433
1422 // shift map 1434 // shift map
1423 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1435 else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1424 1436
1425 QTextStream tmp (buf, IO_ReadOnly); 1437 QTextStream tmp (buf, IO_ReadOnly);
1426 ushort lower, shift; 1438 ushort lower, shift;
1427 tmp >> lower >> shift; 1439 tmp >> lower >> shift;
1428 1440
1429 shiftMap.insert(lower, shift); 1441 shiftMap.insert(lower, shift);
1430 1442
1431 buf = t.readLine(); 1443 buf = t.readLine();
1432 } 1444 }
1433 1445
1434 // meta key map 1446 // meta key map
1435 else if (buf.contains(QRegExp("^\\s*m\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1447 else if (buf.contains(QRegExp("^\\s*m\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1436 1448
1437 QTextStream tmp (buf, IO_ReadOnly); 1449 QTextStream tmp (buf, IO_ReadOnly);
1438 ushort lower, shift; 1450 ushort lower, shift;
1439 QChar m; 1451 QChar m;
1440 tmp >> m >> lower >> shift; 1452 tmp >> m >> lower >> shift;
1441 1453
1442 metaMap.insert(lower, shift); 1454 metaMap.insert(lower, shift);
1443 1455
1444 buf = t.readLine(); 1456 buf = t.readLine();
1445 } 1457 }
1446 1458
1447 // circumflex 1459 // circumflex
1448 else if (buf.contains(QRegExp("^\\s*c\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1460 else if (buf.contains(QRegExp("^\\s*c\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1449 1461
1450 QTextStream tmp (buf, IO_ReadOnly); 1462 QTextStream tmp (buf, IO_ReadOnly);
1451 ushort lower, shift; 1463 ushort lower, shift;
1452 QChar c; 1464 QChar c;
1453 tmp >> c >> lower >> shift; 1465 tmp >> c >> lower >> shift;
1454 1466
1455 circumflexMap.insert(lower, shift); 1467 circumflexMap.insert(lower, shift);
1456 1468
1457 buf = t.readLine(); 1469 buf = t.readLine();
1458 } 1470 }
1459 // diaeresis 1471 // diaeresis
1460 else if (buf.contains(QRegExp("^\\s*d\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1472 else if (buf.contains(QRegExp("^\\s*d\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1461 1473
1462 QTextStream tmp (buf, IO_ReadOnly); 1474 QTextStream tmp (buf, IO_ReadOnly);
1463 ushort lower, shift; 1475 ushort lower, shift;
1464 QChar d; 1476 QChar d;
1465 tmp >> d >> lower >> shift; 1477 tmp >> d >> lower >> shift;
1466 1478
1467 diaeresisMap.insert(lower, shift); 1479 diaeresisMap.insert(lower, shift);
1468 1480
1469 buf = t.readLine(); 1481 buf = t.readLine();
1470 } 1482 }
1471 // back accent 1483 // back accent
1472 else if (buf.contains(QRegExp("^\\s*b\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1484 else if (buf.contains(QRegExp("^\\s*b\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1473 1485
1474 QTextStream tmp (buf, IO_ReadOnly); 1486 QTextStream tmp (buf, IO_ReadOnly);
1475 ushort lower, shift; 1487 ushort lower, shift;
1476 QChar d; 1488 QChar d;
1477 tmp >> d >> lower >> shift; 1489 tmp >> d >> lower >> shift;
1478 1490
1479 baccentMap.insert(lower, shift); 1491 baccentMap.insert(lower, shift);
1480 1492
1481 qDebug ("Estoy aadiendo %i con %i", lower, shift); 1493 qDebug ("Estoy aadiendo %i con %i", lower, shift);
1482 buf = t.readLine(); 1494 buf = t.readLine();
1483 } 1495 }
1484 // accent 1496 // accent
1485 else if (buf.contains(QRegExp("^\\s*a\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) { 1497 else if (buf.contains(QRegExp("^\\s*a\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
1486 1498
1487 QTextStream tmp (buf, IO_ReadOnly); 1499 QTextStream tmp (buf, IO_ReadOnly);
1488 ushort lower, shift; 1500 ushort lower, shift;
1489 QChar d; 1501 QChar d;
1490 tmp >> d >> lower >> shift; 1502 tmp >> d >> lower >> shift;
1491 1503
1492 accentMap.insert(lower, shift); 1504 accentMap.insert(lower, shift);
1493 1505
1494 buf = t.readLine(); 1506 buf = t.readLine();
1495 } 1507 }
1496 1508
1497 // other variables like lang & title 1509 // other variables like lang & title
1498 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) { 1510 else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) {
1499 1511
1500 QTextStream tmp (buf, IO_ReadOnly); 1512 QTextStream tmp (buf, IO_ReadOnly);
1501 QString name, equals, value; 1513 QString name, equals, value;
1502 1514
1503 tmp >> name >> equals >> value; 1515 tmp >> name >> equals >> value;
1504 1516
1505 if (name == "lang") { 1517 if (name == "lang") {
1506 1518
1507 lang = value; 1519 lang = value;
1508 1520
1509 } 1521 }
1510 1522
1511 buf = t.readLine(); 1523 buf = t.readLine();
1512 } 1524 }
1513 // comments 1525 // comments
1514 else if (buf.contains(QRegExp("^\\s*#"))) { 1526 else if (buf.contains(QRegExp("^\\s*#"))) {
1515 1527
1516 buf = t.readLine(); 1528 buf = t.readLine();
1517 1529
1518 } else { // blank line, or garbage 1530 } else { // blank line, or garbage
1519 1531
1520 buf = t.readLine(); 1532 buf = t.readLine();
1521 1533
1522 } 1534 }
1523 1535
1524 } 1536 }
1537
1525 f.close(); 1538 f.close();
1539 } else {
1540 // We couldnt find the selected keymap, give them a configure button
1541 QImage * btn = new QImage((const char ** )kb_config_xpm);
1542 setKey(1, 0x1030, 0, 2, btn);
1526 } 1543 }
1527 1544
1528} 1545}
1529 1546
1547
1530// Keys::setKey {{{2 1548// Keys::setKey {{{2
1531void Keys::setKey(const int row, const int qcode, const ushort unicode, 1549void Keys::setKey(const int row, const int qcode, const ushort unicode,
1532 const int width, QImage *pix) { 1550 const int width, QImage *pix) {
1533 1551
1534 Key * key; 1552 Key * key;
1535 key = new Key; 1553 key = new Key;
1536 key->qcode = qcode; 1554 key->qcode = qcode;
1537 key->unicode = unicode; 1555 key->unicode = unicode;
1538 key->width = width; 1556 key->width = width;
1539 1557
1540 // share key->pressed between same keys 1558 // share key->pressed between same keys
1541 bool found = 0; 1559 bool found = 0;
1542 for (int i = 1; i <= 5; i++) { 1560 for (int i = 1; i <= 5; i++) {
1543 for (unsigned int j = 0; j < keys[i].count(); j++) 1561 for (unsigned int j = 0; j < keys[i].count(); j++)
1544 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) { 1562 if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) {
1545 1563
1546 key->pressed = keys[i].at(j)->pressed; 1564 key->pressed = keys[i].at(j)->pressed;
1547 found = 1; 1565 found = 1;
1548 } 1566 }
1549 1567
1550 } 1568 }
1551 if (!found) { 1569 if (!found) {
1552 1570
1553 key->pressed = new bool; 1571 key->pressed = new bool;
1554 *(key->pressed) = 0; 1572 *(key->pressed) = 0;
1555 } 1573 }
1556 1574
1557 key->pix = pix; 1575 key->pix = pix;
1558 1576
1559 1577
1560 keys[row].append(key); 1578 keys[row].append(key);
1561} 1579}
1562 1580
1563// Keys::~Keys {{{2 1581// Keys::~Keys {{{2
1564Keys::~Keys() { 1582Keys::~Keys() {
1565 1583
1566 for (int i = 1; i <= 5; i++) 1584 for (int i = 1; i <= 5; i++)
1567 for (unsigned int j = 0; j < keys[i].count(); j++) 1585 for (unsigned int j = 0; j < keys[i].count(); j++)
1568 delete keys[i].at(j); 1586 delete keys[i].at(j);
1569 1587
1570} 1588}
1571 1589
1572// Keys:: other functions {{{2 1590// Keys:: other functions {{{2
1573int Keys::width(const int row, const int col) { 1591int Keys::width(const int row, const int col) {
1574 1592
1575 return keys[row].at(col)->width; 1593 return keys[row].at(col)->width;
1576 1594
1577} 1595}
1578 1596
1579int Keys::rows() { 1597int Keys::rows() {
1580 1598
1581 for (int i = 1; i <= 5; i++) { 1599 for (int i = 1; i <= 5; i++) {
1582 1600
1583 if (keys[i].count() == 0) 1601 if (keys[i].count() == 0)
1584 return i - 1; 1602 return i - 1;
1585 1603
1586 } 1604 }
1587 return 5; 1605 return 5;
1588} 1606}
1589 1607
1590ushort Keys::uni(const int row, const int col) { 1608ushort Keys::uni(const int row, const int col) {
1591 1609
1592 return keys[row].at(col)->unicode; 1610 return keys[row].at(col)->unicode;
1593 1611
1594} 1612}
1595 1613
1596int Keys::qcode(const int row, const int col) { 1614int Keys::qcode(const int row, const int col) {
1597 1615
1598 return keys[row].at(col)->qcode; 1616 return keys[row].at(col)->qcode;
1599} 1617}
1600 1618
1601QImage *Keys::pix(const int row, const int col) { 1619QImage *Keys::pix(const int row, const int col) {
1602 1620
1603 return keys[row].at(col)->pix; 1621 return keys[row].at(col)->pix;
1604 1622
1605} 1623}
1606bool Keys::pressed(const int row, const int col) { 1624bool Keys::pressed(const int row, const int col) {
1607 1625
1608 return *(keys[row].at(col)->pressed); 1626 return *(keys[row].at(col)->pressed);
1609} 1627}
1610 1628
1611int Keys::numKeys(const int row) { 1629int Keys::numKeys(const int row) {
1612 1630
1613 return keys[row].count(); 1631 return keys[row].count();
1614} 1632}
1615 1633
1616void Keys::setPressed(const int row, const int col, const bool pressed) { 1634void Keys::setPressed(const int row, const int col, const bool pressed) {
1617 1635
1618 *(keys[row].at(col)->pressed) = pressed; 1636 *(keys[row].at(col)->pressed) = pressed;
1619} 1637}
1620 1638
1621ushort Keys::shift(const ushort uni) { 1639ushort Keys::shift(const ushort uni) {
1622 1640
1623 if (shiftMap[uni]) return shiftMap[uni]; 1641 if (shiftMap[uni]) return shiftMap[uni];
1624 else return 0; 1642 else return 0;
1625} 1643}
1626 1644
1627ushort Keys::meta(const ushort uni) { 1645ushort Keys::meta(const ushort uni) {
1628 1646
1629 if (metaMap[uni]) return metaMap[uni]; 1647 if (metaMap[uni]) return metaMap[uni];
1630 else return 0; 1648 else return 0;
1631} 1649}
1632 1650
1633ushort Keys::circumflex(const ushort uni) { 1651ushort Keys::circumflex(const ushort uni) {
1634 1652
1635 if (circumflexMap[uni]) return circumflexMap[uni]; 1653 if (circumflexMap[uni]) return circumflexMap[uni];
1636 else return 0; 1654 else return 0;
1637} 1655}
1638 1656
1639ushort Keys::diaeresis(const ushort uni) { 1657ushort Keys::diaeresis(const ushort uni) {
1640 1658
1641 if(diaeresisMap[uni]) return diaeresisMap[uni]; 1659 if(diaeresisMap[uni]) return diaeresisMap[uni];
1642 else return 0; 1660 else return 0;
1643} 1661}
1644 1662
1645ushort Keys::baccent(const ushort uni) { 1663ushort Keys::baccent(const ushort uni) {
1646 1664
1647 if(baccentMap[uni]) return baccentMap[uni]; 1665 if(baccentMap[uni]) return baccentMap[uni];
1648 else return 0; 1666 else return 0;
1649} 1667}
1650 1668
1651ushort Keys::accent(const ushort uni) { 1669ushort Keys::accent(const ushort uni) {
1652 1670
1653 if(accentMap[uni]) return accentMap[uni]; 1671 if(accentMap[uni]) return accentMap[uni];
1654 else return 0; 1672 else return 0;
1655} 1673}
1656 1674
1657bool *Keys::pressedPtr(const int row, const int col) { 1675bool *Keys::pressedPtr(const int row, const int col) {
1658 1676
1659 return keys[row].at(col)->pressed; 1677 return keys[row].at(col)->pressed;
1660} 1678}