77{
78 painter->save();
79 painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
80 if (!(option.state & QStyle::State_Enabled)) {
81 painter->setOpacity(0.2);
82 }
83
84 if (!index.isValid()) {
85 painter->restore();
86 return;
87 }
88
90
92
93 if (preview.isNull()) {
94 preview = QImage(512, 512, QImage::Format_RGB32);
95 preview.fill(Qt::red);
96 }
97
98 qreal devicePixelRatioF = painter->device()->devicePixelRatioF();
99
100 QRect paintRect = option.rect.adjusted(1, 1, -1, -1);
102 QImage previewHighDpi =
104 paintRect.size() * devicePixelRatioF,
105 Qt::IgnoreAspectRatio,
106 Qt::SmoothTransformation);
107 previewHighDpi.setDevicePixelRatio(devicePixelRatioF);
108 painter->drawImage(paintRect.x(), paintRect.y(), previewHighDpi);
109 }
110 else {
111 QSize pixSize(paintRect.height(), paintRect.height());
113 pixSize * devicePixelRatioF,
114 Qt::KeepAspectRatio,
115 Qt::SmoothTransformation);
116 previewHighDpi.setDevicePixelRatio(devicePixelRatioF);
117 painter->drawImage(paintRect.x(), paintRect.y(), previewHighDpi);
118
119
120
121 QString dirtyPresetIndicator = QString("");
123 dirtyPresetIndicator = QString("*");
124 }
125
126
127
128
129
130
131
132
133
134
135
136
137
138
140 painter->drawText(pixSize.width() + 10, option.rect.y() + option.rect.height() - 10, presetDisplayName.append(dirtyPresetIndicator));
141
142 }
143
146 QPixmap
pixmap = icon.pixmap(QSize(16,16));
147 painter->drawPixmap(paintRect.x() + 3, paintRect.y() + 3, pixmap);
148 }
149
152 icon.paint(painter, QRect(paintRect.x() + paintRect.height() - 25, paintRect.y() + paintRect.height() - 25, 25, 25));
153 }
154
155 if (option.state & QStyle::State_Selected) {
156 painter->setCompositionMode(QPainter::CompositionMode_HardLight);
157 painter->setOpacity(1.0);
158 painter->fillRect(option.rect, option.palette.highlight());
159
160
161 painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
162 painter->setPen(QPen(option.palette.highlight(), 4, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
163 QRect selectedBorder = option.rect.adjusted(2 , 2, -2, -2);
164 painter->drawRect(selectedBorder);
165 }
166
167 painter->restore();
168
169}
@ 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)