qlineedit.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtWidgets module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QLINEEDIT_H
  40. #define QLINEEDIT_H
  41. #include <QtWidgets/qframe.h>
  42. #include <QtGui/qtextcursor.h>
  43. #include <QtCore/qstring.h>
  44. #include <QtCore/qmargins.h>
  45. QT_BEGIN_NAMESPACE
  46. #ifndef QT_NO_LINEEDIT
  47. class QValidator;
  48. class QMenu;
  49. class QLineEditPrivate;
  50. class QCompleter;
  51. class QStyleOptionFrame;
  52. class QAbstractSpinBox;
  53. class QDateTimeEdit;
  54. class QIcon;
  55. class QToolButton;
  56. class Q_WIDGETS_EXPORT QLineEdit : public QWidget
  57. {
  58. Q_OBJECT
  59. Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask)
  60. Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true)
  61. Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength)
  62. Q_PROPERTY(bool frame READ hasFrame WRITE setFrame)
  63. Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode)
  64. Q_PROPERTY(QString displayText READ displayText)
  65. Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition)
  66. Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
  67. Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
  68. Q_PROPERTY(bool hasSelectedText READ hasSelectedText)
  69. Q_PROPERTY(QString selectedText READ selectedText)
  70. Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled)
  71. Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
  72. Q_PROPERTY(bool undoAvailable READ isUndoAvailable)
  73. Q_PROPERTY(bool redoAvailable READ isRedoAvailable)
  74. Q_PROPERTY(bool acceptableInput READ hasAcceptableInput)
  75. Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText)
  76. Q_PROPERTY(Qt::CursorMoveStyle cursorMoveStyle READ cursorMoveStyle WRITE setCursorMoveStyle)
  77. Q_PROPERTY(bool clearButtonEnabled READ isClearButtonEnabled WRITE setClearButtonEnabled)
  78. public:
  79. enum ActionPosition {
  80. LeadingPosition,
  81. TrailingPosition
  82. };
  83. Q_ENUM(ActionPosition)
  84. explicit QLineEdit(QWidget *parent = Q_NULLPTR);
  85. explicit QLineEdit(const QString &, QWidget *parent = Q_NULLPTR);
  86. ~QLineEdit();
  87. QString text() const;
  88. QString displayText() const;
  89. QString placeholderText() const;
  90. void setPlaceholderText(const QString &);
  91. int maxLength() const;
  92. void setMaxLength(int);
  93. void setFrame(bool);
  94. bool hasFrame() const;
  95. void setClearButtonEnabled(bool enable);
  96. bool isClearButtonEnabled() const;
  97. enum EchoMode { Normal, NoEcho, Password, PasswordEchoOnEdit };
  98. Q_ENUM(EchoMode)
  99. EchoMode echoMode() const;
  100. void setEchoMode(EchoMode);
  101. bool isReadOnly() const;
  102. void setReadOnly(bool);
  103. #ifndef QT_NO_VALIDATOR
  104. void setValidator(const QValidator *);
  105. const QValidator * validator() const;
  106. #endif
  107. #ifndef QT_NO_COMPLETER
  108. void setCompleter(QCompleter *completer);
  109. QCompleter *completer() const;
  110. #endif
  111. QSize sizeHint() const Q_DECL_OVERRIDE;
  112. QSize minimumSizeHint() const Q_DECL_OVERRIDE;
  113. int cursorPosition() const;
  114. void setCursorPosition(int);
  115. int cursorPositionAt(const QPoint &pos);
  116. void setAlignment(Qt::Alignment flag);
  117. Qt::Alignment alignment() const;
  118. void cursorForward(bool mark, int steps = 1);
  119. void cursorBackward(bool mark, int steps = 1);
  120. void cursorWordForward(bool mark);
  121. void cursorWordBackward(bool mark);
  122. void backspace();
  123. void del();
  124. void home(bool mark);
  125. void end(bool mark);
  126. bool isModified() const;
  127. void setModified(bool);
  128. void setSelection(int, int);
  129. bool hasSelectedText() const;
  130. QString selectedText() const;
  131. int selectionStart() const;
  132. bool isUndoAvailable() const;
  133. bool isRedoAvailable() const;
  134. void setDragEnabled(bool b);
  135. bool dragEnabled() const;
  136. void setCursorMoveStyle(Qt::CursorMoveStyle style);
  137. Qt::CursorMoveStyle cursorMoveStyle() const;
  138. QString inputMask() const;
  139. void setInputMask(const QString &inputMask);
  140. bool hasAcceptableInput() const;
  141. void setTextMargins(int left, int top, int right, int bottom);
  142. void setTextMargins(const QMargins &margins);
  143. void getTextMargins(int *left, int *top, int *right, int *bottom) const;
  144. QMargins textMargins() const;
  145. using QWidget::addAction;
  146. void addAction(QAction *action, ActionPosition position);
  147. QAction *addAction(const QIcon &icon, ActionPosition position);
  148. public Q_SLOTS:
  149. void setText(const QString &);
  150. void clear();
  151. void selectAll();
  152. void undo();
  153. void redo();
  154. #ifndef QT_NO_CLIPBOARD
  155. void cut();
  156. void copy() const;
  157. void paste();
  158. #endif
  159. public:
  160. void deselect();
  161. void insert(const QString &);
  162. #ifndef QT_NO_CONTEXTMENU
  163. QMenu *createStandardContextMenu();
  164. #endif
  165. Q_SIGNALS:
  166. void textChanged(const QString &);
  167. void textEdited(const QString &);
  168. void cursorPositionChanged(int, int);
  169. void returnPressed();
  170. void editingFinished();
  171. void selectionChanged();
  172. protected:
  173. void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
  174. void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
  175. void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
  176. void mouseDoubleClickEvent(QMouseEvent *) Q_DECL_OVERRIDE;
  177. void keyPressEvent(QKeyEvent *) Q_DECL_OVERRIDE;
  178. void focusInEvent(QFocusEvent *) Q_DECL_OVERRIDE;
  179. void focusOutEvent(QFocusEvent *) Q_DECL_OVERRIDE;
  180. void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
  181. #ifndef QT_NO_DRAGANDDROP
  182. void dragEnterEvent(QDragEnterEvent *) Q_DECL_OVERRIDE;
  183. void dragMoveEvent(QDragMoveEvent *e) Q_DECL_OVERRIDE;
  184. void dragLeaveEvent(QDragLeaveEvent *e) Q_DECL_OVERRIDE;
  185. void dropEvent(QDropEvent *) Q_DECL_OVERRIDE;
  186. #endif
  187. void changeEvent(QEvent *) Q_DECL_OVERRIDE;
  188. #ifndef QT_NO_CONTEXTMENU
  189. void contextMenuEvent(QContextMenuEvent *) Q_DECL_OVERRIDE;
  190. #endif
  191. void inputMethodEvent(QInputMethodEvent *) Q_DECL_OVERRIDE;
  192. void initStyleOption(QStyleOptionFrame *option) const;
  193. public:
  194. QVariant inputMethodQuery(Qt::InputMethodQuery) const Q_DECL_OVERRIDE;
  195. Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const;
  196. bool event(QEvent *) Q_DECL_OVERRIDE;
  197. protected:
  198. QRect cursorRect() const;
  199. public:
  200. private:
  201. friend class QAbstractSpinBox;
  202. friend class QAccessibleLineEdit;
  203. #ifdef QT_KEYPAD_NAVIGATION
  204. friend class QDateTimeEdit;
  205. #endif
  206. Q_DISABLE_COPY(QLineEdit)
  207. Q_DECLARE_PRIVATE(QLineEdit)
  208. Q_PRIVATE_SLOT(d_func(), void _q_handleWindowActivate())
  209. Q_PRIVATE_SLOT(d_func(), void _q_textEdited(const QString &))
  210. Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged(int, int))
  211. #ifndef QT_NO_COMPLETER
  212. Q_PRIVATE_SLOT(d_func(), void _q_completionHighlighted(const QString &))
  213. #endif
  214. #ifdef QT_KEYPAD_NAVIGATION
  215. Q_PRIVATE_SLOT(d_func(), void _q_editFocusChange(bool))
  216. #endif
  217. Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged())
  218. Q_PRIVATE_SLOT(d_func(), void _q_updateNeeded(const QRect &))
  219. Q_PRIVATE_SLOT(d_func(), void _q_textChanged(const QString &))
  220. Q_PRIVATE_SLOT(d_func(), void _q_clearButtonClicked())
  221. };
  222. #endif // QT_NO_LINEEDIT
  223. QT_END_NAMESPACE
  224. #endif // QLINEEDIT_H