KCompletion

klineedit.h
1 /*
2  This file is part of the KDE libraries
3 
4  This class was originally inspired by Torben Weis'
5  fileentry.cpp for KFM II.
6 
7  SPDX-FileCopyrightText: 1997 Sven Radej <[email protected]>
8  SPDX-FileCopyrightText: 1999 Patrick Ward <[email protected]>
9  SPDX-FileCopyrightText: 1999 Preston Brown <[email protected]>
10 
11  Completely re-designed:
12  SPDX-FileCopyrightText: 2000, 2001 Dawit Alemayehu <[email protected]>
13 
14  SPDX-License-Identifier: LGPL-2.0-or-later
15 */
16 
17 #ifndef KLINEEDIT_H
18 #define KLINEEDIT_H
19 
20 #include <kcompletion.h>
21 #include <kcompletionbase.h>
22 #include <kcompletion_export.h>
23 
24 #include <QLineEdit>
25 
26 class QAction;
27 class QMenu;
28 class KCompletionBox;
29 class QUrl;
30 class KLineEditPrivate;
31 
140 class KCOMPLETION_EXPORT KLineEdit : public QLineEdit, public KCompletionBase //krazy:exclude=qclasses
141 {
142  friend class KComboBox;
143  friend class KLineEditStyle;
144 
145  Q_OBJECT
146  Q_DECLARE_PRIVATE(KLineEdit)
147 #if KCOMPLETION_BUILD_DEPRECATED_SINCE(4, 5)
148  Q_PROPERTY(bool contextMenuEnabled READ isContextMenuEnabled WRITE setContextMenuEnabled)
149 #endif
150 #if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 0)
151  Q_PROPERTY(bool urlDropsEnabled READ urlDropsEnabled WRITE setUrlDropsEnabled)
152 #endif
153  Q_PROPERTY(bool trapEnterKeyEvent READ trapReturnKey WRITE setTrapReturnKey)
154  Q_PROPERTY(bool squeezedTextEnabled READ isSqueezedTextEnabled WRITE setSqueezedTextEnabled)
155 #if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 0)
156  Q_PROPERTY(QString clickMessage READ clickMessage WRITE setClickMessage)
157 #endif
158 #if KCOMPLETION_BUILD_DEPRECATED_SINCE(5, 46)
159  Q_PROPERTY(bool showClearButton READ isClearButtonShown WRITE setClearButtonShown)
160 #endif
161  Q_PROPERTY(bool passwordMode READ passwordMode WRITE setPasswordMode)
162 
163 public:
164 
172  explicit KLineEdit(const QString &string, QWidget *parent = nullptr);
173 
178  explicit KLineEdit(QWidget *parent = nullptr);
179 
183  ~KLineEdit() override;
184 
189  void setUrl(const QUrl &url);
190 
200 
207  void setCompletionModeDisabled(KCompletion::CompletionMode mode, bool disable = true);
208 
209 #if KCOMPLETION_BUILD_DEPRECATED_SINCE(4, 5)
210 
224  KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use QWidget::setContextMenuPolicy(Qt::ContextMenuPolicy)")
225  virtual void setContextMenuEnabled(bool showMenu);
226 #endif
227 
228 #if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5)
229 
233  KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use QWidget::contextMenuPolicy()")
234  bool isContextMenuEnabled() const;
235 #endif
236 
245  void setUrlDropsEnabled(bool enable); // KF6: remove it and don't create LineEditUrlDropEventFilter by default.
246 
250  bool urlDropsEnabled() const;
251 
262  void setTrapReturnKey(bool trap);
263 
270  bool trapReturnKey() const;
271 
280  virtual KCompletionBox *completionBox(bool create = true);
281 
285  void setCompletionObject(KCompletion *, bool handle = true) override;
286 
290  virtual void copy() const;
291 
302  void setSqueezedTextEnabled(bool enable);
303 
308  bool isSqueezedTextEnabled() const;
309 
317  QString originalText() const;
318 
325  QString userText() const;
326 
334  void setCompletionBox(KCompletionBox *box);
335 
336 #if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 0)
337 
343  KCOMPLETION_DEPRECATED_VERSION(5, 0, "Use QLineEdit::setPlaceholderText(const QString&)")
344  void setClickMessage(const QString &msg);
345 #endif
346 
347 #if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 0)
348 
352  KCOMPLETION_DEPRECATED_VERSION(5, 0, "Use QLineEdit::placeholderText()")
353  QString clickMessage() const;
354 #endif
355 
356 #if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 46)
357 
364  KCOMPLETION_DEPRECATED_VERSION(5, 46, "Use QLineEdit::setClearButtonEnabled(bool)")
365  void setClearButtonShown(bool show);
366 #endif
367 
368 #if KCOMPLETION_ENABLE_DEPRECATED_SINCE(5, 46)
369 
374  KCOMPLETION_DEPRECATED_VERSION(5, 46, "Use QLineEdit::isClearButtonEnabled()")
375  bool isClearButtonShown() const;
376 #endif
377 
382  QSize clearButtonUsedSize() const;
383 
391  void doCompletion(const QString &text);
392 
393 Q_SIGNALS:
394 
398  void completionBoxActivated(const QString &);
399 
407  void returnPressed(const QString &);
408 
416  void completion(const QString &);
417 
421  void substringCompletion(const QString &);
422 
423 #if KCOMPLETION_ENABLE_DEPRECATED_SINCE(4, 5)
424 
436  KCOMPLETION_DEPRECATED_VERSION(4, 5, "Use QLineEdit::textEdited(const QString&)")
437  QT_MOC_COMPAT void userTextChanged(const QString &);
438 #endif
439 
451  void textRotation(KCompletionBase::KeyBindingType);
452 
457  void completionModeChanged(KCompletion::CompletionMode);
458 
471  void aboutToShowContextMenu(QMenu *contextMenu);
472 
476  void clearButtonClicked();
477 
478 public Q_SLOTS:
479 
484  virtual void setReadOnly(bool);
485 
496  void rotateText(KCompletionBase::KeyBindingType type);
497 
501  void setCompletedText(const QString &) override;
502 
511  void setCompletedItems(const QStringList &items, bool autoSuggest = true) override;
512 
517  void setSqueezedText(const QString &text);
518 
522  virtual void setText(const QString &);
523 
529  void setPasswordMode(bool passwordMode = true);
530 
534  bool passwordMode() const;
535 
536 protected Q_SLOTS:
537 
542  virtual void makeCompletion(const QString &);
543 
549  void userCancelled(const QString &cancelText);
550 
551 protected:
552 
556  bool event(QEvent *) override;
557 
563  void resizeEvent(QResizeEvent *) override;
564 
570  void keyPressEvent(QKeyEvent *) override;
571 
577  void mousePressEvent(QMouseEvent *) override;
578 
584  void mouseReleaseEvent(QMouseEvent *) override;
585 
591  void mouseDoubleClickEvent(QMouseEvent *) override;
592 
598  void contextMenuEvent(QContextMenuEvent *) override;
599 
606 
615  virtual void setCompletedText(const QString & /*text*/, bool /*marked*/);
616 
621  void setUserSelection(bool userSelection);
622 
626  bool autoSuggest() const;
627 
628  void paintEvent(QPaintEvent *ev) override;
629 
630 private:
632 
633  Q_PRIVATE_SLOT(d_func(), void _k_textChanged(const QString &))
634  Q_PRIVATE_SLOT(d_func(), void _k_completionMenuActivated(QAction *))
635  Q_PRIVATE_SLOT(d_func(), void _k_tripleClickTimeout())
636  Q_PRIVATE_SLOT(d_func(), void _k_restoreSelectionColors())
637  Q_PRIVATE_SLOT(d_func(), void _k_completionBoxTextChanged(const QString &))
638 };
639 
640 #endif
virtual void contextMenuEvent(QContextMenuEvent *event) override
void setText(const QString &)
A helper widget for "completion-widgets" (KLineEdit, KComboBox))
virtual bool event(QEvent *e) override
QMenu * createStandardContextMenu()
virtual void setCompletedText(const QString &text)=0
A pure virtual function that must be implemented by all inheriting classes.
virtual void keyPressEvent(QKeyEvent *event) override
void setReadOnly(bool)
CompletionMode
This enum describes the completion mode used for by the KCompletion class.
Definition: kcompletion.h:129
A generic class for completing QStrings.
Definition: kcompletion.h:115
virtual void paintEvent(QPaintEvent *) override
virtual void mouseReleaseEvent(QMouseEvent *e) override
Q_PROPERTY(...)
An abstract base class for adding a completion feature into widgets.
virtual void setCompletionMode(KCompletion::CompletionMode mode)
Sets the type of completion to be used.
void returnPressed()
An enhanced QLineEdit widget for inputting text.
Definition: klineedit.h:140
A combo box with completion support.
Definition: kcombobox.h:133
KeyBindingType
Constants that represent the items whose shortcut key binding is programmable.
virtual void setCompletionObject(KCompletion *completionObject, bool handleSignals=true)
Sets up the completion object to be used.
virtual void resizeEvent(QResizeEvent *event)
void copy() const const
virtual void setCompletedItems(const QStringList &items, bool autoSuggest=true)=0
A pure virtual function that must be implemented by all inheriting classes.
virtual void mouseDoubleClickEvent(QMouseEvent *e) override
virtual void mousePressEvent(QMouseEvent *e) override
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.