iLand
viewport.h
Go to the documentation of this file.
1/********************************************************************************************
2** iLand - an individual based forest landscape and disturbance model
3** http://iland-model.org
4** Copyright (C) 2009- Werner Rammer, Rupert Seidl
5**
6** This program is free software: you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program. If not, see <http://www.gnu.org/licenses/>.
18********************************************************************************************/
19#ifndef VIEWPORT_H
20#define VIEWPORT_H
21#include <QtGui>
22
24{
25public:
26 Viewport(): m_viewAll(true), m_scale_worldtoscreen(1.) {}
27 Viewport(const QRectF worldrect, const QRect screenrect) { setWorldRect(worldrect); setScreenRect(screenrect); zoomToAll(); }
28 // coordinate transformations
29 const QPointF toWorld(const QPoint pixel);
30 const QPoint toScreen(const QPointF p);
31 const QRect toScreen(const QRectF world) { QPoint p1=toScreen(world.bottomLeft()); QPoint p2=toScreen(world.topRight()); QRect r(p1, QSize(p2.x()-p1.x()+1, p2.y()-p1.y()+1)); return r; }
32 // getters
33 const QRectF viewRect() const { return m_viewport; }
34 bool isVisible(const QPointF &world_coord) const;
35 bool isVisible(const QRectF &world_rect) const;
36 // zoom
37 void zoomToAll();
38 void zoomTo(const QPoint &screen_point, const double factor);
39 void moveTo(const QPoint &screen_from, const QPoint &screen_to);
40 // move
41 void setViewPoint(const QPointF &world_center, const double px_per_meter);
42 // conversion of length
43 double pixelToMeter(const int pixel) { return pixel/m_scale_worldtoscreen; }
44 int meterToPixel(const double meter) { return qRound(meter * m_scale_worldtoscreen);}
45 // setters...
46 void setViewRect(const QRectF &viewrect) { m_viewport = viewrect; }
47 void setWorldRect(const QRectF &worldrect) { m_world = worldrect; }
48 void setScreenRect(const QRect &viewrect);
49private:
50 bool m_viewAll;
51 QRect m_screen;
52 QRectF m_world;
53 QRectF m_viewport;
54 QPointF m_delta_worldtoscreen;
55 double m_scale_worldtoscreen;
56};
57
58
59#endif // VIEWPORT_H
Handles coordinaive transforation between grids (based on real-world metric coordinates).
Definition: viewport.h:24
void setScreenRect(const QRect &viewrect)
sets the screen rect; this also modifies the viewport.
Definition: viewport.cpp:49
double pixelToMeter(const int pixel)
Definition: viewport.h:43
Viewport(const QRectF worldrect, const QRect screenrect)
Definition: viewport.h:27
int meterToPixel(const double meter)
Definition: viewport.h:44
void setViewPoint(const QPointF &world_center, const double px_per_meter)
set 'world_center' as the new center point of the viewport
Definition: viewport.cpp:117
void moveTo(const QPoint &screen_from, const QPoint &screen_to)
move the viewport. screen_from and screen_to give mouse positions (in pixel) from dragging the mouse.
Definition: viewport.cpp:106
void setWorldRect(const QRectF &worldrect)
Definition: viewport.h:47
void setViewRect(const QRectF &viewrect)
Definition: viewport.h:46
const QRect toScreen(const QRectF world)
Definition: viewport.h:31
const QPoint toScreen(const QPointF p)
toScreen() converts world coordinates in screen coordinates using the defined viewport.
Definition: viewport.cpp:40
Viewport()
Definition: viewport.h:26
const QRectF viewRect() const
Definition: viewport.h:33
void zoomTo(const QPoint &screen_point, const double factor)
zoom using a factor of factor.
Definition: viewport.cpp:86
void zoomToAll()
show the full extent of the world.
Definition: viewport.cpp:59
const QPointF toWorld(const QPoint pixel)
toWorld() converts the pixel-information (e.g. by an mouse event) to the corresponding real world coo...
Definition: viewport.cpp:30
bool isVisible(const QPointF &world_coord) const
Definition: viewport.cpp:127