summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2013-11-26 12:31:01 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-28 11:34:33 +0100
commit6f5424466018aaaae5b11e3e5203c7427ffe65bd (patch)
tree824f12b33a77f79eb4eb49bfb9b4e0bee10a58d1
parent1c046369e395888df788242295743eb2def102ee (diff)
downloadqtbase-wip/direct2d-painter.tar.gz
QLineEdit: Extract Method shouldShowPlaceholderText()wip/direct2d-painter
The condition under which the placeholder text should be shown changed recently, so refactor the code to centralize the condition. It turns out that setPlaceholderText() and paintEvent() disagree on the condition already. Change-Id: Id193a9a138042ab0690082dcf634cf7487a5276e Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
-rw-r--r--src/widgets/widgets/qlineedit.cpp4
-rw-r--r--src/widgets/widgets/qlineedit_p.h4
2 files changed, 6 insertions, 2 deletions
diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp
index df5ae0171c..e93e94b83d 100644
--- a/src/widgets/widgets/qlineedit.cpp
+++ b/src/widgets/widgets/qlineedit.cpp
@@ -350,7 +350,7 @@ void QLineEdit::setPlaceholderText(const QString& placeholderText)
Q_D(QLineEdit);
if (d->placeholderText != placeholderText) {
d->placeholderText = placeholderText;
- if (d->control->text().isEmpty())
+ if (d->shouldShowPlaceholderText())
update();
}
}
@@ -1895,7 +1895,7 @@ void QLineEdit::paintEvent(QPaintEvent *)
int minLB = qMax(0, -fm.minLeftBearing());
int minRB = qMax(0, -fm.minRightBearing());
- if (d->control->text().isEmpty() && d->control->preeditAreaText().isEmpty()) {
+ if (d->shouldShowPlaceholderText() && d->control->preeditAreaText().isEmpty()) {
if (!d->placeholderText.isEmpty()) {
QColor col = pal.text().color();
col.setAlpha(128);
diff --git a/src/widgets/widgets/qlineedit_p.h b/src/widgets/widgets/qlineedit_p.h
index 181a23449b..4428832dd9 100644
--- a/src/widgets/widgets/qlineedit_p.h
+++ b/src/widgets/widgets/qlineedit_p.h
@@ -148,6 +148,10 @@ public:
{
return !control->isReadOnly();
}
+ inline bool shouldShowPlaceholderText() const
+ {
+ return control->text().isEmpty();
+ }
static inline QLineEditPrivate *get(QLineEdit *lineEdit) {
return lineEdit->d_func();