All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ZoomLeftAndRightClick.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/ZoomLeftAndRightClick.cpp
22 
23  \brief This class implements a concrete tool to geographic zoom operation using the left and right mouse clicks.
24 */
25 
26 // TerraLib
27 #include "../../../geometry/Coord2D.h"
28 #include "../../../geometry/Envelope.h"
29 #include "../canvas/MapDisplay.h"
30 #include "ZoomLeftAndRightClick.h"
31 
32 // Qt
33 #include <QMouseEvent>
34 
36  te::qt::widgets::MapDisplay* display, const double& zoomFactor,
37  QObject* parent)
38  : AbstractTool(display, parent), m_zoomFactor( zoomFactor )
39 {
40 }
41 
43 {
44 }
45 
47 {
48  if(e->button() == Qt::LeftButton)
49  {
50  // Gets the current display extent
51  const te::gm::Envelope& currentExtent = m_display->getExtent();
52  if(!currentExtent.isValid())
53  return false;
54 
55  // If point is not null, the zoom extent will be centered on this point. Otherwise, keep the current center.
56  te::gm::Coord2D center;
57 #if QT_VERSION >= 0x050000
58  QPointF point( m_display->transform( e->localPos() ) );
59 #else
60  QPointF point( m_display->transform( e->posF() ) );
61 #endif
62  point.isNull() ? center = currentExtent.getCenter() : center = te::gm::Coord2D(point.x(), point.y());
63 
64  // Bulding the zoom extent based on zoom factor value and the given point
65  double w = currentExtent.getWidth() * ( 1.0 / m_zoomFactor ) * 0.5;
66  double h = currentExtent.getHeight() * ( 1.0 / m_zoomFactor ) * 0.5;
67 
68  te::gm::Envelope e(center.x - w, center.y - h, center.x + w, center.y + h);
69 
70  // Updates the map display with the new extent
71  m_display->setExtent(e);
72  }
73  else if( e->button() == Qt::RightButton)
74  {
75  // Gets the current display extent
76  const te::gm::Envelope& currentExtent = m_display->getExtent();
77  if(!currentExtent.isValid())
78  return false;
79 
80  // If point is not null, the zoom extent will be centered on this point. Otherwise, keep the current center.
81  te::gm::Coord2D center;
82 #if QT_VERSION >= 0x050000
83  QPointF point( m_display->transform( e->localPos() ) );
84 #else
85  QPointF point( m_display->transform( e->posF() ) );
86 #endif
87  point.isNull() ? center = currentExtent.getCenter() : center = te::gm::Coord2D(point.x(), point.y());
88 
89  // Bulding the zoom extent based on zoom factor value and the given point
90  double w = currentExtent.getWidth() * m_zoomFactor * 0.5;
91  double h = currentExtent.getHeight() * m_zoomFactor * 0.5;
92 
93  te::gm::Envelope e(center.x - w, center.y - h, center.x + w, center.y + h);
94 
95  // Updates the map display with the new extent
96  m_display->setExtent(e);
97  }
98 
99  return false;
100 }
bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...
double y
y-coordinate.
Definition: Coord2D.h:114
double x
x-coordinate.
Definition: Coord2D.h:113
double getWidth() const
It returns the envelope width.
Definition: Envelope.h:443
A widget to control the display of a set of layers.
Definition: MapDisplay.h:66
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
This class defines an interface for objects that can receive application events and respond to them...
Definition: AbstractTool.h:62
Coord2D getCenter() const
It returns the rectangle's center coordinate.
Definition: Envelope.cpp:51
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
This class implements a concrete tool to geographic zoom operation using the left and right mouse cli...
ZoomLeftAndRightClick(MapDisplay *display, const double &zoomFactor=2.0, QObject *parent=0)
It constructs a zoom click tool associated with the given map display.
double getHeight() const
It returns the envelope height.
Definition: Envelope.h:448
bool isValid() const
It tells if the rectangle is valid or not.
Definition: Envelope.h:438