29 lines
926 B
C++
29 lines
926 B
C++
#include "FileIconProvider.h"
|
|
#include <QFileIconProvider>
|
|
#include <QFileInfo>
|
|
#include <QIcon>
|
|
|
|
FileIconProvider::FileIconProvider()
|
|
: QQuickImageProvider(QQuickImageProvider::Image)
|
|
{}
|
|
|
|
QImage FileIconProvider::requestImage(const QString &id, QSize *size,
|
|
const QSize &requestedSize)
|
|
{
|
|
// QML strips the leading slash from the URL path component, so restore it on Unix.
|
|
QString filePath = id.startsWith(QLatin1Char('/')) ? id : QLatin1Char('/') + id;
|
|
|
|
QFileIconProvider iconProvider;
|
|
QIcon icon = iconProvider.icon(QFileInfo(filePath));
|
|
if (icon.isNull())
|
|
icon = iconProvider.icon(QFileIconProvider::File);
|
|
|
|
QSize target = (requestedSize.width() > 0 && requestedSize.height() > 0)
|
|
? requestedSize : QSize(60, 80);
|
|
|
|
QImage image = icon.pixmap(target).toImage();
|
|
if (size)
|
|
*size = image.size();
|
|
return image;
|
|
}
|