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 | |
40 | #ifndef QLINEEDIT_H |
41 | #define QLINEEDIT_H |
42 | |
43 | #include <QtWidgets/qtwidgetsglobal.h> |
44 | #include <QtWidgets/qframe.h> |
45 | #include <QtGui/qtextcursor.h> |
46 | #include <QtCore/qstring.h> |
47 | #include <QtCore/qmargins.h> |
48 | |
49 | QT_REQUIRE_CONFIG(lineedit); |
50 | |
51 | QT_BEGIN_NAMESPACE |
52 | |
53 | class QValidator; |
54 | class ; |
55 | class QLineEditPrivate; |
56 | class QCompleter; |
57 | class QStyleOptionFrame; |
58 | class QAbstractSpinBox; |
59 | class QDateTimeEdit; |
60 | class QIcon; |
61 | class QToolButton; |
62 | |
63 | class Q_WIDGETS_EXPORT QLineEdit : public QWidget |
64 | { |
65 | Q_OBJECT |
66 | |
67 | Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask) |
68 | Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true) |
69 | Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength) |
70 | Q_PROPERTY(bool frame READ hasFrame WRITE setFrame) |
71 | Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode) |
72 | Q_PROPERTY(QString displayText READ displayText) |
73 | Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition) |
74 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) |
75 | Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false) |
76 | Q_PROPERTY(bool hasSelectedText READ hasSelectedText) |
77 | Q_PROPERTY(QString selectedText READ selectedText) |
78 | Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled) |
79 | Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) |
80 | Q_PROPERTY(bool undoAvailable READ isUndoAvailable) |
81 | Q_PROPERTY(bool redoAvailable READ isRedoAvailable) |
82 | Q_PROPERTY(bool acceptableInput READ hasAcceptableInput) |
83 | Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText) |
84 | Q_PROPERTY(Qt::CursorMoveStyle cursorMoveStyle READ cursorMoveStyle WRITE setCursorMoveStyle) |
85 | Q_PROPERTY(bool clearButtonEnabled READ isClearButtonEnabled WRITE setClearButtonEnabled) |
86 | public: |
87 | enum ActionPosition { |
88 | LeadingPosition, |
89 | TrailingPosition |
90 | }; |
91 | Q_ENUM(ActionPosition) |
92 | |
93 | explicit QLineEdit(QWidget *parent = nullptr); |
94 | explicit QLineEdit(const QString &, QWidget *parent = nullptr); |
95 | ~QLineEdit(); |
96 | |
97 | QString text() const; |
98 | |
99 | QString displayText() const; |
100 | |
101 | QString placeholderText() const; |
102 | void setPlaceholderText(const QString &); |
103 | |
104 | int maxLength() const; |
105 | void setMaxLength(int); |
106 | |
107 | void setFrame(bool); |
108 | bool hasFrame() const; |
109 | |
110 | void setClearButtonEnabled(bool enable); |
111 | bool isClearButtonEnabled() const; |
112 | |
113 | enum EchoMode { Normal, NoEcho, Password, PasswordEchoOnEdit }; |
114 | Q_ENUM(EchoMode) |
115 | EchoMode echoMode() const; |
116 | void setEchoMode(EchoMode); |
117 | |
118 | bool isReadOnly() const; |
119 | void setReadOnly(bool); |
120 | |
121 | #ifndef QT_NO_VALIDATOR |
122 | void setValidator(const QValidator *); |
123 | const QValidator * validator() const; |
124 | #endif |
125 | |
126 | #if QT_CONFIG(completer) |
127 | void setCompleter(QCompleter *completer); |
128 | QCompleter *completer() const; |
129 | #endif |
130 | |
131 | QSize sizeHint() const override; |
132 | QSize minimumSizeHint() const override; |
133 | |
134 | int cursorPosition() const; |
135 | void setCursorPosition(int); |
136 | int cursorPositionAt(const QPoint &pos); |
137 | |
138 | void setAlignment(Qt::Alignment flag); |
139 | Qt::Alignment alignment() const; |
140 | |
141 | void cursorForward(bool mark, int steps = 1); |
142 | void cursorBackward(bool mark, int steps = 1); |
143 | void cursorWordForward(bool mark); |
144 | void cursorWordBackward(bool mark); |
145 | void backspace(); |
146 | void del(); |
147 | void home(bool mark); |
148 | void end(bool mark); |
149 | |
150 | bool isModified() const; |
151 | void setModified(bool); |
152 | |
153 | void setSelection(int, int); |
154 | bool hasSelectedText() const; |
155 | QString selectedText() const; |
156 | int selectionStart() const; |
157 | int selectionEnd() const; |
158 | int selectionLength() const; |
159 | |
160 | bool isUndoAvailable() const; |
161 | bool isRedoAvailable() const; |
162 | |
163 | void setDragEnabled(bool b); |
164 | bool dragEnabled() const; |
165 | |
166 | void setCursorMoveStyle(Qt::CursorMoveStyle style); |
167 | Qt::CursorMoveStyle cursorMoveStyle() const; |
168 | |
169 | QString inputMask() const; |
170 | void setInputMask(const QString &inputMask); |
171 | bool hasAcceptableInput() const; |
172 | |
173 | void setTextMargins(int left, int top, int right, int bottom); |
174 | void setTextMargins(const QMargins &margins); |
175 | QMargins textMargins() const; |
176 | |
177 | #if QT_CONFIG(action) |
178 | using QWidget::addAction; |
179 | void addAction(QAction *action, ActionPosition position); |
180 | QAction *addAction(const QIcon &icon, ActionPosition position); |
181 | #endif |
182 | |
183 | public Q_SLOTS: |
184 | void setText(const QString &); |
185 | void clear(); |
186 | void selectAll(); |
187 | void undo(); |
188 | void redo(); |
189 | #ifndef QT_NO_CLIPBOARD |
190 | void cut(); |
191 | void copy() const; |
192 | void paste(); |
193 | #endif |
194 | |
195 | public: |
196 | void deselect(); |
197 | void insert(const QString &); |
198 | #ifndef QT_NO_CONTEXTMENU |
199 | QMenu *createStandardContextMenu(); |
200 | #endif |
201 | |
202 | Q_SIGNALS: |
203 | void textChanged(const QString &); |
204 | void textEdited(const QString &); |
205 | void cursorPositionChanged(int, int); |
206 | void returnPressed(); |
207 | void editingFinished(); |
208 | void selectionChanged(); |
209 | void inputRejected(); |
210 | |
211 | protected: |
212 | void mousePressEvent(QMouseEvent *) override; |
213 | void mouseMoveEvent(QMouseEvent *) override; |
214 | void mouseReleaseEvent(QMouseEvent *) override; |
215 | void mouseDoubleClickEvent(QMouseEvent *) override; |
216 | void keyPressEvent(QKeyEvent *) override; |
217 | void keyReleaseEvent(QKeyEvent *) override; |
218 | void focusInEvent(QFocusEvent *) override; |
219 | void focusOutEvent(QFocusEvent *) override; |
220 | void paintEvent(QPaintEvent *) override; |
221 | #if QT_CONFIG(draganddrop) |
222 | void dragEnterEvent(QDragEnterEvent *) override; |
223 | void dragMoveEvent(QDragMoveEvent *e) override; |
224 | void dragLeaveEvent(QDragLeaveEvent *e) override; |
225 | void dropEvent(QDropEvent *) override; |
226 | #endif |
227 | void changeEvent(QEvent *) override; |
228 | #ifndef QT_NO_CONTEXTMENU |
229 | void (QContextMenuEvent *) override; |
230 | #endif |
231 | |
232 | void inputMethodEvent(QInputMethodEvent *) override; |
233 | virtual void initStyleOption(QStyleOptionFrame *option) const; |
234 | public: |
235 | QVariant inputMethodQuery(Qt::InputMethodQuery) const override; |
236 | Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const; |
237 | void timerEvent(QTimerEvent *) override; |
238 | bool event(QEvent *) override; |
239 | protected: |
240 | QRect cursorRect() const; |
241 | |
242 | public: |
243 | |
244 | private: |
245 | friend class QAbstractSpinBox; |
246 | friend class QAccessibleLineEdit; |
247 | friend class QComboBox; |
248 | #ifdef QT_KEYPAD_NAVIGATION |
249 | friend class QDateTimeEdit; |
250 | #endif |
251 | Q_DISABLE_COPY(QLineEdit) |
252 | Q_DECLARE_PRIVATE(QLineEdit) |
253 | Q_PRIVATE_SLOT(d_func(), void _q_handleWindowActivate()) |
254 | Q_PRIVATE_SLOT(d_func(), void _q_textEdited(const QString &)) |
255 | Q_PRIVATE_SLOT(d_func(), void _q_cursorPositionChanged(int, int)) |
256 | #if QT_CONFIG(completer) |
257 | Q_PRIVATE_SLOT(d_func(), void _q_completionHighlighted(const QString &)) |
258 | #endif |
259 | #ifdef QT_KEYPAD_NAVIGATION |
260 | Q_PRIVATE_SLOT(d_func(), void _q_editFocusChange(bool)) |
261 | #endif |
262 | Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged()) |
263 | Q_PRIVATE_SLOT(d_func(), void _q_updateNeeded(const QRect &)) |
264 | Q_PRIVATE_SLOT(d_func(), void _q_textChanged(const QString &)) |
265 | Q_PRIVATE_SLOT(d_func(), void _q_clearButtonClicked()) |
266 | Q_PRIVATE_SLOT(d_func(), void _q_controlEditingFinished()) |
267 | }; |
268 | |
269 | QT_END_NAMESPACE |
270 | |
271 | #endif // QLINEEDIT_H |
272 | |