KDELibs4Support

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

KDE's Doxygen guidelines are available online.