code cleanup
This commit is contained in:
parent
c9e959e73f
commit
d64f861e33
@ -8,6 +8,42 @@
|
||||
#include "QskGraphicProvider.h"
|
||||
#include "QskGraphicTextureFactory.h"
|
||||
|
||||
static inline QSize qskGraphicSize( const QskGraphic& graphic,
|
||||
const QSize& requestedSize, QSize* result )
|
||||
{
|
||||
const QSizeF defaultSize = graphic.defaultSize();
|
||||
|
||||
if ( requestedSize.width() == 0 || requestedSize.height() == 0 )
|
||||
return QSize( 0, 0 );
|
||||
|
||||
if ( requestedSize.width() > 0 && requestedSize.height() > 0 )
|
||||
return requestedSize;
|
||||
|
||||
if ( defaultSize.isEmpty() )
|
||||
return requestedSize;
|
||||
|
||||
if ( requestedSize.height() < 0 )
|
||||
{
|
||||
const auto f = requestedSize.width() / defaultSize.width();
|
||||
return QSize( requestedSize.width(),
|
||||
static_cast< int >( f * defaultSize.height() ) );
|
||||
}
|
||||
|
||||
if ( requestedSize.width() < 0 )
|
||||
{
|
||||
const auto f = requestedSize.height() / defaultSize.height();
|
||||
return QSize( f * defaultSize.width(),
|
||||
static_cast< int >( requestedSize.height() ) );
|
||||
}
|
||||
|
||||
const auto ret = defaultSize.toSize();
|
||||
|
||||
if ( result )
|
||||
*result = ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
QskGraphicImageProvider::QskGraphicImageProvider(
|
||||
const QString& providerId, ImageType type )
|
||||
: QQuickImageProvider( type )
|
||||
@ -39,15 +75,11 @@ QImage QskGraphicImageProvider::requestImage(
|
||||
return dummy;
|
||||
}
|
||||
|
||||
const QskGraphic* graphic = requestGraphic( id );
|
||||
const auto graphic = requestGraphic( id );
|
||||
if ( graphic == nullptr )
|
||||
return QImage();
|
||||
|
||||
const QSize sz = effectiveSize( requestedSize, graphic->defaultSize() );
|
||||
|
||||
if ( size )
|
||||
*size = sz;
|
||||
|
||||
const QSize sz = qskGraphicSize( *graphic, requestedSize, size );
|
||||
return graphic->toImage( sz, Qt::KeepAspectRatio );
|
||||
}
|
||||
|
||||
@ -64,15 +96,11 @@ QPixmap QskGraphicImageProvider::requestPixmap(
|
||||
return dummy;
|
||||
}
|
||||
|
||||
const QskGraphic* graphic = requestGraphic( id );
|
||||
const auto graphic = requestGraphic( id );
|
||||
if ( graphic == nullptr )
|
||||
return QPixmap();
|
||||
|
||||
const QSize sz = effectiveSize( requestedSize, graphic->defaultSize() );
|
||||
|
||||
if ( size )
|
||||
*size = sz;
|
||||
|
||||
const QSize sz = qskGraphicSize( *graphic, requestedSize, size );
|
||||
return graphic->toPixmap( sz, Qt::KeepAspectRatio );
|
||||
}
|
||||
|
||||
@ -82,15 +110,11 @@ QQuickTextureFactory* QskGraphicImageProvider::requestTexture(
|
||||
if ( requestedSize.width() == 0 || requestedSize.height() == 0 )
|
||||
return nullptr;
|
||||
|
||||
const QskGraphic* graphic = requestGraphic( id );
|
||||
const auto graphic = requestGraphic( id );
|
||||
if ( graphic == nullptr )
|
||||
return nullptr;
|
||||
|
||||
const QSize sz = effectiveSize( requestedSize, graphic->defaultSize() );
|
||||
|
||||
if ( size )
|
||||
*size = sz;
|
||||
|
||||
const QSize sz = qskGraphicSize( *graphic, requestedSize, size );
|
||||
return new QskGraphicTextureFactory( *graphic, sz );
|
||||
}
|
||||
|
||||
@ -101,32 +125,3 @@ const QskGraphic* QskGraphicImageProvider::requestGraphic( const QString& id ) c
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QSize QskGraphicImageProvider::effectiveSize(
|
||||
const QSize& requestedSize, const QSizeF& defaultSize ) const
|
||||
{
|
||||
if ( requestedSize.width() == 0 || requestedSize.height() == 0 )
|
||||
return QSize( 0, 0 );
|
||||
|
||||
if ( requestedSize.width() > 0 && requestedSize.height() > 0 )
|
||||
return requestedSize;
|
||||
|
||||
if ( defaultSize.isEmpty() )
|
||||
return requestedSize;
|
||||
|
||||
if ( requestedSize.height() < 0 )
|
||||
{
|
||||
const auto f = requestedSize.width() / defaultSize.width();
|
||||
return QSize( requestedSize.width(),
|
||||
static_cast< int >( f * defaultSize.height() ) );
|
||||
}
|
||||
|
||||
if ( requestedSize.width() < 0 )
|
||||
{
|
||||
const auto f = requestedSize.height() / defaultSize.height();
|
||||
return QSize( f * defaultSize.width(),
|
||||
static_cast< int >( requestedSize.height() ) );
|
||||
}
|
||||
|
||||
return defaultSize.toSize();
|
||||
}
|
||||
|
@ -17,9 +17,6 @@ class QSK_EXPORT QskGraphicImageProvider : public QQuickImageProvider
|
||||
QskGraphicImageProvider( const QString& providerId, ImageType );
|
||||
~QskGraphicImageProvider() override;
|
||||
|
||||
void setCacheSize( int );
|
||||
int cacheSize() const;
|
||||
|
||||
QImage requestImage( const QString& id,
|
||||
QSize* size, const QSize& requestedSize ) override;
|
||||
|
||||
@ -33,8 +30,8 @@ class QSK_EXPORT QskGraphicImageProvider : public QQuickImageProvider
|
||||
|
||||
protected:
|
||||
const QskGraphic* requestGraphic( const QString& id ) const;
|
||||
QSize effectiveSize( const QSize& requestedSize, const QSizeF& defaultSize ) const;
|
||||
|
||||
private:
|
||||
const QString m_providerId;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user