Skycoder42
7 years ago
14 changed files with 145 additions and 22 deletions
After Width: | Height: | Size: 260 B |
After Width: | Height: | Size: 432 B |
After Width: | Height: | Size: 260 B |
After Width: | Height: | Size: 214 B |
@ -0,0 +1,8 @@ |
|||
<RCC> |
|||
<qresource prefix="/de/skycoder42/qtmvvm/quick/icons"> |
|||
<file alias="ic_error.svg">icons/ic_error_white_24px.svg</file> |
|||
<file alias="ic_help.svg">icons/ic_help_white_24px.svg</file> |
|||
<file alias="ic_info.svg">icons/ic_info_white_24px.svg</file> |
|||
<file alias="ic_warning.svg">icons/ic_warning_white_24px.svg</file> |
|||
</qresource> |
|||
</RCC> |
@ -0,0 +1,39 @@ |
|||
#include "svgimageprovider.h" |
|||
|
|||
#include <QtGui/QGuiApplication> |
|||
#include <QtGui/QPainter> |
|||
#include <QtGui/QScreen> |
|||
|
|||
#include <QtSvg/QSvgRenderer> |
|||
|
|||
using namespace QtMvvm; |
|||
|
|||
SvgImageProvider::SvgImageProvider() : |
|||
QQuickImageProvider(Image) |
|||
{} |
|||
|
|||
QImage SvgImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize) |
|||
{ |
|||
auto path = QStringLiteral(":/%1.svg").arg(id); |
|||
QScopedPointer<QSvgRenderer, QScopedPointerDeleteLater> renderer(new QSvgRenderer(path)); |
|||
if(renderer->isValid()) { |
|||
QSize tSize; |
|||
if(requestedSize.isValid()) |
|||
tSize = requestedSize; |
|||
else { |
|||
tSize = renderer->defaultSize(); |
|||
tSize *= QGuiApplication::primaryScreen()->devicePixelRatio(); |
|||
} |
|||
|
|||
QImage image(tSize, QImage::Format_ARGB32_Premultiplied); |
|||
image.fill(Qt::transparent); |
|||
QPainter painter(&image); |
|||
renderer->render(&painter); |
|||
*size = image.size(); |
|||
|
|||
return image; |
|||
} else { |
|||
*size = QSize(); |
|||
return QImage(); |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
#ifndef QTMVVM_SVGIMAGEPROVIDER_H |
|||
#define QTMVVM_SVGIMAGEPROVIDER_H |
|||
|
|||
#include <QtQuick/QQuickImageProvider> |
|||
|
|||
namespace QtMvvm { |
|||
|
|||
class SvgImageProvider : public QQuickImageProvider |
|||
{ |
|||
public: |
|||
explicit SvgImageProvider(); |
|||
|
|||
QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override; |
|||
}; |
|||
|
|||
} |
|||
|
|||
#endif // QTMVVM_SVGIMAGEPROVIDER_H
|
Loading…
Reference in new issue