Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief XDG QQuickImageProvider (original source from http://gitlab.unique-conception.org/qt-libraries/lib-qt-qml-tricks)
5 : * @author Gabriel Rauter (rauter.gabriel@gmail.com)
6 : * @author Thomas Boutroue (thebootroo@gmail.com)
7 : * @copyright relicenced under BSD License (see LICENSE.md or https://www.libelektra.org)
8 : */
9 :
10 : #include "QQuickThemeIconProvider.hpp"
11 :
12 : #include <QDebug>
13 : #include <QIcon>
14 :
15 0 : QQuickThemeIconProvider::QQuickThemeIconProvider (void) : QQuickImageProvider (QQuickImageProvider::Pixmap)
16 : {
17 0 : }
18 :
19 0 : QPixmap QQuickThemeIconProvider::requestPixmap (const QString & id, QSize * actualSize, const QSize & requestedSize)
20 : {
21 0 : static const QPixmap EMPTY_PIX = QPixmap ();
22 : static const QSize DEFAULT_SIZE = QSize (128, 128);
23 0 : QPixmap ret = EMPTY_PIX;
24 0 : const QString name = id;
25 0 : const QIcon icon = QIcon::fromTheme (name, QIcon (":/qml/icons/" + name + ".png"));
26 0 : if (!icon.isNull ())
27 : {
28 0 : ret = icon.pixmap (requestedSize.isValid () ? requestedSize : DEFAULT_SIZE);
29 0 : if (!ret.isNull ())
30 : {
31 0 : if (actualSize != Q_NULLPTR)
32 : {
33 0 : (*actualSize) = ret.size ();
34 : }
35 : }
36 : }
37 : else
38 : {
39 0 : qWarning () << "No icon named" << name << "in theme !";
40 : }
41 0 : return ret;
42 : }
|