KDEUI
kcompletion.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KCOMPLETION_H
00021 #define KCOMPLETION_H
00022
00023 #include <kdeui_export.h>
00024 #include <kglobalsettings.h>
00025 #include <ksortablelist.h>
00026 #include <kshortcut.h>
00027
00028 #include <QtCore/QMap>
00029 #include <QtCore/QObject>
00030 #include <QtCore/QString>
00031 #include <QtCore/QStringList>
00032 #include <QtCore/QPointer>
00033
00034 class KCompTreeNode;
00035 class KCompletionPrivate;
00036 class KCompletionBasePrivate;
00037 class KCompletionMatchesWrapper;
00038 class KCompletionMatches;
00039
00130 class KDEUI_EXPORT KCompletion : public QObject
00131 {
00132 Q_ENUMS( CompOrder )
00133 Q_PROPERTY( CompOrder order READ order WRITE setOrder )
00134 Q_PROPERTY( bool ignoreCase READ ignoreCase WRITE setIgnoreCase )
00135 Q_PROPERTY( QStringList items READ items WRITE setItems )
00136 Q_OBJECT
00137
00138 public:
00143 enum CompOrder { Sorted,
00144 Insertion,
00145 Weighted
00146 };
00147
00151 KCompletion();
00152
00156 virtual ~KCompletion();
00157
00180 virtual QString makeCompletion( const QString& string );
00181
00190 QStringList substringCompletion( const QString& string ) const;
00191
00201 QString previousMatch();
00202
00212 QString nextMatch();
00213
00220 virtual const QString& lastMatch() const;
00221
00240 QStringList items() const;
00241
00245 bool isEmpty() const;
00246
00256 virtual void setCompletionMode( KGlobalSettings::Completion mode );
00257
00265 KGlobalSettings::Completion completionMode() const;
00266
00287 virtual void setOrder( CompOrder order );
00288
00294 CompOrder order() const;
00295
00303 virtual void setIgnoreCase( bool ignoreCase );
00304
00311 bool ignoreCase() const;
00312
00319 QStringList allMatches();
00320
00326 QStringList allMatches( const QString& string );
00327
00340 KCompletionMatches allWeightedMatches();
00341
00347 KCompletionMatches allWeightedMatches( const QString& string );
00348
00362 virtual void setSoundsEnabled( bool enable );
00363
00370 bool soundsEnabled() const;
00371
00377 bool hasMultipleMatches() const;
00378
00379 public Q_SLOTS:
00386 void slotMakeCompletion( const QString& string ) {
00387 (void) makeCompletion( string );
00388 }
00389
00395 void slotPreviousMatch() {
00396 (void) previousMatch();
00397 }
00398
00404 void slotNextMatch() {
00405 (void) nextMatch();
00406 }
00407
00408
00409
00415 void insertItems( const QStringList& items );
00416
00432 virtual void setItems( const QStringList& list);
00433
00440 void addItem( const QString& item);
00441
00453 void addItem( const QString& item, uint weight );
00454
00461 void removeItem( const QString& item);
00462
00466 virtual void clear();
00467
00468
00469 Q_SIGNALS:
00476 void match( const QString& item);
00477
00484 void matches( const QStringList& matchlist);
00485
00491 void multipleMatches();
00492
00493 protected:
00507 virtual void postProcessMatch( QString *pMatch ) const;
00508
00519 virtual void postProcessMatches( QStringList * pMatches ) const;
00520
00531 virtual void postProcessMatches( KCompletionMatches * pMatches ) const;
00532
00533 private:
00534 void addWeightedItem( const QString& );
00535 QString findCompletion( const QString& string );
00536 void findAllCompletions( const QString&,
00537 KCompletionMatchesWrapper *matches,
00538 bool& hasMultipleMatches ) const;
00539
00540 void extractStringsFromNode( const KCompTreeNode *,
00541 const QString& beginning,
00542 KCompletionMatchesWrapper *matches,
00543 bool addWeight = false ) const;
00544 void extractStringsFromNodeCI( const KCompTreeNode *,
00545 const QString& beginning,
00546 const QString& restString,
00547 KCompletionMatchesWrapper *matches) const;
00548
00549 enum BeepMode { NoMatch, PartialMatch, Rotation };
00550 void doBeep( BeepMode ) const;
00551
00552 private:
00553 Q_DISABLE_COPY( KCompletion )
00554 KCompletionPrivate* const d;
00555 };
00556
00557
00558 typedef KSortableList<QString> KCompletionMatchesList;
00559 class KCompletionMatchesPrivate;
00560
00579 class KDEUI_EXPORT KCompletionMatches : public KCompletionMatchesList
00580 {
00581 public:
00587 KCompletionMatches( bool sort );
00588
00592 KCompletionMatches( const KCompletionMatches& );
00593
00597 KCompletionMatches &operator=( const KCompletionMatches& );
00598
00602 KCompletionMatches( const KCompletionMatchesWrapper& matches );
00603
00607 ~KCompletionMatches();
00612 void removeDuplicates();
00619 QStringList list( bool sort = true ) const;
00625 bool sorting() const;
00626
00627 private:
00628 KCompletionMatchesPrivate * const d;
00629 };
00630
00645 class KDEUI_EXPORT KCompletionBase
00646 {
00647 public:
00653 enum KeyBindingType {
00657 TextCompletion,
00661 PrevCompletionMatch,
00665 NextCompletionMatch,
00669 SubstringCompletion
00670 };
00671
00672
00673
00674 typedef QMap<KeyBindingType, KShortcut> KeyBindingMap;
00675
00679 KCompletionBase();
00680
00684 virtual ~KCompletionBase();
00685
00701 KCompletion* completionObject( bool hsig = true );
00702
00719 virtual void setCompletionObject( KCompletion* compObj, bool hsig = true );
00720
00733 virtual void setHandleSignals( bool handle );
00734
00745 bool isCompletionObjectAutoDeleted() const;
00746
00756 void setAutoDeleteCompletionObject( bool autoDelete );
00757
00778 void setEnableSignals( bool enable );
00779
00785 bool handleSignals() const;
00786
00792 bool emitSignals() const;
00793
00814 virtual void setCompletionMode( KGlobalSettings::Completion mode );
00815
00824 KGlobalSettings::Completion completionMode() const;
00825
00856 bool setKeyBinding( KeyBindingType item , const KShortcut& key );
00857
00870 KShortcut getKeyBinding( KeyBindingType item ) const;
00871
00883 void useGlobalKeyBindings();
00884
00899 virtual void setCompletedText( const QString& text ) = 0;
00900
00908 virtual void setCompletedItems( const QStringList& items, bool autoSuggest =true ) = 0;
00909
00921 KCompletion* compObj() const;
00922
00923 protected:
00932 KeyBindingMap getKeyBindings() const;
00933
00939 void setDelegate( KCompletionBase *delegate );
00940
00946 KCompletionBase *delegate() const;
00947
00948 private:
00949
00950
00951
00952 void setup( bool, bool, bool );
00953
00954
00955 protected:
00959 virtual void virtual_hook( int id, void* data );
00960 private:
00961 Q_DISABLE_COPY( KCompletionBase )
00962 KCompletionBasePrivate * const d;
00963 };
00964
00965 #endif // KCOMPLETION_H