All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
52 }
53 
55 {
56  if(e->button() != Qt::LeftButton)
57  return false;
58 
59  m_panStarted = true;
60 
61  // Adjusting the action cursor
62  if(m_actionCursor.shape() != Qt::BlankCursor)
63  m_display->setCursor(m_actionCursor);
64 
65  return true;
66 }
67 
69 {
70  if(!m_panStarted)
71  return false;
72 
73  QPointF p = m_display->transform(e->pos());
74 
75  double w = m_currentExtent.getWidth() * 0.5;
76  double h = m_currentExtent.getHeight() * 0.5;
77 
78  te::gm::Envelope auxExt;
79 
80  auxExt.m_llx = p.x() - w;
81  auxExt.m_lly = p.y() - h;
82  auxExt.m_urx = p.x() + w;
83  auxExt.m_ury = p.y() + h;
84 
85  setCurrentExtent(auxExt);
86 
87  return true;
88 }
89 
91 {
92  m_panStarted = false;
93 
94  //emit signal
95  emit extentMoved(m_currentExtent);
96 
97  return true;
98 }
99 
101 {
102  m_currentExtent = e;
103 
104  drawCurrentExtent();
105 }
106 
108 {
109  m_display->getDraftPixmap()->fill(QColor(0, 0, 0, 0));
110  te::qt::widgets::Canvas canvasInstance(m_display->getDraftPixmap());
111  const te::gm::Envelope& mapExt = m_display->getExtent();
112  canvasInstance.setWindow(mapExt.m_llx, mapExt.m_lly, mapExt.m_urx, mapExt.m_ury);
113 
114  canvasInstance.setPolygonContourColor(m_pen.color().rgba());
115  canvasInstance.setPolygonContourWidth(m_pen.width());
116  canvasInstance.setPolygonFillColor(m_brush.color().rgba());
117 
118  te::gm::Geometry* geom = te::gm::GetGeomFromEnvelope(&m_currentExtent, m_display->getSRID());
119 
120  canvasInstance.draw(geom);
121 
122  m_display->repaint();
123 
124  delete geom;
125 }
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:54
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
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
A widget to control the display of a set of layers.
Definition: MapDisplay.h:66
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:62
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:68
~PanExtent()
Destructor.
Definition: PanExtent.cpp:50
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
virtual void setCursor(const QCursor &cursor)
It sets the tool cursor.
QBrush m_brush
The brush used to draw the path.
Definition: PanExtent.h:110
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
A canvas built on top of Qt.
Definition: Canvas.h:54
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
void setCurrentExtent(const te::gm::Envelope &e)
Definition: PanExtent.cpp:100
bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
Definition: PanExtent.cpp:90
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.
Definition: Utils.cpp:38