All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ViewZoomArea.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 // TerraLib
21 #include "ViewZoomArea.h"
22 #include "../../../../geometry/Envelope.h"
23 #include "../View.h"
24 #include "../Scene.h"
25 #include "../../../core/pattern/singleton/Context.h"
26 
27 // Qt
28 #include <QtGui/QMouseEvent>
29 #include <QtGui/QPainter>
30 #include <QtGui/QPixmap>
31 #include <QRubberBand>
32 
33 te::layout::ViewZoomArea::ViewZoomArea(View* view, const QCursor& cursor, QObject* parent)
34  : ViewRubberBand(view, parent),
35  m_zoomStarted(false)
36 {
37  setCursor(cursor);
38 }
39 
41 {
42 
43 }
44 
46 {
47  if(e->button() != Qt::LeftButton)
48  return false;
49 
50  m_zoomStarted = true;
51  m_rect = QRectF();
52 
54 }
55 
57 {
58  if(!m_zoomStarted)
59  return false;
60 
62 }
63 
65 {
66  m_zoomStarted = false;
67 
68  if(!m_view)
69  return false;
70 
71  //Roll back the default tool cursor
72  m_view->viewport()->setCursor(m_cursor);
73 
74  if(e->button() != Qt::LeftButton)
75  return false;
76 
77  Scene* scne = dynamic_cast<Scene*>(m_view->scene());
78 
79  if(!scne)
80  return false;
81 
82  QRect rect = m_rubberBand->geometry().normalized();
83 
85 
86  //Conversion to world coordinates
87  QPolygonF poly = m_view->mapToScene(rect);
88 
89  //Updates
90  QRectF bounding = poly.boundingRect();
91  /*
92  Zoom In Area:
93  Scales the view matrix. The view is scaled according to aspectRatioMode.
94  Ensure that the scene rectangle rect fits inside the viewport
95  */
96  m_view->fitInView(bounding, Qt::KeepAspectRatio);
97 
98  scne->update();
99 
100  return true;
101 }
bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
bool mouseMoveEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse move events for the...
This class implements a concrete tool to geographic pan operation.
virtual void setCursor(const QCursor &cursor)
It sets the tool cursor.
bool mouseMoveEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse move events for the...
~ViewZoomArea()
Destructor.
Class representing the view. This view is child of QGraphicsView, part of Graphics View Framework...
Definition: View.h:89
Class representing the scene. This scene is child of QGraphicsScene, part of Graphics View Framework...
Definition: Scene.h:80
ViewZoomArea(View *view, const QCursor &cursor, QObject *parent=0)
It constructs a zoom area tool associated with the given map display and with the specified cursor...
bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...
bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...