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 <qmap.h>
00024
#include <qptrlist.h>
00025
#include <qobject.h>
00026
#include <qstring.h>
00027
#include <qstringlist.h>
00028
#include <qguardedptr.h>
00029
00030
#include "kdemacros.h"
00031
#include <kglobalsettings.h>
00032
#include <ksortablevaluelist.h>
00033
#include <kshortcut.h>
00034
00035
class KCompTreeNode;
00036
class KCompletionPrivate;
00037
class KCompletionBasePrivate;
00038
class KCompletionMatchesWrapper;
00039
class KCompletionMatches;
00040
class QPopupMenu;
00041
00133 class KCompletion :
public QObject
00134 {
00135 Q_ENUMS(
CompOrder )
00136 Q_PROPERTY(
CompOrder order READ order WRITE
setOrder )
00137 Q_PROPERTY(
bool ignoreCase READ ignoreCase WRITE
setIgnoreCase )
00138 Q_PROPERTY(
QStringList items READ items WRITE
setItems )
00139 Q_OBJECT
00140
00141
public:
00146 enum CompOrder {
Sorted,
00147
Insertion,
00148
Weighted
00149 };
00150
00154
KCompletion();
00155
00156
00157
00161
virtual ~KCompletion();
00162
00185
virtual QString makeCompletion(
const QString& string );
00186
00195
QStringList substringCompletion(
const QString& string )
const;
00196
00206
QString previousMatch();
00207
00217
QString nextMatch();
00218
00225 virtual const QString&
lastMatch()
const {
return myLastMatch; }
00226
00245
QStringList items() const;
00246
00256 virtual
void setCompletionMode(
KGlobalSettings::Completion mode );
00257
00265 KGlobalSettings::Completion completionMode()
const {
00266
return myCompletionMode;
00267 }
00268
00289
virtual void setOrder( CompOrder order );
00290
00296 CompOrder order()
const {
return myOrder; }
00297
00305
virtual void setIgnoreCase(
bool ignoreCase );
00306
00313 bool ignoreCase()
const {
return myIgnoreCase; }
00314
00321
QStringList allMatches();
00322
00328
QStringList allMatches(
const QString& string );
00329
00342
KCompletionMatches allWeightedMatches();
00343
00349
KCompletionMatches allWeightedMatches(
const QString& string );
00350
00364 virtual void setEnableSounds(
bool enable ) { myBeep = enable; }
00365
00373 bool isSoundsEnabled()
const {
return myBeep; }
00374
00380 bool hasMultipleMatches()
const {
return myHasMultipleMatches; }
00381
00382
#ifndef KDE_NO_COMPAT
00383
00387 void enableSounds() { myBeep =
true; }
00388
00393 void disableSounds() { myBeep =
false; }
00394
#endif
00395
00396
public slots:
00403 void slotMakeCompletion(
const QString& string ) {
00404 (
void) makeCompletion( string );
00405 }
00406
00412 void slotPreviousMatch() {
00413 (
void)
previousMatch();
00414 }
00415
00421 void slotNextMatch() {
00422 (
void)
nextMatch();
00423 }
00424
00430
void insertItems(
const QStringList& items );
00431
00447
virtual void setItems(
const QStringList& list);
00448
00455
void addItem(
const QString& item);
00456
00468
void addItem(
const QString& item, uint weight );
00469
00476
void removeItem(
const QString& item);
00477
00481
virtual void clear();
00482
00483
00484 signals:
00491
void match(
const QString& item);
00492
00499
void matches(
const QStringList& matchlist);
00500
00506
void multipleMatches();
00507
00508
protected:
00522 virtual void postProcessMatch(
QString *match )
const { Q_UNUSED(match) }
00523
00534 virtual void postProcessMatches(
QStringList * matches )
const { Q_UNUSED(matches)}
00535
00546 virtual void postProcessMatches(
KCompletionMatches * matches )
const {Q_UNUSED(matches)}
00547
00548
private:
00549
void addWeightedItem(
const QString& );
00550
QString findCompletion(
const QString& string );
00551
void findAllCompletions(
const QString&,
00552 KCompletionMatchesWrapper *matches,
00553
bool& hasMultipleMatches )
const;
00554
00555
void extractStringsFromNode(
const KCompTreeNode *,
00556
const QString& beginning,
00557 KCompletionMatchesWrapper *matches,
00558
bool addWeight =
false )
const;
00559
void extractStringsFromNodeCI(
const KCompTreeNode *,
00560
const QString& beginning,
00561
const QString& restString,
00562 KCompletionMatchesWrapper *matches)
const;
00563
00564
enum BeepMode { NoMatch, PartialMatch, Rotation };
00565
void doBeep( BeepMode ) const;
00566
00567
KGlobalSettings::Completion myCompletionMode;
00568
00569 CompOrder myOrder;
00570
QString myLastString;
00571
QString myLastMatch;
00572
QString myCurrentMatch;
00573
KCompTreeNode * myTreeRoot;
00574
QStringList myRotations;
00575
bool myBeep;
00576
bool myIgnoreCase;
00577
bool myHasMultipleMatches;
00578 uint myRotationIndex;
00579
00580
00581 protected:
00582 virtual
void virtual_hook(
int id,
void* data );
00583 private:
00584 KCompletionPrivate *d;
00585 };
00586
00587
00588 typedef
KSortableValueList<
QString>
KCompletionMatchesList;
00589 class KCompletionMatchesPrivate;
00590
00609 class
KCompletionMatches : public KCompletionMatchesList
00610 {
00611
public:
00612
KCompletionMatches(
bool sort );
00616
KCompletionMatches(
const KCompletionMatchesWrapper& matches );
00617 ~
KCompletionMatches();
00622
void removeDuplicates();
00629
QStringList list(
bool sort =
true )
const;
00635 bool sorting()
const {
00636
return _sorting;
00637 }
00638
private:
00639
bool _sorting;
00640 KCompletionMatchesPrivate* d;
00641 };
00642
00657 class KCompletionBase
00658 {
00659
public:
00665 enum KeyBindingType {
00669 TextCompletion,
00673 PrevCompletionMatch,
00677 NextCompletionMatch,
00681 SubstringCompletion
00682 };
00683
00684
00685
00686
typedef QMap<KeyBindingType, KShortcut> KeyBindingMap;
00687
00691
KCompletionBase();
00692
00696
virtual ~
KCompletionBase();
00697
00719
KCompletion* completionObject(
bool hsig =
true );
00720
00743
virtual void setCompletionObject(
KCompletion* compObj,
bool hsig =
true );
00744
00757
virtual void setHandleSignals(
bool handle );
00758
00769 bool isCompletionObjectAutoDeleted()
const {
00770
return m_delegate ? m_delegate->isCompletionObjectAutoDeleted() : m_bAutoDelCompObj;
00771 }
00772
00782 void setAutoDeleteCompletionObject(
bool autoDelete ) {
00783
if ( m_delegate )
00784 m_delegate->setAutoDeleteCompletionObject( autoDelete );
00785
else
00786 m_bAutoDelCompObj = autoDelete;
00787 }
00788
00809 void setEnableSignals(
bool enable ) {
00810
if ( m_delegate )
00811 m_delegate->setEnableSignals( enable );
00812
else
00813 m_bEmitSignals = enable;
00814 }
00815
00821 bool handleSignals()
const {
return m_delegate ? m_delegate->handleSignals() : m_bHandleSignals; }
00822
00828 bool emitSignals()
const {
return m_delegate ? m_delegate->emitSignals() : m_bEmitSignals; }
00829
00850
virtual void setCompletionMode( KGlobalSettings::Completion mode );
00851
00860 KGlobalSettings::Completion
completionMode()
const {
00861
return m_delegate ? m_delegate->completionMode() : m_iCompletionMode;
00862 }
00863
00894
bool setKeyBinding( KeyBindingType item ,
const KShortcut& key );
00895
00908 const KShortcut& getKeyBinding( KeyBindingType item )
const {
00909
return m_delegate ? m_delegate->getKeyBinding( item ) : m_keyMap[ item ];
00910 }
00911
00923
void useGlobalKeyBindings();
00924
00939
virtual void setCompletedText(
const QString& text ) = 0;
00940
00946
virtual void setCompletedItems(
const QStringList& items ) = 0;
00947
00959 KCompletion* compObj()
const {
return m_delegate ? m_delegate->compObj() : (
KCompletion*) m_pCompObj; }
00960
00961
protected:
00970 KeyBindingMap getKeyBindings()
const {
return m_delegate ? m_delegate->getKeyBindings() : m_keyMap; }
00971
00977
void setDelegate(
KCompletionBase *delegate );
00978
00984 KCompletionBase *delegate()
const {
return m_delegate; }
00985
00986
private:
00987
00988
00989
00990
void setup(
bool,
bool,
bool );
00991
00992
00993
00994
bool m_bAutoDelCompObj;
00995
00996
00997
bool m_bHandleSignals;
00998
00999
bool m_bEmitSignals;
01000
01001 KGlobalSettings::Completion m_iCompletionMode;
01002
01003
QGuardedPtr<KCompletion> m_pCompObj;
01004
01005 KeyBindingMap m_keyMap;
01006
01007
KCompletionBase *m_delegate;
01008
01009
01010
protected:
01011
virtual void virtual_hook(
int id,
void* data );
01012
private:
01013 KCompletionBasePrivate *d;
01014 };
01015
01016
#endif // KCOMPLETION_H