• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
kcompletion.h
1 /* This file is part of the KDE libraries
2  Copyright (C) 1999,2000 Carsten Pfeiffer <pfeiffer@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef KCOMPLETION_H
21 #define KCOMPLETION_H
22 
23 #include <tqmap.h>
24 #include <tqptrlist.h>
25 #include <tqobject.h>
26 #include <tqstring.h>
27 #include <tqstringlist.h>
28 #include <tqguardedptr.h>
29 
30 #include "tdelibs_export.h"
31 #include <tdeglobalsettings.h>
32 #include <ksortablevaluelist.h>
33 #include <tdeshortcut.h>
34 
35 class TDECompTreeNode;
36 class TDECompletionPrivate;
37 class TDECompletionBasePrivate;
38 class TDECompletionMatchesWrapper;
39 class TDECompletionMatches;
40 class TQPopupMenu;
41 
132 class TDECORE_EXPORT TDECompletion : public TQObject
133 {
134  TQ_ENUMS( CompOrder )
135  TQ_PROPERTY( CompOrder order READ order WRITE setOrder )
136  TQ_PROPERTY( bool ignoreCase READ ignoreCase WRITE setIgnoreCase )
137  TQ_PROPERTY( TQStringList items READ items WRITE setItems )
138  Q_OBJECT
139 
140 public:
145  enum CompOrder { Sorted,
146  Insertion,
147  Weighted
148  };
149 
153  TDECompletion();
154 
155  // FIXME: copy constructor, assignment operator...
156 
160  virtual ~TDECompletion();
161 
184  virtual TQString makeCompletion( const TQString& string );
185 
194  TQStringList substringCompletion( const TQString& string ) const;
195 
205  TQString previousMatch();
206 
216  TQString nextMatch();
217 
224  virtual const TQString& lastMatch() const { return myLastMatch; }
225 
244  TQStringList items() const;
245 
249  bool isEmpty() const;
250 
260  virtual void setCompletionMode( TDEGlobalSettings::Completion mode );
261 
269  TDEGlobalSettings::Completion completionMode() const {
270  return myCompletionMode;
271  }
272 
293  virtual void setOrder( CompOrder order );
294 
300  CompOrder order() const { return myOrder; }
301 
309  virtual void setIgnoreCase( bool ignoreCase );
310 
317  bool ignoreCase() const { return myIgnoreCase; }
318 
325  TQStringList allMatches();
326 
332  TQStringList allMatches( const TQString& string );
333 
346  TDECompletionMatches allWeightedMatches();
347 
353  TDECompletionMatches allWeightedMatches( const TQString& string );
354 
368  virtual void setEnableSounds( bool enable ) { myBeep = enable; }
369 
377  bool isSoundsEnabled() const { return myBeep; }
378 
384  bool hasMultipleMatches() const { return myHasMultipleMatches; }
385 
386 #ifndef KDE_NO_COMPAT
387 
391  void enableSounds() { myBeep = true; }
392 
397  void disableSounds() { myBeep = false; }
398 #endif
399 
400 public slots:
407  void slotMakeCompletion( const TQString& string ) {
408  (void) makeCompletion( string );
409  }
410 
416  void slotPreviousMatch() {
417  (void) previousMatch();
418  }
419 
425  void slotNextMatch() {
426  (void) nextMatch();
427  }
428 
429  // FIXME ###: KDE4: unify the nomenclature. We have insertItems, addItem,
430  // setItems...
436  void insertItems( const TQStringList& items );
437 
453  virtual void setItems( const TQStringList& list);
454 
461  void addItem( const TQString& item);
462 
474  void addItem( const TQString& item, uint weight );
475 
482  void removeItem( const TQString& item);
483 
487  virtual void clear();
488 
489 
490 signals:
497  void match( const TQString& item);
498 
505  void matches( const TQStringList& matchlist);
506 
512  void multipleMatches();
513 
514 protected:
528  virtual void postProcessMatch( TQString *match ) const { Q_UNUSED(match) }
529 
540  virtual void postProcessMatches( TQStringList * matches ) const { Q_UNUSED(matches)}
541 
552  virtual void postProcessMatches( TDECompletionMatches * matches ) const {Q_UNUSED(matches)}
553 
554 private:
555  void addWeightedItem( const TQString& );
556  TQString findCompletion( const TQString& string );
557  void findAllCompletions( const TQString&,
558  TDECompletionMatchesWrapper *matches,
559  bool& hasMultipleMatches ) const;
560 
561  void extractStringsFromNode( const TDECompTreeNode *,
562  const TQString& beginning,
563  TDECompletionMatchesWrapper *matches,
564  bool addWeight = false ) const;
565  void extractStringsFromNodeCI( const TDECompTreeNode *,
566  const TQString& beginning,
567  const TQString& restString,
568  TDECompletionMatchesWrapper *matches) const;
569 
570  enum BeepMode { NoMatch, PartialMatch, Rotation };
571  void doBeep( BeepMode ) const;
572 
573  TDEGlobalSettings::Completion myCompletionMode;
574 
575  CompOrder myOrder;
576  TQString myLastString;
577  TQString myLastMatch;
578  TQString myCurrentMatch;
579  TDECompTreeNode * myTreeRoot;
580  TQStringList myRotations;
581  bool myBeep;
582  bool myIgnoreCase;
583  bool myHasMultipleMatches;
584  uint myRotationIndex;
585 
586 
587 protected:
588  virtual void virtual_hook( int id, void* data );
589 private:
590  TDECompletionPrivate *d;
591 };
592 
593 // some more helper stuff
594 typedef KSortableValueList<TQString> TDECompletionMatchesList;
595 class TDECompletionMatchesPrivate;
596 
615 class TDECORE_EXPORT TDECompletionMatches : public TDECompletionMatchesList
616 {
617 public:
618  TDECompletionMatches( bool sort );
622  TDECompletionMatches( const TDECompletionMatchesWrapper& matches );
623  ~TDECompletionMatches();
628  void removeDuplicates();
635  TQStringList list( bool sort = true ) const;
641  bool sorting() const {
642  return _sorting;
643  }
644 private:
645  bool _sorting;
646  TDECompletionMatchesPrivate* d;
647 };
648 
663 class TDECORE_EXPORT TDECompletionBase
664 {
665 public:
671  enum KeyBindingType {
675  TextCompletion,
679  PrevCompletionMatch,
683  NextCompletionMatch,
687  SubstringCompletion
688  };
689 
690 
691  // Map for the key binding types mentioned above.
692  typedef TQMap<KeyBindingType, TDEShortcut> KeyBindingMap;
693 
697  TDECompletionBase();
698 
702  virtual ~TDECompletionBase();
703 
719  TDECompletion* completionObject( bool hsig = true );
720 
737  virtual void setCompletionObject( TDECompletion* compObj, bool hsig = true );
738 
751  virtual void setHandleSignals( bool handle );
752 
763  bool isCompletionObjectAutoDeleted() const {
764  return m_delegate ? m_delegate->isCompletionObjectAutoDeleted() : m_bAutoDelCompObj;
765  }
766 
776  void setAutoDeleteCompletionObject( bool autoDelete ) {
777  if ( m_delegate )
778  m_delegate->setAutoDeleteCompletionObject( autoDelete );
779  else
780  m_bAutoDelCompObj = autoDelete;
781  }
782 
803  void setEnableSignals( bool enable ) {
804  if ( m_delegate )
805  m_delegate->setEnableSignals( enable );
806  else
807  m_bEmitSignals = enable;
808  }
809 
815  bool handleSignals() const { return m_delegate ? m_delegate->handleSignals() : m_bHandleSignals; }
816 
822  bool emitSignals() const { return m_delegate ? m_delegate->emitSignals() : m_bEmitSignals; }
823 
844  virtual void setCompletionMode( TDEGlobalSettings::Completion mode );
845 
854  TDEGlobalSettings::Completion completionMode() const {
855  return m_delegate ? m_delegate->completionMode() : m_iCompletionMode;
856  }
857 
888  bool setKeyBinding( KeyBindingType item , const TDEShortcut& key );
889 
902  const TDEShortcut& getKeyBinding( KeyBindingType item ) const {
903  return m_delegate ? m_delegate->getKeyBinding( item ) : m_keyMap[ item ];
904  }
905 
917  void useGlobalKeyBindings();
918 
933  virtual void setCompletedText( const TQString& text ) = 0;
934 
940  virtual void setCompletedItems( const TQStringList& items ) = 0;
941 
953  TDECompletion* compObj() const { return m_delegate ? m_delegate->compObj() : (TDECompletion*) m_pCompObj; }
954 
955 protected:
964  KeyBindingMap getKeyBindings() const { return m_delegate ? m_delegate->getKeyBindings() : m_keyMap; }
965 
971  void setDelegate( TDECompletionBase *delegate );
972 
978  TDECompletionBase *delegate() const { return m_delegate; }
979 
980 private:
981  // This method simply sets the autodelete boolean for
982  // the completion object, the emit signals and handle
983  // signals internally flags to the provided values.
984  void setup( bool, bool, bool );
985 
986  // Flag that determined whether the completion object
987  // should be deleted when this object is destroyed.
988  bool m_bAutoDelCompObj;
989  // Determines whether this widget handles completion signals
990  // internally or not
991  bool m_bHandleSignals;
992  // Determines whether this widget fires rotation signals
993  bool m_bEmitSignals;
994  // Stores the completion mode locally.
995  TDEGlobalSettings::Completion m_iCompletionMode;
996  // Pointer to Completion object.
997  TQGuardedPtr<TDECompletion> m_pCompObj;
998  // Keybindings
999  KeyBindingMap m_keyMap;
1000  // we may act as a proxy to another TDECompletionBase object
1001  TDECompletionBase *m_delegate;
1002 
1003  // BCI
1004 protected:
1005  virtual void virtual_hook( int id, void* data );
1006 private:
1007  TDECompletionBasePrivate *d;
1008 };
1009 
1010 #endif // KCOMPLETION_H
TDECompletionBase::handleSignals
bool handleSignals() const
Returns true if the object handles the signals.
Definition: kcompletion.h:815
TDECompletionBase::isCompletionObjectAutoDeleted
bool isCompletionObjectAutoDeleted() const
Returns true if the completion object is deleted upon this widget's destruction.
Definition: kcompletion.h:763
TDECompletion::ignoreCase
bool ignoreCase() const
Return whether TDECompletion acts case insensitively or not.
Definition: kcompletion.h:317
TDECompletion::hasMultipleMatches
bool hasMultipleMatches() const
Returns true when more than one match is found.
Definition: kcompletion.h:384
TDECompletionMatches
This structure is returned by TDECompletion::allWeightedMatches .
Definition: kcompletion.h:615
TDECompletion
A generic class for completing QStrings.
Definition: kcompletion.h:132
KSortableValueList
KSortableValueList is a special TQValueList for KSortableItem.
Definition: ksortablevaluelist.h:130
TDECompletion::isSoundsEnabled
bool isSoundsEnabled() const
Tells you whether TDECompletion will play sounds on certain occasions.
Definition: kcompletion.h:377
TDECompletionBase::completionMode
TDEGlobalSettings::Completion completionMode() const
Returns the current completion mode.
Definition: kcompletion.h:854
TDEGlobalSettings::Completion
Completion
This enum describes the completion mode used for by the TDECompletion class.
Definition: tdeglobalsettings.h:178
TDECompletion::enableSounds
void enableSounds()
Definition: kcompletion.h:391
TDECompletionBase
An abstract base class for adding a completion feature into widgets.
Definition: kcompletion.h:663
TDECompletion::slotPreviousMatch
void slotPreviousMatch()
Searches the previous matching item and emits it via match().
Definition: kcompletion.h:416
TDECompletionBase::getKeyBindings
KeyBindingMap getKeyBindings() const
Returns a key-binding map.
Definition: kcompletion.h:964
TDECompletion::setEnableSounds
virtual void setEnableSounds(bool enable)
Enables/disables playing a sound when.
Definition: kcompletion.h:368
TDECompletionBase::getKeyBinding
const TDEShortcut & getKeyBinding(KeyBindingType item) const
Returns the key-binding used for the specified item.
Definition: kcompletion.h:902
TDECompletion::slotNextMatch
void slotNextMatch()
Searches the next matching item and emits it via match().
Definition: kcompletion.h:425
TDECompletionBase::setAutoDeleteCompletionObject
void setAutoDeleteCompletionObject(bool autoDelete)
Sets the completion object when this widget's destructor is called.
Definition: kcompletion.h:776
TDECompletion::slotMakeCompletion
void slotMakeCompletion(const TQString &string)
Attempts to complete "string" and emits the completion via match().
Definition: kcompletion.h:407
TDECompletionBase::emitSignals
bool emitSignals() const
Returns true if the object emits the signals.
Definition: kcompletion.h:822
TDECompletion::Sorted
Use alphabetically sorted order.
Definition: kcompletion.h:145
TDECompletion::postProcessMatches
virtual void postProcessMatches(TQStringList *matches) const
This method is called before a list of all available completions is emitted via matches.
Definition: kcompletion.h:540
TDECompletion::order
CompOrder order() const
Returns the completion order.
Definition: kcompletion.h:300
TDECompletionBase::setEnableSignals
void setEnableSignals(bool enable)
Sets the widget's ability to emit text completion and rotation signals.
Definition: kcompletion.h:803
TDECompletionBase::delegate
TDECompletionBase * delegate() const
Returns the delegation object.
Definition: kcompletion.h:978
TDECompletion::postProcessMatch
virtual void postProcessMatch(TQString *match) const
This method is called after a completion is found and before the matching string is emitted...
Definition: kcompletion.h:528
TDECompletion::CompOrder
CompOrder
Constants that represent the order in which TDECompletion performs completion-lookups.
Definition: kcompletion.h:145
TDECompletion::disableSounds
void disableSounds()
Definition: kcompletion.h:397
TDECompletionBase::KeyBindingType
KeyBindingType
Constants that represent the items whose short-cut key-binding is programmable.
Definition: kcompletion.h:671
TDEShortcut
The TDEShortcut class is used to represent a keyboard shortcut to an action.
Definition: tdeshortcut.h:543
TDECompletionBase::compObj
TDECompletion * compObj() const
Returns a pointer to the completion object.
Definition: kcompletion.h:953
TDECompletionBase::TextCompletion
Text completion (by default Ctrl-E).
Definition: kcompletion.h:675
TDECompTreeNode
A helper class for TDECompletion.
Definition: kcompletion_private.h:84
TDECompletion::completionMode
TDEGlobalSettings::Completion completionMode() const
Return the current completion mode.
Definition: kcompletion.h:269
TDECompletion::postProcessMatches
virtual void postProcessMatches(TDECompletionMatches *matches) const
This method is called before a list of all available completions is emitted via matches.
Definition: kcompletion.h:552
TDECompletion::Insertion
Use order of insertion.
Definition: kcompletion.h:146
TDECompletionBase::NextCompletionMatch
Switch to next completion (by default Ctrl-Down).
Definition: kcompletion.h:683
TDECompletion::lastMatch
virtual const TQString & lastMatch() const
Returns the last match.
Definition: kcompletion.h:224
TDECompletionMatches::sorting
bool sorting() const
If sorting() returns false, the matches aren't sorted by their weight, even if true is passed to list...
Definition: kcompletion.h:641
TDECompletionBase::PrevCompletionMatch
Switch to previous completion (by default Ctrl-Up).
Definition: kcompletion.h:679

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.8.8
This website is maintained by Timothy Pearson.