| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QLINEEDIT_H |
| 5 | #define QLINEEDIT_H |
| 6 | |
| 7 | #include <QtWidgets/qtwidgetsglobal.h> |
| 8 | #include <QtWidgets/qframe.h> |
| 9 | #include <QtGui/qtextcursor.h> |
| 10 | #include <QtCore/qstring.h> |
| 11 | #include <QtCore/qmargins.h> |
| 12 | |
| 13 | QT_REQUIRE_CONFIG(lineedit); |
| 14 | |
| 15 | QT_BEGIN_NAMESPACE |
| 16 | |
| 17 | class QValidator; |
| 18 | class ; |
| 19 | class QLineEditPrivate; |
| 20 | class QCompleter; |
| 21 | class QStyleOptionFrame; |
| 22 | class QAbstractSpinBox; |
| 23 | class QDateTimeEdit; |
| 24 | class QIcon; |
| 25 | class QToolButton; |
| 26 | |
| 27 | class Q_WIDGETS_EXPORT QLineEdit : public QWidget |
| 28 | { |
| 29 | Q_OBJECT |
| 30 | |
| 31 | Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask) |
| 32 | Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true) |
| 33 | Q_PROPERTY(int maxLength READ maxLength WRITE setMaxLength) |
| 34 | Q_PROPERTY(bool frame READ hasFrame WRITE setFrame) |
| 35 | Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode) |
| 36 | Q_PROPERTY(QString displayText READ displayText) |
| 37 | Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition) |
| 38 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) |
| 39 | Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false) |
| 40 | Q_PROPERTY(bool hasSelectedText READ hasSelectedText) |
| 41 | Q_PROPERTY(QString selectedText READ selectedText) |
| 42 | Q_PROPERTY(bool dragEnabled READ dragEnabled WRITE setDragEnabled) |
| 43 | Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) |
| 44 | Q_PROPERTY(bool undoAvailable READ isUndoAvailable) |
| 45 | Q_PROPERTY(bool redoAvailable READ isRedoAvailable) |
| 46 | Q_PROPERTY(bool acceptableInput READ hasAcceptableInput) |
| 47 | Q_PROPERTY(QString placeholderText READ placeholderText WRITE setPlaceholderText) |
| 48 | Q_PROPERTY(Qt::CursorMoveStyle cursorMoveStyle READ cursorMoveStyle WRITE setCursorMoveStyle) |
| 49 | Q_PROPERTY(bool clearButtonEnabled READ isClearButtonEnabled WRITE setClearButtonEnabled) |
| 50 | public: |
| 51 | enum ActionPosition { |
| 52 | LeadingPosition, |
| 53 | TrailingPosition |
| 54 | }; |
| 55 | Q_ENUM(ActionPosition) |
| 56 | |
| 57 | explicit QLineEdit(QWidget *parent = nullptr); |
| 58 | explicit QLineEdit(const QString &, QWidget *parent = nullptr); |
| 59 | ~QLineEdit(); |
| 60 | |
| 61 | QString text() const; |
| 62 | |
| 63 | QString displayText() const; |
| 64 | |
| 65 | QString placeholderText() const; |
| 66 | void setPlaceholderText(const QString &); |
| 67 | |
| 68 | int maxLength() const; |
| 69 | void setMaxLength(int); |
| 70 | |
| 71 | void setFrame(bool); |
| 72 | bool hasFrame() const; |
| 73 | |
| 74 | void setClearButtonEnabled(bool enable); |
| 75 | bool isClearButtonEnabled() const; |
| 76 | |
| 77 | enum EchoMode { Normal, NoEcho, Password, PasswordEchoOnEdit }; |
| 78 | Q_ENUM(EchoMode) |
| 79 | EchoMode echoMode() const; |
| 80 | void setEchoMode(EchoMode); |
| 81 | |
| 82 | bool isReadOnly() const; |
| 83 | void setReadOnly(bool); |
| 84 | |
| 85 | #ifndef QT_NO_VALIDATOR |
| 86 | void setValidator(const QValidator *); |
| 87 | const QValidator * validator() const; |
| 88 | #endif |
| 89 | |
| 90 | #if QT_CONFIG(completer) |
| 91 | void setCompleter(QCompleter *completer); |
| 92 | QCompleter *completer() const; |
| 93 | #endif |
| 94 | |
| 95 | QSize sizeHint() const override; |
| 96 | QSize minimumSizeHint() const override; |
| 97 | |
| 98 | int cursorPosition() const; |
| 99 | void setCursorPosition(int); |
| 100 | int cursorPositionAt(const QPoint &pos); |
| 101 | |
| 102 | void setAlignment(Qt::Alignment flag); |
| 103 | Qt::Alignment alignment() const; |
| 104 | |
| 105 | void cursorForward(bool mark, int steps = 1); |
| 106 | void cursorBackward(bool mark, int steps = 1); |
| 107 | void cursorWordForward(bool mark); |
| 108 | void cursorWordBackward(bool mark); |
| 109 | void backspace(); |
| 110 | void del(); |
| 111 | void home(bool mark); |
| 112 | void end(bool mark); |
| 113 | |
| 114 | bool isModified() const; |
| 115 | void setModified(bool); |
| 116 | |
| 117 | void setSelection(int, int); |
| 118 | bool hasSelectedText() const; |
| 119 | QString selectedText() const; |
| 120 | int selectionStart() const; |
| 121 | int selectionEnd() const; |
| 122 | int selectionLength() const; |
| 123 | |
| 124 | bool isUndoAvailable() const; |
| 125 | bool isRedoAvailable() const; |
| 126 | |
| 127 | void setDragEnabled(bool b); |
| 128 | bool dragEnabled() const; |
| 129 | |
| 130 | void setCursorMoveStyle(Qt::CursorMoveStyle style); |
| 131 | Qt::CursorMoveStyle cursorMoveStyle() const; |
| 132 | |
| 133 | QString inputMask() const; |
| 134 | void setInputMask(const QString &inputMask); |
| 135 | bool hasAcceptableInput() const; |
| 136 | |
| 137 | void setTextMargins(int left, int top, int right, int bottom); |
| 138 | void setTextMargins(const QMargins &margins); |
| 139 | QMargins textMargins() const; |
| 140 | |
| 141 | #if QT_CONFIG(action) |
| 142 | using QWidget::addAction; |
| 143 | void addAction(QAction *action, ActionPosition position); |
| 144 | QAction *addAction(const QIcon &icon, ActionPosition position); |
| 145 | #endif |
| 146 | |
| 147 | public Q_SLOTS: |
| 148 | void setText(const QString &); |
| 149 | void clear(); |
| 150 | void selectAll(); |
| 151 | void undo(); |
| 152 | void redo(); |
| 153 | #ifndef QT_NO_CLIPBOARD |
| 154 | void cut(); |
| 155 | void copy() const; |
| 156 | void paste(); |
| 157 | #endif |
| 158 | |
| 159 | public: |
| 160 | void deselect(); |
| 161 | void insert(const QString &); |
| 162 | #ifndef QT_NO_CONTEXTMENU |
| 163 | QMenu *createStandardContextMenu(); |
| 164 | #endif |
| 165 | |
| 166 | Q_SIGNALS: |
| 167 | void textChanged(const QString &); |
| 168 | void textEdited(const QString &); |
| 169 | void cursorPositionChanged(int, int); |
| 170 | void returnPressed(); |
| 171 | void editingFinished(); |
| 172 | void selectionChanged(); |
| 173 | void inputRejected(); |
| 174 | |
| 175 | protected: |
| 176 | void mousePressEvent(QMouseEvent *) override; |
| 177 | void mouseMoveEvent(QMouseEvent *) override; |
| 178 | void mouseReleaseEvent(QMouseEvent *) override; |
| 179 | void mouseDoubleClickEvent(QMouseEvent *) override; |
| 180 | void keyPressEvent(QKeyEvent *) override; |
| 181 | void keyReleaseEvent(QKeyEvent *) override; |
| 182 | void focusInEvent(QFocusEvent *) override; |
| 183 | void focusOutEvent(QFocusEvent *) override; |
| 184 | void paintEvent(QPaintEvent *) override; |
| 185 | #if QT_CONFIG(draganddrop) |
| 186 | void dragEnterEvent(QDragEnterEvent *) override; |
| 187 | void dragMoveEvent(QDragMoveEvent *e) override; |
| 188 | void dragLeaveEvent(QDragLeaveEvent *e) override; |
| 189 | void dropEvent(QDropEvent *) override; |
| 190 | #endif |
| 191 | void changeEvent(QEvent *) override; |
| 192 | #ifndef QT_NO_CONTEXTMENU |
| 193 | void (QContextMenuEvent *) override; |
| 194 | #endif |
| 195 | |
| 196 | void inputMethodEvent(QInputMethodEvent *) override; |
| 197 | virtual void initStyleOption(QStyleOptionFrame *option) const; |
| 198 | public: |
| 199 | QVariant inputMethodQuery(Qt::InputMethodQuery) const override; |
| 200 | Q_INVOKABLE QVariant inputMethodQuery(Qt::InputMethodQuery property, QVariant argument) const; |
| 201 | void timerEvent(QTimerEvent *) override; |
| 202 | bool event(QEvent *) override; |
| 203 | protected: |
| 204 | QRect cursorRect() const; |
| 205 | |
| 206 | public: |
| 207 | |
| 208 | private: |
| 209 | friend class QAbstractSpinBox; |
| 210 | friend class QAccessibleLineEdit; |
| 211 | friend class QComboBox; |
| 212 | #ifdef QT_KEYPAD_NAVIGATION |
| 213 | friend class QDateTimeEdit; |
| 214 | #endif |
| 215 | Q_DISABLE_COPY(QLineEdit) |
| 216 | Q_DECLARE_PRIVATE(QLineEdit) |
| 217 | }; |
| 218 | |
| 219 | QT_END_NAMESPACE |
| 220 | |
| 221 | #endif // QLINEEDIT_H |
| 222 | |