-rw-r--r-- | inputmethods/handwriting/qimpenhelp.cpp | 12 | ||||
-rw-r--r-- | inputmethods/handwriting/qimpeninput.cpp | 24 | ||||
-rw-r--r-- | inputmethods/handwriting/qimpensetup.cpp | 12 |
3 files changed, 24 insertions, 24 deletions
diff --git a/inputmethods/handwriting/qimpenhelp.cpp b/inputmethods/handwriting/qimpenhelp.cpp index a294301..0727931 100644 --- a/inputmethods/handwriting/qimpenhelp.cpp +++ b/inputmethods/handwriting/qimpenhelp.cpp @@ -1,386 +1,386 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** 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 ** not clear to you. ** **********************************************************************/ #include "qimpenwidget.h" #include "qimpencombining.h" #include "qimpenmatch.h" #include "qimpenhelp.h" #include <qpe/qpeapplication.h> #include <qpe/global.h> #include <qpe/config.h> #include <qpe/stringutil.h> #include <qtextview.h> #include <qlabel.h> #include <qlistbox.h> #include <qcombobox.h> #include <qpushbutton.h> #include <qlayout.h> #include <qtimer.h> #include <qtextstream.h> /* XPM */ static const char * const left_xpm[] = { "16 16 2 1", " c None", ". c #000000", " ", " ", " ", " . ", " .. ", " ... ", " .... ", " ..... ", " ...... ", " ..... ", " .... ", " ... ", " .. ", " . ", " ", " "}; /* XPM */ static const char * const right_xpm[] = { "16 16 2 1", " c None", ". c #000000", " ", " ", " ", " . ", " .. ", " ... ", " .... ", " ..... ", " ...... ", " ..... ", " .... ", " ... ", " .. ", " . ", " ", " "}; class CharListItem : public QListBoxText { public: CharListItem( const QString &text, uint c ) : QListBoxText( text ) { _code = c; } uint code() const { return _code; } protected: uint _code; }; HandwritingHelp::HandwritingHelp( QIMPenProfile *p, QWidget *parent, const char *name, WFlags f ) : QTabWidget( parent, name, f ) { setCaption( tr("Handwriting Help") ); QTextView *help = new QTextView( this ); help->setFrameStyle( QFrame::NoFrame ); help->setText( tr( "<ul><li>When you start to use the handwriting recogniser " "write slowly, accurately and firmly." "<li>Use the guide lines when drawing your characters." "<li>When drawing a character with multiple strokes, each " "successive stroke must be drawn before the grayed strokes are erased." "<li>Practice your handwriting using the handwriting trainer." "<li>When adding your own character templates make sure they " "are sufficiently different from other characters' templates." "</ul>") ); addTab( help, tr("Tips") ); HandwritingTrainer *trainer = new HandwritingTrainer( p, this ); addTab( trainer, tr("Trainer") ); } void HandwritingHelp::showEvent( QShowEvent * ) { Global::hideInputMethod(); } void HandwritingHelp::hideEvent( QHideEvent * ) { Global::showInputMethod(); } //--------------------------------------------------------------------------- HandwritingTrainer::HandwritingTrainer( QIMPenProfile *p, QWidget *parent, const char *name ) : QWidget( parent, name ), profile(p) { QGridLayout *gl = new QGridLayout( this, 4, 2, 0, 4 ); gl->setColStretch( 1, 1 ); gl->setRowStretch(3, 1); charSetCombo = new QComboBox( this ); gl->addMultiCellWidget( charSetCombo, 0, 0, 0, 1 ); connect( charSetCombo, SIGNAL(activated(int)), SLOT(selectCharSet(int))); QIMPenCharSetIterator it( profile->charSets() ); for ( ; it.current(); ++it ) { charSetCombo->insertItem( it.current()->description() ); } charList = new QListBox( this ); charList->setHScrollBarMode( QListBox::AlwaysOff ); charList->setFixedWidth(80); connect( charList, SIGNAL(highlighted(int)), this, SLOT(selectChar(int)) ); gl->addWidget(charList, 1, 0); result = new QLabel( this ); result->setAlignment(AlignLeft | AlignVCenter | WordBreak); result->setText( tr( "Select a reference character from the list. Practice writing in " "the area on the right.")); gl->addMultiCellWidget(result, 1, 2, 1, 1); matcher = new QIMPenMatch( this ); matcher->setCharSet( currentSet ); connect( matcher, SIGNAL(noMatch()), this, SLOT(noMatch()) ); - connect( matcher, SIGNAL(matchedCharacters(const QIMPenCharMatchList &)), - this, SLOT(matched(const QIMPenCharMatchList &)) ); + connect( matcher, SIGNAL(matchedCharacters(const QIMPenCharMatchList&)), + this, SLOT(matched(const QIMPenCharMatchList&)) ); QHBoxLayout *hb = new QHBoxLayout(); gl->addLayout( hb, 2, 0 ); prevBtn = new QPushButton( this ); prevBtn->setPixmap( QPixmap( (const char **)left_xpm ) ); connect( prevBtn, SIGNAL(clicked()), SLOT(prevChar())); hb->addWidget( prevBtn ); nextBtn = new QPushButton( this ); nextBtn->setPixmap( QPixmap( (const char **)right_xpm ) ); connect( nextBtn, SIGNAL(clicked()), SLOT(nextChar())); hb->addWidget( nextBtn ); refPw = new QIMPenWidget( this ); refPw->setReadOnly( TRUE ); gl->addWidget( refPw, 3, 0 ); pracPw = new QIMPenWidget( this ); connect( matcher, SIGNAL(removeStroke()), pracPw, SLOT(removeStroke()) ); connect( pracPw, SIGNAL(beginStroke()), this, SLOT(beginStroke()) ); - connect( pracPw, SIGNAL(stroke( QIMPenStroke * )), - this, SLOT(strokeEntered( QIMPenStroke * )) ); + connect( pracPw, SIGNAL(stroke(QIMPenStroke*)), + this, SLOT(strokeEntered(QIMPenStroke*)) ); connect( pracPw, SIGNAL(beginStroke()), matcher, SLOT(beginStroke()) ); - connect( pracPw, SIGNAL(stroke( QIMPenStroke * )), - matcher, SLOT(strokeEntered( QIMPenStroke * )) ); + connect( pracPw, SIGNAL(stroke(QIMPenStroke*)), + matcher, SLOT(strokeEntered(QIMPenStroke*)) ); gl->addWidget( pracPw, 3, 1 ); redrawTimer = new QTimer( this ); connect( redrawTimer, SIGNAL(timeout()), this, SLOT(redrawChar()) ); redrawTimer->start( 5000 ); currentSet = 0; charSetCombo->setCurrentItem( 1 ); selectCharSet( 1 ); } HandwritingTrainer::~HandwritingTrainer() { } void HandwritingTrainer::showEvent( QShowEvent * ) { redrawChar(); redrawTimer->start( 5000 ); } void HandwritingTrainer::setCurrentChar( QIMPenChar *c ) { currentChar = c; refPw->showCharacter( currentChar ); pracPw->clear(); if ( currentChar ) { prevBtn->setEnabled( findPrev() != 0 ); nextBtn->setEnabled( findNext() != 0 ); } redrawTimer->start( 5000 ); } void HandwritingTrainer::selectChar( int i ) { static int last_char = 0; if (last_char != i) { result->setText(""); } currentChar = 0; currentCode = ((CharListItem *)charList->item(i))->code(); QIMPenCharIterator it(currentSet->characters() ); for ( ; it.current(); ++it ) { if ( it.current()->character() == currentCode && !it.current()->testFlag( QIMPenChar::Deleted ) ) { setCurrentChar( it.current() ); break; } } if ( !it.current() ) setCurrentChar( 0 ); } void HandwritingTrainer::selectCharSet( int i ) { if ( currentSet ) { refPw->removeCharSet( 0 ); pracPw->removeCharSet( 0 ); result->setText(""); } currentSet = profile->charSets().at( i ); fillCharList(); refPw->insertCharSet( currentSet ); pracPw->insertCharSet( currentSet ); matcher->setCharSet( currentSet ); if ( charList->count() ) { charList->setSelected( 0, TRUE ); selectChar(0); } } void HandwritingTrainer::noMatch() { result->setText( tr("No match") ); } void HandwritingTrainer::matched( const QIMPenCharMatchList &ml ) { int maxErr = 20000 + (*ml.begin()).penChar->strokeLength(0) * 1000; int baseErr = (*ml.begin()).penChar->strokeLength(0) * 250; unsigned int numStrokes = (*ml.begin()).penChar->strokeCount(); QIMPenCharMatchList::ConstIterator it; /* for ( it = ml.begin(); it != ml.end(); ++it ) { if ( (*it).penChar->strokeCount() == numStrokes ) { if ( (*it).error > maxErr ) maxErr = (*it).error; } } */ int i; QString res; QTextStream ts(&res, IO_WriteOnly); ts << "<qt>" << tr("Matched: "); for ( i = 0, it = ml.begin(); it != ml.end() && i < 4; ++it, i++ ) { if ( (*it).penChar->strokeCount() == numStrokes ) { int rate = 100 - ( ((*it).error - baseErr) * 100 ) / maxErr; if ( it != ml.begin() ) { if ( rate < -10 ) continue; ts << "<br>"; ts << tr("Similar to: "); } ts << "<big>"; if ( (*it).penChar->character() == currentChar->character() ) ts << "<b>"; ts << Qtopia::escapeString((*it).penChar->name()); ts << " (" << rateString(rate) << ")"; if ( (*it).penChar->character() == currentChar->character() ) ts << "</b>"; ts << "</big>"; } } ts << "</qt>"; result->setText( res ); } QString HandwritingTrainer::rateString( int rate ) const { if ( rate < 1 ) rate = 1; if ( rate > 100 ) rate = 100; return tr("%1%").arg(rate); } void HandwritingTrainer::prevChar() { QIMPenChar *pc = findPrev(); if ( pc ) setCurrentChar( pc ); } void HandwritingTrainer::nextChar() { QIMPenChar *pc = findNext(); if ( pc ) setCurrentChar( pc ); } void HandwritingTrainer::redrawChar() { if ( currentChar ) refPw->showCharacter( currentChar ); } void HandwritingTrainer::beginStroke() { redrawTimer->start( 5000 ); } void HandwritingTrainer::strokeEntered( QIMPenStroke * ) { pracPw->greyStroke(); } QIMPenChar *HandwritingTrainer::findPrev() { if ( !currentChar ) return 0; QIMPenCharIterator it( currentSet->characters() ); bool found = FALSE; for ( it.toLast(); it.current(); --it ) { if ( !found && it.current() == currentChar ) found = TRUE; else if ( found && it.current()->character() == currentCode && !it.current()->testFlag( QIMPenChar::Deleted ) ) { return it.current(); } } return 0; } QIMPenChar *HandwritingTrainer::findNext() { if ( !currentChar ) return 0; QIMPenCharIterator it( currentSet->characters() ); bool found = FALSE; for ( ; it.current(); ++it ) { if ( !found && it.current() == currentChar ) found = TRUE; else if ( found && it.current()->character() == currentCode && !it.current()->testFlag( QIMPenChar::Deleted ) ) { return it.current(); } } return 0; diff --git a/inputmethods/handwriting/qimpeninput.cpp b/inputmethods/handwriting/qimpeninput.cpp index db33c9b..d073cdf 100644 --- a/inputmethods/handwriting/qimpeninput.cpp +++ b/inputmethods/handwriting/qimpeninput.cpp @@ -1,404 +1,404 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** 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 ** not clear to you. ** **********************************************************************/ #include "qimpenwidget.h" #include "qimpensetup.h" #include "qimpeninput.h" #include "qimpencombining.h" #include "qimpenwordpick.h" #include "qimpenmatch.h" #include "qimpenhelp.h" #include <qpe/qpeapplication.h> #include <qpe/qdawg.h> #include <qpe/config.h> #include <qpe/global.h> #include <qlayout.h> #include <qpushbutton.h> #include <qlabel.h> #include <qtimer.h> #include <qdir.h> #include <limits.h> // We'll use little pixmaps for the buttons to save screen space. /* XPM */ static const char * const pen_xpm[] = { "12 12 4 1", " c None", ". c #000000", "+ c #FFFFFF", "@ c #808080", " . ", " .+. ", " ..@@.", " .+@.. ", " .+@@. ", " .+@@. ", " .+@@. ", " .@.@. ", " .@@. ", " .... ", " .. ", " "}; /* XPM */ static char * bs_xpm[] = { "12 12 5 1", " c None", ". c #333333", "+ c #000000", "@ c #FFFFFF", "# c #666666", " ", " ", " ", " . ", " ++ ", " +@#+++++. ", " +@@@@@@@@+ ", " +@#+++++. ", " ++ ", " . ", " ", " "}; /* XPM */ static char * enter_xpm[] = { "12 12 5 1", " c None", ". c #333333", "+ c #000000", "@ c #FFFFFF", "# c #666666", " ", " .+. ", " +@+ ", " . +@+ ", " ++ +@+ ", " +@#++++@+ ", " +@@@@@@@@+ ", " +@#+++++. ", " ++ ", " . ", " ", " "}; /* XPM */ static char * help_xpm[] = { "12 12 5 1", " c None", ". c #000000", "+ c #FFFFFF", "@ c #666666", "# c #333333", " ", " ... ", " .+++. ", " .+..@+. ", " #.# .+. ", " .+. ", " .+. ", " .+. ", " .+. ", " #.# ", " .+. ", " #.# "}; /*! \class QIMPenInput qimpeninput.h Pen input widget. */ QIMPenInput::QIMPenInput( QWidget *parent, const char *name, WFlags wf ) : QFrame( parent, name, wf ), helpDlg(0), profile(0) { setFrameStyle( Box | Plain ); profileList.setAutoDelete( true ); matcher = new QIMPenMatch( this ); connect( matcher, SIGNAL(keypress(uint)), this, SLOT(keypress(uint)) ); connect( matcher, SIGNAL(erase()), this, SLOT(erase()) ); QGridLayout *gl = new QGridLayout( this, 5, 2, 1, 0 ); gl->setColStretch( 0, 1 ); wordPicker = new QIMPenWordPick( this ); - connect( wordPicker, SIGNAL(wordClicked(const QString &)), - this, SLOT(wordPicked(const QString &)) ); - connect( matcher, SIGNAL(matchedCharacters(const QIMPenCharMatchList &)), - this, SLOT(matchedCharacters(const QIMPenCharMatchList &)) ); + connect( wordPicker, SIGNAL(wordClicked(const QString&)), + this, SLOT(wordPicked(const QString&)) ); + connect( matcher, SIGNAL(matchedCharacters(const QIMPenCharMatchList&)), + this, SLOT(matchedCharacters(const QIMPenCharMatchList&)) ); connect( matcher, SIGNAL(matchedWords(const QIMPenMatch::MatchWordList&)), wordPicker, SLOT(setWords(const QIMPenMatch::MatchWordList&)) ); QFont f("smallsmooth",9); QFontInfo fi( f ); wordPicker->setFont( f ); wordPicker->setBackgroundColor( white ); gl->addMultiCellWidget( wordPicker, 0, 0, 0, 1 ); if ( !Global::fixedDawg().root() || !matcher->isWordMatchingEnabled() ) wordPicker->hide(); pw = new QIMPenWidget( this ); gl->addMultiCellWidget( pw, 1, 4, 0, 0 ); int bh = pw->sizeHint().height()/4; QPushButton *b = new QPushButton( this ); b->setFocusPolicy( NoFocus ); b->setPixmap( QPixmap( (const char **)bs_xpm ) ); b->setFixedHeight(pw->sizeHint().height()-3*bh); // left-over space goes here b->setAutoRepeat( TRUE ); gl->addWidget( b, 1, 1 ); connect( b, SIGNAL(clicked()), SLOT(backspace())); b = new QPushButton( this ); b->setFocusPolicy( NoFocus ); b->setPixmap( QPixmap( (const char **)enter_xpm ) ); b->setFixedHeight(bh); b->setAutoRepeat( TRUE ); gl->addWidget( b, 2, 1 ); connect( b, SIGNAL(clicked()), SLOT(enter())); helpBtn = new QPushButton( this ); helpBtn->setFocusPolicy( NoFocus ); helpBtn->setPixmap( QPixmap( (const char **)help_xpm ) ); helpBtn->setFixedHeight(bh); gl->addWidget( helpBtn, 3, 1 ); connect( helpBtn, SIGNAL(clicked()), SLOT(help())); QPixmap pm( (const char **)pen_xpm ); setupBtn = new QPushButton( this ); setupBtn->setFocusPolicy( NoFocus ); setupBtn->setPixmap( pm ); setupBtn->setFixedHeight(bh); gl->addWidget( setupBtn, 4, 1 ); connect( setupBtn, SIGNAL(clicked()), SLOT(setup())); connect( matcher, SIGNAL(removeStroke()), pw, SLOT(removeStroke()) ); - connect( pw, SIGNAL(changeCharSet( QIMPenCharSet * )), - matcher, SLOT(setCharSet( QIMPenCharSet * )) ); - connect( pw, SIGNAL(changeCharSet( int )), - this, SLOT(selectCharSet( int )) ); + connect( pw, SIGNAL(changeCharSet(QIMPenCharSet*)), + matcher, SLOT(setCharSet(QIMPenCharSet*)) ); + connect( pw, SIGNAL(changeCharSet(int)), + this, SLOT(selectCharSet(int)) ); connect( pw, SIGNAL(beginStroke()), matcher, SLOT(beginStroke()) ); - connect( pw, SIGNAL(stroke( QIMPenStroke * )), - this, SLOT(strokeEntered( QIMPenStroke * )) ); - connect( pw, SIGNAL(stroke( QIMPenStroke * )), - matcher, SLOT(strokeEntered( QIMPenStroke * )) ); + connect( pw, SIGNAL(stroke(QIMPenStroke*)), + this, SLOT(strokeEntered(QIMPenStroke*)) ); + connect( pw, SIGNAL(stroke(QIMPenStroke*)), + matcher, SLOT(strokeEntered(QIMPenStroke*)) ); shortcutCharSet = 0; currCharSet = 0; setupDlg = 0; profile = 0; mode = Normal; loadProfiles(); } QIMPenInput::~QIMPenInput() { delete (HandwritingHelp*) helpDlg; } QSize QIMPenInput::sizeHint() const { int fw = frameWidth(); int ps = wordPicker->isHidden() ? 0 : wordPicker->sizeHint().height(); return pw->sizeHint() + QSize( fw*2, fw*2+ps ); } void QIMPenInput::loadProfiles() { profileList.clear(); profile = 0; delete shortcutCharSet; shortcutCharSet = new QIMPenCharSet(); shortcutCharSet->setTitle( tr("Shortcut") ); QString path = QPEApplication::qpeDir() + "etc/qimpen"; QDir dir( path, "*.conf" ); QStringList list = dir.entryList(); QStringList::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { QIMPenProfile *p = new QIMPenProfile( path + "/" + *it ); profileList.append( p ); if ( p->shortcut() ) { QIMPenCharIterator it( p->shortcut()->characters() ); for ( ; it.current(); ++it ) { shortcutCharSet->addChar( new QIMPenChar(*it.current()) ); } } } Config config( "handwriting" ); config.setGroup( "Settings" ); QString prof = config.readEntry( "Profile", "Default" ); selectProfile( prof ); } void QIMPenInput::selectProfile( const QString &name ) { QListIterator<QIMPenProfile> it( profileList ); for ( ; it.current(); ++it ) { if ( it.current()->name() == name ) { profile = it.current(); break; } } if ( !it.current() ) return; pw->clearCharSets(); baseSets.clear(); matcher->setMultiStrokeTimeout( profile->multiStrokeTimeout() ); matcher->setWordMatchingEnabled( profile->matchWords() ); if ( !Global::fixedDawg().root() || !matcher->isWordMatchingEnabled() ) wordPicker->hide(); else wordPicker->show(); if ( profile->uppercase() && profile->style() == QIMPenProfile::BothCases ) { baseSets.append( profile->uppercase() ); pw->insertCharSet( profile->uppercase() ); } if ( profile->lowercase() ) { baseSets.append( profile->lowercase() ); pw->insertCharSet( profile->lowercase(), profile->style() == QIMPenProfile::BothCases ? 1 : 2 ); } if ( profile->numeric() ) { baseSets.append( profile->numeric() ); pw->insertCharSet( profile->numeric() ); } if ( helpDlg ) delete (HandwritingHelp*) helpDlg; } void QIMPenInput::wordPicked( const QString &w ) { int bs = matcher->word().length(); for ( int i = 0; i < bs; i++ ) keypress( Qt::Key_Backspace << 16 ); for ( unsigned int i = 0; i < w.length(); i++ ) keypress( w[i].unicode() ); matcher->resetState(); wordPicker->clear(); } void QIMPenInput::selectCharSet( int idx ) { if ( mode == Switch ) { //qDebug( "Switch back to normal" ); pw->changeCharSet( baseSets.at(currCharSet), currCharSet ); mode = Normal; } currCharSet = idx; } void QIMPenInput::beginStroke() { } void QIMPenInput::strokeEntered( QIMPenStroke * ) { pw->greyStroke(); } void QIMPenInput::erase() { keypress( Qt::Key_Backspace << 16 ); } void QIMPenInput::matchedCharacters( const QIMPenCharMatchList &cl ) { const QIMPenChar *ch = cl.first().penChar; int scan = ch->character() >> 16; if ( scan < QIMPenChar::ModeBase ) return; // We matched a special character... switch ( scan ) { case QIMPenChar::Caps: if ( profile->style() == QIMPenProfile::ToggleCases ) { // qDebug( "Caps" ); if ( mode == SwitchLock ) { // qDebug( "Switch to normal" ); pw->changeCharSet( profile->lowercase(), currCharSet ); mode = Switch; } else { // qDebug( "Switch to upper" ); pw->changeCharSet( profile->uppercase(), currCharSet ); mode = Switch; } } break; case QIMPenChar::CapsLock: if ( profile->style() == QIMPenProfile::ToggleCases ) { // qDebug( "CapsLock" ); if ( mode == Switch && baseSets.at(currCharSet) == profile->uppercase() ) { // qDebug( "Switch to normal" ); pw->changeCharSet( profile->lowercase(), currCharSet ); // change our base set back to lower. baseSets.remove( currCharSet ); baseSets.insert( currCharSet, profile->lowercase() ); mode = Normal; } else { // qDebug( "Switch to caps lock" ); pw->changeCharSet( profile->uppercase(), currCharSet ); // change our base set to upper. baseSets.remove( currCharSet ); baseSets.insert( currCharSet, profile->uppercase() ); mode = SwitchLock; } } break; case QIMPenChar::Punctuation: if ( profile->punctuation() ) { //qDebug( "Switch to punctuation" ); pw->changeCharSet( profile->punctuation(), currCharSet ); mode = Switch; } break; case QIMPenChar::Symbol: if ( profile->symbol() ) { //qDebug( "Switch to symbol" ); pw->changeCharSet( profile->symbol(), currCharSet ); mode = Switch; } break; case QIMPenChar::Shortcut: if ( shortcutCharSet ) { diff --git a/inputmethods/handwriting/qimpensetup.cpp b/inputmethods/handwriting/qimpensetup.cpp index d0f9ffd..d1297a9 100644 --- a/inputmethods/handwriting/qimpensetup.cpp +++ b/inputmethods/handwriting/qimpensetup.cpp @@ -1,536 +1,536 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** 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 ** not clear to you. ** **********************************************************************/ #include "qimpenwidget.h" #include "qimpenprefbase.h" #include "qimpensetup.h" #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qcombobox.h> #include <qlistbox.h> #include <qlabel.h> #include <qpushbutton.h> #include <qlayout.h> #include <qpixmap.h> #include <qbuttongroup.h> #include <qslider.h> #include <qtabwidget.h> #include <qdir.h> #include <qmessagebox.h> /* XPM */ static const char * const left_xpm[] = { "16 16 2 1", " c None", ". c #000000", " ", " ", " ", " . ", " .. ", " ... ", " .... ", " ..... ", " ...... ", " ..... ", " .... ", " ... ", " .. ", " . ", " ", " "}; /* XPM */ static const char * const right_xpm[] = { "16 16 2 1", " c None", ". c #000000", " ", " ", " ", " . ", " .. ", " ... ", " .... ", " ..... ", " ...... ", " ..... ", " .... ", " ... ", " .. ", " . ", " ", " "}; QIMPenSetup::QIMPenSetup( QIMPenProfile *p, QWidget *parent, const char *name, bool modal, int WFlags ) : QDialog( parent, name, modal, WFlags ), profileCombo(0), profile(p) { setCaption( tr("Setup Handwriting Input") ); QVBoxLayout *vb = new QVBoxLayout( this ); #define MULTIPROFILE #ifdef MULTIPROFILE profileList.setAutoDelete( true ); QHBoxLayout *hb = new QHBoxLayout( vb ); hb->setMargin( 6 ); QLabel *l = new QLabel( tr("Character Profile:"), this ); hb->addWidget( l ); profileCombo = new QComboBox( this ); - connect( profileCombo, SIGNAL(activated(const QString &)), - this, SLOT(selectProfile(const QString &)) ); + connect( profileCombo, SIGNAL(activated(const QString&)), + this, SLOT(selectProfile(const QString&)) ); hb->addWidget( profileCombo ); #else profileList.append( profile ); #endif qWarning("profiles: %d", profileList.count()); QTabWidget *tw = new QTabWidget( this ); vb->addWidget( tw ); pref = new QIMPenPrefBase( this ); tw->addTab( pref, tr("Preferences") ); pref->inputStyle->setExclusive( TRUE ); style = profile->style() == QIMPenProfile::ToggleCases ? 1 : 0; pref->inputStyle->setButton( style ); connect( pref->inputStyle, SIGNAL(clicked(int)), this, SLOT(styleClicked(int)) ); pref->inputStyle->setEnabled( profile->canSelectStyle() ); multiTimeout = profile->multiStrokeTimeout(); pref->multiStrokeSlider->setValue( multiTimeout ); multiTimeoutChanged( multiTimeout ); connect( pref->multiStrokeSlider, SIGNAL(valueChanged(int)), this, SLOT(multiTimeoutChanged(int)) ); edit = new QIMPenEdit( p, tw ); tw->addTab( edit, tr("Customize") ); #ifdef MULTIPROFILE loadProfiles(); #endif } void QIMPenSetup::loadProfiles() { QString path = QPEApplication::qpeDir() + "etc/qimpen"; QDir dir( path, "*.conf" ); QStringList list = dir.entryList(); QStringList::Iterator it; for ( it = list.begin(); it != list.end(); ++it ) { QIMPenProfile *p = new QIMPenProfile( path + "/" + *it ); profileList.append( p ); profileCombo->insertItem( p->name() ); if ( p->name() == profile->name() ) { profileCombo->setCurrentItem( profileCombo->count()-1 ); profile = p; edit->setProfile( profile ); } } } void QIMPenSetup::styleClicked( int id ) { style = id; } void QIMPenSetup::multiTimeoutChanged( int v ) { multiTimeout = v; pref->multiStrokeLabel->setText( tr("%1 ms").arg(v) ); } void QIMPenSetup::selectProfile( const QString &p ) { if ( p == profile->name() ) return; profile->setStyle( style ? QIMPenProfile::ToggleCases : QIMPenProfile::BothCases ); profile->setMultiStrokeTimeout( multiTimeout ); for ( int i = 0; i < (int)profileList.count(); i++ ) { if ( profileList.at(i)->name() == p ) { profile = profileList.at(i); style = profile->style() == QIMPenProfile::ToggleCases ? 1 : 0; pref->inputStyle->setButton( style ); pref->inputStyle->setEnabled( profile->canSelectStyle() ); multiTimeout = profile->multiStrokeTimeout(); pref->multiStrokeSlider->setValue( multiTimeout ); multiTimeoutChanged( multiTimeout ); edit->setProfile( profile ); break; } } } void QIMPenSetup::accept() { profile->setStyle( style ? QIMPenProfile::ToggleCases : QIMPenProfile::BothCases ); profile->setMultiStrokeTimeout( multiTimeout ); // Save current profile if ( profileCombo ) { Config config( "handwriting" ); config.setGroup( "Settings" ); config.writeEntry( "Profile", profileCombo->currentText() ); } // Save charsets bool ok = TRUE; for ( int i = 0; i < (int)profileList.count(); i++ ) { QIMPenProfile *prof = profileList.at(i); QIMPenCharSetIterator it(prof->charSets()); for ( ; it.current(); ++it ) { if ( !(it.current()->save( QIMPenCharSet::User )) ) { ok = FALSE; break; } } } if ( !ok ) { if ( QMessageBox::critical( 0, tr( "Out of space" ), tr("Unable to save information.\n" "Free up some space\n" "and try again.\n" "\nQuit anyway?"), QMessageBox::Yes|QMessageBox::Escape, QMessageBox::No|QMessageBox::Default ) != QMessageBox::No ) { QDialog::accept(); } } else { QDialog::accept(); } } //--------------------------------------------------------------------------- QIMPenInputCharDlg::QIMPenInputCharDlg( QWidget *parent, const char *name, bool modal, int WFlags) : QDialog( parent, name, modal, WFlags ) { setCaption( tr("Enter new character") ); uni = 0; QVBoxLayout *vb = new QVBoxLayout( this, 10 ); QHBoxLayout *hb = new QHBoxLayout(); vb->addLayout( hb ); QLabel *label = new QLabel( tr("Character:"), this ); hb->addWidget( label ); QComboBox *cb = new QComboBox( TRUE, this ); connect( cb, SIGNAL(activated(int)), SLOT(setSpecial(int)) ); - connect( cb, SIGNAL(textChanged(const QString &)), - SLOT(setCharacter(const QString &)) ); + connect( cb, SIGNAL(textChanged(const QString&)), + SLOT(setCharacter(const QString&)) ); addSpecial( cb ); cb->setEditText( "" ); hb->addWidget( cb ); hb = new QHBoxLayout(); vb->addLayout( hb ); QPushButton *pb = new QPushButton( "OK", this ); connect( pb, SIGNAL(clicked()), SLOT(accept())); hb->addWidget( pb ); pb = new QPushButton( "Cancel", this ); connect( pb, SIGNAL(clicked()), SLOT(reject())); hb->addWidget( pb ); cb->setFocus(); } void QIMPenInputCharDlg::addSpecial( QComboBox *cb ) { int i = 0; while ( qimpen_specialKeys[i].code != Key_unknown ) { cb->insertItem( qimpen_specialKeys[i].name ); i++; } } void QIMPenInputCharDlg::setSpecial( int sp ) { uni = qimpen_specialKeys[sp].code << 16; } void QIMPenInputCharDlg::setCharacter( const QString &string ) { uni = string[0].unicode(); } //--------------------------------------------------------------------------- class CharListItem : public QListBoxText { public: CharListItem( const QString &text, uint c ) : QListBoxText( text ) { _code = c; } uint code() const { return _code; } protected: uint _code; }; /*! \class QIMPenEdit qimpensetup.h Class to allow users to input totally useless character definitions which could match any number of the default set. */ QIMPenEdit::QIMPenEdit( QIMPenProfile *p, QWidget *parent, const char *name ) : QWidget( parent, name ), profile(p) { currentChar = 0; currentCode = 0; inputChar = new QIMPenChar(); QVBoxLayout *tvb = new QVBoxLayout( this, 5 ); QGridLayout *gl = new QGridLayout( tvb, 4, 2 ); gl->setRowStretch( 1, 1 ); gl->addRowSpacing( 2, 35 ); gl->addRowSpacing( 3, 35 ); charSetCombo = new QComboBox( this ); gl->addMultiCellWidget( charSetCombo, 0, 0, 0, 1 ); connect( charSetCombo, SIGNAL(activated(int)), SLOT(selectCharSet(int))); QIMPenCharSetIterator it( profile->charSets() ); for ( ; it.current(); ++it ) { charSetCombo->insertItem( it.current()->description() ); } charList = new QListBox( this ); charList->setMinimumHeight( charList->sizeHint().height() ); connect( charList, SIGNAL(highlighted(int)), SLOT(selectChar(int)) ); gl->addWidget( charList, 1, 0 ); pw = new QIMPenWidget( this ); pw->setFixedHeight( 75 ); gl->addMultiCellWidget( pw, 2, 3, 0, 0 ); - connect( pw, SIGNAL(stroke(QIMPenStroke *)), - SLOT(newStroke(QIMPenStroke *)) ); + connect( pw, SIGNAL(stroke(QIMPenStroke*)), + SLOT(newStroke(QIMPenStroke*)) ); QVBoxLayout *vb = new QVBoxLayout(); gl->addLayout( vb, 1, 1 ); newBtn = new QPushButton( tr("New..."), this ); connect( newBtn, SIGNAL(clicked()), SLOT(addNewChar()) ); vb->addWidget( newBtn ); addBtn = new QPushButton( tr("Add"), this ); connect( addBtn, SIGNAL(clicked()), SLOT(addChar()) ); vb->addWidget( addBtn ); removeBtn = new QPushButton( tr("Remove"), this ); connect( removeBtn, SIGNAL(clicked()), SLOT(removeChar()) ); vb->addWidget( removeBtn ); QPushButton *pb = new QPushButton( tr("Default"), this ); connect( pb, SIGNAL(clicked()), SLOT(defaultChars()) ); vb->addWidget( pb ); QHBoxLayout *hb = new QHBoxLayout(); gl->addLayout( hb, 2, 1 ); prevBtn = new QPushButton( this ); prevBtn->setPixmap( QPixmap( (const char **)left_xpm ) ); connect( prevBtn, SIGNAL(clicked()), SLOT(prevChar())); hb->addWidget( prevBtn ); nextBtn = new QPushButton( this ); nextBtn->setPixmap( QPixmap( (const char **)right_xpm ) ); connect( nextBtn, SIGNAL(clicked()), SLOT(nextChar())); hb->addWidget( nextBtn ); pb = new QPushButton( tr("Clear"), this ); connect( pb, SIGNAL(clicked()), SLOT(clearChar()) ); gl->addWidget( pb, 3, 1 ); //-- #if !defined(Q_WS_QWS) hb = new QHBoxLayout( tvb ); pb = new QPushButton( tr("OK"), this ); connect( pb, SIGNAL(clicked()), SLOT(accept()) ); hb->addWidget( pb ); pb = new QPushButton( tr("Cancel"), this ); connect( pb, SIGNAL(clicked()), SLOT(reject()) ); hb->addWidget( pb ); #endif selectCharSet( 0 ); charList->setFocus(); resize( minimumSize() ); enableButtons(); } void QIMPenEdit::setProfile( QIMPenProfile *p ) { profile = p; charSetCombo->clear(); QIMPenCharSetIterator it( profile->charSets() ); for ( ; it.current(); ++it ) { if ( ! it.current()->hidden() ) charSetCombo->insertItem( it.current()->description() ); } selectCharSet( 0 ); charList->setFocus(); enableButtons(); } void QIMPenEdit::selectCharSet( QIMPenCharSet *c ) { int i = 0; QIMPenCharSetIterator it( profile->charSets() ); for ( ; it.current(); ++it, i++ ) { if ( it.current() == c ) { charSetCombo->setCurrentItem( i ); selectCharSet( i ); } } } /*! Fill the character list box with the characters. Duplicates are not inserted. */ void QIMPenEdit::fillCharList() { charList->clear(); QIMPenCharIterator it( currentSet->characters() ); CharListItem *li = 0; for ( ; it.current(); ++it ) { uint ch = it.current()->character(); QString n = it.current()->name(); if ( !n.isEmpty() ) li = new CharListItem( n, ch ); if ( li ) { CharListItem *i = (CharListItem *)charList->findItem( li->text() ); if ( !i || i->code() != ch ) { charList->insertItem( li ); } else { delete li; li = 0; } } } currentChar = 0; } void QIMPenEdit::enableButtons() { bool add = !inputChar->isEmpty(); newBtn->setEnabled( add ); addBtn->setEnabled( add ); removeBtn->setEnabled( currentChar ); } /*! Find the previous character with the same code as the current one. returns 0 if there is no previous character. */ QIMPenChar *QIMPenEdit::findPrev() { if ( !currentChar ) return 0; QIMPenCharIterator it( currentSet->characters() ); bool found = FALSE; for ( it.toLast(); it.current(); --it ) { if ( !found && it.current() == currentChar ) found = TRUE; else if ( found && it.current()->character() == currentCode && !it.current()->testFlag( QIMPenChar::Deleted ) ) { return it.current(); } } return 0; } /*! Find the next character with the same code as the current one. returns 0 if there is no next character. */ QIMPenChar *QIMPenEdit::findNext() { if ( !currentChar ) return 0; QIMPenCharIterator it( currentSet->characters() ); bool found = FALSE; for ( ; it.current(); ++it ) { if ( !found && it.current() == currentChar ) found = TRUE; else if ( found && it.current()->character() == currentCode && !it.current()->testFlag( QIMPenChar::Deleted ) ) { return it.current(); } } return 0; } void QIMPenEdit::setCurrentChar( QIMPenChar *pc ) { currentChar = pc; pw->showCharacter( currentChar ); if ( currentChar ) { prevBtn->setEnabled( findPrev() != 0 ); nextBtn->setEnabled( findNext() != 0 ); } } void QIMPenEdit::prevChar() { QIMPenChar *pc = findPrev(); if ( pc ) setCurrentChar( pc ); } void QIMPenEdit::nextChar() { QIMPenChar *pc = findNext(); if ( pc ) setCurrentChar( pc ); } void QIMPenEdit::clearChar() { inputChar->clear(); pw->clear(); enableButtons(); } void QIMPenEdit::selectChar( int i ) { |