• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • misc
screeninfo.cc
Go to the documentation of this file.
1 // Copyright (C) 2002 Dominique Devriese <devriese@kde.org>
2 
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.
7 
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.
12 
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., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17 
18 #include "screeninfo.h"
19 
20 #include <cmath>
21 
22 ScreenInfo::ScreenInfo( const Rect& docRect, const QRect& viewRect )
23  : mkrect( docRect.normalized() ), mqrect( viewRect.normalized() )
24 {
25 }
26 
27 Rect ScreenInfo::fromScreen( const QRect& r ) const
28 {
29  return Rect(
30  fromScreen( r.topLeft() ),
31  fromScreen( r.bottomRight() )
32  ).normalized();
33 }
34 
35 Coordinate ScreenInfo::fromScreen( const QPoint& p ) const
36 {
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();
42 }
43 
44 QPoint ScreenInfo::toScreen( const Coordinate& p ) const
45 {
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 );
51 }
52 
53 QRect ScreenInfo::toScreen( const Rect& r ) const
54 {
55  return QRect(
56  toScreen( r.bottomLeft() ),
57  toScreen( r.topRight() )
58  ).normalized();
59 }
60 
61 double ScreenInfo::pixelWidth() const
62 {
63  Coordinate a = fromScreen( QPoint( 0, 0 ) );
64  Coordinate b = fromScreen( QPoint( 0, 1000 ) );
65  return std::fabs( b.y - a.y ) / 1000;
66 }
67 
68 const Rect& ScreenInfo::shownRect() const
69 {
70  return mkrect;
71 }
72 
73 void ScreenInfo::setShownRect( const Rect& r )
74 {
75  mkrect = r;
76 }
77 
78 const QRect ScreenInfo::viewRect() const
79 {
80  return mqrect;
81 }
82 
83 void ScreenInfo::setViewRect( const QRect& r )
84 {
85  mqrect = r;
86 }
87 
88 double ScreenInfo::normalMiss( int width ) const
89 {
90  int twidth = width == -1 ? 1 : width;
91  return (twidth+2)*pixelWidth();
92 }
ScreenInfo::viewRect
const QRect viewRect() const
Definition: screeninfo.cc:78
Rect::width
double width() const
Definition: rect.cc:204
ScreenInfo::normalMiss
double normalMiss(int width) const
Definition: screeninfo.cc:88
Rect::bottomLeft
Coordinate bottomLeft() const
Definition: rect.cc:161
Rect
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: rect.h:34
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
ScreenInfo::toScreen
QPoint toScreen(const Coordinate &p) const
Definition: screeninfo.cc:44
ScreenInfo::setViewRect
void setViewRect(const QRect &r)
Definition: screeninfo.cc:83
ScreenInfo::setShownRect
void setShownRect(const Rect &r)
Definition: screeninfo.cc:73
Rect::topRight
Coordinate topRight() const
Definition: rect.cc:176
Rect::normalized
Rect normalized() const
Definition: rect.cc:249
screeninfo.h
Coordinate::x
double x
X Component.
Definition: coordinate.h:126
ScreenInfo::pixelWidth
double pixelWidth() const
Definition: screeninfo.cc:61
Coordinate::y
double y
Y Component.
Definition: coordinate.h:129
ScreenInfo::shownRect
const Rect & shownRect() const
Definition: screeninfo.cc:68
ScreenInfo::fromScreen
Coordinate fromScreen(const QPoint &p) const
Definition: screeninfo.cc:35
ScreenInfo::ScreenInfo
ScreenInfo(const Rect &docRect, const QRect &viewRect)
Definition: screeninfo.cc:22
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal