1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-21 00:12:06 +02:00

Add DpiScaler for fixed pixel sizes conversion

This commit is contained in:
Teo Mrnjavac 2013-07-29 19:21:18 +02:00
parent 76dc215036
commit 07877add3c
3 changed files with 114 additions and 0 deletions

View File

@ -101,6 +101,7 @@ set( libGuiSources
resolvers/JSResolverHelper.cpp
resolvers/ScriptEngine.cpp
utils/DpiScaler.cpp
utils/ImageRegistry.cpp
utils/WidgetDragFilter.cpp
utils/XspfGenerator.cpp

View 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();
}
}

View 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