All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ZoomLeftAndRightClick.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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 <QtGui/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  QPointF point( m_display->transform( e->posF() ) );
58  point.isNull() ? center = currentExtent.getCenter() : center = te::gm::Coord2D(point.x(), point.y());
59 
60  // Bulding the zoom extent based on zoom factor value and the given point
61  double w = currentExtent.getWidth() * ( 1.0 / m_zoomFactor ) * 0.5;
62  double h = currentExtent.getHeight() * ( 1.0 / m_zoomFactor ) * 0.5;
63 
64  te::gm::Envelope e(center.x - w, center.y - h, center.x + w, center.y + h);
65 
66  // Updates the map display with the new extent
67  m_display->setExtent(e);
68  }
69  else if( e->button() == Qt::RightButton)
70  {
71  // Gets the current display extent
72  const te::gm::Envelope& currentExtent = m_display->getExtent();
73  if(!currentExtent.isValid())
74  return false;
75 
76  // If point is not null, the zoom extent will be centered on this point. Otherwise, keep the current center.
77  te::gm::Coord2D center;
78  QPointF point( m_display->transform( e->posF() ) );
79  point.isNull() ? center = currentExtent.getCenter() : center = te::gm::Coord2D(point.x(), point.y());
80 
81  // Bulding the zoom extent based on zoom factor value and the given point
82  double w = currentExtent.getWidth() * m_zoomFactor * 0.5;
83  double h = currentExtent.getHeight() * m_zoomFactor * 0.5;
84 
85  te::gm::Envelope e(center.x - w, center.y - h, center.x + w, center.y + h);
86 
87  // Updates the map display with the new extent
88  m_display->setExtent(e);
89  }
90 
91  return false;
92 }
bool isValid() const
It tells if the rectangle is valid or not.
Definition: Envelope.h:438
double getWidth() const
It returns the envelope width.
Definition: Envelope.h:443
double y
y-coordinate.
Definition: Coord2D.h:87
This class defines an interface for objects that can receive application events and respond to them...
Definition: AbstractTool.h:62
double getHeight() const
It returns the envelope height.
Definition: Envelope.h:448
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
ZoomLeftAndRightClick(MapDisplay *display, const double &zoomFactor=2.0, QObject *parent=0)
It constructs a zoom click tool associated with the given map display.
A widget to control the display of a set of layers.
Definition: MapDisplay.h:65
This class implements a concrete tool to geographic zoom operation using the left and right mouse cli...
Coord2D getCenter() const
It returns the rectangle&#39;s center coordinate.
Definition: Envelope.cpp:48
double x
x-coordinate.
Definition: Coord2D.h:86
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51