File indexing completed on 2024-03-24 17:26:26

0001 #include "IconProvider.h"
0002 #include <QDebug>
0003 #include <QIcon>
0004 
0005 IconProvider::IconProvider() :
0006     QQuickImageProvider(QQuickImageProvider::Pixmap)
0007 {
0008 
0009 }
0010 
0011 QPixmap IconProvider::requestPixmap(const QString &id, QSize *actualSize, const QSize &requestedSize)
0012 {
0013     QSize size(requestedSize);
0014     if (size.height() <= 0) {
0015         size.setHeight(128);
0016     }
0017     if (size.width() <= 0) {
0018         size.setWidth(128);
0019     }
0020 
0021     QIcon icon(QIcon::fromTheme(id));
0022     QPixmap pixmap(icon.pixmap(qMin(size.height(), size.width())));
0023 
0024     if (actualSize) {
0025         *actualSize = pixmap.size();
0026     }
0027 
0028     return pixmap;
0029 }
0030 
0031 
0032 QQmlImageProviderBase::Flags IconProvider::flags() const
0033 {
0034     return QQmlImageProviderBase::ForceAsynchronousImageLoading;
0035 }