kcompletion.h
/* This file is part of the KDE libraries
Copyright (C) 1999,2000 Carsten Pfeiffer <pfeiffer@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCOMPLETION_H
#define KCOMPLETION_H
#include <qmap.h>
#include <qptrlist.h>
#include <qobject.h>
#include <qstring.h>
#include <qstringlist.h>
#include <qguardedptr.h>
#include "kdelibs_export.h"
#include <kglobalsettings.h>
#include <ksortablevaluelist.h>
#include <kshortcut.h>
class KCompTreeNode;
class KCompletionPrivate;
class KCompletionBasePrivate;
class KCompletionMatchesWrapper;
class KCompletionMatches;
class QPopupMenu;
class KDECORE_EXPORT KCompletion : public QObject
{
Q_ENUMS( CompOrder )
Q_PROPERTY( CompOrder order READ order WRITE setOrder )
Q_PROPERTY( bool ignoreCase READ ignoreCase WRITE setIgnoreCase )
Q_PROPERTY( QStringList items READ items WRITE setItems )
Q_OBJECT
public:
enum CompOrder { Sorted,
Insertion,
Weighted
};
KCompletion();
// FIXME: copy constructor, assignment operator...
virtual ~KCompletion();
virtual QString makeCompletion( const QString& string );
QStringList substringCompletion( const QString& string ) const;
QString previousMatch();
QString nextMatch();
virtual const QString& lastMatch() const { return myLastMatch; }
QStringList items() const;
bool isEmpty() const;
virtual void setCompletionMode( KGlobalSettings::Completion mode );
KGlobalSettings::Completion completionMode() const {
return myCompletionMode;
}
virtual void setOrder( CompOrder order );
CompOrder order() const { return myOrder; }
virtual void setIgnoreCase( bool ignoreCase );
bool ignoreCase() const { return myIgnoreCase; }
QStringList allMatches();
QStringList allMatches( const QString& string );
KCompletionMatches allWeightedMatches();
KCompletionMatches allWeightedMatches( const QString& string );
virtual void setEnableSounds( bool enable ) { myBeep = enable; }
bool isSoundsEnabled() const { return myBeep; }
bool hasMultipleMatches() const { return myHasMultipleMatches; }
#ifndef KDE_NO_COMPAT
void enableSounds() { myBeep = true; }
void disableSounds() { myBeep = false; }
#endif
public slots:
void slotMakeCompletion( const QString& string ) {
(void) makeCompletion( string );
}
void slotPreviousMatch() {
(void) previousMatch();
}
void slotNextMatch() {
(void) nextMatch();
}
// FIXME ###: KDE4: unify the nomenclature. We have insertItems, addItem,
// setItems...
void insertItems( const QStringList& items );
virtual void setItems( const QStringList& list);
void addItem( const QString& item);
void addItem( const QString& item, uint weight );
void removeItem( const QString& item);
virtual void clear();
signals:
void match( const QString& item);
void matches( const QStringList& matchlist);
void multipleMatches();
protected:
virtual void postProcessMatch( QString *match ) const { Q_UNUSED(match) }
virtual void postProcessMatches( QStringList * matches ) const { Q_UNUSED(matches)}
virtual void postProcessMatches( KCompletionMatches * matches ) const {Q_UNUSED(matches)}
private:
void addWeightedItem( const QString& );
QString findCompletion( const QString& string );
void findAllCompletions( const QString&,
KCompletionMatchesWrapper *matches,
bool& hasMultipleMatches ) const;
void extractStringsFromNode( const KCompTreeNode *,
const QString& beginning,
KCompletionMatchesWrapper *matches,
bool addWeight = false ) const;
void extractStringsFromNodeCI( const KCompTreeNode *,
const QString& beginning,
const QString& restString,
KCompletionMatchesWrapper *matches) const;
enum BeepMode { NoMatch, PartialMatch, Rotation };
void doBeep( BeepMode ) const;
KGlobalSettings::Completion myCompletionMode;
CompOrder myOrder;
QString myLastString;
QString myLastMatch;
QString myCurrentMatch;
KCompTreeNode * myTreeRoot;
QStringList myRotations;
bool myBeep;
bool myIgnoreCase;
bool myHasMultipleMatches;
uint myRotationIndex;
protected:
virtual void virtual_hook( int id, void* data );
private:
KCompletionPrivate *d;
};
// some more helper stuff
typedef KSortableValueList<QString> KCompletionMatchesList;
class KCompletionMatchesPrivate;
class KDECORE_EXPORT KCompletionMatches : public KCompletionMatchesList
{
public:
KCompletionMatches( bool sort );
KCompletionMatches( const KCompletionMatchesWrapper& matches );
~KCompletionMatches();
void removeDuplicates();
QStringList list( bool sort = true ) const;
bool sorting() const {
return _sorting;
}
private:
bool _sorting;
KCompletionMatchesPrivate* d;
};
class KDECORE_EXPORT KCompletionBase
{
public:
enum KeyBindingType {
TextCompletion,
PrevCompletionMatch,
NextCompletionMatch,
SubstringCompletion
};
// Map for the key binding types mentioned above.
typedef QMap<KeyBindingType, KShortcut> KeyBindingMap;
KCompletionBase();
virtual ~KCompletionBase();
KCompletion* completionObject( bool hsig = true );
virtual void setCompletionObject( KCompletion* compObj, bool hsig = true );
virtual void setHandleSignals( bool handle );
bool isCompletionObjectAutoDeleted() const {
return m_delegate ? m_delegate->isCompletionObjectAutoDeleted() : m_bAutoDelCompObj;
}
void setAutoDeleteCompletionObject( bool autoDelete ) {
if ( m_delegate )
m_delegate->setAutoDeleteCompletionObject( autoDelete );
else
m_bAutoDelCompObj = autoDelete;
}
void setEnableSignals( bool enable ) {
if ( m_delegate )
m_delegate->setEnableSignals( enable );
else
m_bEmitSignals = enable;
}
bool handleSignals() const { return m_delegate ? m_delegate->handleSignals() : m_bHandleSignals; }
bool emitSignals() const { return m_delegate ? m_delegate->emitSignals() : m_bEmitSignals; }
virtual void setCompletionMode( KGlobalSettings::Completion mode );
KGlobalSettings::Completion completionMode() const {
return m_delegate ? m_delegate->completionMode() : m_iCompletionMode;
}
bool setKeyBinding( KeyBindingType item , const KShortcut& key );
const KShortcut& getKeyBinding( KeyBindingType item ) const {
return m_delegate ? m_delegate->getKeyBinding( item ) : m_keyMap[ item ];
}
void useGlobalKeyBindings();
virtual void setCompletedText( const QString& text ) = 0;
virtual void setCompletedItems( const QStringList& items ) = 0;
KCompletion* compObj() const { return m_delegate ? m_delegate->compObj() : (KCompletion*) m_pCompObj; }
protected:
KeyBindingMap getKeyBindings() const { return m_delegate ? m_delegate->getKeyBindings() : m_keyMap; }
void setDelegate( KCompletionBase *delegate );
KCompletionBase *delegate() const { return m_delegate; }
private:
// This method simply sets the autodelete boolean for
// the completion object, the emit signals and handle
// signals internally flags to the provided values.
void setup( bool, bool, bool );
// Flag that determined whether the completion object
// should be deleted when this object is destroyed.
bool m_bAutoDelCompObj;
// Determines whether this widget handles completion signals
// internally or not
bool m_bHandleSignals;
// Determines whether this widget fires rotation signals
bool m_bEmitSignals;
// Stores the completion mode locally.
KGlobalSettings::Completion m_iCompletionMode;
// Pointer to Completion object.
QGuardedPtr<KCompletion> m_pCompObj;
// Keybindings
KeyBindingMap m_keyMap;
// we may act as a proxy to another KCompletionBase object
KCompletionBase *m_delegate;
// BCI
protected:
virtual void virtual_hook( int id, void* data );
private:
KCompletionBasePrivate *d;
};
#endif // KCOMPLETION_H
KCompletionBase::getKeyBinding
const KShortcut & getKeyBinding(KeyBindingType item) const
Returns the key-binding used for the specified item.
Definition: kcompletion.h:902
KCompletionBase::setEnableSignals
void setEnableSignals(bool enable)
Sets the widget's ability to emit text completion and rotation signals.
Definition: kcompletion.h:803
KCompletion::Sorted
Use alphabetically sorted order.
Definition: kcompletion.h:145
KCompletion::slotMakeCompletion
void slotMakeCompletion(const QString &string)
Attempts to complete "string" and emits the completion via match().
Definition: kcompletion.h:407
KSortableValueList
KSortableValueList is a special QValueList for KSortableItem.
Definition: ksortablevaluelist.h:130
KCompletion::enableSounds
void enableSounds()
Definition: kcompletion.h:391
KCompletionBase::NextCompletionMatch
Switch to next completion (by default Ctrl-Down).
Definition: kcompletion.h:683
KCompletionBase::TextCompletion
Text completion (by default Ctrl-E).
Definition: kcompletion.h:675
KCompletion::CompOrder
CompOrder
Constants that represent the order in which KCompletion performs completion-lookups.
Definition: kcompletion.h:145
KCompletion::slotPreviousMatch
void slotPreviousMatch()
Searches the previous matching item and emits it via match().
Definition: kcompletion.h:416
KShortcut
The KShortcut class is used to represent a keyboard shortcut to an action.
Definition: kshortcut.h:543
KCompletion::disableSounds
void disableSounds()
Definition: kcompletion.h:397
KCompletion::Insertion
Use order of insertion.
Definition: kcompletion.h:146
KCompletionBase::PrevCompletionMatch
Switch to previous completion (by default Ctrl-Up).
Definition: kcompletion.h:679
KCompletion::postProcessMatches
virtual void postProcessMatches(KCompletionMatches *matches) const
This method is called before a list of all available completions is emitted via matches.
Definition: kcompletion.h:552
KCompletionBase::delegate
KCompletionBase * delegate() const
Returns the delegation object.
Definition: kcompletion.h:978
KCompletionMatches::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
KCompletion
A generic class for completing QStrings.
Definition: kcompletion.h:132
KCompletion::postProcessMatches
virtual void postProcessMatches(QStringList *matches) const
This method is called before a list of all available completions is emitted via matches.
Definition: kcompletion.h:540
KCompletionBase::handleSignals
bool handleSignals() const
Returns true if the object handles the signals.
Definition: kcompletion.h:815
KCompletionBase::setAutoDeleteCompletionObject
void setAutoDeleteCompletionObject(bool autoDelete)
Sets the completion object when this widget's destructor is called.
Definition: kcompletion.h:776
KCompletionMatches
This structure is returned by KCompletion::allWeightedMatches .
Definition: kcompletion.h:615
KCompletion::lastMatch
virtual const QString & lastMatch() const
Returns the last match.
Definition: kcompletion.h:224
KCompletionBase::isCompletionObjectAutoDeleted
bool isCompletionObjectAutoDeleted() const
Returns true if the completion object is deleted upon this widget's destruction.
Definition: kcompletion.h:763
KCompletion::completionMode
KGlobalSettings::Completion completionMode() const
Return the current completion mode.
Definition: kcompletion.h:269
KCompTreeNode
A helper class for KCompletion.
Definition: kcompletion_private.h:84
KCompletion::order
CompOrder order() const
Returns the completion order.
Definition: kcompletion.h:300
KCompletionBase
An abstract base class for adding a completion feature into widgets.
Definition: kcompletion.h:663
KCompletion::postProcessMatch
virtual void postProcessMatch(QString *match) const
This method is called after a completion is found and before the matching string is emitted...
Definition: kcompletion.h:528
KCompletion::ignoreCase
bool ignoreCase() const
Return whether KCompletion acts case insensitively or not.
Definition: kcompletion.h:317
KGlobalSettings::Completion
Completion
This enum describes the completion mode used for by the KCompletion class.
Definition: kglobalsettings.h:170
KCompletionBase::emitSignals
bool emitSignals() const
Returns true if the object emits the signals.
Definition: kcompletion.h:822
KCompletionBase::KeyBindingType
KeyBindingType
Constants that represent the items whose short-cut key-binding is programmable.
Definition: kcompletion.h:671
KCompletion::slotNextMatch
void slotNextMatch()
Searches the next matching item and emits it via match().
Definition: kcompletion.h:425
KCompletionBase::getKeyBindings
KeyBindingMap getKeyBindings() const
Returns a key-binding map.
Definition: kcompletion.h:964
KCompletion::hasMultipleMatches
bool hasMultipleMatches() const
Returns true when more than one match is found.
Definition: kcompletion.h:384
KCompletion::isSoundsEnabled
bool isSoundsEnabled() const
Tells you whether KCompletion will play sounds on certain occasions.
Definition: kcompletion.h:377
KCompletionBase::completionMode
KGlobalSettings::Completion completionMode() const
Returns the current completion mode.
Definition: kcompletion.h:854
KCompletionBase::compObj
KCompletion * compObj() const
Returns a pointer to the completion object.
Definition: kcompletion.h:953
KCompletion::setEnableSounds
virtual void setEnableSounds(bool enable)
Enables/disables playing a sound when.
Definition: kcompletion.h:368

KDE Home | KDE Accessibility Home | Description of Access Keys