1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-18 20:40:43 +01:00

Merge pull request #4102 from Tatsh/fix-edittagdialog-rtl

In the tag editor, make the reset button appear on the left side for RTL
Fixes #2673
This commit is contained in:
David Sansome 2014-01-11 22:39:24 -08:00
commit 7c1dc5d6cf
2 changed files with 28 additions and 5 deletions

View File

@ -32,7 +32,8 @@ ExtendedEditor::ExtendedEditor(QWidget* widget, int extra_right_padding,
reset_button_(new QToolButton(widget)),
extra_right_padding_(extra_right_padding),
draw_hint_(draw_hint),
font_point_size_(widget->font().pointSizeF() - 1)
font_point_size_(widget->font().pointSizeF() - 1),
is_rtl_(false)
{
clear_button_->setIcon(IconLoader::Load("edit-clear-locationbar-ltr"));
clear_button_->setIconSize(QSize(16, 16));
@ -118,15 +119,22 @@ void ExtendedEditor::Paint(QPaintDevice* device) {
}
} else {
clear_button_->setVisible(has_clear_button_);
Resize();
}
}
void ExtendedEditor::Resize() {
const QSize sz = clear_button_->sizeHint();
const int frame_width = widget_->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
clear_button_->move(frame_width, (widget_->rect().height() - sz.height()) / 2);
reset_button_->move(widget_->width() - frame_width - sz.width() - extra_right_padding_,
(widget_->rect().height() - sz.height()) / 2);
const int y = (widget_->rect().height() - sz.height()) / 2;
clear_button_->move(frame_width, 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);
}
}
@ -137,6 +145,16 @@ LineEdit::LineEdit(QWidget* parent)
connect(reset_button_, SIGNAL(clicked()), SIGNAL(Reset()));
}
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()) {
set_rtl(QString(text.at(0)).isRightToLeft());
}
}
void LineEdit::paintEvent(QPaintEvent* e) {
QLineEdit::paintEvent(e);
Paint(this);

View File

@ -86,6 +86,7 @@ protected:
int extra_right_padding_;
bool draw_hint_;
qreal font_point_size_;
bool is_rtl_;
};
class LineEdit : public QLineEdit,
@ -102,13 +103,17 @@ public:
// ExtendedEditor
void set_focus() { QLineEdit::setFocus(); }
QString text() const { return QLineEdit::text(); }
void set_text(const QString& text) { QLineEdit::setText(text); }
void set_text(const QString& text);
void set_enabled(bool enabled) { QLineEdit::setEnabled(enabled); }
protected:
void paintEvent(QPaintEvent*);
void resizeEvent(QResizeEvent*);
private:
bool is_rtl() const { return is_rtl_; }
void set_rtl(bool rtl) { is_rtl_ = rtl; }
signals:
void Reset();
};