# kdecore Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kcompletion.h

    00001 /* This file is part of the KDE libraries
    00002     Copyright (C) 1999,2000 Carsten Pfeiffer <pfeiffer@kde.org>
    00003
    00004     This library is free software; you can redistribute it and/or
    00005     modify it under the terms of the GNU Library General Public
    00006     License as published by the Free Software Foundation; either
    00007     version 2 of the License, or (at your option) any later version.
    00008
    00009     This library is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012     Library General Public License for more details.
    00013
    00014     You should have received a copy of the GNU Library General Public License
    00015     along with this library; see the file COPYING.LIB.  If not, write to
    00016     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017     Boston, MA 02111-1307, USA.
    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 <kglobalsettings.h>
    00031 #include <ksortablevaluelist.h>
    00032 #include <kshortcut.h>
    00033
    00034 class KCompTreeNode;
    00035 class KCompletionPrivate;
    00036 class KCompletionBasePrivate;
    00037 class KCompletionMatchesWrapper;
    00038 class KCompletionMatches;
    00039 class QPopupMenu;
    00040
    00130 class 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
    00153     // FIXME: copy constructor, assignment constructor...
    00154
    00158     virtual ~KCompletion();
    00159
    00182     virtual QString makeCompletion( const QString& string );
    00183
    00192     QStringList substringCompletion( const QString& string ) const;
    00193
    00203     QString previousMatch();
    00204
    00214     QString nextMatch();
    00215
    00222     virtual const QString& lastMatch() const { return myLastMatch; }
    00223
    00242     QStringList items() const;
    00243
    00253     virtual void setCompletionMode( KGlobalSettings::Completion mode );
    00254
    00262     KGlobalSettings::Completion completionMode() const {
    00263         return myCompletionMode;
    00264     }
    00265
    00286     virtual void setOrder( CompOrder order );
    00287
    00293     CompOrder order() const { return myOrder; }
    00294
    00302     virtual void setIgnoreCase( bool ignoreCase );
    00303
    00310     bool ignoreCase() const { return myIgnoreCase; }
    00311
    00318     QStringList allMatches();
    00319
    00325     QStringList allMatches( const QString& string );
    00326
    00339     KCompletionMatches allWeightedMatches();
    00340
    00346     KCompletionMatches allWeightedMatches( const QString& string );
    00347
    00361     virtual void setEnableSounds( bool enable ) { myBeep = enable; }
    00362
    00370     bool isSoundsEnabled() const { return myBeep; }
    00371
    00377     bool hasMultipleMatches() const { return myHasMultipleMatches; }
    00378
    00379 #ifndef KDE_NO_COMPAT
    00380
    00384     void enableSounds() { myBeep = true; }
    00385
    00390     void disableSounds() { myBeep = false; }
    00391 #endif
    00392
    00393 public slots:
    00400     void slotMakeCompletion( const QString& string ) {
    00401         (void) makeCompletion( string );
    00402     }
    00403
    00409     void slotPreviousMatch() {
    00410         (void) previousMatch();
    00411     }
    00412
    00418     void slotNextMatch() {
    00419         (void) nextMatch();
    00420     }
    00421
    00427     void insertItems( const QStringList& items );
    00428
    00444     virtual void setItems( const QStringList& list);
    00445
    00452     void addItem( const QString& item);
    00453
    00465     void addItem( const QString& item, uint weight );
    00466
    00473     void removeItem( const QString& item);
    00474
    00478     virtual void clear();
    00479
    00480
    00481 signals:
    00488     void match( const QString& item);
    00489
    00496     void matches( const QStringList& matchlist);
    00497
    00503     void multipleMatches();
    00504
    00505 protected:
    00519     virtual void postProcessMatch( QString *match ) const { Q_UNUSED(match) }
    00520
    00531     virtual void postProcessMatches( QStringList * matches ) const { Q_UNUSED(matches)}
    00532
    00543     virtual void postProcessMatches( KCompletionMatches * matches ) const {Q_UNUSED(matches)}
    00544
    00545 private:
    00546     void                addWeightedItem( const QString& );
    00547     QString             findCompletion( const QString& string );
    00548     void                findAllCompletions( const QString&,
    00549                                             KCompletionMatchesWrapper *matches,
    00550                                             bool& hasMultipleMatches ) const;
    00551
    00552     void extractStringsFromNode( const KCompTreeNode *,
    00553                                  const QString& beginning,
    00554                                  KCompletionMatchesWrapper *matches,
    00555                                  bool addWeight = false ) const;
    00556     void extractStringsFromNodeCI( const KCompTreeNode *,
    00557                                    const QString& beginning,
    00558                                    const QString& restString,
    00559                                    KCompletionMatchesWrapper *matches) const;
    00560
    00561     enum                BeepMode { NoMatch, PartialMatch, Rotation };
    00562     void                doBeep( BeepMode ) const;
    00563
    00564     KGlobalSettings::Completion myCompletionMode;
    00565
    00566     CompOrder           myOrder;
    00567     QString             myLastString;
    00568     QString             myLastMatch;
    00569     QString             myCurrentMatch;
    00570     KCompTreeNode *     myTreeRoot;
    00571     QStringList         myRotations;
    00572     bool                myBeep;
    00573     bool                myIgnoreCase;
    00574     bool                myHasMultipleMatches;
    00575     uint                myRotationIndex;
    00576
    00577
    00578 protected:
    00579     virtual void virtual_hook( int id, void* data );
    00580 private:
    00581     KCompletionPrivate *d;
    00582 };
    00583
    00584 // some more helper stuff
    00585 typedef KSortableValueList<QString> KCompletionMatchesList;
    00586 class KCompletionMatchesPrivate;
    00587
    00606 class KCompletionMatches
    00607     : public KCompletionMatchesList
    00608 {
    00609 public:
    00610     KCompletionMatches( bool sort );
    00614     KCompletionMatches( const KCompletionMatchesWrapper& matches );
    00615     ~KCompletionMatches();
    00620     void removeDuplicates();
    00627     QStringList list( bool sort = true ) const;
    00633     bool sorting() const {
    00634         return _sorting;
    00635     }
    00636 private:
    00637     bool _sorting;
    00638     KCompletionMatchesPrivate* d;
    00639 };
    00640
    00655 class KCompletionBase
    00656 {
    00657
    00658 public:
    00659
    00665     enum KeyBindingType {
    00669         TextCompletion,
    00673         PrevCompletionMatch,
    00677         NextCompletionMatch,
    00681         SubstringCompletion
    00682     };
    00683
    00684
    00685     // Map for the key binding types mentioned above.
    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& cut );
    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     // This method simply sets the autodelete boolean for
    00988     // the completion object, the emit signals and handle
    00989     // signals internally flags to the provided values.
    00990     void setup( bool, bool, bool );
    00991
    00992     // Flag that determined whether the completion object
    00993     // should be deleted when this object is destroyed.
    00994     bool m_bAutoDelCompObj;
    00995     // Determines whether this widget handles completion signals
    00996     // internally or not
    00997     bool m_bHandleSignals;
    00998     // Determines whether this widget fires rotation signals
    00999     bool m_bEmitSignals;
    01000     // Stores the completion mode locally.
    01001     KGlobalSettings::Completion m_iCompletionMode;
    01002     // Pointer to Completion object.
    01003     QGuardedPtr<KCompletion> m_pCompObj;
    01004     // Keybindings
    01005     KeyBindingMap m_keyMap;
    01006     // we may act as a proxy to another KCompletionBase object
    01007     KCompletionBase *m_delegate;
    01008
    01009     // BCI
    01010 protected:
    01011     virtual void virtual_hook( int id, void* data );
    01012 private:
    01013     KCompletionBasePrivate *d;
    01014 };
    01015
    01016 #endif // KCOMPLETION_H

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:46:22 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001