From f4315304f79bc491177a86a9f194f09aceef1d0b Mon Sep 17 00:00:00 2001 From: nowrep Date: Mon, 10 Jun 2013 23:06:17 +0200 Subject: [PATCH] [GreaseMonkey] Fixed buttons in script list with RTL layout. --- .../settings/gm_settingslistdelegate.cpp | 18 ++++++++++++------ .../settings/gm_settingslistwidget.cpp | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/plugins/GreaseMonkey/settings/gm_settingslistdelegate.cpp b/src/plugins/GreaseMonkey/settings/gm_settingslistdelegate.cpp index 1192502e7..a666c10d7 100644 --- a/src/plugins/GreaseMonkey/settings/gm_settingslistdelegate.cpp +++ b/src/plugins/GreaseMonkey/settings/gm_settingslistdelegate.cpp @@ -43,6 +43,7 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte const QWidget* w = opt.widget; const QStyle* style = w ? w->style() : QApplication::style(); + const Qt::LayoutDirection direction = w ? w->layoutDirection() : QApplication::layoutDirection(); const int height = opt.rect.height(); const int center = height / 2 + opt.rect.top(); @@ -70,16 +71,19 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte QStyleOptionViewItemV4 opt2 = opt; opt2.checkState == Qt::Checked ? opt2.state |= QStyle::State_On : opt2.state |= QStyle::State_Off; QRect styleCheckBoxRect = style->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt2, w); - opt2.rect = QRect(leftPosition, checkboxYPos, styleCheckBoxRect.width(), styleCheckBoxRect.height()); + styleCheckBoxRect.setRect(leftPosition, checkboxYPos, styleCheckBoxRect.width(), styleCheckBoxRect.height()); + QRect visualCheckBoxRect = style->visualRect(direction, opt.rect, styleCheckBoxRect); + opt2.rect = visualCheckBoxRect; style->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt2, painter, w); - leftPosition = opt2.rect.right() + m_padding; + leftPosition = styleCheckBoxRect.right() + m_padding; // Draw icon const int iconSize = 32; const int iconYPos = center - (iconSize / 2); QRect iconRect(leftPosition, iconYPos, iconSize, iconSize); + QRect visualIconRect = style->visualRect(direction, opt.rect, iconRect); QPixmap pixmap = index.data(Qt::DecorationRole).value().pixmap(iconSize); - painter->drawPixmap(iconRect, pixmap); + painter->drawPixmap(visualIconRect, pixmap); leftPosition = iconRect.right() + m_padding; // Draw script name @@ -88,8 +92,9 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte const int rightTitleEdge = rightPosition - m_padding; const int leftPosForVersion = titleMetrics.width(name) + m_padding; QRect nameRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height()); + QRect visualNameRect = style->visualRect(direction, opt.rect, nameRect); painter->setFont(titleFont); - style->drawItemText(painter, nameRect, Qt::AlignLeft, opt.palette, true, name, colorRole); + style->drawItemText(painter, visualNameRect, Qt::AlignLeft, opt.palette, true, name, colorRole); // Draw version const QString &version = index.data(Qt::UserRole).toString(); @@ -101,7 +106,7 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte // Draw description const int infoYPos = nameRect.bottom() + opt.fontMetrics.leading(); - QRect infoRect(nameRect.x(), infoYPos, nameRect.width(), opt.fontMetrics.height()); + QRect infoRect(visualNameRect.x(), infoYPos, nameRect.width(), opt.fontMetrics.height()); const QString &info = opt.fontMetrics.elidedText(index.data(Qt::UserRole + 1).toString(), Qt::ElideRight, infoRect.width()); painter->setFont(opt.font); style->drawItemText(painter, infoRect, Qt::TextSingleLine | Qt::AlignLeft, opt.palette, true, info, colorRole); @@ -110,7 +115,8 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte const int removeIconSize = 16; const int removeIconYPos = center - (removeIconSize / 2); QRect removeIconRect(rightPosition, removeIconYPos, removeIconSize, removeIconSize); - painter->drawPixmap(removeIconRect, m_removePixmap); + QRect visualRemoveIconRect = style->visualRect(direction, opt.rect, removeIconRect); + painter->drawPixmap(visualRemoveIconRect, m_removePixmap); } QSize GM_SettingsListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const diff --git a/src/plugins/GreaseMonkey/settings/gm_settingslistwidget.cpp b/src/plugins/GreaseMonkey/settings/gm_settingslistwidget.cpp index 69e9fb14b..09a974428 100644 --- a/src/plugins/GreaseMonkey/settings/gm_settingslistwidget.cpp +++ b/src/plugins/GreaseMonkey/settings/gm_settingslistwidget.cpp @@ -62,5 +62,5 @@ bool GM_SettingsListWidget::containsRemoveIcon(const QPoint &pos) const QRect removeIconRect(removeIconPosition, removeIconYPos, 16, 16); - return removeIconRect.contains(pos); + return style()->visualRect(layoutDirection(), rect, removeIconRect).contains(pos); }