Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qlineedit_p.h
Go to the documentation of this file.
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_P_H
5#define QLINEEDIT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtWidgets/private/qtwidgetsglobal_p.h>
19
20#include "private/qwidget_p.h"
21#include "QtWidgets/qlineedit.h"
22#if QT_CONFIG(toolbutton)
23#include "QtWidgets/qtoolbutton.h"
24#endif
25#include "QtGui/qtextlayout.h"
26#include "QtGui/qicon.h"
27#include "QtWidgets/qstyleoption.h"
28#include "QtCore/qbasictimer.h"
29#if QT_CONFIG(completer)
30#include "QtWidgets/qcompleter.h"
31#endif
32#include "QtCore/qpointer.h"
33#include "QtCore/qmimedata.h"
34#include <QtCore/qmargins.h>
35
36#include "private/qwidgetlinecontrol_p.h"
37
38#include <algorithm>
39
41
43
45
46// QLineEditIconButton: This is a simple helper class that represents clickable icons that fade in with text
47#if QT_CONFIG(toolbutton)
48class Q_AUTOTEST_EXPORT QLineEditIconButton : public QToolButton
49{
51 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
52public:
53 explicit QLineEditIconButton(QWidget *parent = nullptr);
54
55 qreal opacity() const { return m_opacity; }
56 void setOpacity(qreal value);
57#if QT_CONFIG(animation)
58 void animateShow(bool visible);
59
60 bool shouldHideWithText() const;
61 void setHideWithText(bool hide);
62 bool needsSpace() const {
63 if (m_fadingOut)
64 return false;
65 return isVisibleTo(parentWidget());
66 }
67#endif
68
69protected:
70 void actionEvent(QActionEvent *e) override;
71 void paintEvent(QPaintEvent *event) override;
72
73private slots:
74 void updateCursor();
75
76#if QT_CONFIG(animation)
77 void onAnimationFinished();
78#endif
79
80private:
81#if QT_CONFIG(animation)
82 void startOpacityAnimation(qreal endValue);
83#endif
84 QLineEditPrivate *lineEditPrivate() const;
85
86 qreal m_opacity;
87
88#if QT_CONFIG(animation)
89 bool m_hideWithText = false;
90 bool m_fadingOut = false;
91#endif
92
93};
94#endif // QT_CONFIG(toolbutton)
95
97{
98 Q_DECLARE_PUBLIC(QLineEdit)
99public:
101 SideWidgetFadeInWithText = 0x1,
102 SideWidgetCreatedByWidgetAction = 0x2,
103 SideWidgetClearButton = 0x4
104 };
105
107 explicit SideWidgetEntry(QWidget *w = nullptr, QAction *a = nullptr, int _flags = 0) : widget(w), action(a), flags(_flags) {}
108
111 int flags;
112 };
113 typedef std::vector<SideWidgetEntry> SideWidgetEntryList;
114
121
123 : control(nullptr), frame(1), contextMenuEnabled(1), cursorVisible(0),
124 dragEnabled(0), clickCausedFocus(0), edited(0), hscroll(0), vscroll(0),
125 alignment(Qt::AlignLeading | Qt::AlignVCenter),
126 textMargins{0, 0, 0, 0},
127 lastTextSize(0), mouseYThreshold(0)
128 {
129 }
130
132 {
133 }
134
136
137#ifndef QT_NO_CONTEXTMENU
138 QPointer<QAction> selectAllAction;
139#endif
140 void init(const QString&);
141 void initMouseYThreshold();
142
143 QRect adjustedControlRect(const QRect &) const;
144
146 bool inSelection(int x) const;
147 QRect cursorRect() const;
148 void setCursorVisible(bool visible);
149 void setText(const QString& text);
150
151 QString textBeforeCursor(int curPos) const;
152 QString textAfterCursor(int curPos) const;
153 void updatePasswordEchoEditing(bool);
154
155 void resetInputMethod();
156
157 inline bool shouldEnableInputMethod() const
158 {
159#if defined (Q_OS_ANDROID)
160 return !control->isReadOnly() || control->isSelectableByMouse();
161#else
162 return !control->isReadOnly();
163#endif
164 }
165 inline bool shouldShowPlaceholderText() const
166 {
167 return control->text().isEmpty() && control->preeditAreaText().isEmpty()
168 && !((alignment & Qt::AlignHCenter) && q_func()->hasFocus());
169 }
170
172 return lineEdit->d_func();
173 }
174
186 static const int verticalMargin;
187 static const int horizontalMargin;
188
189 bool sendMouseEventToInputContext(QMouseEvent *e);
190
191 QRect adjustedContentsRect() const;
192
193 void handleWindowActivate();
194 void textEdited(const QString &);
195 void cursorPositionChanged(int, int);
196#ifdef QT_KEYPAD_NAVIGATION
197 void editFocusChange(bool);
198#endif
199 void selectionChanged();
200 void updateNeeded(const QRect &);
201#if QT_CONFIG(completer)
202 void connectCompleter();
203 void disconnectCompleter();
204 void completionHighlighted(const QString &);
205#endif
207#if QT_CONFIG(draganddrop)
208 QBasicTimer dndTimer;
209 void drag();
210#endif
211 void textChanged(const QString &);
212 void clearButtonClicked();
213 void controlEditingFinished();
214
215 QMargins textMargins; // use effectiveTextMargins() in case of icon.
216
218
219#if QT_CONFIG(action)
220 QWidget *addAction(QAction *newAction, QAction *before, QLineEdit::ActionPosition, int flags = 0);
221 void removeAction(QAction *action);
222#endif
223 SideWidgetParameters sideWidgetParameters() const;
224 QIcon clearButtonIcon() const;
225 void setClearButtonEnabled(bool enabled);
226 void positionSideWidgets();
227 inline bool hasSideWidgets() const { return !leadingSideWidgets.empty() || !trailingSideWidgets.empty(); }
229 { return q_func()->layoutDirection() == Qt::LeftToRight ? leadingSideWidgets : trailingSideWidgets; }
231 { return q_func()->layoutDirection() == Qt::LeftToRight ? trailingSideWidgets : leadingSideWidgets; }
232
233 QMargins effectiveTextMargins() const;
234
235private:
236 struct SideWidgetLocation {
238 int index;
239
240 bool isValid() const { return index >= 0; }
241 };
242 friend class QTypeInfo<SideWidgetLocation>;
243
244#if QT_CONFIG(action)
245 SideWidgetLocation findSideWidget(const QAction *a) const;
246#endif
247
248 SideWidgetEntryList leadingSideWidgets;
249 SideWidgetEntryList trailingSideWidgets;
250 int lastTextSize;
251 int mouseYThreshold;
252};
254Q_DECLARE_TYPEINFO(QLineEditPrivate::SideWidgetLocation, Q_PRIMITIVE_TYPE);
255
257
258#endif // QLINEEDIT_P_H
void setText(const QString &text)
The QActionEvent class provides an event that is generated when a QAction is added,...
The QAction class provides an abstraction for user commands that can be added to different user inter...
Definition qaction.h:30
\inmodule QtCore
Definition qbasictimer.h:18
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
QBasicTimer tripleClickTimer
static const int horizontalMargin
static const int verticalMargin
QWidgetLineControl * control
bool shouldEnableInputMethod() const
QPointer< QAction > selectAllAction
static QLineEditPrivate * get(QLineEdit *lineEdit)
const SideWidgetEntryList & leftSideWidgetList() const
QMargins textMargins
const SideWidgetEntryList & rightSideWidgetList() const
bool shouldShowPlaceholderText() const
QString placeholderText
bool hasSideWidgets() const
std::vector< SideWidgetEntry > SideWidgetEntryList
The QLineEdit widget is a one-line text editor.
Definition qlineedit.h:28
ActionPosition
This enum type describes how a line edit should display the action widgets to be added.
Definition qlineedit.h:51
\inmodule QtCore
Definition qmargins.h:24
\inmodule QtGui
Definition qevent.h:196
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore\reentrant
Definition qrect.h:30
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
CursorPosition
\value CursorBetweenCharacters \value CursorOnCharacter
@ CursorBetweenCharacters
The QToolButton class provides a quick-access button to commands or options, usually used inside a QT...
Definition qtoolbutton.h:20
void actionEvent(QActionEvent *) override
\reimp
void paintEvent(QPaintEvent *) override
Paints the button in response to the paint event.
QString preeditAreaText() const
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
bool isVisibleTo(const QWidget *) const
Returns true if this widget would become visible if ancestor is shown; otherwise returns false.
Definition qwidget.cpp:8643
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
void removeAction(QAction *action)
Removes the action action from this widget's list of actions.
Definition qwidget.cpp:3186
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3117
QOpenGLWidget * widget
[1]
QString text
void textChanged(const QString &newText)
uint alignment
Combined button and popup list for selecting options.
Definition qcompare.h:63
@ AlignHCenter
Definition qnamespace.h:148
@ LeftToRight
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLbitfield flags
struct _cl_event * event
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_AUTOTEST_EXPORT
#define QT_REQUIRE_CONFIG(feature)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define slots
@ Q_PRIMITIVE_TYPE
Definition qtypeinfo.h:157
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
unsigned int uint
Definition qtypes.h:34
double qreal
Definition qtypes.h:187
QObject::connect nullptr
QLineEdit * lineEdit
edit hide()
QFrame frame
[0]
SideWidgetEntry(QWidget *w=nullptr, QAction *a=nullptr, int _flags=0)