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

Added RTL support to PluginListDelegate class.

This commit is contained in:
S. Razi Alavizadeh 2012-08-14 01:51:37 +04:30
parent 1fea4cdbc3
commit d72e7bed7b

View File

@ -35,6 +35,7 @@ void PluginListDelegate::paint(QPainter* painter, const QStyleOptionViewItem &op
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();
@ -62,16 +63,19 @@ void PluginListDelegate::paint(QPainter* painter, const QStyleOptionViewItem &op
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<QIcon>().pixmap(iconSize);
painter->drawPixmap(iconRect, pixmap);
painter->drawPixmap(visualIconRect, pixmap);
leftPosition = iconRect.right() + m_padding;
// Draw plugin name
@ -80,8 +84,9 @@ void PluginListDelegate::paint(QPainter* painter, const QStyleOptionViewItem &op
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();
@ -93,7 +98,7 @@ void PluginListDelegate::paint(QPainter* painter, const QStyleOptionViewItem &op
// Draw info
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);