Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qlineedit_p.cpp
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// Qt-Security score:significant reason:default
4
5#include "qlineedit.h"
6#include "qlineedit_p.h"
7
8#include "qvariant.h"
9#if QT_CONFIG(itemviews)
10#include "qabstractitemview.h"
11#endif
12#if QT_CONFIG(draganddrop)
13#include "qdrag.h"
14#endif
15#if QT_CONFIG(action)
16# include "qwidgetaction.h"
17#endif
18#include "qclipboard.h"
19#if QT_CONFIG(accessibility)
20#include "qaccessible.h"
21#endif
22#ifndef QT_NO_IM
23#include "qinputmethod.h"
24#include "qlist.h"
25#endif
26#include <qpainter.h>
27#if QT_CONFIG(animation)
28#include <qpropertyanimation.h>
29#endif
30#include <qstylehints.h>
31#include <qvalidator.h>
32
34
35const int QLineEditPrivate::verticalMargin(1);
36const int QLineEditPrivate::horizontalMargin(2);
37
38// Needs to be kept in sync with QLineEdit::paintEvent
39QRect QLineEditPrivate::adjustedControlRect(const QRect &rect) const
40{
41 QRect widgetRect = !rect.isEmpty() ? rect : q_func()->rect();
42 QRect cr = adjustedContentsRect();
43 int cix = cr.x() - hscroll + horizontalMargin;
44 return widgetRect.translated(QPoint(cix, vscroll - control->ascent() + q_func()->fontMetrics().ascent()));
45}
46
47int QLineEditPrivate::xToPos(int x, QTextLine::CursorPosition betweenOrOn) const
48{
49 QRect cr = adjustedContentsRect();
50 x-= cr.x() - hscroll + horizontalMargin;
51 return control->xToPos(x, betweenOrOn);
52}
53
54QString QLineEditPrivate::textBeforeCursor(int curPos) const
55{
56 const QString &text = control->text();
57 return text.mid(0, curPos);
58}
59
60QString QLineEditPrivate::textAfterCursor(int curPos) const
61{
62 const QString &text = control->text();
63 return text.mid(curPos);
64}
65
66bool QLineEditPrivate::inSelection(int x) const
67{
68 x -= adjustedContentsRect().x() - hscroll + horizontalMargin;
69 return control->inSelection(x);
70}
71
72QRect QLineEditPrivate::cursorRect() const
73{
74 return adjustedControlRect(control->cursorRect());
75}
76
77#if QT_CONFIG(completer)
78void QLineEditPrivate::connectCompleter()
79{
80 Q_Q(const QLineEdit);
81 QObject::connect(control->completer(), qOverload<const QString &>(&QCompleter::activated),
82 q, &QLineEdit::setText);
83 QObjectPrivate::connect(control->completer(), qOverload<const QString &>(&QCompleter::highlighted),
84 this, &QLineEditPrivate::completionHighlighted);
85}
86
87void QLineEditPrivate::disconnectCompleter()
88{
89 Q_Q(const QLineEdit);
90 QObject::disconnect(control->completer(), qOverload<const QString &>(&QCompleter::activated),
91 q, &QLineEdit::setText);
92 QObjectPrivate::disconnect(control->completer(), qOverload<const QString &>(&QCompleter::highlighted),
93 this, &QLineEditPrivate::completionHighlighted);
94}
95
96void QLineEditPrivate::completionHighlighted(const QString &newText)
97{
98 Q_Q(QLineEdit);
99 if (control->completer()->completionMode() != QCompleter::InlineCompletion) {
100 q->setText(newText);
101 } else {
102 int c = control->cursor();
103 QString text = control->text();
104 q->setText(QStringView{text}.left(c) + QStringView{newText}.mid(c));
105 control->moveCursor(control->end(), false);
106 control->moveCursor(c, true);
107 }
108}
109
110#endif // QT_CONFIG(completer)
111
112void QLineEditPrivate::handleWindowActivate()
113{
114 Q_Q(QLineEdit);
115 if (!q->hasFocus() && control->hasSelectedText())
116 control->deselect();
117}
118
119void QLineEditPrivate::textEdited(const QString &text)
120{
121 Q_Q(QLineEdit);
122 edited = true;
123 emit q->textEdited(text);
124#if QT_CONFIG(completer)
125 if (control->completer()
126 && control->completer()->completionMode() != QCompleter::InlineCompletion)
127 control->complete(-1); // update the popup on cut/paste/del
128#endif
129}
130
131void QLineEditPrivate::cursorPositionChanged(int from, int to)
132{
133 Q_Q(QLineEdit);
134 q->update();
135 emit q->cursorPositionChanged(from, to);
136}
137
138void QLineEditPrivate::selectionChanged()
139{
140 Q_Q(QLineEdit);
141 if (control->preeditAreaText().isEmpty()) {
142 QStyleOptionFrame opt;
143 q->initStyleOption(&opt);
144 bool showCursor = control->hasSelectedText() ?
145 q->style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, &opt, q):
146 q->hasFocus();
147 setCursorVisible(showCursor);
148 }
149
150 emit q->selectionChanged();
151#if QT_CONFIG(accessibility)
152 QAccessibleTextSelectionEvent ev(q, control->selectionStart(), control->selectionEnd());
153 ev.setCursorPosition(control->cursorPosition());
154 QAccessible::updateAccessibility(&ev);
155#endif
156}
157
158void QLineEditPrivate::updateNeeded(const QRect &rect)
159{
160 q_func()->update(adjustedControlRect(rect));
161}
162
163void QLineEditPrivate::init(const QString& txt)
164{
165 Q_Q(QLineEdit);
166
167 const auto qUpdateMicroFocus = [q]()
168 {
169 q->updateMicroFocus();
170 };
171 control = new QWidgetLineControl(txt);
172 control->setParent(q);
173 control->setFont(q->font());
174 QObject::connect(control, &QWidgetLineControl::textChanged,
175 q, &QLineEdit::textChanged);
176 QObjectPrivate::connect(control, &QWidgetLineControl::textEdited,
177 this, &QLineEditPrivate::textEdited);
178 QObjectPrivate::connect(control, &QWidgetLineControl::cursorPositionChanged,
179 this, &QLineEditPrivate::cursorPositionChanged);
180 QObjectPrivate::connect(control, &QWidgetLineControl::selectionChanged,
181 this, &QLineEditPrivate::selectionChanged);
182 QObjectPrivate::connect(control, &QWidgetLineControl::editingFinished,
183 this, &QLineEditPrivate::controlEditingFinished);
184 QObject::connect(control, &QWidgetLineControl::cursorPositionChanged,
185 q, qUpdateMicroFocus);
186
187 QObject::connect(control, &QWidgetLineControl::textChanged,
188 q, qUpdateMicroFocus);
189
190 QObject::connect(control, &QWidgetLineControl::updateMicroFocus,
191 q, qUpdateMicroFocus);
192
193 // for now, going completely overboard with updates.
194 QObject::connect(control, &QWidgetLineControl::selectionChanged,
195 q, qOverload<>(&QLineEdit::update));
196
197 QObject::connect(control, &QWidgetLineControl::selectionChanged,
198 q, qUpdateMicroFocus);
199
200 QObject::connect(control, &QWidgetLineControl::displayTextChanged,
201 q, qOverload<>(&QLineEdit::update));
202
203 QObjectPrivate::connect(control, &QWidgetLineControl::updateNeeded,
204 this, &QLineEditPrivate::updateNeeded);
205 QObject::connect(control, &QWidgetLineControl::inputRejected,
206 q, &QLineEdit::inputRejected);
207
208 QStyleOptionFrame opt;
209 q->initStyleOption(&opt);
210 control->setPasswordCharacter(char16_t(q->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, q)));
211 control->setPasswordMaskDelay(q->style()->styleHint(QStyle::SH_LineEdit_PasswordMaskDelay, &opt, q));
212#ifndef QT_NO_CURSOR
213 q->setCursor(Qt::IBeamCursor);
214#endif
215 q->setFocusPolicy(Qt::StrongFocus);
216 q->setAttribute(Qt::WA_InputMethodEnabled);
217 // Specifies that this widget can use more, but is able to survive on
218 // less, horizontal space; and is fixed vertically.
219 q->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed, QSizePolicy::LineEdit));
220 q->setBackgroundRole(QPalette::Base);
221 q->setAttribute(Qt::WA_KeyCompression);
222 q->setMouseTracking(true);
223 q->setAcceptDrops(true);
224
225 q->setAttribute(Qt::WA_MacShowFocusRect);
226
227 initMouseYThreshold();
228}
229
230void QLineEditPrivate::initMouseYThreshold()
231{
232 mouseYThreshold = QGuiApplication::styleHints()->mouseQuickSelectionThreshold();
233}
234
235QRect QLineEditPrivate::adjustedContentsRect() const
236{
237 Q_Q(const QLineEdit);
238 QStyleOptionFrame opt;
239 q->initStyleOption(&opt);
240 QRect r = q->style()->subElementRect(QStyle::SE_LineEditContents, &opt, q);
241 r = r.marginsRemoved(effectiveTextMargins());
242 return r;
243}
244
245void QLineEditPrivate::setCursorVisible(bool visible)
246{
247 Q_Q(QLineEdit);
248 if ((bool)cursorVisible == visible)
249 return;
250 cursorVisible = visible;
251 if (control->inputMask().isEmpty())
252 q->update(cursorRect());
253 else
254 q->update();
255}
256
257void QLineEditPrivate::setText(const QString& text)
258{
259 edited = true;
260 control->setText(text);
261}
262
263void QLineEditPrivate::updatePasswordEchoEditing(bool editing)
264{
265 Q_Q(QLineEdit);
266 control->updatePasswordEchoEditing(editing);
267 q->setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod());
268}
269
270void QLineEditPrivate::resetInputMethod()
271{
272 Q_Q(QLineEdit);
273 if (q->hasFocus() && qApp) {
274 QGuiApplication::inputMethod()->reset();
275 }
276}
277
278/*!
279 \class QLineEditPrivate
280 \inmodule QtWidgets
281 \internal
282*/
283
284/*!
285 This function is not intended as polymorphic usage. Just a shared code
286 fragment that calls QInputMethod::invokeAction for this
287 class.
288*/
289bool QLineEditPrivate::sendMouseEventToInputContext( QMouseEvent *e )
290{
291#if !defined QT_NO_IM
292 if ( control->composeMode() ) {
293 int tmp_cursor = xToPos(e->position().toPoint().x());
294 int mousePos = tmp_cursor - control->cursor();
295 if ( mousePos < 0 || mousePos > control->preeditAreaText().size() )
296 mousePos = -1;
297
298 if (mousePos >= 0) {
299 if (e->type() == QEvent::MouseButtonRelease)
300 QGuiApplication::inputMethod()->invokeAction(QInputMethod::Click, mousePos);
301
302 return true;
303 }
304 }
305#else
306 Q_UNUSED(e);
307#endif
308
309 return false;
310}
311
312#if QT_CONFIG(draganddrop)
313void QLineEditPrivate::drag()
314{
315 Q_Q(QLineEdit);
316 dndTimer.stop();
317 QMimeData *data = new QMimeData;
318 data->setText(control->selectedText());
319 QDrag *drag = new QDrag(q);
320 drag->setMimeData(data);
321 Qt::DropAction action = drag->exec(Qt::CopyAction);
322 if (action == Qt::MoveAction && !control->isReadOnly() && drag->target() != q)
323 control->removeSelection();
324}
325#endif // QT_CONFIG(draganddrop)
326
327
328#if QT_CONFIG(toolbutton)
329QLineEditIconButton::QLineEditIconButton(QWidget *parent)
330 : QToolButton(parent)
331 , m_opacity(0)
332{
333 setFocusPolicy(Qt::NoFocus);
334}
335
336QLineEditPrivate *QLineEditIconButton::lineEditPrivate() const
337{
338 QLineEdit *le = qobject_cast<QLineEdit *>(parentWidget());
339 return le ? static_cast<QLineEditPrivate *>(qt_widget_private(le)) : nullptr;
340}
341
342void QLineEditIconButton::paintEvent(QPaintEvent *)
343{
344 QPainter painter(this);
345 QIcon::Mode mode = QIcon::Disabled;
346 if (isEnabled())
347 mode = isDown() ? QIcon::Active : QIcon::Normal;
348 const QLineEditPrivate *lep = lineEditPrivate();
349 const int iconWidth = lep ? lep->sideWidgetParameters().iconSize : 16;
350 const QSize iconSize(iconWidth, iconWidth);
351 QRect pixmapRect = QRect(QPoint(0, 0), iconSize);
352 pixmapRect.moveCenter(rect().center());
353 painter.setOpacity(m_opacity);
354 icon().paint(&painter, pixmapRect, Qt::AlignCenter, mode, QIcon::Off);
355}
356
357void QLineEditIconButton::actionEvent(QActionEvent *e)
358{
359 switch (e->type()) {
360 case QEvent::ActionChanged: {
361 const auto *action = e->action();
362 if (isVisibleTo(parentWidget()) != action->isVisible()) {
363 setVisible(action->isVisible());
364 if (QLineEditPrivate *lep = lineEditPrivate())
365 lep->positionSideWidgets();
366 }
367 }
368 break;
369 default:
370 break;
371 }
372 QToolButton::actionEvent(e);
373}
374
375void QLineEditIconButton::setOpacity(qreal value)
376{
377 if (!qFuzzyCompare(m_opacity, value)) {
378 m_opacity = value;
379 updateCursor();
380 update();
381 }
382}
383
384#if QT_CONFIG(animation)
385bool QLineEditIconButton::shouldHideWithText() const
386{
387 return m_hideWithText;
388}
389
390void QLineEditIconButton::setHideWithText(bool hide)
391{
392 m_hideWithText = hide;
393}
394
395void QLineEditIconButton::onAnimationFinished()
396{
397 if (shouldHideWithText() && isVisible() && m_fadingOut) {
398 hide();
399 m_fadingOut = false;
400
401 // Invalidate previous geometry to take into account new size of side widgets
402 if (auto le = lineEditPrivate())
403 le->updateGeometry_helper(true);
404 }
405}
406
407void QLineEditIconButton::animateShow(bool visible)
408{
409 m_fadingOut = !visible;
410
411 if (shouldHideWithText() && !isVisible()) {
412 show();
413
414 // Invalidate previous geometry to take into account new size of side widgets
415 if (auto le = lineEditPrivate())
416 le->updateGeometry_helper(true);
417 }
418
419 startOpacityAnimation(visible ? 1.0 : 0.0);
420}
421
422void QLineEditIconButton::startOpacityAnimation(qreal endValue)
423{
424 QPropertyAnimation *animation = new QPropertyAnimation(this, QByteArrayLiteral("opacity"), this);
425 connect(animation, &QPropertyAnimation::finished, this, &QLineEditIconButton::onAnimationFinished);
426
427 animation->setDuration(160);
428 animation->setEndValue(endValue);
429 animation->start(QAbstractAnimation::DeleteWhenStopped);
430}
431#endif
432
433void QLineEditIconButton::updateCursor()
434{
435#ifndef QT_NO_CURSOR
436 setCursor(qFuzzyCompare(m_opacity, qreal(1.0)) || !parentWidget() ? QCursor(Qt::ArrowCursor) : parentWidget()->cursor());
437#endif
438}
439#endif // QT_CONFIG(toolbutton)
440
441#if QT_CONFIG(animation) && QT_CONFIG(toolbutton)
442static void displayWidgets(const QLineEditPrivate::SideWidgetEntryList &widgets, bool display)
443{
444 for (const auto &e : widgets) {
445 if (e.flags & QLineEditPrivate::SideWidgetFadeInWithText)
446 static_cast<QLineEditIconButton *>(e.widget)->animateShow(display);
447 }
448}
449#endif
450
451void QLineEditPrivate::textChanged(const QString &text)
452{
453 if (hasSideWidgets()) {
454 const int newTextSize = text.size();
455 if (!newTextSize || !lastTextSize) {
456 lastTextSize = newTextSize;
457#if QT_CONFIG(animation) && QT_CONFIG(toolbutton)
458 const bool display = newTextSize > 0;
459 displayWidgets(leadingSideWidgets, display);
460 displayWidgets(trailingSideWidgets, display);
461#endif
462 }
463 }
464}
465
466void QLineEditPrivate::clearButtonClicked()
467{
468 Q_Q(QLineEdit);
469 if (!q->text().isEmpty()) {
470 q->clear();
471 textEdited(QString());
472 }
473}
474
475void QLineEditPrivate::controlEditingFinished()
476{
477 Q_Q(QLineEdit);
478 edited = false;
479 emit q->returnPressed();
480 emit q->editingFinished();
481}
482
483QLineEditPrivate::SideWidgetParameters QLineEditPrivate::sideWidgetParameters() const
484{
485 Q_Q(const QLineEdit);
486 SideWidgetParameters result;
487 result.iconSize = q->style()->pixelMetric(QStyle::PM_LineEditIconSize, nullptr, q);
488 result.margin = q->style()->pixelMetric(QStyle::PM_LineEditIconMargin, nullptr, q);
489 result.widgetWidth = result.iconSize + 6;
490 result.widgetHeight = result.iconSize + 2;
491 return result;
492}
493
494QIcon QLineEditPrivate::clearButtonIcon() const
495{
496 Q_Q(const QLineEdit);
497 QStyleOptionFrame styleOption;
498 q->initStyleOption(&styleOption);
499 return q->style()->standardIcon(QStyle::SP_LineEditClearButton, &styleOption, q);
500}
501
502void QLineEditPrivate::setClearButtonEnabled(bool enabled)
503{
504#if QT_CONFIG(action)
505 for (const SideWidgetEntry &e : trailingSideWidgets) {
506 if (e.flags & SideWidgetClearButton) {
507 e.action->setEnabled(enabled);
508 break;
509 }
510 }
511#else
512 Q_UNUSED(enabled);
513#endif
514}
515
516void QLineEditPrivate::positionSideWidgets()
517{
518 Q_Q(QLineEdit);
519 if (hasSideWidgets()) {
520 const QRect contentRect = q->rect();
521 const SideWidgetParameters p = sideWidgetParameters();
522 const int delta = p.margin + p.widgetWidth;
523 QRect widgetGeometry(QPoint(p.margin, (contentRect.height() - p.widgetHeight) / 2),
524 QSize(p.widgetWidth, p.widgetHeight));
525 for (const SideWidgetEntry &e : leftSideWidgetList()) {
526 e.widget->setGeometry(widgetGeometry);
527#if QT_CONFIG(action)
528 if (e.action->isVisible())
529 widgetGeometry.moveLeft(widgetGeometry.left() + delta);
530#else
531 Q_UNUSED(delta);
532#endif
533 }
534 widgetGeometry.moveLeft(contentRect.width() - p.widgetWidth - p.margin);
535 for (const SideWidgetEntry &e : rightSideWidgetList()) {
536 e.widget->setGeometry(widgetGeometry);
537#if QT_CONFIG(action)
538 if (e.action->isVisible())
539 widgetGeometry.moveLeft(widgetGeometry.left() - delta);
540#endif
541 }
542 }
543}
544
545#if QT_CONFIG(action)
546QLineEditPrivate::SideWidgetLocation QLineEditPrivate::findSideWidget(const QAction *a) const
547{
548 int i = 0;
549 for (const auto &e : leadingSideWidgets) {
550 if (a == e.action)
551 return {QLineEdit::LeadingPosition, i};
552 ++i;
553 }
554 i = 0;
555 for (const auto &e : trailingSideWidgets) {
556 if (a == e.action)
557 return {QLineEdit::TrailingPosition, i};
558 ++i;
559 }
560 return {QLineEdit::LeadingPosition, -1};
561}
562
563QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineEdit::ActionPosition position, int flags)
564{
565 Q_Q(QLineEdit);
566 if (!newAction)
567 return nullptr;
568 if (!hasSideWidgets()) { // initial setup.
569 QObjectPrivate::connect(q, &QLineEdit::textChanged,
570 this, &QLineEditPrivate::textChanged);
571 lastTextSize = q->text().size();
572 }
573 QWidget *w = nullptr;
574 // Store flags about QWidgetAction here since removeAction() may be called from ~QAction,
575 // in which a qobject_cast<> no longer works.
576 if (QWidgetAction *widgetAction = qobject_cast<QWidgetAction *>(newAction)) {
577 if ((w = widgetAction->requestWidget(q)))
578 flags |= SideWidgetCreatedByWidgetAction;
579 }
580 if (!w) {
581#if QT_CONFIG(toolbutton)
582 QLineEditIconButton *toolButton = new QLineEditIconButton(q);
583 toolButton->setIcon(newAction->icon());
584 toolButton->setOpacity(lastTextSize > 0 || !(flags & SideWidgetFadeInWithText) ? 1 : 0);
585 if (flags & SideWidgetClearButton) {
586 QObjectPrivate::connect(toolButton, &QToolButton::clicked,
587 this, &QLineEditPrivate::clearButtonClicked);
588
589#if QT_CONFIG(animation)
590 // The clear button is handled only by this widget. The button should be really
591 // shown/hidden in order to calculate size hints correctly.
592 toolButton->setHideWithText(true);
593#endif
594 }
595 toolButton->setDefaultAction(newAction);
596 w = toolButton;
597#else
598 return nullptr;
599#endif
600 }
601
602 // QTBUG-59957: clear button should be the leftmost action.
603 if (!before && !(flags & SideWidgetClearButton) && position == QLineEdit::TrailingPosition) {
604 for (const SideWidgetEntry &e : trailingSideWidgets) {
605 if (e.flags & SideWidgetClearButton) {
606 before = e.action;
607 break;
608 }
609 }
610 }
611
612 // If there is a 'before' action, it takes preference
613
614 // There's a bug in GHS compiler that causes internal error on the following code.
615 // The affected GHS compiler versions are 2016.5.4 and 2017.1. GHS internal reference
616 // to track the progress of this issue is TOOLS-26637.
617 // This temporary workaround allows to compile with GHS toolchain and should be
618 // removed when GHS provides a patch to fix the compiler issue.
619
620#if defined(Q_CC_GHS)
621 const SideWidgetLocation loc = {position, -1};
622 const auto location = before ? findSideWidget(before) : loc;
623#else
624 const auto location = before ? findSideWidget(before) : SideWidgetLocation{position, -1};
625#endif
626
627 SideWidgetEntryList &list = location.position == QLineEdit::TrailingPosition ? trailingSideWidgets : leadingSideWidgets;
628 list.insert(location.isValid() ? list.begin() + location.index : list.end(),
629 SideWidgetEntry(w, newAction, flags));
630 positionSideWidgets();
631 w->show();
632 return w;
633}
634
635void QLineEditPrivate::removeAction(QAction *action)
636{
637 Q_Q(QLineEdit);
638 const auto location = findSideWidget(action);
639 if (!location.isValid())
640 return;
641 SideWidgetEntryList &list = location.position == QLineEdit::TrailingPosition ? trailingSideWidgets : leadingSideWidgets;
642 SideWidgetEntry entry = list[location.index];
643 list.erase(list.begin() + location.index);
644 if (entry.flags & SideWidgetCreatedByWidgetAction) {
645 // If the cast fails, the QAction is in the process of being deleted
646 // and has already ceased to be a QWidgetAction; in the process, it
647 // will release its widget itself, and calling releaseWidget() here
648 // would be UB, so don't:
649 if (const auto a = qobject_cast<QWidgetAction*>(entry.action))
650 a->releaseWidget(entry.widget);
651 } else {
652 delete entry.widget;
653 }
654 positionSideWidgets();
655 if (!hasSideWidgets()) // Last widget, remove connection
656 QObjectPrivate::connect(q, &QLineEdit::textChanged,
657 this, &QLineEditPrivate::textChanged);
658 q->update();
659}
660#endif // QT_CONFIG(action)
661
662static int effectiveTextMargin(int defaultMargin, const QLineEditPrivate::SideWidgetEntryList &widgets,
663 const QLineEditPrivate::SideWidgetParameters &parameters)
664{
665 if (widgets.empty())
666 return defaultMargin;
667
668 const auto visibleSideWidgetCount = std::count_if(widgets.begin(), widgets.end(),
669 [](const QLineEditPrivate::SideWidgetEntry &e) {
670#if QT_CONFIG(toolbutton) && QT_CONFIG(animation)
671 // a button that's fading out doesn't get any space
672 if (auto* iconButton = qobject_cast<QLineEditIconButton*>(e.widget))
673 return iconButton->needsSpace();
674
675#endif
676 return e.widget->isVisibleTo(e.widget->parentWidget());
677 });
678
679 return defaultMargin + (parameters.margin + parameters.widgetWidth) * visibleSideWidgetCount;
680}
681
682QMargins QLineEditPrivate::effectiveTextMargins() const
683{
684 return {effectiveTextMargin(textMargins.left(), leftSideWidgetList(), sideWidgetParameters()),
685 textMargins.top(),
686 effectiveTextMargin(textMargins.right(), rightSideWidgetList(), sideWidgetParameters()),
687 textMargins.bottom()};
688}
689
690
691QT_END_NAMESPACE
692
693#include "moc_qlineedit_p.cpp"
Combined button and popup list for selecting options.
static int effectiveTextMargin(int defaultMargin, const QLineEditPrivate::SideWidgetEntryList &widgets, const QLineEditPrivate::SideWidgetParameters &parameters)