10#include <QApplication>
36 QSize scaled =
source.size().scaled(
iconSize, Qt::KeepAspectRatio);
37 qreal
scale = scaled.width()/(qreal)(
source.width());
44 int scaleInt = qRound(scale);
45 result =
source.scaled(scaleInt*
source.size(), Qt::KeepAspectRatio, Qt::FastTransformation);
47 result = result.scaled(
iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
49 result =
source.scaled(
iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
57 result = result.convertToFormat(QImage::Format_ARGB32)
61 QPainter painter(&result);
62 QColor textColor = qApp->palette().color(QPalette::Text);
63 QColor backgroundColor = qApp->palette().color(QPalette::Window);
65 painter.setPen(blendedColor);
66 painter.setBrush(QBrush(blendedColor));
68 painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
69 painter.drawRect(result.rect().adjusted(0, 0, -1, -1));
72 painter.setPen(blendedColorBrighter);
73 painter.setBrush(QBrush());
75 painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
76 painter.drawRect(result.rect().adjusted(0, 0, -1, -1));
80 return QIcon(QPixmap::fromImage(result));
93 || mimeType ==
"application/x-krita-archive"
94 || mimeType ==
"image/openraster") {
98 QString thumbnailpath;
99 if (store->hasFile(QString(
"Thumbnails/thumbnail.png"))){
100 thumbnailpath = QString(
"Thumbnails/thumbnail.png");
102 else if (store->hasFile(QString(
"mergedimage.png"))) {
103 thumbnailpath = QString(
"mergedimage.png");
105 else if (store->hasFile(QString(
"preview.png"))) {
106 thumbnailpath = QString(
"preview.png");
108 if (!thumbnailpath.isEmpty() && store->open(thumbnailpath)) {
110 QByteArray bytes = store->read(store->size());
113 img.loadFromData(bytes);
124 }
else if (mimeType ==
"image/tiff" || mimeType ==
"image/x-tiff" || mimeType ==
"image/jxl") {
128 doc->setFileBatchMode(
true);
133 QSize imageSize =
bounds.size();
134 if (imageSize.width() >
iconSize.width() || imageSize.height() >
iconSize.height()) {
135 imageSize.scale(
iconSize, Qt::KeepAspectRatio);
137 const QImage &thumbnail = projection->
createThumbnail(imageSize.width(), imageSize.height(),
bounds);
138 icon = createIcon(thumbnail,
iconSize);
KisMagneticGraph::vertex_descriptor source(typename KisMagneticGraph::edge_descriptor e, KisMagneticGraph g)
#define KIS_DECLARE_STATIC_INITIALIZER
int iconSize(qreal width, qreal height)
static QByteArray nativeFormatMimeType()
The KisFileIconCreator class creates a thumbnail from a file on disk.
bool createFileIcon(QString path, QIcon &icon, qreal devicePixelRatioF, QSize iconSize) override
createFileIcon creates an icon from the file on disk
static QString mimeTypeForFile(const QString &file, bool checkExistingFiles=true)
Find the mimetype for the given filename. The filename must include a suffix.
QImage createThumbnail(qint32 maxw, qint32 maxh, QRect rect, qreal oversample=1, KoColorConversionTransformation::Intent renderingIntent=KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::ConversionFlags conversionFlags=KoColorConversionTransformation::internalConversionFlags())
QRect exactBounds() const
static KisPart * instance()
static KisAbstractFileIconCreator * s_iconCreator
static KoStore * createStore(const QString &fileName, Mode mode, const QByteArray &appIdentification=QByteArray(), Backend backend=Auto, bool writeMimetype=true)
QColor blendColors(const QColor &c1, const QColor &c2, qreal r1)