2
// Copyright 2007 Jim Bublitz <jbublitz@nwinternet.com>
3
// Earlier copyrights 1998 - 2006 Jim Bublitz also apply
7
// PyKDE4 module kdeui version KDE 3.92.0
10
// This file is part of PyKDE4.
12
// PyKDE4 is free software; you can redistribute it and/or modify
13
// it under the terms of the GNU Lesser General Public License as
14
// published by the Free Software Foundation; either version 2.1 of
15
// the License, or (at your option) any later version.
17
// PyKDE4 is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
// GNU General Public License for more details.
22
// You should have received a copy of the GNU General Public License
23
// along with this program. If not, see <http://www.gnu.org/licenses/>.
27
#include <kcombobox.h>
28
#include <khistorycombobox.h>
29
#include <klineedit.h>
30
#include <klistwidgetsearchline.h>
31
#include <ktreewidgetsearchline.h>
32
#include <krestrictedline.h>
36
class KCompletion : QObject
39
#include <kcompletion.h>
53
virtual QString makeCompletion (const QString&);
54
QStringList substringCompletion (const QString&) const;
55
QString previousMatch ();
57
virtual const QString& lastMatch () const;
58
QStringList items () const;
59
bool isEmpty () const;
60
virtual void setCompletionMode (KGlobalSettings::Completion);
61
KGlobalSettings::Completion completionMode () const;
62
virtual void setOrder (KCompletion::CompOrder);
63
KCompletion::CompOrder order () const;
64
virtual void setIgnoreCase (bool);
65
bool ignoreCase () const;
66
QStringList allMatches ();
67
QStringList allMatches (const QString&);
68
//ig KCompletionMatches allWeightedMatches ();
69
//ig KCompletionMatches allWeightedMatches (const QString&);
70
virtual void setSoundsEnabled (bool);
71
bool soundsEnabled () const;
72
bool hasMultipleMatches () const;
75
void slotMakeCompletion (const QString&);
76
void slotPreviousMatch ();
77
void slotNextMatch ();
78
void insertItems (const QStringList&);
79
virtual void setItems (const QStringList&);
80
void addItem (const QString&);
81
void addItem (const QString&, uint);
82
void removeItem (const QString&);
83
virtual void clear ();
86
void match (const QString&);
87
void matches (const QStringList&);
88
void multipleMatches ();
91
virtual void postProcessMatch (QString*) const;
92
virtual void postProcessMatches (QStringList*) const;
93
//ig virtual void postProcessMatches (KCompletionMatches*) const;
95
}; // class KCompletion
98
//ig class KCompletionMatches : KCompletionMatchesList;
101
class KCompletionBase
104
#include <kcompletion.h>
118
typedef QMap<KCompletionBase::KeyBindingType, KShortcut> KeyBindingMap;
120
KCompletion* completionObject (bool = 1);
121
virtual void setCompletionObject (KCompletion*, bool = 1);
122
virtual void setHandleSignals (bool);
123
bool isCompletionObjectAutoDeleted () const;
124
void setAutoDeleteCompletionObject (bool);
125
void setEnableSignals (bool);
126
bool handleSignals () const;
127
bool emitSignals () const;
128
virtual void setCompletionMode (KGlobalSettings::Completion);
129
KGlobalSettings::Completion completionMode () const;
130
bool setKeyBinding (KCompletionBase::KeyBindingType, const KShortcut&);
131
KShortcut getKeyBinding (KCompletionBase::KeyBindingType) const;
132
void useGlobalKeyBindings ();
133
virtual void setCompletedText (const QString&) = 0;
134
virtual void setCompletedItems (const QStringList&, bool = 1) = 0;
135
KCompletion* compObj () const;
138
KCompletionBase::KeyBindingMap getKeyBindings () const;
139
void setDelegate (KCompletionBase*);
140
KCompletionBase* delegate () const;
143
//igx virtual void virtual_hook (int, void*);
145
// Subclasses for KCompletionBase
148
%ConvertToSubClassCode
150
if (dynamic_cast<KComboBox*>(sipCpp))
152
sipClass = sipClass_KComboBox;
153
if (dynamic_cast<KHistoryComboBox*>(sipCpp))
154
sipClass = sipClass_KHistoryComboBox;
156
else if (dynamic_cast<KLineEdit*>(sipCpp))
158
sipClass = sipClass_KLineEdit;
159
if (dynamic_cast<KListWidgetSearchLine*>(sipCpp))
160
sipClass = sipClass_KListWidgetSearchLine;
161
else if (dynamic_cast<KTreeWidgetSearchLine*>(sipCpp))
162
sipClass = sipClass_KTreeWidgetSearchLine;
163
else if (dynamic_cast<KRestrictedLine*>(sipCpp))
164
sipClass = sipClass_KRestrictedLine;
171
}; // class KCompletionBase
173
//ig typedef KSortableList<QString> KCompletionMatchesList;
176
%MappedType QMap<KCompletionBase::KeyBindingType,KShortcut>
183
// Create the dictionary.
184
PyObject *d = PyDict_New();
189
// Set the dictionary elements.
190
QMap<KCompletionBase::KeyBindingType, KShortcut>::const_iterator i = sipCpp->constBegin();
192
while (i != sipCpp->constEnd())
194
KShortcut *t = new KShortcut(i.value());
196
PyObject *kobj = PyInt_FromLong((int)i.key());
197
PyObject *tobj = sipConvertFromNewInstance(t, sipClass_KShortcut, sipTransferObj);
199
if (kobj == NULL || tobj == NULL || PyDict_SetItem(d, kobj, tobj) < 0)
224
PyObject *kobj, *tobj;
225
#if PY_VERSION_HEX >= 0x02050000
231
// Check the type if that is all that is required.
232
if (sipIsErr == NULL)
234
if (!PyDict_Check(sipPy))
237
while (PyDict_Next(sipPy, &i, &kobj, &tobj))
238
if (!sipCanConvertToInstance(tobj, sipClass_KShortcut, SIP_NOT_NONE))
244
QMap<KCompletionBase::KeyBindingType, KShortcut> *qm = new QMap<KCompletionBase::KeyBindingType, KShortcut>;
246
while (PyDict_Next(sipPy, &i, &kobj, &tobj))
249
int k = PyInt_AsLong(kobj);
250
KShortcut *t = reinterpret_cast<KShortcut *>(sipConvertToInstance(tobj, sipClass_KShortcut, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
254
sipReleaseInstance(t, sipClass_KShortcut, state);
260
qm->insert((KCompletionBase::KeyBindingType)k, *t);
262
sipReleaseInstance(t, sipClass_KShortcut, state);
267
return sipGetState(sipTransferObj);