Subversion Repositories public iLand

Rev

Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1211 werner 1
/********************************************************************************************
2
**    iLand - an individual based forest landscape and disturbance model
3
**    http://iland.boku.ac.at
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
********************************************************************************************/
808 werner 19
#ifndef VIEWPORT_H
20
#define VIEWPORT_H
21
#include <QtGui>
22
 
23
class Viewport
24
{
25
public:
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(), p2.y()-p1.y())); 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);
49
private:
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