75{
76 painter->save();
77 painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
78 if (!(option.state & QStyle::State_Enabled)) {
79 painter->setOpacity(0.2);
80 }
81
82 if (!index.isValid()) {
83 painter->restore();
84 return;
85 }
86
88
90
91 if (preview.isNull()) {
92 preview = QImage(512, 512, QImage::Format_RGB32);
93 preview.fill(Qt::red);
94 }
95
96 qreal devicePixelRatioF = painter->device()->devicePixelRatioF();
97
98 QRect paintRect = option.rect.adjusted(1, 1, -1, -1);
100 QImage previewHighDpi =
102 paintRect.size() * devicePixelRatioF,
103 Qt::IgnoreAspectRatio,
104 Qt::SmoothTransformation);
105 previewHighDpi.setDevicePixelRatio(devicePixelRatioF);
106 painter->drawImage(paintRect.x(), paintRect.y(), previewHighDpi);
107 }
108 else {
109 QSize pixSize(paintRect.height(), paintRect.height());
111 pixSize * devicePixelRatioF,
112 Qt::KeepAspectRatio,
113 Qt::SmoothTransformation);
114 previewHighDpi.setDevicePixelRatio(devicePixelRatioF);
115 painter->drawImage(paintRect.x(), paintRect.y(), previewHighDpi);
116
117
118
119 QString dirtyPresetIndicator = QString("");
121 dirtyPresetIndicator = QString("*");
122 }
123
124
125
126
127
128
129
130
131
132
133
134
135
136
138 painter->drawText(pixSize.width() + 10, option.rect.y() + option.rect.height() - 10, presetDisplayName.append(dirtyPresetIndicator));
139
140 }
141
144 QPixmap
pixmap = icon.pixmap(QSize(16,16));
145 painter->drawPixmap(paintRect.x() + 3, paintRect.y() + 3, pixmap);
146 }
147
150 icon.paint(painter, QRect(paintRect.x() + paintRect.height() - 25, paintRect.y() + paintRect.height() - 25, 25, 25));
151 }
152
153 if (option.state & QStyle::State_Selected) {
154 painter->setCompositionMode(QPainter::CompositionMode_HardLight);
155 painter->setOpacity(1.0);
156 painter->fillRect(option.rect, option.palette.highlight());
157
158
159 painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
160 painter->setPen(QPen(option.palette.highlight(), 4, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
161 QRect selectedBorder = option.rect.adjusted(2 , 2, -2, -2);
162 painter->drawRect(selectedBorder);
163 }
164
165 painter->restore();
166
167}
@ Dirty
A dirty resource is one that has been modified locally but not saved.
@ BrokenStatus
Whether the resource is broken (bool)
static KisResourceThumbnailCache * instance()
QImage getImage(const QModelIndex &index, const QSize size=QSize(-1, -1), Qt::AspectRatioMode aspectMode=Qt::IgnoreAspectRatio, Qt::TransformationMode transformMode=Qt::FastTransformation)
QIcon loadIcon(const QString &name)