137 if (preview.isNull()) {
138 preview = QImage(512, 512, QImage::Format_RGB32);
139 preview.fill(Qt::red);
142 qreal devicePixelRatioF = painter->device()->devicePixelRatioF();
144 QRect paintRect = option.rect.adjusted(1, 1, -1, -1);
146 QImage previewHighDpi =
148 paintRect.size() * devicePixelRatioF,
149 Qt::IgnoreAspectRatio,
150 Qt::SmoothTransformation);
151 previewHighDpi.setDevicePixelRatio(devicePixelRatioF);
152 painter->drawImage(paintRect.x(), paintRect.y(), previewHighDpi);
156 QPixmap pixmap = icon.pixmap(QSize(16,16));
157 painter->drawPixmap(paintRect.x() + 3, paintRect.y() + 3, pixmap);
162 icon.paint(painter, QRect(paintRect.x() + paintRect.height() - 25, paintRect.y() + paintRect.height() - 25, 25, 25));
165 if (option.state & QStyle::State_Selected) {
166 painter->setCompositionMode(QPainter::CompositionMode_HardLight);
167 painter->setOpacity(1.0);
168 painter->fillRect(option.rect, option.palette.highlight());
171 painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
172 painter->setPen(QPen(option.palette.highlight(), 4, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
173 QRect selectedBorder = option.rect.adjusted(2 , 2, -2, -2);
174 painter->drawRect(selectedBorder);
183 qreal devicePixelRatioF = painter->device()->devicePixelRatioF();
184 const bool isSelected = option.state & QStyle::State_Selected;
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);
190 textColor = textColor.lightnessF() < 0.5 ? QColor(Qt::black) : QColor(Qt::white);
193 painter->fillRect(option.rect, borderColor);
194 QRect innerRect = option.rect.adjusted(2, 2, -2, -2);
195 painter->fillRect(innerRect, backgroundColor);
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);
205 painter->setCompositionMode(QPainter::CompositionMode_HardLight);
206 painter->setOpacity(1.0);
207 painter->fillRect(innerRect, accentColor);
208 painter->setCompositionMode(QPainter::CompositionMode_SourceOver);
215 QRect imageRect = innerRect.adjusted(2, 2, -2, -2);
217 if (preview.isNull()) {
218 preview = QImage(imageRect.height() * devicePixelRatioF,
219 imageRect.height() * devicePixelRatioF,
220 QImage::Format_RGB32);
221 preview.fill(Qt::red);
227 QSize(imageRect.height(), imageRect.height()) * devicePixelRatioF,
228 Qt::IgnoreAspectRatio,
229 Qt::SmoothTransformation);
231 previewHighDpi.setDevicePixelRatio(devicePixelRatioF);
233 painter->drawImage(imageRect.topLeft(), previewHighDpi);
234 innerRect = innerRect.adjusted(innerRect.height(), 2, -2, 0);
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;
244 QRect strokeRect = innerRect;
245 strokeRect.setHeight(qMax(10, innerRect.height() - (textAreaHeight - textAreaTopTrim)));
247 QSize previewSize = strokeRect.size() * devicePixelRatioF;
248 const QString paintOpId =
253 if (strokePreview.isNull()) {
254 strokePreview = QImage(previewSize, QImage::Format_ARGB32_Premultiplied);
255 strokePreview.fill(Qt::transparent);
258 strokePreview.setDevicePixelRatio(devicePixelRatioF);
259 painter->drawImage(strokeRect.topLeft(), strokePreview);
263 .replace(QLatin1Char(
'_'), QLatin1Char(
' '));
265 presetDisplayName.append(QLatin1Char(
'*'));
267 QString elidedName = fm.elidedText(presetDisplayName, Qt::ElideRight, innerRect.width() - 14);
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);
278 QPixmap pixmap = icon.pixmap(QSize(16, 16));
279 painter->drawPixmap(innerRect.x() + 3, innerRect.y() + 3, pixmap);
284 icon.paint(painter, QRect(innerRect.right() - 25, innerRect.y() + 3, 22, 22));
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);