summaryrefslogtreecommitdiff
path: root/inputmethods/pickboard/pickboardcfg.cpp
Unidiff
Diffstat (limited to 'inputmethods/pickboard/pickboardcfg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/pickboard/pickboardcfg.cpp69
1 files changed, 38 insertions, 31 deletions
diff --git a/inputmethods/pickboard/pickboardcfg.cpp b/inputmethods/pickboard/pickboardcfg.cpp
index d500266..70a89cd 100644
--- a/inputmethods/pickboard/pickboardcfg.cpp
+++ b/inputmethods/pickboard/pickboardcfg.cpp
@@ -1,16 +1,16 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of the 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
@@ -25,35 +25,37 @@
25 25
26#include <qpainter.h> 26#include <qpainter.h>
27#include <qlist.h> 27#include <qlist.h>
28#include <qbitmap.h> 28#include <qbitmap.h>
29#include <qlayout.h> 29#include <qlayout.h>
30#include <qvbox.h> 30#include <qvbox.h>
31#include <qdialog.h> 31#include <qdialog.h>
32#include <qscrollview.h> 32#include <qscrollview.h>
33#include <qpopupmenu.h> 33#include <qpopupmenu.h>
34#include <qhbuttongroup.h> 34#include <qhbuttongroup.h>
35#include <qpushbutton.h> 35#include <qpushbutton.h>
36#include <qmessagebox.h> 36#include <qmessagebox.h>
37#ifdef QWS
37#include <qwindowsystem_qws.h> 38#include <qwindowsystem_qws.h>
39#endif
38 40
39static const char * pickboard_help = 41static const char * pickboard_help =
40 "<h1>The Pickboard</h1>" 42 QT_TRANSLATE_NOOP("PickboardConfig", "<h1>The Pickboard</h1>"
41 "<i>The smallest and fastest way to type.</i>" 43 "<i>The smallest and fastest way to type.</i>"
42 "<p>" 44 "<p>"
43 "Enter a word by tapping letter-groups and picking the word." 45 "Enter a word by tapping letter-groups and picking the word."
44 "<br>Enter spaces with \"Space\", or other keys through \"KEY\"." 46 "<br>Enter spaces with \"Space\", or other keys through \"KEY\"."
45 "<br>Use \"Shift\" to capitalize words that are not normally capitalized." 47 "<br>Use \"Shift\" to capitalize words that are not normally capitalized."
46 "<br>Press \"Shift\" twice for an all-capitals word." 48 "<br>Press \"Shift\" twice for an all-capitals word."
47 "<br>Add custom words by picking them, then selecting \"Add...\" from the menu on the right." 49 "<br>Add custom words by picking them, then selecting \"Add...\" from the menu on the right." )
48 ; 50 ;
49 51
50const int intermatchmargin=5; 52const int intermatchmargin=5;
51 53
52 54
53PickboardConfig::~PickboardConfig() { } 55PickboardConfig::~PickboardConfig() { }
54 56
55void PickboardConfig::updateRows(int from, int to) 57void PickboardConfig::updateRows(int from, int to)
56{ 58{
57 if ( from != to ) { // (all) 59 if ( from != to ) { // (all)
58 parent->update(); 60 parent->update();
59 } else { 61 } else {
@@ -67,28 +69,32 @@ void PickboardConfig::updateItem(int r, int)
67{ 69{
68 updateRows(r,r); 70 updateRows(r,r);
69} 71}
70 72
71void PickboardConfig::changeMode(int m) 73void PickboardConfig::changeMode(int m)
72{ 74{
73 parent->setMode(m); 75 parent->setMode(m);
74} 76}
75void PickboardConfig::generateText(const QString& s) 77void PickboardConfig::generateText(const QString& s)
76{ 78{
77#if defined(Q_WS_QWS) || defined(_WS_QWS_) 79#if defined(Q_WS_QWS) || defined(_WS_QWS_)
78 for (int i=0; i<(int)s.length(); i++) { 80 for (int i=0; i<(int)s.length(); i++) {
79 parent->emitKey(s[i].unicode(), 0, 0, true, false); 81 uint code = 0;
80 parent->emitKey(s[i].unicode(), 0, 0, false, false); 82 if ( s[i].unicode() >= 'a' && s[i].unicode() <= 'z' ) {
83 code = s[i].unicode() - 'a' + Key_A;
84 }
85 parent->emitKey(s[i].unicode(), code, 0, true, false);
86 parent->emitKey(s[i].unicode(), code, 0, false, false);
81 } 87 }
82#endif 88#endif
83} 89}
84void PickboardConfig::generateKey( int k ) 90void PickboardConfig::generateKey( int k )
85{ 91{
86#if defined(Q_WS_QWS) || defined(_WS_QWS_) 92#if defined(Q_WS_QWS) || defined(_WS_QWS_)
87 parent->emitKey(0, k, 0, true, false); 93 parent->emitKey(0, k, 0, true, false);
88 parent->emitKey(0, k, 0, false, false); 94 parent->emitKey(0, k, 0, false, false);
89#endif 95#endif
90} 96}
91 97
92void PickboardConfig::pickPoint(const QPoint& p, bool press) 98void PickboardConfig::pickPoint(const QPoint& p, bool press)
93{ 99{
94 if ( press ) { 100 if ( press ) {
@@ -103,40 +109,40 @@ void PickboardConfig::pickPoint(const QPoint& p, bool press)
103 return; 109 return;
104 } 110 }
105 y += ls; 111 y += ls;
106 } 112 }
107 } else if ( pressx >= 0 ) { 113 } else if ( pressx >= 0 ) {
108 pickInRow( pressrow, pressx, FALSE ); 114 pickInRow( pressrow, pressx, FALSE );
109 pressx = -1; 115 pressx = -1;
110 } 116 }
111} 117}
112 118
113void PickboardConfig::fillMenu(QPopupMenu& menu) 119void PickboardConfig::fillMenu(QPopupMenu& menu)
114{ 120{
115 menu.insertItem("Reset",100); 121 menu.insertItem(tr("Reset"),100);
116 menu.insertSeparator(); 122 menu.insertSeparator();
117 menu.insertItem("Help",1); 123 menu.insertItem(tr("Help"),1);
118} 124}
119 125
120void PickboardConfig::doMenu(int i) 126void PickboardConfig::doMenu(int i)
121{ 127{
122 switch (i) { 128 switch (i) {
123 case 100: 129 case 100:
124 if ( parent->currentMode() ) { 130 if ( parent->currentMode() ) {
125 changeMode(0); 131 changeMode(0);
126 updateRows(0,1); 132 updateRows(0,1);
127 } 133 }
128 break; 134 break;
129 case 1: { 135 case 1: {
130 QMessageBox help("Pickboard Help", pickboard_help, 136 QMessageBox help(tr("Pickboard Help"), tr(pickboard_help),
131 QMessageBox::NoIcon, 1, 0, 0); 137 QMessageBox::NoIcon, 1, 0, 0);
132 help.showMaximized(); 138 help.showMaximized();
133 help.exec(); 139 help.exec();
134 } 140 }
135 } 141 }
136} 142}
137 143
138void StringConfig::draw(QPainter* p) 144void StringConfig::draw(QPainter* p)
139{ 145{
140 QFontMetrics fm = p->fontMetrics(); 146 QFontMetrics fm = p->fontMetrics();
141 147
142 for (int r=0; r<nrows; r++) { 148 for (int r=0; r<nrows; r++) {
@@ -149,28 +155,28 @@ void StringConfig::draw(QPainter* p)
149 for (; !(s=text(r,i)).isNull(); ++i) { 155 for (; !(s=text(r,i)).isNull(); ++i) {
150 int w = fm.width(s); 156 int w = fm.width(s);
151 tw += w; 157 tw += w;
152 } 158 }
153 bool spread = spreadRow(r);// && parent->width() > tw; 159 bool spread = spreadRow(r);// && parent->width() > tw;
154 int xw = spread ? (parent->width()-tw)/(i-1) : 3; 160 int xw = spread ? (parent->width()-tw)/(i-1) : 3;
155 int x = spread ? (parent->width()-tw-xw*(i-1))/2 : 2; 161 int x = spread ? (parent->width()-tw-xw*(i-1))/2 : 2;
156 162
157 i=0; 163 i=0;
158 for (; !(s=text(r,i)).isNull(); ++i) { 164 for (; !(s=text(r,i)).isNull(); ++i) {
159 int w = fm.width(s)+xw; 165 int w = fm.width(s)+xw;
160 if ( highlight(r,i) ) { 166 if ( highlight(r,i) ) {
161 p->fillRect(x-xw/2,1+fm.descent()-fm.lineSpacing(),w,fm.lineSpacing(),::Qt::black); 167 p->fillRect(x-xw/2,1+fm.descent()-fm.lineSpacing(),w,fm.lineSpacing(),Qt::black);
162 p->setPen(::Qt::white); 168 p->setPen(Qt::white);
163 }else{ 169 }else{
164 p->setPen(::Qt::black); 170 p->setPen(Qt::black);
165 } 171 }
166 p->drawText(x,-fm.descent()-1,s); 172 p->drawText(x,-fm.descent()-1,s);
167 x += w; 173 x += w;
168 } 174 }
169 } 175 }
170} 176}
171 177
172void StringConfig::pickInRow(int r, int xpos, bool press) 178void StringConfig::pickInRow(int r, int xpos, bool press)
173{ 179{
174 QFontMetrics fm = parent->fontMetrics(); 180 QFontMetrics fm = parent->fontMetrics();
175 181
176 int tw=0; 182 int tw=0;
@@ -284,27 +290,27 @@ PickboardAdd::PickboardAdd(QWidget* owner, const QStringList& setlist) :
284 setMaximumHeight(200); // ### QDialog shouldn't allow us to be bigger than the screen 290 setMaximumHeight(200); // ### QDialog shouldn't allow us to be bigger than the screen
285 QVBox *letters = new QVBox(sv); 291 QVBox *letters = new QVBox(sv);
286 letters->setSpacing(0); 292 letters->setSpacing(0);
287 lc = new LetterChoice*[setlist.count()]; 293 lc = new LetterChoice*[setlist.count()];
288 nlc = (int)setlist.count(); 294 nlc = (int)setlist.count();
289 for (int i=0; i<nlc; i++) { 295 for (int i=0; i<nlc; i++) {
290 lc[i] = new LetterChoice(letters,setlist[i]); 296 lc[i] = new LetterChoice(letters,setlist[i]);
291 connect(lc[i],SIGNAL(changed()),this,SLOT(checkAllDone())); 297 connect(lc[i],SIGNAL(changed()),this,SLOT(checkAllDone()));
292 } 298 }
293 sv->addChild(letters); 299 sv->addChild(letters);
294 QHBox* hb = new QHBox(this); 300 QHBox* hb = new QHBox(this);
295 hb->setSpacing(0); 301 hb->setSpacing(0);
296 yes = new QPushButton("OK",hb); 302 yes = new QPushButton(tr("OK"),hb);
297 yes->setEnabled(FALSE); 303 yes->setEnabled(FALSE);
298 QPushButton *no = new QPushButton("Cancel",hb); 304 QPushButton *no = new QPushButton(tr("Cancel"),hb);
299 connect(yes, SIGNAL(clicked()), this, SLOT(accept())); 305 connect(yes, SIGNAL(clicked()), this, SLOT(accept()));
300 connect(no, SIGNAL(clicked()), this, SLOT(reject())); 306 connect(no, SIGNAL(clicked()), this, SLOT(reject()));
301} 307}
302 308
303PickboardAdd::~PickboardAdd() 309PickboardAdd::~PickboardAdd()
304{ 310{
305 delete [] lc; 311 delete [] lc;
306} 312}
307 313
308QString PickboardAdd::word() const 314QString PickboardAdd::word() const
309{ 315{
310 QString str; 316 QString str;
@@ -334,29 +340,29 @@ void PickboardAdd::checkAllDone()
334 return; 340 return;
335 } 341 }
336 yes->setEnabled(TRUE); 342 yes->setEnabled(TRUE);
337 } 343 }
338} 344}
339 345
340 346
341void DictFilterConfig::doMenu(int i) 347void DictFilterConfig::doMenu(int i)
342{ 348{
343 switch (i) { 349 switch (i) {
344 case 300: 350 case 300:
345 if ( input.count() == 0 ) { 351 if ( input.count() == 0 ) {
346 QMessageBox::information(0, "Adding Words", 352 QMessageBox::information(0, tr("Adding Words"),
347 "To add words, pick the letters,\nthen " 353 tr("To add words, pick the letters,\nthen "
348 "open the Add dialog. In that\ndialog, tap " 354 "open the Add dialog. In that\ndialog, tap "
349 "the correct letters\nfrom the list " 355 "the correct letters\nfrom the list "
350 "(tap twice for\ncapitals)."); 356 "(tap twice for\ncapitals)."));
351 } else { 357 } else {
352 PickboardAdd add(parent,capitalize(input)); 358 PickboardAdd add(parent,capitalize(input));
353 if ( add.exec() ) 359 if ( add.exec() )
354 generateText(add.word()); 360 generateText(add.word());
355 input.clear(); 361 input.clear();
356 matches.clear(); 362 matches.clear();
357 updateRows(0,0); 363 updateRows(0,0);
358 } 364 }
359 break; 365 break;
360 case 100: 366 case 100:
361 if ( !input.isEmpty() ) { 367 if ( !input.isEmpty() ) {
362 input.clear(); 368 input.clear();
@@ -365,25 +371,25 @@ void DictFilterConfig::doMenu(int i)
365 updateRows(0,1); 371 updateRows(0,1);
366 break; 372 break;
367 } // else fall through 373 } // else fall through
368 default: 374 default:
369 StringConfig::doMenu(i); 375 StringConfig::doMenu(i);
370 } 376 }
371 shift = 0; 377 shift = 0;
372 lit0 = -1; 378 lit0 = -1;
373} 379}
374 380
375QString DictFilterConfig::text(int r, int i) 381QString DictFilterConfig::text(int r, int i)
376{ 382{
377 QStringList l = r ? sets : input.isEmpty() ? othermodes : matches; 383 QStringList l = r ? sets_a : input.isEmpty() ? othermodes : matches;
378 return i < (int)l.count() ? 384 return i < (int)l.count() ?
379 (input.isEmpty() ? l[i] : capitalize(l[i])) 385 (input.isEmpty() ? l[i] : capitalize(l[i]))
380 : QString::null; 386 : QString::null;
381} 387}
382 388
383bool DictFilterConfig::spreadRow(int r) 389bool DictFilterConfig::spreadRow(int r)
384{ 390{
385 return r ? TRUE : input.isEmpty() ? TRUE : FALSE; 391 return r ? TRUE : input.isEmpty() ? TRUE : FALSE;
386} 392}
387 393
388QStringList DictFilterConfig::capitalize(const QStringList& l) 394QStringList DictFilterConfig::capitalize(const QStringList& l)
389{ 395{
@@ -417,68 +423,68 @@ QString DictFilterConfig::capitalize(const QString& s)
417 return s.upper(); 423 return s.upper();
418 break; 424 break;
419 } 425 }
420 return s; 426 return s;
421} 427}
422 428
423void DictFilterConfig::pick(bool press, int row, int item) 429void DictFilterConfig::pick(bool press, int row, int item)
424{ 430{
425 if ( row == 0 ) { 431 if ( row == 0 ) {
426 if ( press ) { 432 if ( press ) {
427 if ( input.isEmpty() ) { 433 if ( input.isEmpty() ) {
428 lit0 = item; 434 lit0 = item;
429 if ( othermodes[item] == "Space" ) { 435 if ( othermodes[item] == PickboardPicks::tr("Space") ) {
430 updateItem(row,item); 436 updateItem(row,item);
431 generateText(" "); 437 generateText(" ");
432 } else if ( othermodes[item] == "Back" ) { 438 } else if ( othermodes[item] == PickboardPicks::tr("Back") ) {
433 updateItem(row,item); 439 updateItem(row,item);
434 generateKey(::Qt::Key_Backspace); 440 generateKey(::Qt::Key_Backspace);
435 } else if ( othermodes[item] == "Enter" ) { 441 } else if ( othermodes[item] == PickboardPicks::tr("Enter") ) {
436 updateItem(row,item); 442 updateItem(row,item);
437 generateKey(::Qt::Key_Return); 443 generateKey(::Qt::Key_Return);
438 } else if ( othermodes[item] == "Shift" ) { 444 } else if ( othermodes[item] == PickboardPicks::tr("Shift") ) {
439 updateItem(row,item); 445 updateItem(row,item);
440 shift = (shift+1)%3; 446 shift = (shift+1)%3;
441 } 447 }
442 } 448 }
443 } else { 449 } else {
444 if ( !input.isEmpty() ) { 450 if ( !input.isEmpty() ) {
445 input.clear(); 451 input.clear();
446 if ( item>=0 ) { 452 if ( item>=0 ) {
447 generateText(capitalize(matches[item])); 453 generateText(capitalize(matches[item]));
448 } 454 }
449 shift = 0; 455 shift = 0;
450 matches.clear(); 456 matches.clear();
451 updateRows(0,0); 457 updateRows(0,0);
452 } else if ( item < 3 ) { 458 } else if ( item < 3 ) {
453 lit0 = -1; 459 lit0 = -1;
454 changeMode(item+1); // I'm mode 0! #### 460 changeMode(item+1); // I'm mode 0! ####
455 updateRows(0,1); 461 updateRows(0,1);
456 } 462 }
457 if ( lit0 >= 0 ) { 463 if ( lit0 >= 0 ) {
458 if ( !shift || othermodes[lit0] != "Shift" ) { 464 if ( !shift || othermodes[lit0] != PickboardPicks::tr("Shift") ) {
459 updateItem(0,lit0); 465 updateItem(0,lit0);
460 lit0 = -1; 466 lit0 = -1;
461 } 467 }
462 } 468 }
463 } 469 }
464 } else { 470 } else {
465 lit0 = -1; 471 lit0 = -1;
466 if ( press && item >= 0 ) { 472 if ( press && item >= 0 ) {
467 lit1 = item; 473 lit1 = item;
468 add(sets[item]); 474 add(sets[item]);
469 updateItem(1,item); 475 updateItem(1,item);
470 updateRows(0,0); 476 updateRows(0,0);
471 } else { 477 } else {
472 updateItem(1,lit1); 478 updateItem(1,lit1);
473 lit1 = -1; 479 lit1 = -1;
474 } 480 }
475 } 481 }
476} 482}
477 483
478bool DictFilterConfig::scanMatch(const QString& set, const QChar& l) const 484bool DictFilterConfig::scanMatch(const QString& set, const QChar& l) const
479{ 485{
480 return set == "?" || set == "*" || set.contains(l); 486 return set == "?" || set == "*" || set.contains(l);
481} 487}
482 488
483//static int visit=0; 489//static int visit=0;
484//static int lvisit=0; 490//static int lvisit=0;
@@ -559,37 +565,38 @@ void DictFilterConfig::add(const QString& set)
559 } 565 }
560 } 566 }
561 } 567 }
562//qDebug("%d+%d visits",lvisit,visit); 568//qDebug("%d+%d visits",lvisit,visit);
563} 569}
564 570
565bool DictFilterConfig::highlight(int r,int c) const 571bool DictFilterConfig::highlight(int r,int c) const
566{ 572{
567 return r == 0 ? c == lit0 : c == lit1; 573 return r == 0 ? c == lit0 : c == lit1;
568} 574}
569 575
570 576
571void DictFilterConfig::addSet(const QString& s) 577void DictFilterConfig::addSet(const QString& appearance, const QString& set)
572{ 578{
573 sets.append(s); 579 sets_a.append( appearance );
580 sets.append( set );
574} 581}
575 582
576void DictFilterConfig::addMode(const QString& s) 583void DictFilterConfig::addMode(const QString& s)
577{ 584{
578 othermodes.append(s); 585 othermodes.append(s);
579} 586}
580 587
581void DictFilterConfig::fillMenu(QPopupMenu& menu) 588void DictFilterConfig::fillMenu(QPopupMenu& menu)
582{ 589{
583 menu.insertItem("Add...",300); 590 menu.insertItem(tr("Add..."),300);
584 StringConfig::fillMenu(menu); 591 StringConfig::fillMenu(menu);
585} 592}
586 593
587QValueList<QPixmap> KeycodeConfig::row(int i) 594QValueList<QPixmap> KeycodeConfig::row(int i)
588{ 595{
589 return i ? keypm2 : keypm1; 596 return i ? keypm2 : keypm1;
590} 597}
591 598
592void KeycodeConfig::pickInRow(int r, int xpos, bool press) 599void KeycodeConfig::pickInRow(int r, int xpos, bool press)
593{ 600{
594 QValueList<QPixmap> pl = row(r); 601 QValueList<QPixmap> pl = row(r);
595 QValueList<QPixmap>::Iterator it; 602 QValueList<QPixmap>::Iterator it;