1 // Copyright (C) 2002 Dominique Devriese <devriese@kde.org>
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 #include "screeninfo.h"
22 ScreenInfo::ScreenInfo( const Rect
& docRect
, const QRect
& viewRect
)
23 : mkrect( docRect
.normalized() ), mqrect( viewRect
.normalize() )
27 Rect
ScreenInfo::fromScreen( const QRect
& r
) const
30 fromScreen( r
.topLeft() ),
31 fromScreen( r
.bottomRight() )
35 Coordinate
ScreenInfo::fromScreen( const QPoint
& p
) const
37 // invert the y-axis: 0 is at the bottom !
38 Coordinate
t( p
.x(), mqrect
.height() - p
.y() );
41 return t
+ mkrect
.bottomLeft();
44 QPoint
ScreenInfo::toScreen( const Coordinate
& p
) const
46 Coordinate t
= p
- mkrect
.bottomLeft();
49 // invert the y-axis: 0 is at the bottom !
50 return QPoint( (int) t
.x
, mqrect
.height() - (int) t
.y
);
53 QRect
ScreenInfo::toScreen( const Rect
& r
) const
56 toScreen( r
.bottomLeft() ),
57 toScreen( r
.topRight() )
61 double ScreenInfo::pixelWidth() const
63 Coordinate a
= fromScreen( QPoint( 0, 0 ) );
64 Coordinate b
= fromScreen( QPoint( 0, 1000 ) );
65 return std::fabs( b
.y
- a
.y
) / 1000;
68 const Rect
& ScreenInfo::shownRect() const
73 void ScreenInfo::setShownRect( const Rect
& r
)
78 const QRect
ScreenInfo::viewRect() const
83 void ScreenInfo::setViewRect( const QRect
& r
)
88 double ScreenInfo::normalMiss( int width
) const
90 int twidth
= width
== -1 ? 1 : width
;
91 return (twidth
+2)*pixelWidth();