summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qlineedit.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-05-26 07:22:13 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-07-30 13:05:11 +0300
commit7940bc32a1a4256a9ab4c032f2123c9fea8c6202 (patch)
tree1e8a31a8355efac9e3d53ff872c0ef7711ef0ae5 /src/widgets/widgets/qlineedit.cpp
parent31ffc7bf2a0efe40116764a8c84939d2df4cdeae (diff)
QLineEdit: use QMargins internally instead of 4 x int
Replace the four ints xTextMargin with one QMargins member, and the effectiveXTextMargin() function with effectiveTextMargins(). The left and right effective margins were always used together, so this in no case leads to extra work, compared to separate functions. Change-Id: I46d061919ffac297142213ccb4033caa0288b554 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/widgets/widgets/qlineedit.cpp')
-rw-r--r--src/widgets/widgets/qlineedit.cpp40
1 files changed, 18 insertions, 22 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index 0fedb65f0c..28d18872ce 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -684,11 +684,12 @@ QSize QLineEdit::sizeHint() const
ensurePolished();
QFontMetrics fm(font());
const int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this);
+ const QMargins tm = d->effectiveTextMargins();
int h = qMax(fm.height(), qMax(14, iconSize - 2)) + 2 * QLineEditPrivate::verticalMargin
- + d->topTextMargin + d->bottomTextMargin
+ + tm.top() + tm.bottom()
+ d->topmargin + d->bottommargin;
int w = fm.horizontalAdvance(QLatin1Char('x')) * 17 + 2 * QLineEditPrivate::horizontalMargin
- + d->effectiveLeftTextMargin() + d->effectiveRightTextMargin()
+ + tm.left() + tm.right()
+ d->leftmargin + d->rightmargin; // "some"
QStyleOptionFrame opt;
initStyleOption(&opt);
@@ -708,11 +709,12 @@ QSize QLineEdit::minimumSizeHint() const
Q_D(const QLineEdit);
ensurePolished();
QFontMetrics fm = fontMetrics();
+ const QMargins tm = d->effectiveTextMargins();
int h = fm.height() + qMax(2 * QLineEditPrivate::verticalMargin, fm.leading())
- + d->topTextMargin + d->bottomTextMargin
+ + tm.top() + tm.bottom()
+ d->topmargin + d->bottommargin;
int w = fm.maxWidth()
- + d->effectiveLeftTextMargin() + d->effectiveRightTextMargin()
+ + tm.left() + tm.right()
+ d->leftmargin + d->rightmargin;
QStyleOptionFrame opt;
initStyleOption(&opt);
@@ -1131,13 +1133,7 @@ bool QLineEdit::hasAcceptableInput() const
*/
void QLineEdit::setTextMargins(int left, int top, int right, int bottom)
{
- Q_D(QLineEdit);
- d->leftTextMargin = left;
- d->topTextMargin = top;
- d->rightTextMargin = right;
- d->bottomTextMargin = bottom;
- updateGeometry();
- update();
+ setTextMargins({left, top, right, bottom});
}
/*!
@@ -1148,7 +1144,10 @@ void QLineEdit::setTextMargins(int left, int top, int right, int bottom)
*/
void QLineEdit::setTextMargins(const QMargins &margins)
{
- setTextMargins(margins.left(), margins.top(), margins.right(), margins.bottom());
+ Q_D(QLineEdit);
+ d->textMargins = margins;
+ updateGeometry();
+ update();
}
/*!
@@ -1159,15 +1158,15 @@ void QLineEdit::setTextMargins(const QMargins &margins)
*/
void QLineEdit::getTextMargins(int *left, int *top, int *right, int *bottom) const
{
- Q_D(const QLineEdit);
+ QMargins m = textMargins();
if (left)
- *left = d->leftTextMargin;
+ *left = m.left();
if (top)
- *top = d->topTextMargin;
+ *top = m.top();
if (right)
- *right = d->rightTextMargin;
+ *right = m.right();
if (bottom)
- *bottom = d->bottomTextMargin;
+ *bottom = m.bottom();
}
/*!
@@ -1179,7 +1178,7 @@ void QLineEdit::getTextMargins(int *left, int *top, int *right, int *bottom) con
QMargins QLineEdit::textMargins() const
{
Q_D(const QLineEdit);
- return QMargins(d->leftTextMargin, d->topTextMargin, d->rightTextMargin, d->bottomTextMargin);
+ return d->textMargins;
}
/*!
@@ -1950,10 +1949,7 @@ void QLineEdit::paintEvent(QPaintEvent *)
initStyleOption(&panel);
style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this);
QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this);
- r.setX(r.x() + d->effectiveLeftTextMargin());
- r.setY(r.y() + d->topTextMargin);
- r.setRight(r.right() - d->effectiveRightTextMargin());
- r.setBottom(r.bottom() - d->bottomTextMargin);
+ r = r.marginsRemoved(d->effectiveTextMargins());
p.setClipRect(r);
QFontMetrics fm = fontMetrics();