kdecore Library API Documentation

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 "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 // FIXME: copy constructor, assignment operator... 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 // some more helper stuff 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 // 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& 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 // 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
KDE Logo
This file is part of the documentation for kdecore Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 20 09:48:25 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003