KCompletion

kcombobox.h
1 /*
2  This file is part of the KDE libraries
3 
4  SPDX-FileCopyrightText: 2000, 2001 Dawit Alemayehu <[email protected]>
5  SPDX-FileCopyrightText: 2000, 2001 Carsten Pfeiffer <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.1-or-later
8 */
9 
10 #ifndef KCOMBOBOX_H
11 #define KCOMBOBOX_H
12 
13 #include <kcompletion.h>
14 
15 #include <kcompletionbase.h>
16 #include <kcompletion_export.h>
17 
18 #include <QComboBox>
19 
20 class KCompletionBox;
21 class KComboBoxPrivate;
22 
23 class QLineEdit;
24 class QMenu;
25 
133 class KCOMPLETION_EXPORT KComboBox : public QComboBox, public KCompletionBase //krazy:exclude=qclasses
134 {
135  Q_OBJECT
136  Q_PROPERTY(bool autoCompletion READ autoCompletion WRITE setAutoCompletion)
137 #if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 0)
138  Q_PROPERTY(bool urlDropsEnabled READ urlDropsEnabled WRITE setUrlDropsEnabled)
139 #endif
140  Q_PROPERTY(bool trapReturnKey READ trapReturnKey WRITE setTrapReturnKey)
141  Q_DECLARE_PRIVATE(KComboBox)
142 
143 public:
144 
150  explicit KComboBox(QWidget *parent = nullptr);
151 
158  explicit KComboBox(bool rw, QWidget *parent = nullptr);
159 
163  ~KComboBox() override;
164 
165 #if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5)
166 
170  KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use KComboBox::insertUrl(int, const QUrl&)")
171  void insertURL(const QUrl &url, int index = -1)
172  {
173  insertUrl(index < 0 ? count() : index, url);
174  }
175  KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use KComboBox::insertUrl(int, const QIcon&, const QUrl&)")
176  void insertURL(const QPixmap &pixmap, const QUrl &url, int index = -1)
177  {
178  insertUrl(index < 0 ? count() : index, QIcon(pixmap), url);
179  }
180  KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use KComboBox::changeUrl(int, const QUrl&)")
181  void changeURL(const QUrl &url, int index)
182  {
183  changeUrl(index, url);
184  }
185  KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use KComboBox::changeUrl(int, const QIcon&, const QUrl&)")
186  void changeURL(const QPixmap &pixmap, const QUrl &url, int index)
187  {
188  changeUrl(index, QIcon(pixmap), url);
189  }
190 #endif
191 
198  void setEditUrl(const QUrl &url);
199 
206  void addUrl(const QUrl &url);
207 
214  void addUrl(const QIcon &icon, const QUrl &url);
215 
222  void insertUrl(int index, const QUrl &url);
223 
231  void insertUrl(int index, const QIcon &icon, const QUrl &url);
232 
239  void changeUrl(int index, const QUrl &url);
240 
247  void changeUrl(int index, const QIcon &icon, const QUrl &url);
248 
257  int cursorPosition() const;
258 
269  virtual void setAutoCompletion(bool autocomplete);
270 
280  bool autoCompletion() const;
281 
282 #if KCOMPLETION_BUILD_DEPRECATED_SINCE(4, 5)
283 
297  KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use QWidget::setContextMenuPolicy(...)")
298  virtual void setContextMenuEnabled(bool showMenu);
299 #endif
300 
301 #if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 0)
302 
312  KCOMPLETION_DEPRECATED_VERSION(5, 0, "Use KComboBox::lineEdit()->installEventFilter(...) with a LineEditUrlDropEventFilter")
313  void setUrlDropsEnabled(bool enable);
314 #endif
315 
319  bool urlDropsEnabled() const;
320 
330  bool contains(const QString &text) const;
331 
345  void setTrapReturnKey(bool trap);
346 
353  bool trapReturnKey() const;
354 
365  KCompletionBox *completionBox(bool create = true);
366 
376  virtual void setLineEdit(QLineEdit *);
377 
385  void setEditable(bool editable);
386 
387 Q_SIGNALS:
393  void returnPressed();
394 
404  void returnPressed(const QString &);
405 
414  void completion(const QString &);
415 
419  void substringCompletion(const QString &);
420 
433  void textRotation(KCompletionBase::KeyBindingType);
434 
439  void completionModeChanged(KCompletion::CompletionMode);
440 
450  void aboutToShowContextMenu(QMenu *contextMenu);
451 
452 public Q_SLOTS:
453 
471  void rotateText(KCompletionBase::KeyBindingType type);
472 
479  void setCompletedText(const QString &) override;
480 
485  void setCompletedItems(const QStringList &items, bool autosubject = true) override;
486 
493  void setCurrentItem(const QString &item, bool insert = false, int index = -1);
494 
495 protected Q_SLOTS:
496 
508  virtual void makeCompletion(const QString &);
509 
510 protected:
519  virtual void setCompletedText(const QString &text, bool marked);
520 
521  // TODO KF6: make public like in base classes, so consumers do not need to cast to base classes
522  // when they have a KComboBox (or subclasses) object and want to access this property
523  QSize minimumSizeHint() const override;
524 
525 private:
527  Q_PRIVATE_SLOT(d_func(), void _k_lineEditDeleted())
528 };
529 
530 #endif
531 
void setLineEdit(QLineEdit *edit)
A helper widget for "completion-widgets" (KLineEdit, KComboBox))
virtual void setCompletedText(const QString &text)=0
A pure virtual function that must be implemented by all inheriting classes.
void setEditable(bool editable)
int count() const const
bool autoCompletion() const const
virtual QSize minimumSizeHint() const const override
CompletionMode
This enum describes the completion mode used for by the KCompletion class.
Definition: kcompletion.h:129
void setAutoCompletion(bool enable)
Q_PROPERTY(...)
An abstract base class for adding a completion feature into widgets.
A combo box with completion support.
Definition: kcombobox.h:133
KeyBindingType
Constants that represent the items whose shortcut key binding is programmable.
virtual void setCompletedItems(const QStringList &items, bool autoSuggest=true)=0
A pure virtual function that must be implemented by all inheriting classes.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Aug 10 2020 22:55:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.