PanExtent.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/widgets/tools/PanExtent.h
22 
23  \brief This class implements a concrete tool to pan a user defined extent.
24 */
25 
26 // TerraLib
27 #include "../../../geometry/Geometry.h"
28 #include "../../../geometry/Utils.h"
29 #include "../canvas/Canvas.h"
30 #include "../canvas/MapDisplay.h"
31 #include "PanExtent.h"
32 
33 // Qt
34 #include <QMouseEvent>
35 #include <QPainter>
36 #include <QPixmap>
37 
38 te::qt::widgets::PanExtent::PanExtent(te::qt::widgets::MapDisplay* display, const QCursor& cursor, const QCursor& actionCursor, QObject* parent)
39  : AbstractTool(display, parent),
40  m_panStarted(false),
41  m_actionCursor(actionCursor)
42 {
43  setCursor(cursor);
44 
45  m_pen.setColor(QColor(0, 0, 0));
46  m_pen.setWidth(2);
47  m_brush = QColor(233, 88, 63, 80);
48 }
49 
51 
53 {
54  if(e->button() != Qt::LeftButton)
55  return false;
56 
57  m_panStarted = true;
58 
59  // Adjusting the action cursor
60  if(m_actionCursor.shape() != Qt::BlankCursor)
61  m_display->setCursor(m_actionCursor);
62 
63  return true;
64 }
65 
67 {
68  if(!m_panStarted)
69  return false;
70 
71  QPointF p = m_display->transform(e->pos());
72 
73  double w = m_currentExtent.getWidth() * 0.5;
74  double h = m_currentExtent.getHeight() * 0.5;
75 
76  te::gm::Envelope auxExt;
77 
78  auxExt.m_llx = p.x() - w;
79  auxExt.m_lly = p.y() - h;
80  auxExt.m_urx = p.x() + w;
81  auxExt.m_ury = p.y() + h;
82 
83  setCurrentExtent(auxExt);
84 
85  return true;
86 }
87 
89 {
90  m_panStarted = false;
91 
92  //emit signal
94 
95  return true;
96 }
97 
99 {
100  m_currentExtent = e;
101 
103 }
104 
106 {
107  m_display->getDraftPixmap()->fill(Qt::transparent);
109  const te::gm::Envelope& mapExt = m_display->getExtent();
110  canvasInstance.setWindow(mapExt.m_llx, mapExt.m_lly, mapExt.m_urx, mapExt.m_ury);
111 
112  canvasInstance.setPolygonContourColor(m_pen.color().rgba());
113  canvasInstance.setPolygonContourWidth(m_pen.width());
114  canvasInstance.setPolygonFillColor(m_brush.color().rgba());
115 
117 
118  canvasInstance.draw(geom);
119 
120  m_display->repaint();
121 
122  delete geom;
123 }
bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...
Definition: PanExtent.cpp:52
QCursor m_actionCursor
An optional cursor to be used during the pan user action.
Definition: PanExtent.h:108
bool m_panStarted
Flag that indicates if pan operation was started.
Definition: PanExtent.h:106
double m_urx
Upper right corner x-coordinate.
PanExtent(MapDisplay *display, const QCursor &cursor, const QCursor &actionCursor=Qt::BlankCursor, QObject *parent=0)
It constructs a pan tool associated with the given map display and with the specified cursors...
Definition: PanExtent.cpp:38
double getWidth() const
It returns the envelope width.
A widget to control the display of a set of layers.
QPen m_pen
The pen used to draw the path.
Definition: PanExtent.h:109
This class defines an interface for objects that can receive application events and respond to them...
Definition: AbstractTool.h:63
bool mouseMoveEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse move events for the...
Definition: PanExtent.cpp:66
double m_llx
Lower left corner x-coordinate.
virtual QPointF transform(const QPointF &p)
Transforms the given point, in screen coordinates, to a point in world coordinates.
An Envelope defines a 2D rectangular region.
virtual int getSRID() const
It return the Spatial Reference System used by the Map Display.
virtual void setCursor(const QCursor &cursor)
It sets the tool cursor.
virtual const te::gm::Envelope & getExtent() const
It returns the world extent showned by the MapDisplay.
QBrush m_brush
The brush used to draw the path.
Definition: PanExtent.h:110
te::gm::Polygon * p
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
double m_lly
Lower left corner y-coordinate.
void extentMoved(te::gm::Envelope e)
virtual QPixmap * getDraftPixmap() const
It returns the map display draft pixmap.
double m_ury
Upper right corner y-coordinate.
void setCurrentExtent(const te::gm::Envelope &e)
Definition: PanExtent.cpp:98
MapDisplay * m_display
The map display associated with the tool.
Definition: AbstractTool.h:171
bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
Definition: PanExtent.cpp:88
te::gm::Envelope m_currentExtent
Definition: PanExtent.h:112
double getHeight() const
It returns the envelope height.
This class implements a concrete tool to pan a user defined extent.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.