|
| 1 | +/* |
| 2 | + * QML Material - An application framework implementing Material Design. |
| 3 | + * Copyright (C) 2015 Ricardo Vieira <[email protected]> |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU Lesser General Public License as |
| 7 | + * published by the Free Software Foundation, either version 2.1 of the |
| 8 | + * License, or (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU Lesser General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU Lesser General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | +#include <qqmlextensionplugin.h> |
| 20 | + |
| 21 | +#include <qqmlengine.h> |
| 22 | +#include <qquickimageprovider.h> |
| 23 | +#include <QImage> |
| 24 | +#include <QPainter> |
| 25 | + |
| 26 | +class MaterialIconProvider : public QQuickImageProvider |
| 27 | +{ |
| 28 | +public: |
| 29 | + MaterialIconProvider() |
| 30 | + : QQuickImageProvider(QQuickImageProvider::Pixmap) |
| 31 | + { |
| 32 | + } |
| 33 | + |
| 34 | + QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) |
| 35 | + { |
| 36 | + int width = 100; |
| 37 | + int height = 50; |
| 38 | + QImage icon = QImage("/lib/qt/qml/Material/icons/" + id + ".svg"); |
| 39 | + |
| 40 | + if (size) |
| 41 | + *size = QSize(width, height); |
| 42 | + |
| 43 | + return QPixmap::fromImage(icon); |
| 44 | + } |
| 45 | +}; |
| 46 | + |
| 47 | +class ImageProviderExtensionPlugin : public QQmlExtensionPlugin |
| 48 | +{ |
| 49 | + Q_OBJECT |
| 50 | + Q_PLUGIN_METADATA(IID "Material") |
| 51 | +public: |
| 52 | + void registerTypes(const char *uri) |
| 53 | + { |
| 54 | + Q_UNUSED(uri); |
| 55 | + } |
| 56 | + |
| 57 | + void initializeEngine(QQmlEngine *engine, const char *uri) |
| 58 | + { |
| 59 | + Q_UNUSED(uri); |
| 60 | + engine->addImageProvider("material", new MaterialIconProvider); |
| 61 | + } |
| 62 | + |
| 63 | +}; |
| 64 | + |
| 65 | +#include "materialiconprovider.moc" |
0 commit comments