| 40 | } |
| 41 | |
| 42 | void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const |
| 43 | { |
| 44 | GM_Script *script = static_cast<GM_Script*>(index.data(Qt::UserRole + 10).value<void*>()); |
| 45 | if (!script) |
| 46 | return; |
| 47 | |
| 48 | QStyleOptionViewItem opt = option; |
| 49 | initStyleOption(&opt, index); |
| 50 | |
| 51 | const QWidget* w = opt.widget; |
| 52 | const QStyle* style = w ? w->style() : QApplication::style(); |
| 53 | const int height = opt.rect.height(); |
| 54 | const int center = height / 2 + opt.rect.top(); |
| 55 | |
| 56 | // forced to LTR, see issue#967 |
| 57 | painter->setLayoutDirection(Qt::LeftToRight); |
| 58 | |
| 59 | // Prepare title font |
| 60 | QFont titleFont = opt.font; |
| 61 | titleFont.setBold(true); |
| 62 | titleFont.setPointSize(titleFont.pointSize() + 1); |
| 63 | |
| 64 | const QFontMetrics titleMetrics(titleFont); |
| 65 | const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text; |
| 66 | |
| 67 | QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; |
| 68 | if (cg == QPalette::Normal && !(opt.state & QStyle::State_Active)) { |
| 69 | cg = QPalette::Inactive; |
| 70 | } |
| 71 | |
| 72 | #ifdef Q_OS_WIN |
| 73 | opt.palette.setColor(QPalette::All, QPalette::HighlightedText, opt.palette.color(QPalette::Active, QPalette::Text)); |
| 74 | opt.palette.setColor(QPalette::All, QPalette::Highlight, opt.palette.base().color().darker(108)); |
| 75 | #endif |
| 76 | |
| 77 | QPalette textPalette = opt.palette; |
| 78 | textPalette.setCurrentColorGroup(cg); |
| 79 | |
| 80 | int leftPosition = m_padding; |
| 81 | int rightPosition = opt.rect.right() - m_padding - 16; // 16 for remove button |
| 82 | if (!script->downloadUrl().isEmpty()) |
| 83 | rightPosition -= m_padding + 16; // 16 for update button |
| 84 | |
| 85 | // Draw background |
| 86 | style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, w); |
| 87 | |
| 88 | // Draw checkbox |
| 89 | const int checkboxSize = 18; |
| 90 | const int checkboxYPos = center - (checkboxSize / 2); |
| 91 | QStyleOptionViewItem opt2 = opt; |
| 92 | opt2.checkState == Qt::Checked ? opt2.state |= QStyle::State_On : opt2.state |= QStyle::State_Off; |
| 93 | QRect styleCheckBoxRect = style->subElementRect(QStyle::SE_ItemViewItemCheckIndicator, &opt2, w); |
| 94 | opt2.rect = QRect(leftPosition, checkboxYPos, styleCheckBoxRect.width(), styleCheckBoxRect.height()); |
| 95 | style->drawPrimitive(QStyle::PE_IndicatorItemViewItemCheck, &opt2, painter, w); |
| 96 | leftPosition = opt2.rect.right() + m_padding; |
| 97 | |
| 98 | // Draw icon |
| 99 | const int iconSize = 32; |
nothing calls this directly
no test coverage detected