From a700bea095df33284d2ac5fed34e48670193467f Mon Sep 17 00:00:00 2001 From: Arnaud Bienner Date: Sat, 18 Jan 2014 00:23:07 +0100 Subject: [PATCH] Revert "Set padding-right correctly instead of moving the clear icon" This reverts commit 5c057459859f470033dac550ead560283c7676e1. --- src/widgets/lineedit.cpp | 28 ++++++++++++---------------- src/widgets/lineedit.h | 11 ++++++----- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/widgets/lineedit.cpp b/src/widgets/lineedit.cpp index 7eb594708..5d524a675 100644 --- a/src/widgets/lineedit.cpp +++ b/src/widgets/lineedit.cpp @@ -81,21 +81,18 @@ void ExtendedEditor::set_reset_button(bool visible) { void ExtendedEditor::UpdateButtonGeometry() { const int frame_width = widget_->style()->pixelMetric(QStyle::PM_DefaultFrameWidth); - int left = frame_width + 1 + ( + const int left = frame_width + 1 + ( has_clear_button() ? clear_button_->sizeHint().width() : 0); - int right = frame_width + 1 + ( + const int right = frame_width + 1 + ( has_reset_button() ? reset_button_->sizeHint().width() : 0); - if (is_rtl()) { - qSwap(left, right); - } + widget_->setStyleSheet( QString("QLineEdit { padding-left: %1px; padding-right: %2px; }") .arg(left).arg(right)); QSize msz = widget_->minimumSizeHint(); - int width = msz.width() + (clear_button_->sizeHint().width() + frame_width + 1) * 2 + extra_right_padding_; - int height = qMax(msz.height(), clear_button_->sizeHint().height() + frame_width * 2 + 2); - widget_->setMinimumSize(width, height); + widget_->setMinimumSize(msz.width() + (clear_button_->sizeHint().width() + frame_width + 1) * 2 + extra_right_padding_, + qMax(msz.height(), clear_button_->sizeHint().height() + frame_width * 2 + 2)); } void ExtendedEditor::Paint(QPaintDevice* device) { @@ -131,7 +128,12 @@ void ExtendedEditor::Resize() { const int y = (widget_->rect().height() - sz.height()) / 2; clear_button_->move(frame_width, y); - reset_button_->move(widget_->width() - frame_width - sz.width() - extra_right_padding_, y); + + if (!is_rtl_) { + reset_button_->move(widget_->width() - frame_width - sz.width() - extra_right_padding_, y); + } else { + reset_button_->move((has_clear_button() ? sz.width() + 4 : 0) + frame_width, y); + } } @@ -143,13 +145,6 @@ LineEdit::LineEdit(QWidget* parent) connect(this, SIGNAL(textChanged(QString)), SLOT(text_changed(QString))); } -void LineEdit::set_rtl(bool rtl) { - if (rtl != is_rtl_) { - is_rtl_ = rtl; - UpdateButtonGeometry(); - } -} - void LineEdit::text_changed(const QString& text) { if (text.isEmpty()) { // Consider empty string as LTR @@ -159,6 +154,7 @@ void LineEdit::text_changed(const QString& text) { // compare only the first character set_rtl(QString(text.at(0)).isRightToLeft()); } + Resize(); } void LineEdit::paintEvent(QPaintEvent* e) { diff --git a/src/widgets/lineedit.h b/src/widgets/lineedit.h index 191252a2b..e730ae29d 100644 --- a/src/widgets/lineedit.h +++ b/src/widgets/lineedit.h @@ -72,11 +72,8 @@ public: protected: void Paint(QPaintDevice* device); void Resize(); - // Change the value of the "right to left" (direction) property. - // Will recompute whatever is needed (UpdateButtonGeometry, ...) if the value - // changed. - void set_rtl(bool rtl); - bool is_rtl() const { return is_rtl_; } + +private: void UpdateButtonGeometry(); protected: @@ -113,6 +110,10 @@ protected: void paintEvent(QPaintEvent*); void resizeEvent(QResizeEvent*); +private: + bool is_rtl() const { return is_rtl_; } + void set_rtl(bool rtl) { is_rtl_ = rtl; } + private slots: void text_changed(const QString& text);