6#include "QskGraphicImageProvider.h"
8#include "QskGraphicProvider.h"
9#include "QskGraphicTextureFactory.h"
11static inline QSize qskGraphicSize(
const QskGraphic& graphic,
12 const QSize& requestedSize, QSize* result )
14 const QSizeF defaultSize = graphic.defaultSize();
16 if ( requestedSize.width() == 0 || requestedSize.height() == 0 )
19 if ( requestedSize.width() > 0 && requestedSize.height() > 0 )
22 if ( defaultSize.isEmpty() )
25 if ( requestedSize.height() < 0 )
27 const auto f = requestedSize.width() / defaultSize.width();
28 return QSize( requestedSize.width(),
29 static_cast< int >( f * defaultSize.height() ) );
32 if ( requestedSize.width() < 0 )
34 const auto f = requestedSize.height() / defaultSize.height();
35 return QSize(
static_cast< int >( f * defaultSize.width() ),
36 static_cast< int >( requestedSize.height() ) );
39 const auto ret = defaultSize.toSize();
47QskGraphicImageProvider::QskGraphicImageProvider(
48 const QString& providerId, ImageType type )
49 : QQuickImageProvider( type )
50 , m_providerId( providerId )
54QskGraphicImageProvider::~QskGraphicImageProvider()
58QString QskGraphicImageProvider::graphicProviderId()
const
63QImage QskGraphicImageProvider::requestImage(
64 const QString&
id, QSize* size,
const QSize& requestedSize )
68 if ( requestedSize.width() == 0 || requestedSize.height() == 0 )
74 static QImage dummy( 1, 1, QImage::Format_ARGB32_Premultiplied );
78 const auto graphic = requestGraphic(
id );
79 if ( graphic ==
nullptr )
82 const QSize sz = qskGraphicSize( *graphic, requestedSize, size );
83 return graphic->toImage( sz, Qt::KeepAspectRatio );
86QPixmap QskGraphicImageProvider::requestPixmap(
87 const QString&
id, QSize* size,
const QSize& requestedSize )
89 if ( requestedSize.width() == 0 || requestedSize.height() == 0 )
95 static QPixmap dummy( 1, 1 );
99 const auto graphic = requestGraphic(
id );
100 if ( graphic ==
nullptr )
103 const QSize sz = qskGraphicSize( *graphic, requestedSize, size );
104 return graphic->toPixmap( sz, Qt::KeepAspectRatio );
107QQuickTextureFactory* QskGraphicImageProvider::requestTexture(
108 const QString&
id, QSize* size,
const QSize& requestedSize )
110 if ( requestedSize.width() == 0 || requestedSize.height() == 0 )
113 const auto graphic = requestGraphic(
id );
114 if ( graphic ==
nullptr )
117 const QSize sz = qskGraphicSize( *graphic, requestedSize, size );
121const QskGraphic* QskGraphicImageProvider::requestGraphic(
const QString&
id )
const
123 if (
auto graphicProvider = Qsk::graphicProvider( m_providerId ) )
124 return graphicProvider->requestGraphic(
id );
A paint device for scalable graphics.