• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • util
kcompletion.h
Go to the documentation of this file.
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 <kdeui_export.h>
24#include <kglobalsettings.h>
25#include <ksortablelist.h>
26#include <kshortcut.h>
27
28#include <QtCore/QMap>
29#include <QtCore/QObject>
30#include <QtCore/QString>
31#include <QtCore/QStringList>
32#include <QtCore/QPointer>
33
34class KCompTreeNode;
35class KCompletionPrivate;
36class KCompletionBasePrivate;
37class KCompletionMatchesWrapper;
38class KCompletionMatches;
39
130class KDEUI_EXPORT KCompletion : public QObject
131{
132 Q_ENUMS( CompOrder )
133 Q_PROPERTY( CompOrder order READ order WRITE setOrder )
134 Q_PROPERTY( bool ignoreCase READ ignoreCase WRITE setIgnoreCase )
135 Q_PROPERTY( QStringList items READ items WRITE setItems )
136 Q_OBJECT
137
138public:
143 enum CompOrder { Sorted,
144 Insertion,
145 Weighted
146 };
147
151 KCompletion();
152
156 virtual ~KCompletion();
157
180 virtual QString makeCompletion( const QString& string );
181
190 QStringList substringCompletion( const QString& string ) const;
191
201 QString previousMatch();
202
212 QString nextMatch();
213
220 virtual const QString& lastMatch() const;
221
240 QStringList items() const;
241
245 bool isEmpty() const;
246
256 virtual void setCompletionMode( KGlobalSettings::Completion mode );
257
265 KGlobalSettings::Completion completionMode() const;
266
287 virtual void setOrder( CompOrder order );
288
294 CompOrder order() const;
295
303 virtual void setIgnoreCase( bool ignoreCase );
304
311 bool ignoreCase() const;
312
319 QStringList allMatches();
320
326 QStringList allMatches( const QString& string );
327
340 KCompletionMatches allWeightedMatches();
341
347 KCompletionMatches allWeightedMatches( const QString& string );
348
362 virtual void setSoundsEnabled( bool enable );
363
370 bool soundsEnabled() const;
371
377 bool hasMultipleMatches() const;
378
379public Q_SLOTS:
386 void slotMakeCompletion( const QString& string ) { //inline (redirect)
387 (void) makeCompletion( string );
388 }
389
395 void slotPreviousMatch() { //inline (redirect)
396 (void) previousMatch();
397 }
398
404 void slotNextMatch() { //inline (redirect)
405 (void) nextMatch();
406 }
407
408 // FIXME ###: KDE4: unify the nomenclature. We have insertItems, addItem,
409 // setItems...
415 void insertItems( const QStringList& items );
416
432 virtual void setItems( const QStringList& list);
433
440 void addItem( const QString& item);
441
453 void addItem( const QString& item, uint weight );
454
461 void removeItem( const QString& item);
462
466 virtual void clear();
467
468
469Q_SIGNALS:
476 void match( const QString& item);
477
484 void matches( const QStringList& matchlist);
485
491 void multipleMatches();
492
493protected:
507 virtual void postProcessMatch( QString *pMatch ) const;
508
519 virtual void postProcessMatches( QStringList * pMatches ) const;
520
531 virtual void postProcessMatches( KCompletionMatches * pMatches ) const;
532
533private:
534 void addWeightedItem( const QString& );
535 QString findCompletion( const QString& string );
536 void findAllCompletions( const QString&,
537 KCompletionMatchesWrapper *matches,
538 bool& hasMultipleMatches ) const;
539
540 void extractStringsFromNode( const KCompTreeNode *,
541 const QString& beginning,
542 KCompletionMatchesWrapper *matches,
543 bool addWeight = false ) const;
544 void extractStringsFromNodeCI( const KCompTreeNode *,
545 const QString& beginning,
546 const QString& restString,
547 KCompletionMatchesWrapper *matches) const;
548
549 enum BeepMode { NoMatch, PartialMatch, Rotation };
550 void doBeep( BeepMode ) const;
551
552private:
553 Q_DISABLE_COPY( KCompletion )
554 KCompletionPrivate* const d;
555};
556
557// some more helper stuff
558typedef KSortableList<QString> KCompletionMatchesList;
559class KCompletionMatchesPrivate;
560
579class KDEUI_EXPORT KCompletionMatches : public KCompletionMatchesList
580{
581public:
587 KCompletionMatches( bool sort );
588
592 KCompletionMatches( const KCompletionMatches& );
593
597 KCompletionMatches &operator=( const KCompletionMatches& );
598
602 KCompletionMatches( const KCompletionMatchesWrapper& matches );
603
607 ~KCompletionMatches();
612 void removeDuplicates();
619 QStringList list( bool sort = true ) const;
625 bool sorting() const;
626
627private:
628 KCompletionMatchesPrivate * const d;
629};
630
645class KDEUI_EXPORT KCompletionBase
646{
647public:
653 enum KeyBindingType {
657 TextCompletion,
661 PrevCompletionMatch,
665 NextCompletionMatch,
669 SubstringCompletion
670 };
671
672
673 // Map for the key binding types mentioned above.
674 typedef QMap<KeyBindingType, KShortcut> KeyBindingMap;
675
679 KCompletionBase();
680
684 virtual ~KCompletionBase();
685
701 KCompletion* completionObject( bool hsig = true );
702
719 virtual void setCompletionObject( KCompletion* compObj, bool hsig = true );
720
733 virtual void setHandleSignals( bool handle );
734
745 bool isCompletionObjectAutoDeleted() const;
746
756 void setAutoDeleteCompletionObject( bool autoDelete );
757
778 void setEnableSignals( bool enable );
779
785 bool handleSignals() const;
786
792 bool emitSignals() const;
793
814 virtual void setCompletionMode( KGlobalSettings::Completion mode );
815
824 KGlobalSettings::Completion completionMode() const;
825
856 bool setKeyBinding( KeyBindingType item , const KShortcut& key );
857
870 KShortcut getKeyBinding( KeyBindingType item ) const;
871
883 void useGlobalKeyBindings();
884
899 virtual void setCompletedText( const QString& text ) = 0;
900
908 virtual void setCompletedItems( const QStringList& items, bool autoSuggest =true ) = 0;
909
921 KCompletion* compObj() const;
922
923protected:
932 KeyBindingMap getKeyBindings() const;
933
939 void setDelegate( KCompletionBase *delegate );
940
946 KCompletionBase *delegate() const;
947
948private:
949 // This method simply sets the autodelete boolean for
950 // the completion object, the emit signals and handle
951 // signals internally flags to the provided values.
952 void setup( bool, bool, bool );
953
954 // BCI
955protected:
959 virtual void virtual_hook( int id, void* data );
960private:
961 Q_DISABLE_COPY( KCompletionBase )
962 KCompletionBasePrivate * const d;
963};
964
965#endif // KCOMPLETION_H
KCompletionBase
An abstract base class for adding a completion feature into widgets.
Definition: kcompletion.h:646
KCompletionBase::setCompletedItems
virtual void setCompletedItems(const QStringList &items, bool autoSuggest=true)=0
A pure virtual function that must be implemented by all inheriting classes.
KCompletionBase::setCompletedText
virtual void setCompletedText(const QString &text)=0
A pure virtual function that must be implemented by all inheriting classes.
KCompletionBase::KeyBindingMap
QMap< KeyBindingType, KShortcut > KeyBindingMap
Definition: kcompletion.h:674
KCompletionBase::KeyBindingType
KeyBindingType
Constants that represent the items whose short-cut key-binding is programmable.
Definition: kcompletion.h:653
KCompletionBase::NextCompletionMatch
@ NextCompletionMatch
Switch to next completion (by default Ctrl-Down).
Definition: kcompletion.h:665
KCompletionBase::PrevCompletionMatch
@ PrevCompletionMatch
Switch to previous completion (by default Ctrl-Up).
Definition: kcompletion.h:661
KCompletionBase::TextCompletion
@ TextCompletion
Text completion (by default Ctrl-E).
Definition: kcompletion.h:657
KCompletionMatches
This structure is returned by KCompletion::allWeightedMatches .
Definition: kcompletion.h:580
KCompletion
A generic class for completing QStrings.
Definition: kcompletion.h:131
KCompletion::slotPreviousMatch
void slotPreviousMatch()
Searches the previous matching item and emits it via match().
Definition: kcompletion.h:395
KCompletion::multipleMatches
void multipleMatches()
This signal is emitted, when calling makeCompletion() and more than one matching item is found.
KCompletion::matches
void matches(const QStringList &matchlist)
All matching items.
KCompletion::CompOrder
CompOrder
Constants that represent the order in which KCompletion performs completion-lookups.
Definition: kcompletion.h:143
KCompletion::Insertion
@ Insertion
Use order of insertion.
Definition: kcompletion.h:144
KCompletion::slotMakeCompletion
void slotMakeCompletion(const QString &string)
Attempts to complete "string" and emits the completion via match().
Definition: kcompletion.h:386
KCompletion::match
void match(const QString &item)
The matching item.
KCompletion::slotNextMatch
void slotNextMatch()
Searches the next matching item and emits it via match().
Definition: kcompletion.h:404
KGlobalSettings::Completion
Completion
This enum describes the completion mode used for by the KCompletion class.
Definition: kglobalsettings.h:179
KShortcut
Represents a keyboard shortcut.
Definition: kshortcut.h:58
KSortableList
QMap
QObject
KCompletionMatchesList
KSortableList< QString > KCompletionMatchesList
Definition: kcompletion.h:558
kdeui_export.h
kglobalsettings.h
kshortcut.h
Defines platform-independent classes for keyboard shortcut handling.
ksortablelist.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal