179{
182
183 qreal devicePixelRatioF = painter->device()->devicePixelRatioF();
184 const bool isSelected = option.state & QStyle::State_Selected;
185
186 const QColor backgroundColor = option.palette.color(QPalette::Window);
187 const QColor borderColor = option.palette.color(QPalette::Mid);
188 QColor textColor = option.palette.color(QPalette::Text);
189 if (isSelected) {
190 textColor = textColor.lightnessF() < 0.5 ? QColor(Qt::black) : QColor(Qt::white);
191 }
192
193 painter->fillRect(option.rect, borderColor);
194 QRect innerRect = option.rect.adjusted(2, 2, -2, -2);
195 painter->fillRect(innerRect, backgroundColor);
196
197 if (isSelected) {
198 const QColor accentColor = option.palette.highlight().color();
199 const qreal bgLightness = backgroundColor.lightnessF();
200 const qreal accentLightness = accentColor.lightnessF();
201 const bool sameSide =
202 (bgLightness >= 0.5 && accentLightness >= 0.5) ||
203 (bgLightness < 0.5 && accentLightness < 0.5);
204 if (sameSide) {
205 painter->setCompositionMode(QPainter::CompositionMode_HardLight);
206 painter->setOpacity(1.0);
207 painter->fillRect(innerRect, accentColor);
208 painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
209 }
210 }
211
214
215 QRect imageRect = innerRect.adjusted(2, 2, -2, -2);
216
217 if (preview.isNull()) {
218 preview = QImage(imageRect.height() * devicePixelRatioF,
219 imageRect.height() * devicePixelRatioF,
220 QImage::Format_RGB32);
221 preview.fill(Qt::red);
222 }
223
224
226 index,
227 QSize(imageRect.height(), imageRect.height()) * devicePixelRatioF,
228 Qt::IgnoreAspectRatio,
229 Qt::SmoothTransformation);
230
231 previewHighDpi.setDevicePixelRatio(devicePixelRatioF);
232
233 painter->drawImage(imageRect.topLeft(), previewHighDpi);
234 innerRect = innerRect.adjusted(innerRect.height(), 2, -2, 0);
235 }
236
237
238 QFontMetrics fm(painter->font());
239 const int bottomPadding = 1;
240 const int topPadding = 1;
241 const int textAreaHeight = fm.height() + 4 + bottomPadding +topPadding;
242 const int textAreaTopTrim = 3;
243
244 QRect strokeRect = innerRect;
245 strokeRect.setHeight(qMax(10, innerRect.height() - (textAreaHeight - textAreaTopTrim)));
246
247 QSize previewSize = strokeRect.size() * devicePixelRatioF;
248 const QString paintOpId =
251
253 if (strokePreview.isNull()) {
254 strokePreview = QImage(previewSize, QImage::Format_ARGB32_Premultiplied);
255 strokePreview.fill(Qt::transparent);
256 }
257
258 strokePreview.setDevicePixelRatio(devicePixelRatioF);
259 painter->drawImage(strokeRect.topLeft(), strokePreview);
260
262 .toString()
263 .replace(QLatin1Char('_'), QLatin1Char(' '));
264 if (dirty) {
265 presetDisplayName.append(QLatin1Char('*'));
266 }
267 QString elidedName = fm.elidedText(presetDisplayName, Qt::ElideRight, innerRect.width() - 14);
268
269 QRect textRect = innerRect;
270 textRect.setTop(innerRect.bottom() - textAreaHeight + topPadding);
271 textRect.setLeft(innerRect.left() + 7);
272 textRect.setBottom(innerRect.bottom() - bottomPadding);
273 painter->setPen(textColor);
274 painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, elidedName);
275
276 if (dirty) {
278 QPixmap
pixmap = icon.pixmap(QSize(16, 16));
279 painter->drawPixmap(innerRect.x() + 3, innerRect.y() + 3, pixmap);
280 }
281
284 icon.paint(painter, QRect(innerRect.right() - 25, innerRect.y() + 3, 22, 22));
285 }
286
287 if (isSelected) {
288 painter->setPen(QPen(option.palette.highlight(), 4, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
289 QRect selectedBorder = option.rect.adjusted(2, 2, -2, -2);
290 painter->drawRect(selectedBorder);
291 }
292}
@ Dirty
A dirty resource is one that has been modified locally but not saved.
@ BrokenStatus
Whether the resource is broken (bool)
static KisBrushStrokePreviewCache * instance()
static bool needsStripedBackground(const QString &paintOpId)
True if paint engine needs striped background (colorsmudge, deform, filter).
QImage getPreview(int presetId, const QSize &size, qreal pixelRatio)
Get cached preview scaled to size, or placeholder if not cached.
static KisResourceMetaDataModel * resourceMetadataModel()
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)