29{
30 if (!index.isValid()) return;
31
32 painter->save();
33
38
40
41 qreal devicePixelRatioF = painter->device()->devicePixelRatioF();
42
43 if (thumbnail.isNull()) {
44
45 thumbnail =
koIcon(
"warning").pixmap(option.decorationSize).toImage();
46 if (storageType == "Folder") {
47 thumbnail =
koIcon(
"document-open").pixmap(option.decorationSize).toImage();
48 }
49 else if (storageType == "Adobe Style Library") {
50 thumbnail =
koIcon(
"layer-style-enabled").pixmap(option.decorationSize).toImage();
51 if (!thumbnail.isNull()) {
52 thumbnail = thumbnail.scaled(option.decorationSize, Qt::KeepAspectRatio, Qt::FastTransformation);
53 }
54 }
55 else if (storageType == "Adobe Brush Library") {
56 thumbnail =
koIcon(
"select-all").pixmap(option.decorationSize).toImage();
57 }
58 else if (storageType == "Memory") {
59 if (location != "memory") {
60 thumbnail =
koIcon(
"document-new").pixmap(option.decorationSize).toImage();
61 } else {
62 thumbnail =
koIcon(
"drive-harddisk").pixmap(option.decorationSize).toImage();
63 }
64
65 }
66 else if (storageType == "Bundle") {
67 thumbnail =
koIcon(
"bundle_archive").pixmap(option.decorationSize).toImage();
68 }
69
70 } else {
71 if (!thumbnail.isNull()) {
72 thumbnail = thumbnail.scaled(option.decorationSize*devicePixelRatioF, Qt::KeepAspectRatio, Qt::SmoothTransformation);
73 }
74 thumbnail.setDevicePixelRatio(devicePixelRatioF);
75 }
76
77 QColor penColor(option.palette.text().color());
78
79 QStyleOptionViewItem opt = option;
80
81 if (active) {
82 opt.state = QStyle::State_Sunken;
83 }
84
85 QApplication::style()->drawPrimitive(QStyle::PE_PanelButtonTool, &opt, painter);
86
87 painter->setPen(penColor);
88 painter->drawImage(option.rect.topLeft()+QPoint(4, 4), thumbnail, thumbnail.rect());
89
90
91
92 QStyleOptionButton checkboxOption;
93 checkboxOption.rect = QRect(option.rect.x() + option.decorationSize.width() + 8,
94 option.rect.y() + option.rect.height() - 30,
95 20, 20);
96 checkboxOption.state = active ? QStyle::State_On : QStyle::State_Off;
97 QApplication::style()->drawControl(QStyle::CE_CheckBox, &checkboxOption, painter);
98
99
100
101 QRect text = option.rect;
102 text.setLeft(text.left()+option.decorationSize.width()+8);
103 text.setTop(text.top()+4);
104 painter->drawText(text, Qt::TextWordWrap,
name.split(
"_").join(
" "));
105
106 painter->restore();
107}
#define koIcon(name)
Use these macros for icons without any issues.
const char * name(StandardAction id)