-rw-r--r-- | inputmethods/handwriting/qimpenchar.cpp | 5 | ||||
-rw-r--r-- | inputmethods/handwriting/qimpenchar.h | 3 | ||||
-rw-r--r-- | inputmethods/handwriting/qimpenprofile.cpp | 25 | ||||
-rw-r--r-- | inputmethods/handwriting/qimpenprofile.h | 2 | ||||
-rw-r--r-- | inputmethods/handwriting/qimpensetup.cpp | 3 |
5 files changed, 35 insertions, 3 deletions
diff --git a/inputmethods/handwriting/qimpenchar.cpp b/inputmethods/handwriting/qimpenchar.cpp index 0c37e5c..929f370 100644 --- a/inputmethods/handwriting/qimpenchar.cpp +++ b/inputmethods/handwriting/qimpenchar.cpp @@ -221,268 +221,271 @@ QDataStream &operator<< (QDataStream &s, const QIMPenChar &ws) ++it; } return s; } /*! Read the character's data from the stream. */ QDataStream &operator>> (QDataStream &s, QIMPenChar &ws) { s >> ws.ch; s >> ws.flags; if ( ws.flags & QIMPenChar::Data ) s >> ws.d; unsigned size; s >> size; for ( unsigned i = 0; i < size; i++ ) { QIMPenStroke *st = new QIMPenStroke(); s >> *st; ws.strokes.append( st ); } return s; } //=========================================================================== bool QIMPenCharMatch::operator>( const QIMPenCharMatch &m ) { return error > m.error; } bool QIMPenCharMatch::operator<( const QIMPenCharMatch &m ) { return error < m.error; } bool QIMPenCharMatch::operator<=( const QIMPenCharMatch &m ) { return error <= m.error; } //=========================================================================== /*! \class QIMPenCharSet qimpenchar.h Maintains a set of related characters. */ QIMPenCharSet::QIMPenCharSet() { chars.setAutoDelete( TRUE ); desc = "Unnamed"; csTitle = "abc"; csType = Unknown; maxStrokes = 0; } /*! Construct and load a characters set from file \a fn. */ QIMPenCharSet::QIMPenCharSet( const QString &fn ) { chars.setAutoDelete( TRUE ); desc = "Unnamed"; csTitle = "abc"; csType = Unknown; maxStrokes = 0; load( fn, System ); } const QString &QIMPenCharSet::filename( Domain d ) const { if ( d == System ) return sysFilename; else return userFilename; } void QIMPenCharSet::setFilename( const QString &fn, Domain d ) { if ( d == System ) sysFilename = fn; else if ( d == User ) userFilename = fn; } /*! Load a character set from file \a fn. */ bool QIMPenCharSet::load( const QString &fn, Domain d ) { setFilename( fn, d ); bool ok = FALSE; QFile file( fn ); if ( file.open( IO_ReadOnly ) ) { QDataStream ds( &file ); QString version; ds >> version; ds >> csTitle; ds >> desc; int major = version.mid( 4, 1 ).toInt(); int minor = version.mid( 6 ).toInt(); if ( major >= 1 && minor > 0 ) { ds >> (Q_INT8 &)csType; } else { if ( csTitle == "abc" ) csType = Lower; else if ( csTitle == "ABC" ) csType = Upper; else if ( csTitle == "123" ) csType = Numeric; else if ( fn == "Combining" ) csType = Combining; } while ( !ds.atEnd() ) { QIMPenChar *pc = new QIMPenChar; ds >> *pc; if ( d == User ) markDeleted( pc->character() ); // override system addChar( pc ); } if ( file.status() == IO_Ok ) ok = TRUE; } - + setHidden ( false ); return ok; } /*! Save this character set. */ bool QIMPenCharSet::save( Domain d ) { if ( filename( d ).isEmpty() ) return FALSE; + if ( hidden() ) + return TRUE; + bool ok = FALSE; QString fn = filename( d ); QString tmpFn = fn + ".new"; QFile file( tmpFn ); if ( file.open( IO_WriteOnly|IO_Raw ) ) { QByteArray buf; QDataStream ds( buf, IO_WriteOnly ); ds << QString( "QPT 1.1" ); ds << csTitle; ds << desc; ds << (Q_INT8)csType; QIMPenCharIterator ci( chars ); for ( ; ci.current(); ++ci ) { QIMPenChar *pc = ci.current(); if ( ( ( (d == System) && pc->testFlag( QIMPenChar::System ) ) || ( (d == User) && !pc->testFlag( QIMPenChar::System ) ) ) && ( !pc->testFlag (QIMPenChar::Combined ) ) ) { ds << *pc; } } file.writeBlock( buf ); file.close(); if ( file.status() == IO_Ok ) ok = TRUE; } if ( ok ) { if ( ::rename( tmpFn.latin1(), fn.latin1() ) < 0 ) { qWarning( "problem renaming file %s to %s, errno: %d", tmpFn.latin1(), fn.latin1(), errno ); // remove the tmp file, otherwise, it will just lay around... QFile::remove( tmpFn.latin1() ); ok = FALSE; } } return ok; } QIMPenChar *QIMPenCharSet::at( int i ) { return chars.at(i); } void QIMPenCharSet::markDeleted( uint ch ) { QIMPenCharIterator ci( chars ); for ( ; ci.current(); ++ci ) { QIMPenChar *pc = ci.current(); if ( pc->character() == ch && pc->testFlag( QIMPenChar::System ) ) pc->setFlag( QIMPenChar::Deleted ); } } /*! Find the best matches for \a ch in this character set. */ QIMPenCharMatchList QIMPenCharSet::match( QIMPenChar *ch ) { QIMPenCharMatchList matches; QIMPenCharIterator ci( chars ); for ( ; ci.current(); ++ci ) { QIMPenChar *tmplChar = ci.current(); if ( tmplChar->testFlag( QIMPenChar::Deleted ) ) { continue; } int err; if ( ch->penStrokes().count() <= tmplChar->penStrokes().count() ) { err = ch->match( tmplChar ); if ( err <= QIMPEN_MATCH_THRESHOLD ) { if (tmplChar->penStrokes().count() != ch->penStrokes().count()) err = QMIN(err*3, QIMPEN_MATCH_THRESHOLD); QIMPenCharMatchList::Iterator it; for ( it = matches.begin(); it != matches.end(); ++it ) { if ( (*it).penChar->character() == tmplChar->character() && (*it).penChar->penStrokes().count() == tmplChar->penStrokes().count() ) { if ( (*it).error > err ) (*it).error = err; break; } } if ( it == matches.end() ) { QIMPenCharMatch m; m.error = err; m.penChar = tmplChar; matches.append( m ); } } } } qHeapSort( matches ); /* QIMPenCharMatchList::Iterator it; for ( it = matches.begin(); it != matches.end(); ++it ) { qDebug( "Match: \'%c\', error %d, strokes %d", (*it).penChar->character(), (*it).error, (*it).penChar->penStrokes().count() ); } */ return matches; } /*! Add a character \a ch to this set. QIMPenCharSet will delete this character when it is no longer needed. */ void QIMPenCharSet::addChar( QIMPenChar *ch ) { if ( ch->penStrokes().count() > maxStrokes ) maxStrokes = ch->penStrokes().count(); chars.append( ch ); } /*! Remove a character by reference \a ch from this set. QIMPenCharSet will delete this character. */ void QIMPenCharSet::removeChar( QIMPenChar *ch ) { chars.remove( ch ); } /*! Move the character up the list of characters. */ void QIMPenCharSet::up( QIMPenChar *ch ) diff --git a/inputmethods/handwriting/qimpenchar.h b/inputmethods/handwriting/qimpenchar.h index efd6f16..e4e7645 100644 --- a/inputmethods/handwriting/qimpenchar.h +++ b/inputmethods/handwriting/qimpenchar.h @@ -1,157 +1,160 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of 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. ** **********************************************************************/ #ifndef QIMPENCHAR_H_ #define QIMPENCHAR_H_ #include <qlist.h> #include <qvaluelist.h> #include <qcstring.h> #include "qimpenstroke.h" struct QIMPenSpecialKeys { int code; char *name; }; extern const QIMPenSpecialKeys qimpen_specialKeys[]; class QIMPenChar { public: QIMPenChar(); QIMPenChar( const QIMPenChar & ); unsigned int character() const { return ch; } void setCharacter( unsigned int c ) { ch = c; } const QString &data() const { return d; } void setData( const QString &ba ) { d = ba; } QString name() const; bool isEmpty() const { return strokes.isEmpty(); } unsigned int strokeCount() const { return strokes.count(); } unsigned int strokeLength( int s ) const; void clear(); int match( QIMPenChar *ch ); const QIMPenStrokeList &penStrokes() { return strokes; } QPoint startingPoint() const { return strokes.getFirst()->startingPoint(); } QRect boundingRect(); void setFlag( int f ) { flags |= f; } void clearFlag( int f ) { flags &= ~f; } bool testFlag( int f ) { return flags & f; } enum Flags { System=0x01, Deleted=0x02, CombineRight=0x04, Data=0x08, Combined=0x10 }; // Correspond to codes in template files. Do not change values. enum Mode { ModeBase=0x4000, Caps=0x4001, Shortcut=0x4002, CapsLock=0x4003, Punctuation=0x4004, Symbol=0x4005, Extended=0x4006 }; QIMPenChar &operator=( const QIMPenChar &s ); void addStroke( QIMPenStroke * ); protected: unsigned int ch; QString d; Q_UINT8 flags; QIMPenStrokeList strokes; friend QDataStream &operator<< (QDataStream &, const QIMPenChar &); friend QDataStream &operator>> (QDataStream &, QIMPenChar &); }; typedef QList<QIMPenChar> QIMPenCharList; typedef QListIterator<QIMPenChar> QIMPenCharIterator; QDataStream & operator<< (QDataStream & s, const QIMPenChar &ws); QDataStream & operator>> (QDataStream & s, QIMPenChar &ws); struct QIMPenCharMatch { int error; QIMPenChar *penChar; bool operator>( const QIMPenCharMatch &m ); bool operator<( const QIMPenCharMatch &m ); bool operator<=( const QIMPenCharMatch &m ); }; typedef QValueList<QIMPenCharMatch> QIMPenCharMatchList; class QIMPenCharSet { public: QIMPenCharSet(); QIMPenCharSet( const QString &fn ); bool isEmpty() const { return chars.isEmpty(); } unsigned int count() const { return chars.count(); } void clear() { chars.clear(); } void setDescription( const QString &d ) { desc = d; } QString description() const { return desc; } void setTitle( const QString &t ) { csTitle = t; } QString title() const { return csTitle; } QIMPenCharMatchList match( QIMPenChar *ch ); void addChar( QIMPenChar *ch ); void removeChar( QIMPenChar *ch ); QIMPenChar *at( int i ); + void setHidden ( const bool &b ) { phidden = &b; } + bool hidden() const { return phidden; } unsigned maximumStrokes() const { return maxStrokes; } void up( QIMPenChar *ch ); void down( QIMPenChar *ch ); enum Domain { System, User }; enum Type { Unknown=0x00, Lower=0x01, Upper=0x02, Combining=0x04, Numeric=0x08, Punctuation=0x10, Symbol=0x20, Shortcut=0x40 }; const QIMPenCharList &characters() const { return chars; } void setType( Type t ) { csType = t; } Type type() const { return csType; } const QString &filename( Domain d ) const; void setFilename( const QString &fn, Domain d=System ); bool load( const QString &fn, Domain d=System ); bool save( Domain d=System ); protected: void markDeleted( uint ch ); protected: QString csTitle; QString desc; QString sysFilename; QString userFilename; Type csType; unsigned maxStrokes; QIMPenCharList chars; QIMPenCharMatchList matches; + bool phidden : 1; }; typedef QList<QIMPenCharSet> QIMPenCharSetList; typedef QListIterator<QIMPenCharSet> QIMPenCharSetIterator; #endif diff --git a/inputmethods/handwriting/qimpenprofile.cpp b/inputmethods/handwriting/qimpenprofile.cpp index 3b1b5e9..b1a6592 100644 --- a/inputmethods/handwriting/qimpenprofile.cpp +++ b/inputmethods/handwriting/qimpenprofile.cpp @@ -1,245 +1,268 @@ /********************************************************************** ** 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 "qimpencombining.h" #include "qimpenprofile.h" #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/global.h> QIMPenProfile::QIMPenProfile( const QString &fn ) : filename( fn ) { sets.setAutoDelete( true ); Config config( filename, Config::File ); config.setGroup( "Handwriting" ); pname = config.readEntry( "Name" ); pdesc = config.readEntry( "Description" ); tstyle = config.readBoolEntry( "CanSelectStyle", false ); wordMatch = config.readBoolEntry( "MatchWords", true ); config.setGroup( "Settings" ); pstyle = BothCases; QString s = config.readEntry( "Style", "BothCases" ); if ( s == "ToggleCases" ) pstyle = ToggleCases; + QString t = config.readEntry( "Mono", "Dual" ); + pmono = (QString::fromLatin1("Mono") == t ); + msTimeout = config.readNumEntry( "MultiTimeout", 500 ); // Read user configuration Config usrConfig( userConfig() ); usrConfig.setGroup( "Settings" ); msTimeout = usrConfig.readNumEntry( "MultiTimeout", msTimeout ); if ( tstyle && usrConfig.hasKey( "Style" ) ) { pstyle = BothCases; QString s = usrConfig.readEntry( "Style", "BothCases" ); if ( s == "ToggleCases" ) pstyle = ToggleCases; } } void QIMPenProfile::setStyle( Style s ) { if ( tstyle && s != pstyle ) { pstyle = s; Config config( userConfig() ); config.setGroup( "Settings" ); QString s = pstyle == ToggleCases ? "ToggleCases" : "BothCases"; config.writeEntry( "Style", s ); } } void QIMPenProfile::setMultiStrokeTimeout( int t ) { if ( t != msTimeout ) { msTimeout = t; Config config( userConfig() ); config.setGroup( "Settings" ); config.writeEntry( "MultiTimeout", msTimeout ); } } QString QIMPenProfile::userConfig() { QString un = filename; int pos = un.findRev( '/' ); if ( pos >= 0 ) un = un.mid( pos + 1 ); pos = un.find( '.' ); if ( pos > 0 ) un.truncate( pos ); un = "handwriting-" + un; // No tr return un; } void QIMPenProfile::loadData() { Config config( filename, Config::File ); config.setGroup( "CharSets" ); QString baseDir = QPEApplication::qpeDir(); baseDir += "/etc/"; // accents QIMPenCombining *combining = 0; QString s = config.readEntry( "Combining" ); if ( !s.isEmpty() ) { combining = new QIMPenCombining( baseDir + "qimpen/" + s ); if ( combining->isEmpty() ) { delete combining; combining = 0; } } // uppercase latin1 QIMPenCharSet *cs = 0; s = config.readEntry( "Uppercase" ); - if ( !s.isEmpty() ) { + if ( !s.isEmpty() && !mono() ) { cs = new QIMPenCharSet( baseDir + "qimpen/" + s ); cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User ); if ( !cs->isEmpty() ) { if ( combining ) combining->addCombined( cs ); sets.append( cs ); } else { delete cs; } } // lowercase latin1 s = config.readEntry( "Lowercase" ); if ( !s.isEmpty() ) { + if ( mono() ) { + cs = new QIMPenCharSet ( baseDir + "qimpen/" + s ); + cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User ); + if ( !cs->isEmpty() ) { + cs->setTitle( cs->title().upper() ); + cs->setType( QIMPenCharSet::Upper ); + cs->setHidden ( true ); + QIMPenCharIterator it( cs->characters() ); + for ( ; it.current(); ++it ) { + uint ch = it.current()->character(); + if ( ch >= 'a' && ch <= 'z' ) + it.current()->setCharacter( QChar(ch).upper() ); + } + if ( combining ) + combining->addCombined( cs ); + sets.append( cs ); + } else { + delete cs; + } + } cs = new QIMPenCharSet( baseDir + "qimpen/" + s ); cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User ); if ( !cs->isEmpty() ) { if ( combining ) combining->addCombined( cs ); sets.append( cs ); } else { delete cs; } } // numeric (may comtain punctuation and symbols) s = config.readEntry( "Numeric" ); if ( !s.isEmpty() ) { cs = new QIMPenCharSet( baseDir + "qimpen/" + s ); cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User ); if ( !cs->isEmpty() ) { sets.append( cs ); } else { delete cs; } } // punctuation s = config.readEntry( "Punctuation" ); if ( !s.isEmpty() ) { cs = new QIMPenCharSet( baseDir + "qimpen/" + s ); cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User ); if ( !cs->isEmpty() ) { sets.append( cs ); } else { delete cs; } } // symbol s = config.readEntry( "Symbol" ); if ( !s.isEmpty() ) { cs = new QIMPenCharSet( baseDir + "qimpen/" + s ); cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User ); if ( !cs->isEmpty() ) { sets.append( cs ); } else { delete cs; } } // shortcut s = config.readEntry( "Shortcut" ); if ( !s.isEmpty() ) { cs = new QIMPenCharSet( baseDir + "qimpen/" + s ); cs->load( Global::applicationFileName("qimpen",s), QIMPenCharSet::User ); if ( !cs->isEmpty() ) { sets.append( cs ); } else { delete cs; } } if ( combining ) delete combining; } QIMPenCharSet *QIMPenProfile::uppercase() { return find( QIMPenCharSet::Upper ); } QIMPenCharSet *QIMPenProfile::lowercase() { return find( QIMPenCharSet::Lower ); } QIMPenCharSet *QIMPenProfile::numeric() { return find( QIMPenCharSet::Numeric ); } QIMPenCharSet *QIMPenProfile::punctuation() { return find( QIMPenCharSet::Punctuation ); } QIMPenCharSet *QIMPenProfile::symbol() { return find( QIMPenCharSet::Symbol ); } QIMPenCharSet *QIMPenProfile::shortcut() { return find( QIMPenCharSet::Shortcut ); } QIMPenCharSetList &QIMPenProfile::charSets() { if ( sets.isEmpty() ) loadData(); return sets; } QIMPenCharSet *QIMPenProfile::find( QIMPenCharSet::Type t ) { if ( sets.isEmpty() ) loadData(); QIMPenCharSetIterator it( sets ); for ( ; it.current(); ++it ) { if ( it.current()->type() == t ) return it.current(); } return 0; } diff --git a/inputmethods/handwriting/qimpenprofile.h b/inputmethods/handwriting/qimpenprofile.h index 4ce4367..adfa866 100644 --- a/inputmethods/handwriting/qimpenprofile.h +++ b/inputmethods/handwriting/qimpenprofile.h @@ -1,70 +1,72 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of 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. ** **********************************************************************/ #ifndef QIMPENPROFILE_H_ #define QIMPENPROFILE_H_ #include "qimpenchar.h" class QIMPenProfile { public: QIMPenProfile( const QString &fn ); const QString &name() const { return pname; } const QString &description() const { return pdesc; } enum Style { ToggleCases, BothCases }; Style style() const { return pstyle; } + bool mono() const { return pmono; } void setStyle( Style s ); bool canSelectStyle() const { return tstyle; } int multiStrokeTimeout() const { return msTimeout; } void setMultiStrokeTimeout( int t ); bool matchWords() const { return wordMatch; } QIMPenCharSet *uppercase(); QIMPenCharSet *lowercase(); QIMPenCharSet *numeric(); QIMPenCharSet *punctuation(); QIMPenCharSet *symbol(); QIMPenCharSet *shortcut(); QIMPenCharSet *find( QIMPenCharSet::Type t ); QIMPenCharSetList &charSets(); private: QString userConfig(); void loadData(); private: QIMPenCharSetList sets; QString filename; QString pname; QString pdesc; Style pstyle; bool tstyle; int msTimeout; bool wordMatch; + bool pmono; }; #endif diff --git a/inputmethods/handwriting/qimpensetup.cpp b/inputmethods/handwriting/qimpensetup.cpp index 2441102..d0f9ffd 100644 --- a/inputmethods/handwriting/qimpensetup.cpp +++ b/inputmethods/handwriting/qimpensetup.cpp @@ -276,257 +276,258 @@ void QIMPenInputCharDlg::addSpecial( QComboBox *cb ) } 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 *)) ); 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 ) { - charSetCombo->insertItem( it.current()->description() ); + 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(); } |