mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
[GreaseMonkey] set list of userscripts as LTR widget.
-its contents are in LTR regardless of interface language. -Closes #967
This commit is contained in:
parent
e690dbdd2c
commit
b472bd2021
@ -43,10 +43,12 @@ 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();
|
||||
|
||||
// forced to LTR, see issue#967
|
||||
painter->setLayoutDirection(Qt::LeftToRight);
|
||||
|
||||
// Prepare title font
|
||||
QFont titleFont = opt.font;
|
||||
titleFont.setBold(true);
|
||||
@ -71,19 +73,16 @@ 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);
|
||||
styleCheckBoxRect.setRect(leftPosition, checkboxYPos, styleCheckBoxRect.width(), styleCheckBoxRect.height());
|
||||
QRect visualCheckBoxRect = style->visualRect(direction, opt.rect, styleCheckBoxRect);
|
||||
opt2.rect = visualCheckBoxRect;
|
||||
opt2.rect = QRect(leftPosition, checkboxYPos, styleCheckBoxRect.width(), styleCheckBoxRect.height());
|
||||
style->drawPrimitive(QStyle::PE_IndicatorViewItemCheck, &opt2, painter, w);
|
||||
leftPosition = styleCheckBoxRect.right() + m_padding;
|
||||
leftPosition = opt2.rect.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<QIcon>().pixmap(iconSize);
|
||||
painter->drawPixmap(visualIconRect, pixmap);
|
||||
painter->drawPixmap(iconRect, pixmap);
|
||||
leftPosition = iconRect.right() + m_padding;
|
||||
|
||||
// Draw script name
|
||||
@ -92,9 +91,8 @@ 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, visualNameRect, Qt::AlignLeft, opt.palette, true, name, colorRole);
|
||||
style->drawItemText(painter, nameRect, Qt::AlignLeft, opt.palette, true, name, colorRole);
|
||||
|
||||
// Draw version
|
||||
const QString &version = index.data(Qt::UserRole).toString();
|
||||
@ -106,7 +104,7 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte
|
||||
|
||||
// Draw description
|
||||
const int infoYPos = nameRect.bottom() + opt.fontMetrics.leading();
|
||||
QRect infoRect(visualNameRect.x(), infoYPos, nameRect.width(), opt.fontMetrics.height());
|
||||
QRect infoRect(nameRect.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);
|
||||
@ -115,8 +113,7 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte
|
||||
const int removeIconSize = 16;
|
||||
const int removeIconYPos = center - (removeIconSize / 2);
|
||||
QRect removeIconRect(rightPosition, removeIconYPos, removeIconSize, removeIconSize);
|
||||
QRect visualRemoveIconRect = style->visualRect(direction, opt.rect, removeIconRect);
|
||||
painter->drawPixmap(visualRemoveIconRect, m_removePixmap);
|
||||
painter->drawPixmap(removeIconRect, m_removePixmap);
|
||||
}
|
||||
|
||||
QSize GM_SettingsListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
|
@ -25,6 +25,8 @@ GM_SettingsListWidget::GM_SettingsListWidget(QWidget* parent)
|
||||
: QListWidget(parent)
|
||||
, m_delegate(new GM_SettingsListDelegate(this))
|
||||
{
|
||||
// forced to LTR, see issue#967
|
||||
setLayoutDirection(Qt::LeftToRight);
|
||||
setItemDelegate(m_delegate);
|
||||
}
|
||||
|
||||
@ -62,5 +64,5 @@ bool GM_SettingsListWidget::containsRemoveIcon(const QPoint &pos) const
|
||||
|
||||
QRect removeIconRect(removeIconPosition, removeIconYPos, 16, 16);
|
||||
|
||||
return style()->visualRect(layoutDirection(), rect, removeIconRect).contains(pos);
|
||||
return removeIconRect.contains(pos);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user