moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kig / misc / screeninfo.cc
blob12836978b7031bbadc29582a1fb975b28b08eae0
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
16 // 02111-1307, USA.
18 #include "screeninfo.h"
20 #include <cmath>
22 ScreenInfo::ScreenInfo( const Rect& docRect, const QRect& viewRect )
23 : mkrect( docRect.normalized() ), mqrect( viewRect.normalize() )
27 Rect ScreenInfo::fromScreen( const QRect& r ) const
29 return Rect(
30 fromScreen( r.topLeft() ),
31 fromScreen( r.bottomRight() )
32 ).normalized();
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() );
39 t *= mkrect.width();
40 t /= mqrect.width();
41 return t + mkrect.bottomLeft();
44 QPoint ScreenInfo::toScreen( const Coordinate& p ) const
46 Coordinate t = p - mkrect.bottomLeft();
47 t *= mqrect.width();
48 t /= mkrect.width();
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
55 return QRect(
56 toScreen( r.bottomLeft() ),
57 toScreen( r.topRight() )
58 ).normalize();
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
70 return mkrect;
73 void ScreenInfo::setShownRect( const Rect& r )
75 mkrect = r;
78 const QRect ScreenInfo::viewRect() const
80 return mqrect;
83 void ScreenInfo::setViewRect( const QRect& r )
85 mqrect = r;
88 double ScreenInfo::normalMiss( int width ) const
90 int twidth = width == -1 ? 1 : width;
91 return (twidth+2)*pixelWidth();