ZoomArea.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/ZoomArea.cpp
22 
23  \brief This class implements a concrete tool to geographic zoom in operation using a boundary rectangle.
24 */
25 
26 // TerraLib
27 #include "../../../geometry/Envelope.h"
28 #include "../canvas/MapDisplay.h"
29 #include "ZoomArea.h"
30 
31 // Qt
32 #include <QMouseEvent>
33 
35  : RubberBand(display, parent),
36  m_zoomStarted(false)
37 {
38  setCursor(cursor);
39 }
40 
42 
44 {
45  if(e->button() != Qt::LeftButton)
46  return false;
47 
48  m_zoomStarted = true;
49  m_rect = QRectF();
50 
52 }
53 
55 {
56  if(!m_zoomStarted)
57  return false;
58 
60 }
61 
63 {
64  m_zoomStarted = false;
65 
66  if(e->button() != Qt::LeftButton)
67  return false;
68 
70 
71  if(m_rect.isNull()) // Zoom by click
72  {
73  QRect displayRect = m_display->rect();
74  m_rect = QRectF(displayRect.topLeft() * 0.5, displayRect.bottomRight() * 0.5);
75  m_rect.moveCenter(m_origin);
76  }
77 
78  // Converts zoom boundary to world coordinates
79  QPointF ll(m_rect.left(), m_rect.bottom());
80  QPointF ur(m_rect.right(), m_rect.top());
81  ll = m_display->transform(ll);
82  ur = m_display->transform(ur);
83 
84  // Updates the map display with the new extent
85  te::gm::Envelope envelope(ll.x(), ll.y(), ur.x(), ur.y());
86  m_display->setExtent(envelope);
87 
88  return true;
89 }
virtual bool mouseMoveEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse move events for the...
Definition: RubberBand.cpp:53
bool m_zoomStarted
Flag that indicates if zoom area operation was started.
Definition: ZoomArea.h:115
virtual bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
Definition: RubberBand.cpp:70
QPoint m_origin
Origin point on mouse pressed.
Definition: RubberBand.h:92
virtual bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...
Definition: RubberBand.cpp:47
bool mouseMoveEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse move events for the...
Definition: ZoomArea.cpp:54
A widget to control the display of a set of layers.
This class implements a concrete tool to geographic zoom in operation using a boundary rectangle...
QRectF m_rect
The boundary rectangle managed by the rubber band.
Definition: RubberBand.h:93
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 void setCursor(const QCursor &cursor)
It sets the tool cursor.
This class provides a rectangle that can indicate a boundary.
Definition: RubberBand.h:52
MapDisplay * m_display
The map display associated with the tool.
Definition: AbstractTool.h:171
bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...
Definition: ZoomArea.cpp:43
ZoomArea(MapDisplay *display, const QCursor &cursor, QObject *parent=0)
It constructs a zoom area tool associated with the given map display and with the specified cursor...
Definition: ZoomArea.cpp:34
virtual void setExtent(te::gm::Envelope &e, bool doRefresh=true)
It sets the world visible area and refreshes the contents in the map display.
bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
Definition: ZoomArea.cpp:62