1/* This file is part of the KDE libraries
2 Copyright (C) 2000 David Faure <faure@kde.org>, Alexander Neundorf <neundorf@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 KEDITLISTBOX_H
21#define KEDITLISTBOX_H
22
23#include <kdeui_export.h>
24
25#include <QtGui/QGroupBox>
26#include <QtGui/QStringListModel>
27
28class KLineEdit;
29class KComboBox;
30class QListView;
31class QPushButton;
32
33class KEditListBoxPrivate;
34/**
35 * @brief An editable listbox
36 *
37 * @deprecated in favor of KEditListWidget embedded in a QGroupBox.
38 */
39class KDEUI_EXPORT KEditListBox : public QGroupBox
40{
41 Q_OBJECT
42
43 Q_FLAGS( Buttons )
44 Q_PROPERTY( Buttons buttons READ buttons WRITE setButtons )
45 Q_PROPERTY( QStringList items READ items WRITE setItems NOTIFY changed USER true )
46
47public:
48 class CustomEditorPrivate;
49
50 /**
51 * Custom editor class
52 **/
53 class KDEUI_EXPORT CustomEditor
54 {
55 public:
56 CustomEditor();
57 CustomEditor( QWidget *repWidget, KLineEdit *edit );
58 CustomEditor( KComboBox *combo );
59 virtual ~CustomEditor();
60
61 void setRepresentationWidget( QWidget *repWidget );
62 void setLineEdit( KLineEdit *edit );
63
64 virtual QWidget *representationWidget() const;
65 virtual KLineEdit *lineEdit() const;
66
67 private:
68 friend class CustomEditorPrivate;
69 CustomEditorPrivate *const d;
70
71 Q_DISABLE_COPY(CustomEditor)
72 };
73
74 public:
75
76 /**
77 * Enumeration of the buttons, the listbox offers. Specify them in the
78 * constructor in the buttons parameter, or in setButtons.
79 */
80 enum Button {
81 Add = 0x0001,
82 Remove = 0x0002,
83 UpDown = 0x0004,
84 All = Add | Remove | UpDown
85 };
86
87 Q_DECLARE_FLAGS( Buttons, Button )
88
89 /**
90 * Create an editable listbox.
91 */
92 explicit KEditListBox(QWidget *parent = 0);
93
94 /**
95 * Create an editable listbox.
96 *
97 * The same as the other constructor, additionally it takes
98 * @p title, which will be the title of the groupbox around the listbox.
99 */
100 explicit KEditListBox(const QString& title, QWidget *parent = 0);
101
102// ### KDE5: remove name arguments and simplify (merge?!) constructors
103
104 /**
105 * Create an editable listbox.
106 *
107 * \deprecated
108 *
109 * If @p checkAtEntering is true, after every character you type
110 * in the line edit KEditListBox will enable or disable
111 * the Add-button, depending whether the current content of the
112 * line edit is already in the listbox. Maybe this can become a
113 * performance hit with large lists on slow machines.
114 * If @p checkAtEntering is false,
115 * it will be checked if you press the Add-button. It is not
116 * possible to enter items twice into the listbox.
117 */
118 explicit KDE_DEPRECATED KEditListBox(QWidget *parent, const char *name,
119 bool checkAtEntering = false, Buttons buttons = All );
120 /**
121 * Create an editable listbox.
122 *
123 * \deprecated
124 *
125 * The same as the other constructor, additionally it takes
126 * @p title, which will be the title of the frame around the listbox.
127 */
128 explicit KDE_DEPRECATED KEditListBox(const QString& title, QWidget *parent,
129 const char *name, bool checkAtEntering = false,
130 Buttons buttons = All );
131
132 /**
133 * Another constructor, which allows to use a custom editing widget
134 * instead of the standard KLineEdit widget. E.g. you can use a
135 * KUrlRequester or a KComboBox as input widget. The custom
136 * editor must consist of a lineedit and optionally another widget that
137 * is used as representation. A KComboBox or a KUrlRequester have a
138 * KLineEdit as child-widget for example, so the KComboBox is used as
139 * the representation widget.
140 *
141 * @see KUrlRequester::customEditor(), setCustomEditor
142 */
143 KEditListBox( const QString& title,
144 const CustomEditor &customEditor,
145 QWidget *parent = 0, const char *name = 0,
146 bool checkAtEntering = false, Buttons buttons = All );
147
148 virtual ~KEditListBox();
149
150 /**
151 * Return a pointer to the embedded QListView.
152 */
153 QListView* listView() const;
154 /**
155 * Return a pointer to the embedded KLineEdit.
156 */
157 KLineEdit* lineEdit() const;
158 /**
159 * Return a pointer to the Add button
160 */
161 QPushButton* addButton() const;
162 /**
163 * Return a pointer to the Remove button
164 */
165 QPushButton* removeButton() const;
166 /**
167 * Return a pointer to the Up button
168 */
169 QPushButton* upButton() const;
170 /**
171 * Return a pointer to the Down button
172 */
173 QPushButton* downButton() const;
174
175 /**
176 * See Q3ListBox::count()
177 */
178 int count() const;
179 /**
180 * See Q3ListBox::insertStringList()
181 */
182 void insertStringList(const QStringList& list, int index=-1);
183 /**
184 * See Q3ListBox::insertItem()
185 */
186 void insertItem(const QString& text, int index=-1);
187 /**
188 * Clears both the listbox and the line edit.
189 */
190 void clear();
191 /**
192 * See Q3ListBox::text()
193 */
194 QString text(int index) const;
195 /**
196 * See Q3ListBox::currentItem()
197 */
198 int currentItem() const;
199 /**
200 * See Q3ListBox::currentText()
201 */
202 QString currentText() const;
203
204 /**
205 * @returns a stringlist of all items in the listbox
206 */
207 QStringList items() const;
208
209 /**
210 * Clears the listbox and sets the contents to @p items
211 */
212 void setItems(const QStringList& items);
213
214 /**
215 * Returns which buttons are visible
216 */
217 Buttons buttons() const;
218
219 /**
220 * Specifies which buttons should be visible
221 */
222 void setButtons( Buttons buttons );
223
224 /**
225 * If @p check is true, after every character you type
226 * in the line edit KEditListBox will enable or disable
227 * the Add-button, depending whether the current content of the
228 * line edit is already in the listbox. Maybe this can become a
229 * performance hit with large lists on slow machines.
230 * If @p check is false,
231 * it will be checked if you press the Add-button. It is not
232 * possible to enter items twice into the listbox.
233 * Default is false.
234 */
235 void setCheckAtEntering(bool check);
236
237 /**
238 * Returns true if check at entering is enabled.
239 */
240 bool checkAtEntering();
241
242 /**
243 * Allows to use a custom editing widget
244 * instead of the standard KLineEdit widget. E.g. you can use a
245 * KUrlRequester or a KComboBox as input widget. The custom
246 * editor must consist of a lineedit and optionally another widget that
247 * is used as representation. A KComboBox or a KUrlRequester have a
248 * KLineEdit as child-widget for example, so the KComboBox is used as
249 * the representation widget.
250 *
251 * @since 4.1
252 */
253 void setCustomEditor( const CustomEditor& editor );
254
255 /**
256 * Reimplented for interal reasons. The API is not affected.
257 */
258 bool eventFilter( QObject* o, QEvent* e );
259
260 Q_SIGNALS:
261 void changed();
262
263 /**
264 * This signal is emitted when the user adds a new string to the list,
265 * the parameter is the added string.
266 */
267 void added( const QString & text );
268
269 /**
270 * This signal is emitted when the user removes a string from the list,
271 * the parameter is the removed string.
272 */
273 void removed( const QString & text );
274
275 protected Q_SLOTS: // KDE5: make private?
276 void moveItemUp();
277 void moveItemDown();
278 void addItem();
279 void removeItem();
280 void enableMoveButtons(const QModelIndex&, const QModelIndex&);
281 void typedSomething(const QString& text);
282
283 private Q_SLOTS:
284 void slotSelectionChanged( const QItemSelection& selected, const QItemSelection& deselected );
285
286 private:
287 friend class KEditListBoxPrivate;
288 KEditListBoxPrivate* const d;
289
290 Q_DISABLE_COPY(KEditListBox)
291};
292
293Q_DECLARE_OPERATORS_FOR_FLAGS(KEditListBox::Buttons)
294
295#endif
296