mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 13:47:26 +02:00
Add DpiScaler for fixed pixel sizes conversion
This commit is contained in:
@@ -101,6 +101,7 @@ set( libGuiSources
|
|||||||
resolvers/JSResolverHelper.cpp
|
resolvers/JSResolverHelper.cpp
|
||||||
resolvers/ScriptEngine.cpp
|
resolvers/ScriptEngine.cpp
|
||||||
|
|
||||||
|
utils/DpiScaler.cpp
|
||||||
utils/ImageRegistry.cpp
|
utils/ImageRegistry.cpp
|
||||||
utils/WidgetDragFilter.cpp
|
utils/WidgetDragFilter.cpp
|
||||||
utils/XspfGenerator.cpp
|
utils/XspfGenerator.cpp
|
||||||
|
62
src/libtomahawk/utils/DpiScaler.cpp
Normal file
62
src/libtomahawk/utils/DpiScaler.cpp
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "DpiScaler.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace TomahawkUtils
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
DpiScaler::DpiScaler( const QPaintDevice* that )
|
||||||
|
: that( 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 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QSize
|
||||||
|
DpiScaler::scaled( const QSize& size ) const
|
||||||
|
{
|
||||||
|
return scaled( size.width(), size.height() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
DpiScaler::scaledX( int x ) const
|
||||||
|
{
|
||||||
|
return scaled( x, 0 ).width();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
DpiScaler::scaledY( int y ) const
|
||||||
|
{
|
||||||
|
return scaled( 0, y ).height();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
51
src/libtomahawk/utils/DpiScaler.h
Normal file
51
src/libtomahawk/utils/DpiScaler.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DPISCALER_H
|
||||||
|
#define DPISCALER_H
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
#include <QPaintDevice>
|
||||||
|
#include <QSize>
|
||||||
|
|
||||||
|
namespace TomahawkUtils
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The DpiScaler class provides some convenience methods to recompute fixed pixel sizes
|
||||||
|
* into values suitable for different environment DPI settings.
|
||||||
|
* Usage:
|
||||||
|
* class Foo : public QWidget, private TomahawkUtils::DpiScaler {...};
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const QPaintDevice* that;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // DPISCALER_H
|
Reference in New Issue
Block a user