1
/* This file is part of the KDE project
3
Copyright 2010 Johannes Simon <johannes.simon@gmail.com>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Library General Public
7
License as published by the Free Software Foundation; either
8
version 2 of the License, or (at your option) any later version.
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Library General Public License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to
17
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
Boston, MA 02110-1301, USA.
26
#include "ScreenConversions.h"
35
using namespace KChart;
37
qreal ScreenConversions::pxToPtX( qreal px )
39
return KoUnit( KoUnit::Inch ).fromUserValue( px / KoDpi::dpiX() );
42
qreal ScreenConversions::pxToPtY( qreal px )
44
return KoUnit( KoUnit::Inch ).fromUserValue( px / KoDpi::dpiY() );
47
qreal ScreenConversions::ptToPxX( qreal pt )
49
return KoUnit::toInch( pt ) * KoDpi::dpiX();
52
qreal ScreenConversions::ptToPxY( qreal pt )
54
return KoUnit::toInch( pt ) * KoDpi::dpiY();
57
void ScreenConversions::scaleFromPtToPx( QPainter &painter )
59
const qreal inPerPt = KoUnit::toInch( 1.0 );
60
painter.scale( 1.0 / (inPerPt * KoDpi::dpiX()), 1.0 / (inPerPt * KoDpi::dpiY()) );
63
QSize ScreenConversions::scaleFromPtToPx( const QSizeF &size )
65
return QSizeF( ptToPxX( size.width() ), ptToPxY( size.height() ) ).toSize();
68
QSizeF ScreenConversions::scaleFromPxToPt( const QSize &size )
70
return QSizeF( pxToPtX( size.width() ), pxToPtY( size.height() ) );
73
QPoint ScreenConversions::scaleFromPtToPx( const QPointF &point )
75
return QPointF( ptToPxX( point.x() ), ptToPxY( point.y() ) ).toPoint();
78
QRect ScreenConversions::scaleFromPtToPx( const QRectF &rect )
80
return QRect( scaleFromPtToPx( rect.topLeft() ),
81
scaleFromPtToPx( rect.size() ) );