Skip to content

Commit

Permalink
Change a bit the LTR logic (move the clear button also when editing/r…
Browse files Browse the repository at this point in the history
…emoving the text
  • Loading branch information
ArnaudBienner committed Jan 12, 2014
1 parent 062889b commit 3838bd7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/widgets/lineedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ void ExtendedEditor::Paint(QPaintDevice* device) {
}
} else {
clear_button_->setVisible(has_clear_button_);
Resize();
}
}

Expand All @@ -143,16 +142,19 @@ LineEdit::LineEdit(QWidget* parent)
ExtendedEditor(this)
{
connect(reset_button_, SIGNAL(clicked()), SIGNAL(Reset()));
connect(this, SIGNAL(textChanged(QString)), SLOT(text_changed(QString)));
}

void LineEdit::set_text(const QString& text) {
QLineEdit::setText(text);

// For some reason Qt will detect any text with LTR at the end as LTR, so instead
// compare only the first character
if (!text.isEmpty()) {
void LineEdit::text_changed(const QString& text) {
if (text.isEmpty()) {
// Consider empty string as LTR
set_rtl(false);
} else {
// For some reason Qt will detect any text with LTR at the end as LTR, so instead
// compare only the first character
set_rtl(QString(text.at(0)).isRightToLeft());
}
Resize();
}

void LineEdit::paintEvent(QPaintEvent* e) {
Expand Down
5 changes: 4 additions & 1 deletion src/widgets/lineedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class LineEdit : public QLineEdit,
// ExtendedEditor
void set_focus() { QLineEdit::setFocus(); }
QString text() const { return QLineEdit::text(); }
void set_text(const QString& text);
void set_text(const QString& text) { QLineEdit::setText(text); }
void set_enabled(bool enabled) { QLineEdit::setEnabled(enabled); }

protected:
Expand All @@ -114,6 +114,9 @@ class LineEdit : public QLineEdit,
bool is_rtl() const { return is_rtl_; }
void set_rtl(bool rtl) { is_rtl_ = rtl; }

private slots:
void text_changed(const QString& text);

signals:
void Reset();
};
Expand Down

0 comments on commit 3838bd7

Please sign in to comment.