diff --git a/src/libtomahawk/utils/DpiScaler.cpp b/src/libtomahawk/utils/DpiScaler.cpp index 8b7897abc..712868bf1 100644 --- a/src/libtomahawk/utils/DpiScaler.cpp +++ b/src/libtomahawk/utils/DpiScaler.cpp @@ -32,30 +32,59 @@ DpiScaler::DpiScaler( const QPaintDevice* that ) QSize DpiScaler::scaled( int w, int h ) const { - float ratioX = that->logicalDpiX() / 100.0; - float ratioY = that->logicalDpiY() / 100.0; - return QSize( qRound( w * ratioX ), qRound( h * ratioY ) ); + return scaled( that, w, h ); } QSize DpiScaler::scaled( const QSize& size ) const { - return scaled( size.width(), size.height() ); + return scaled( that, size ); } int DpiScaler::scaledX( int x ) const { - return scaled( x, 0 ).width(); + return scaledX( that, x ); } int DpiScaler::scaledY( int y ) const { - return scaled( 0, y ).height(); + return scaledY( that, y ); +} + +// static methods start here + +QSize +DpiScaler::scaled( const QPaintDevice* pd, int w, int h ) +{ + return QSize( scaledX( pd, w ), scaledY( pd, h ) ); +} + + +QSize +DpiScaler::scaled( const QPaintDevice* pd, const QSize& size ) +{ + return scaled( pd, size.width(), size.height() ); +} + + +int +DpiScaler::scaledX( const QPaintDevice* pd, int x ) +{ + float ratioX = pd->logicalDpiX() / 100.0; + return qRound( x * ratioX ); +} + + +int +DpiScaler::scaledY( const QPaintDevice* pd, int y ) +{ + float ratioY = pd->logicalDpiY() / 100.0; + return qRound( y * ratioY ); } diff --git a/src/libtomahawk/utils/DpiScaler.h b/src/libtomahawk/utils/DpiScaler.h index b2598a149..d05da046f 100644 --- a/src/libtomahawk/utils/DpiScaler.h +++ b/src/libtomahawk/utils/DpiScaler.h @@ -37,11 +37,18 @@ class DLLEXPORT DpiScaler { public: DpiScaler( const QPaintDevice* that ); + QSize scaled( int w, int h ) const; QSize scaled( const QSize& size ) const; int scaledX( int x ) const; int scaledY( int y ) const; + // convenience one-shot methods, usable without composing or private-inheriting DpiScaler + static QSize scaled( const QPaintDevice* pd, int w, int h ); + static QSize scaled( const QPaintDevice* pd, const QSize& size ); + inline static int scaledX( const QPaintDevice* pd, int x ); + inline static int scaledY( const QPaintDevice* pd, int y ); + private: const QPaintDevice* that; };