All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Pan.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/Pan.cpp
22 
23  \brief This class implements a concrete tool to geographic pan operation.
24 */
25 
26 // TerraLib
27 #include "../../../geometry/Envelope.h"
28 #include "../canvas/MapDisplay.h"
29 #include "Pan.h"
30 
31 // Qt
32 #include <QMouseEvent>
33 #include <QPainter>
34 #include <QPixmap>
35 
36 te::qt::widgets::Pan::Pan(te::qt::widgets::MapDisplay* display, const QCursor& cursor, const QCursor& actionCursor, QObject* parent)
37  : AbstractTool(display, parent),
38  m_panStarted(false),
39  m_actionCursor(actionCursor)
40 {
41  setCursor(cursor);
42 }
43 
45 {
46 }
47 
49 {
50  if(e->button() != Qt::LeftButton)
51  return false;
52 
53  m_panStarted = true;
54  m_origin = e->pos();
55  m_delta *= 0;
56 
57  // Adjusting the action cursor
58  if(m_actionCursor.shape() != Qt::BlankCursor)
59  m_display->setCursor(m_actionCursor);
60 
61  return true;
62 }
63 
65 {
66  if(!m_panStarted)
67  return false;
68 
69  // Calculates the delta value
70  m_delta = e->pos() - m_origin;
71 
72  // Gets the draft map display pixmap
73  QPixmap* draft = m_display->getDraftPixmap();
74  draft->fill();
75 
76  // Gets the current result of map display, i.e. The draw layer composition.
77  QPixmap* result = m_display->getDisplayPixmap();
78 
79  // Let's draw!
80  QPainter painter(draft);
81  painter.drawPixmap(0, 0, *result); // Draw the current result.
82  painter.save();
83  painter.setOpacity(0.3); // Adjusting transparency feedback.
84  painter.drawPixmap(m_delta, *result); // Draw the current result translated.
85  painter.restore();
86 
87  m_display->repaint();
88 
89  return true;
90 }
91 
93 {
94  m_panStarted = false;
95 
96  // Roll back the default tool cursor
97  m_display->setCursor(m_cursor);
98 
99  if(e->button() != Qt::LeftButton || m_delta.isNull())
100  return false;
101 
102  // Clears the draft map display pixmap
103  QPixmap* draft = m_display->getDraftPixmap();
104  draft->fill(Qt::transparent);
105 
106  // Calculates the extent translated
107  QRect rec(0, 0, m_display->width(), m_display->height());
108  QPoint center = rec.center();
109  center -= m_delta;
110  rec.moveCenter(center);
111 
112  // Conversion to world coordinates
113  QPointF ll(rec.left(), rec.bottom());
114  QPointF ur(rec.right(), rec.top());
115  ll = m_display->transform(ll);
116  ur = m_display->transform(ur);
117 
118  // Updates the map display with the new extent
119  te::gm::Envelope envelope(ll.x(), ll.y(), ur.x(), ur.y());
120  m_display->setExtent(envelope);
121 
122  return true;
123 }
bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
Definition: Pan.cpp:92
Pan(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: Pan.cpp:36
A widget to control the display of a set of layers.
Definition: MapDisplay.h:66
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: Pan.cpp:64
bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...
Definition: Pan.cpp:48
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
virtual void setCursor(const QCursor &cursor)
It sets the tool cursor.
This class implements a concrete tool to geographic pan operation.
~Pan()
Destructor.
Definition: Pan.cpp:44