1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

[GreaseMonkey] Fixed buttons in script list with RTL layout.

This commit is contained in:
nowrep 2013-06-10 23:06:17 +02:00
parent 6abb37d6a1
commit f4315304f7
2 changed files with 13 additions and 7 deletions

View File

@ -43,6 +43,7 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte
const QWidget* w = opt.widget; const QWidget* w = opt.widget;
const QStyle* style = w ? w->style() : QApplication::style(); 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 height = opt.rect.height();
const int center = height / 2 + opt.rect.top(); const int center = height / 2 + opt.rect.top();
@ -70,16 +71,19 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte
QStyleOptionViewItemV4 opt2 = opt; QStyleOptionViewItemV4 opt2 = opt;
opt2.checkState == Qt::Checked ? opt2.state |= QStyle::State_On : opt2.state |= QStyle::State_Off; opt2.checkState == Qt::Checked ? opt2.state |= QStyle::State_On : opt2.state |= QStyle::State_Off;
QRect styleCheckBoxRect = style->subElementRect(QStyle::SE_ViewItemCheckIndicator, &opt2, w); 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); style->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt2, painter, w);
leftPosition = opt2.rect.right() + m_padding; leftPosition = styleCheckBoxRect.right() + m_padding;
// Draw icon // Draw icon
const int iconSize = 32; const int iconSize = 32;
const int iconYPos = center - (iconSize / 2); const int iconYPos = center - (iconSize / 2);
QRect iconRect(leftPosition, iconYPos, iconSize, iconSize); QRect iconRect(leftPosition, iconYPos, iconSize, iconSize);
QRect visualIconRect = style->visualRect(direction, opt.rect, iconRect);
QPixmap pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(iconSize); QPixmap pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(iconSize);
painter->drawPixmap(iconRect, pixmap); painter->drawPixmap(visualIconRect, pixmap);
leftPosition = iconRect.right() + m_padding; leftPosition = iconRect.right() + m_padding;
// Draw script name // Draw script name
@ -88,8 +92,9 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte
const int rightTitleEdge = rightPosition - m_padding; const int rightTitleEdge = rightPosition - m_padding;
const int leftPosForVersion = titleMetrics.width(name) + m_padding; const int leftPosForVersion = titleMetrics.width(name) + m_padding;
QRect nameRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height()); QRect nameRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height());
QRect visualNameRect = style->visualRect(direction, opt.rect, nameRect);
painter->setFont(titleFont); 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 // Draw version
const QString &version = index.data(Qt::UserRole).toString(); const QString &version = index.data(Qt::UserRole).toString();
@ -101,7 +106,7 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte
// Draw description // Draw description
const int infoYPos = nameRect.bottom() + opt.fontMetrics.leading(); 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()); const QString &info = opt.fontMetrics.elidedText(index.data(Qt::UserRole + 1).toString(), Qt::ElideRight, infoRect.width());
painter->setFont(opt.font); painter->setFont(opt.font);
style->drawItemText(painter, infoRect, Qt::TextSingleLine | Qt::AlignLeft, opt.palette, true, info, colorRole); 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 removeIconSize = 16;
const int removeIconYPos = center - (removeIconSize / 2); const int removeIconYPos = center - (removeIconSize / 2);
QRect removeIconRect(rightPosition, removeIconYPos, removeIconSize, removeIconSize); 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 QSize GM_SettingsListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const

View File

@ -62,5 +62,5 @@ bool GM_SettingsListWidget::containsRemoveIcon(const QPoint &pos) const
QRect removeIconRect(removeIconPosition, removeIconYPos, 16, 16); QRect removeIconRect(removeIconPosition, removeIconYPos, 16, 16);
return removeIconRect.contains(pos); return style()->visualRect(layoutDirection(), rect, removeIconRect).contains(pos);
} }