-rw-r--r-- | inputmethods/pickboard/pickboard.cpp | 25 | ||||
-rw-r--r-- | inputmethods/pickboard/pickboardcfg.cpp | 69 | ||||
-rw-r--r-- | inputmethods/pickboard/pickboardcfg.h | 19 | ||||
-rw-r--r-- | inputmethods/pickboard/pickboardimpl.cpp | 6 | ||||
-rw-r--r-- | inputmethods/pickboard/pickboardpicks.cpp | 31 |
5 files changed, 91 insertions, 59 deletions
diff --git a/inputmethods/pickboard/pickboard.cpp b/inputmethods/pickboard/pickboard.cpp index 087144e..1611cb0 100644 --- a/inputmethods/pickboard/pickboard.cpp +++ b/inputmethods/pickboard/pickboard.cpp @@ -1,16 +1,16 @@ /********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** -** This file is part of Qtopia Environment. +** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are @@ -25,25 +25,43 @@ #include <qpainter.h> #include <qlist.h> #include <qbitmap.h> #include <qlayout.h> #include <qvbox.h> #include <qdialog.h> #include <qscrollview.h> #include <qpopupmenu.h> #include <qhbuttongroup.h> #include <qpushbutton.h> #include <qmessagebox.h> +#ifdef QWS #include <qwindowsystem_qws.h> +#endif + +/*! \class Pickboard + \brief The Pickboard class provides an input method + based on a virtual keyboard combined with word-completion. + + This version of Pickboard is Dual Licensed Software. However, for you to be + able to license the technology to others, you may require a T9(R) Text + Input license from Tegic Communications Corporation. More information can + be found at http://www.t9.com/. + + \legalese + This version of Pickboard is Dual Licensed Software. However, for you to be + able to license the technology to others, you may require a T9(R) Text + Input license from Tegic Communications Corporation. More information can + be found at http://www.t9.com/. +*/ /* XPM */ static const char * const menu_xpm[]={ "9 9 2 1", "a c #000000", ". c None", ".........", ".........", ".........", "....a....", "...aaa...", "..aaaaa..", @@ -65,25 +83,28 @@ public: parent,SIGNAL(key(ushort,ushort,ushort,bool,bool))); } PickboardPicks* picks; QPushButton* menu; }; Pickboard::Pickboard(QWidget* parent, const char* name, WFlags f) : QFrame(parent,name,f) { (new QHBoxLayout(this))->setAutoAdd(TRUE); d = new PickboardPrivate(this); +// under Win32 we may not have smallsmooth font +#ifndef Q_OS_WIN32 setFont( QFont( "smallsmooth", 9 ) ); +#endif } Pickboard::~Pickboard() { delete d; } void Pickboard::resetState() { d->picks->resetState(); } 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 @@ /********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** -** This file is part of Qtopia Environment. +** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are @@ -25,35 +25,37 @@ #include <qpainter.h> #include <qlist.h> #include <qbitmap.h> #include <qlayout.h> #include <qvbox.h> #include <qdialog.h> #include <qscrollview.h> #include <qpopupmenu.h> #include <qhbuttongroup.h> #include <qpushbutton.h> #include <qmessagebox.h> +#ifdef QWS #include <qwindowsystem_qws.h> +#endif static const char * pickboard_help = - "<h1>The Pickboard</h1>" + QT_TRANSLATE_NOOP("PickboardConfig", "<h1>The Pickboard</h1>" "<i>The smallest and fastest way to type.</i>" "<p>" "Enter a word by tapping letter-groups and picking the word." "<br>Enter spaces with \"Space\", or other keys through \"KEY\"." "<br>Use \"Shift\" to capitalize words that are not normally capitalized." "<br>Press \"Shift\" twice for an all-capitals word." - "<br>Add custom words by picking them, then selecting \"Add...\" from the menu on the right." + "<br>Add custom words by picking them, then selecting \"Add...\" from the menu on the right." ) ; const int intermatchmargin=5; PickboardConfig::~PickboardConfig() { } void PickboardConfig::updateRows(int from, int to) { if ( from != to ) { // (all) parent->update(); } else { @@ -67,28 +69,32 @@ void PickboardConfig::updateItem(int r, int) { updateRows(r,r); } void PickboardConfig::changeMode(int m) { parent->setMode(m); } void PickboardConfig::generateText(const QString& s) { #if defined(Q_WS_QWS) || defined(_WS_QWS_) for (int i=0; i<(int)s.length(); i++) { - parent->emitKey(s[i].unicode(), 0, 0, true, false); - parent->emitKey(s[i].unicode(), 0, 0, false, false); + uint code = 0; + if ( s[i].unicode() >= 'a' && s[i].unicode() <= 'z' ) { + code = s[i].unicode() - 'a' + Key_A; + } + parent->emitKey(s[i].unicode(), code, 0, true, false); + parent->emitKey(s[i].unicode(), code, 0, false, false); } -#endif +#endif } void PickboardConfig::generateKey( int k ) { #if defined(Q_WS_QWS) || defined(_WS_QWS_) parent->emitKey(0, k, 0, true, false); parent->emitKey(0, k, 0, false, false); #endif } void PickboardConfig::pickPoint(const QPoint& p, bool press) { if ( press ) { @@ -103,40 +109,40 @@ void PickboardConfig::pickPoint(const QPoint& p, bool press) return; } y += ls; } } else if ( pressx >= 0 ) { pickInRow( pressrow, pressx, FALSE ); pressx = -1; } } void PickboardConfig::fillMenu(QPopupMenu& menu) { - menu.insertItem("Reset",100); + menu.insertItem(tr("Reset"),100); menu.insertSeparator(); - menu.insertItem("Help",1); + menu.insertItem(tr("Help"),1); } void PickboardConfig::doMenu(int i) { switch (i) { case 100: if ( parent->currentMode() ) { changeMode(0); updateRows(0,1); } break; case 1: { - QMessageBox help("Pickboard Help", pickboard_help, + QMessageBox help(tr("Pickboard Help"), tr(pickboard_help), QMessageBox::NoIcon, 1, 0, 0); help.showMaximized(); help.exec(); } } } void StringConfig::draw(QPainter* p) { QFontMetrics fm = p->fontMetrics(); for (int r=0; r<nrows; r++) { @@ -149,28 +155,28 @@ void StringConfig::draw(QPainter* p) for (; !(s=text(r,i)).isNull(); ++i) { int w = fm.width(s); tw += w; } bool spread = spreadRow(r);// && parent->width() > tw; int xw = spread ? (parent->width()-tw)/(i-1) : 3; int x = spread ? (parent->width()-tw-xw*(i-1))/2 : 2; i=0; for (; !(s=text(r,i)).isNull(); ++i) { int w = fm.width(s)+xw; if ( highlight(r,i) ) { - p->fillRect(x-xw/2,1+fm.descent()-fm.lineSpacing(),w,fm.lineSpacing(),::Qt::black); - p->setPen(::Qt::white); + p->fillRect(x-xw/2,1+fm.descent()-fm.lineSpacing(),w,fm.lineSpacing(),Qt::black); + p->setPen(Qt::white); }else{ - p->setPen(::Qt::black); + p->setPen(Qt::black); } p->drawText(x,-fm.descent()-1,s); x += w; } } } void StringConfig::pickInRow(int r, int xpos, bool press) { QFontMetrics fm = parent->fontMetrics(); int tw=0; @@ -284,27 +290,27 @@ PickboardAdd::PickboardAdd(QWidget* owner, const QStringList& setlist) : setMaximumHeight(200); // ### QDialog shouldn't allow us to be bigger than the screen QVBox *letters = new QVBox(sv); letters->setSpacing(0); lc = new LetterChoice*[setlist.count()]; nlc = (int)setlist.count(); for (int i=0; i<nlc; i++) { lc[i] = new LetterChoice(letters,setlist[i]); connect(lc[i],SIGNAL(changed()),this,SLOT(checkAllDone())); } sv->addChild(letters); QHBox* hb = new QHBox(this); hb->setSpacing(0); - yes = new QPushButton("OK",hb); + yes = new QPushButton(tr("OK"),hb); yes->setEnabled(FALSE); - QPushButton *no = new QPushButton("Cancel",hb); + QPushButton *no = new QPushButton(tr("Cancel"),hb); connect(yes, SIGNAL(clicked()), this, SLOT(accept())); connect(no, SIGNAL(clicked()), this, SLOT(reject())); } PickboardAdd::~PickboardAdd() { delete [] lc; } QString PickboardAdd::word() const { QString str; @@ -334,29 +340,29 @@ void PickboardAdd::checkAllDone() return; } yes->setEnabled(TRUE); } } void DictFilterConfig::doMenu(int i) { switch (i) { case 300: if ( input.count() == 0 ) { - QMessageBox::information(0, "Adding Words", - "To add words, pick the letters,\nthen " + QMessageBox::information(0, tr("Adding Words"), + tr("To add words, pick the letters,\nthen " "open the Add dialog. In that\ndialog, tap " "the correct letters\nfrom the list " - "(tap twice for\ncapitals)."); + "(tap twice for\ncapitals).")); } else { PickboardAdd add(parent,capitalize(input)); if ( add.exec() ) generateText(add.word()); input.clear(); matches.clear(); updateRows(0,0); } break; case 100: if ( !input.isEmpty() ) { input.clear(); @@ -365,25 +371,25 @@ void DictFilterConfig::doMenu(int i) updateRows(0,1); break; } // else fall through default: StringConfig::doMenu(i); } shift = 0; lit0 = -1; } QString DictFilterConfig::text(int r, int i) { - QStringList l = r ? sets : input.isEmpty() ? othermodes : matches; + QStringList l = r ? sets_a : input.isEmpty() ? othermodes : matches; return i < (int)l.count() ? (input.isEmpty() ? l[i] : capitalize(l[i])) : QString::null; } bool DictFilterConfig::spreadRow(int r) { return r ? TRUE : input.isEmpty() ? TRUE : FALSE; } QStringList DictFilterConfig::capitalize(const QStringList& l) { @@ -417,68 +423,68 @@ QString DictFilterConfig::capitalize(const QString& s) return s.upper(); break; } return s; } void DictFilterConfig::pick(bool press, int row, int item) { if ( row == 0 ) { if ( press ) { if ( input.isEmpty() ) { lit0 = item; - if ( othermodes[item] == "Space" ) { + if ( othermodes[item] == PickboardPicks::tr("Space") ) { updateItem(row,item); generateText(" "); - } else if ( othermodes[item] == "Back" ) { + } else if ( othermodes[item] == PickboardPicks::tr("Back") ) { updateItem(row,item); generateKey(::Qt::Key_Backspace); - } else if ( othermodes[item] == "Enter" ) { - updateItem(row,item); + } else if ( othermodes[item] == PickboardPicks::tr("Enter") ) { + updateItem(row,item); generateKey(::Qt::Key_Return); - } else if ( othermodes[item] == "Shift" ) { + } else if ( othermodes[item] == PickboardPicks::tr("Shift") ) { updateItem(row,item); shift = (shift+1)%3; } } } else { if ( !input.isEmpty() ) { input.clear(); if ( item>=0 ) { generateText(capitalize(matches[item])); } shift = 0; matches.clear(); updateRows(0,0); } else if ( item < 3 ) { lit0 = -1; changeMode(item+1); // I'm mode 0! #### updateRows(0,1); } if ( lit0 >= 0 ) { - if ( !shift || othermodes[lit0] != "Shift" ) { - updateItem(0,lit0); + if ( !shift || othermodes[lit0] != PickboardPicks::tr("Shift") ) { + updateItem(0,lit0); lit0 = -1; } } } } else { lit0 = -1; if ( press && item >= 0 ) { lit1 = item; add(sets[item]); - updateItem(1,item); + updateItem(1,item); updateRows(0,0); } else { - updateItem(1,lit1); + updateItem(1,lit1); lit1 = -1; } } } bool DictFilterConfig::scanMatch(const QString& set, const QChar& l) const { return set == "?" || set == "*" || set.contains(l); } //static int visit=0; //static int lvisit=0; @@ -559,37 +565,38 @@ void DictFilterConfig::add(const QString& set) } } } //qDebug("%d+%d visits",lvisit,visit); } bool DictFilterConfig::highlight(int r,int c) const { return r == 0 ? c == lit0 : c == lit1; } -void DictFilterConfig::addSet(const QString& s) +void DictFilterConfig::addSet(const QString& appearance, const QString& set) { - sets.append(s); + sets_a.append( appearance ); + sets.append( set ); } void DictFilterConfig::addMode(const QString& s) { othermodes.append(s); } void DictFilterConfig::fillMenu(QPopupMenu& menu) { - menu.insertItem("Add...",300); + menu.insertItem(tr("Add..."),300); StringConfig::fillMenu(menu); } QValueList<QPixmap> KeycodeConfig::row(int i) { return i ? keypm2 : keypm1; } void KeycodeConfig::pickInRow(int r, int xpos, bool press) { QValueList<QPixmap> pl = row(r); QValueList<QPixmap>::Iterator it; diff --git a/inputmethods/pickboard/pickboardcfg.h b/inputmethods/pickboard/pickboardcfg.h index b1913df..92c6420 100644 --- a/inputmethods/pickboard/pickboardcfg.h +++ b/inputmethods/pickboard/pickboardcfg.h @@ -1,16 +1,16 @@ /********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** -** This file is part of Qtopia Environment. +** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are @@ -67,25 +67,26 @@ public: QString word() const; bool exec(); private slots: void checkAllDone(); private: QPushButton *yes; LetterChoice **lc; int nlc; }; -class PickboardConfig : QObject { +class PickboardConfig : public QObject { + Q_OBJECT public: PickboardConfig(PickboardPicks* p) : parent(p), nrows(2), pressx(-1) { } virtual ~PickboardConfig(); virtual void pickPoint(const QPoint& p, bool press); virtual void draw(QPainter*)=0; virtual void fillMenu(QPopupMenu&); virtual void doMenu(int); protected: void updateRows(int from, int to); virtual void updateItem(int r, int i); virtual void pickInRow(int r, int xpos, bool press)=0; @@ -95,114 +96,118 @@ protected: void generateKey( int k ); virtual void pick(bool press, int row, int item)=0; protected: PickboardPicks* parent; int nrows; private: int pressrow, pressx; }; class StringConfig : public PickboardConfig { + Q_OBJECT public: StringConfig(PickboardPicks* p) : PickboardConfig(p) { } void draw(QPainter* p); protected: virtual QString text(int r, int i)=0; virtual bool spreadRow(int i)=0; - virtual QColor rowColor(int) { return ::Qt::black; } + virtual QColor rowColor(int) { return Qt::black; } virtual void pickInRow(int r, int xpos, bool press); virtual void updateItem(int r, int i); virtual bool highlight(int,int) const; }; class CharStringConfig : public StringConfig { + Q_OBJECT QString input; QStringList chars; public: CharStringConfig(PickboardPicks* p) : StringConfig(p) { } void addChar(const QString& s); virtual void doMenu(int); protected: QString text(int r, int i); bool spreadRow(int i); void pick(bool press, int row, int item); }; class DictFilterConfig : public StringConfig { + Q_OBJECT QStringList matches; + QStringList sets_a; QStringList sets; QStringList othermodes; int lit0; int lit1; int shift; QString capitalize(const QString& s); QStringList capitalize(const QStringList& s); public: QStringList input; DictFilterConfig(PickboardPicks* p) : StringConfig(p) { shift = 0; lit0 = -1; lit1 = -1; } - void addSet(const QString& s); + void addSet(const QString& apperance, const QString& set); void addMode(const QString& s); void fillMenu(QPopupMenu& menu); void doMenu(int i); void add(const QString& set); protected: QString text(int r, int i); bool spreadRow(int i); void pick(bool press, int row, int item); bool scanMatch(const QString& set, const QChar& l) const; void scan(const QDawg::Node* n, int ipos, const QString& str, int length, bool extend); void scanLengths(const QDawg::Node* n, int ipos, int& bitarray); bool highlight(int r,int c) const; }; class CharConfig : public StringConfig { + Q_OBJECT QStringList chars1; QStringList chars2; public: CharConfig(PickboardPicks* p) : StringConfig(p) { } void addChar(int r, const QString& s); protected: QString text(int r, int i); bool spreadRow(int); void pick(bool press, int row, int item); }; class KeycodeConfig : public PickboardConfig { QValueList<int> keys1; QValueList<int> keys2; QValueList<QPixmap> keypm1; QValueList<QPixmap> keypm2; - static const int xw = 8; - static const int xmarg = 8; + enum { xw = 8, xmarg = 8 }; public: KeycodeConfig(PickboardPicks* p) : PickboardConfig(p) { } void addKey(int r, const QPixmap& pm, int code); void addGap(int r, int w); void draw(QPainter* p); protected: void pickInRow(int r, int xpos, bool press); QValueList<QPixmap> row(int i); diff --git a/inputmethods/pickboard/pickboardimpl.cpp b/inputmethods/pickboard/pickboardimpl.cpp index 9a21229..f839452 100644 --- a/inputmethods/pickboard/pickboardimpl.cpp +++ b/inputmethods/pickboard/pickboardimpl.cpp @@ -1,16 +1,16 @@ /********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** -** This file is part of Qtopia Environment. +** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are @@ -18,25 +18,25 @@ ** **********************************************************************/ #include <qapplication.h> #include <qobject.h> #include <qpixmap.h> #include "pickboard.h" #include "pickboardimpl.h" /* XPM */ static const char * pb_xpm[]={ "28 7 2 1", "# c #303030", -" c None", +" c None", // No tr " ########################## ", " # # # # # # # ", " # # # # # # # ", " ########################## ", " # # # # # # ", " # # # # # # ", " ########################## "}; PickboardImpl::PickboardImpl() : pickboard(0), icn(0) { diff --git a/inputmethods/pickboard/pickboardpicks.cpp b/inputmethods/pickboard/pickboardpicks.cpp index a80bbf8..b9d9928 100644 --- a/inputmethods/pickboard/pickboardpicks.cpp +++ b/inputmethods/pickboard/pickboardpicks.cpp @@ -1,16 +1,16 @@ /********************************************************************** -** Copyright (C) 2000 Trolltech AS. All rights reserved. +** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** -** This file is part of Qtopia Environment. +** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are @@ -24,25 +24,27 @@ #include <qpainter.h> #include <qlist.h> #include <qbitmap.h> #include <qlayout.h> #include <qvbox.h> #include <qdialog.h> #include <qscrollview.h> #include <qpopupmenu.h> #include <qhbuttongroup.h> #include <qpushbutton.h> #include <qmessagebox.h> +#ifdef QWS #include <qwindowsystem_qws.h> +#endif void PickboardPicks::doMenu() { QWidget* cause = (QWidget*)sender(); // evil QPopupMenu popup(this); config()->fillMenu(popup); QPoint pos = cause->mapToGlobal(cause->rect().topRight()); QSize sz = popup.sizeHint(); pos.ry() -= sz.height(); pos.rx() -= sz.width(); @@ -239,48 +241,45 @@ static const char *Space_xpm[] = { "a.......a", "a.......a", "a.......a", "a.......a", "a.......a", "a.......a", "aaaaaaaaa" }; PickboardPicks::PickboardPicks(QWidget* parent, const char* name, WFlags f ) : QFrame(parent,name,f) { + configs.setAutoDelete( TRUE ); } void PickboardPicks::initialise(void) { setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed)); mode = 0; DictFilterConfig* dc = new DictFilterConfig(this); - dc->addSet("ABC"); - dc->addSet("DEF"); - dc->addSet("GHI"); - dc->addSet("JKL"); - dc->addSet("MNO"); - dc->addSet("PQR"); - dc->addSet("STU"); - dc->addSet("VWX"); - dc->addSet("YZ-'"); + QStringList sets_a = QStringList::split(' ',tr("ABC DEF GHI JKL MNO PQR STU VWX YZ-'")); + QStringList sets = QStringList::split(' ', + tr("ABC%/1iso8859-15 DEF%/1iso8859-15 GHI%/1iso8859-15 JKL MNO%/1iso8859-15 PQR%/1iso8859-15 STU%/1iso8859-15 VWX YZ-'%/1iso8859-15")); + for (QStringList::ConstIterator it = sets.begin(), it_a = sets_a.begin(); it!=sets.end(); ++it,++it_a) + dc->addSet(*it_a,*it); dc->addMode("123"); dc->addMode("@*!?"); - dc->addMode("KEY"); - dc->addMode("Space"); - dc->addMode("Back"); - dc->addMode("Enter"); - dc->addMode("Shift"); + dc->addMode(tr("KEY")); + dc->addMode(tr("Space")); + dc->addMode(tr("Back")); + dc->addMode(tr("Enter")); + dc->addMode(tr("Shift")); configs.append(dc); CharStringConfig* number = new CharStringConfig(this); number->addChar("0"); number->addChar("1"); number->addChar("2"); number->addChar("3"); number->addChar("4"); number->addChar("5"); number->addChar("6"); number->addChar("7"); number->addChar("8"); |