00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef OCOMPLETION_H
00032 #define OCOMPLETION_H
00033
00034
00035
00036 #include <qmap.h>
00037 #include <qlist.h>
00038 #include <qobject.h>
00039 #include <qstring.h>
00040 #include <qstringlist.h>
00041 #include <qguardedptr.h>
00042
00043
00044
00045 #include <opie2/oglobalsettings.h>
00046 #include <opie2/osortablevaluelist.h>
00047
00048
00049
00050 class OCompTreeNode;
00051 class OCompletionPrivate;
00052 class OCompletionBasePrivate;
00053 class OCompletionMatchesWrapper;
00054 class OCompletionMatches;
00055 class QPopupMenu;
00056
00057
00058 class OShortcut
00059 {
00060 public:
00061 bool isNull() const { return true; };
00062 bool operator == ( const OShortcut& bla ) const { return false; };
00063 };
00064
00065
00155 class OCompletion : public QObject
00156 {
00157 Q_ENUMS( CompOrder )
00158 Q_PROPERTY( CompOrder order READ order WRITE setOrder )
00159 Q_PROPERTY( bool ignoreCase READ ignoreCase WRITE setIgnoreCase )
00160 Q_PROPERTY( QStringList items READ items WRITE setItems )
00161 Q_OBJECT
00162
00163 public:
00168 enum CompOrder { Sorted, Insertion, Weighted };
00169
00173 OCompletion();
00174
00175
00176
00180 virtual ~OCompletion();
00181
00203 virtual QString makeCompletion( const QString& string );
00204
00211 QStringList substringCompletion( const QString& string ) const;
00212
00221 QString previousMatch();
00222
00231 QString nextMatch();
00232
00238 virtual const QString& lastMatch() const { return myLastMatch; }
00239
00258 QStringList items() const;
00259
00268 virtual void setCompletionMode( OGlobalSettings::Completion mode );
00269
00276 OGlobalSettings::Completion completionMode() const { return myCompletionMode; };
00277
00297 virtual void setOrder( CompOrder order );
00298
00303 CompOrder order() const { return myOrder; }
00304
00311 virtual void setIgnoreCase( bool ignoreCase );
00312
00318 bool ignoreCase() const { return myIgnoreCase; };
00319
00326 QStringList allMatches();
00327
00331 QStringList allMatches( const QString& string );
00332
00344 OCompletionMatches allWeightedMatches();
00345
00349 OCompletionMatches allWeightedMatches( const QString& string );
00350
00363 virtual void setEnableSounds( bool enable ) { myBeep = enable; }
00364
00371 bool isSoundsEnabled() const { return myBeep; };
00372
00377 bool hasMultipleMatches() const { return myHasMultipleMatches; };
00378
00379 public slots:
00385 void slotMakeCompletion( const QString& string ) { (void) makeCompletion( string ); };
00386
00392 void slotPreviousMatch() { (void) previousMatch(); };
00393
00399 void slotNextMatch() { (void) nextMatch(); };
00400
00405 void insertItems( const QStringList& items );
00406
00421 virtual void setItems( const QStringList& );
00422
00428 void addItem( const QString& );
00429
00439 void addItem( const QString&, uint weight );
00440
00446 void removeItem( const QString& );
00447
00451 virtual void clear();
00452
00453 signals:
00459 void match( const QString& );
00460
00466 void matches( const QStringList& );
00467
00473 void multipleMatches();
00474
00475 protected:
00488 virtual void postProcessMatch( QString * ) const {}
00489
00499 virtual void postProcessMatches( QStringList * ) const {}
00500
00510 virtual void postProcessMatches( OCompletionMatches * ) const {}
00511
00512 private:
00513 void addWeightedItem( const QString& );
00514 QString findCompletion( const QString& string );
00515 void findAllCompletions( const QString&, OCompletionMatchesWrapper *matches, bool& hasMultipleMatches ) const;
00516
00517 void extractStringsFromNode( const OCompTreeNode *,
00518 const QString& beginning,
00519 OCompletionMatchesWrapper *matches,
00520 bool addWeight = false ) const;
00521 void extractStringsFromNodeCI( const OCompTreeNode *,
00522 const QString& beginning,
00523 const QString& restString,
00524 OCompletionMatchesWrapper *matches) const;
00525
00526 enum BeepMode { NoMatch, PartialMatch, Rotation };
00527 void doBeep( BeepMode ) const;
00528
00529 OGlobalSettings::Completion myCompletionMode;
00530
00531 CompOrder myOrder;
00532 QString myLastString;
00533 QString myLastMatch;
00534 QString myCurrentMatch;
00535 OCompTreeNode * myTreeRoot;
00536 QStringList myRotations;
00537 bool myBeep;
00538 bool myIgnoreCase;
00539 bool myHasMultipleMatches;
00540 uint myRotationIndex;
00541
00542 private:
00543 OCompletionPrivate *d;
00544 };
00545
00546
00547 typedef OSortableValueList<QString> OCompletionMatchesList;
00548 class OCompletionMatchesPrivate;
00549
00569 class OCompletionMatches
00570 : public OCompletionMatchesList
00571 {
00572 public:
00573 OCompletionMatches( bool sort );
00577 OCompletionMatches( const OCompletionMatchesWrapper& matches );
00578 ~OCompletionMatches();
00583 void removeDuplicates();
00589 QStringList list( bool sort = true ) const;
00594 bool sorting() const {
00595 return _sorting;
00596 }
00597 private:
00598 bool _sorting;
00599 OCompletionMatchesPrivate* d;
00600 };
00601
00602 #endif // OCOMPLETION_H