All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ViewRubberBand.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 "ViewRubberBand.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 
34  AbstractViewTool(view, parent),
35  m_started(false),
36  m_draft(0),
37  m_rubberBand(0)
38 {
39  // Setups the rubber band style
40  m_pen.setStyle(Qt::DashLine);
41  m_pen.setColor(QColor(100, 177, 216));
42  m_pen.setWidth(2);
43  m_brush.setColor(QColor(100, 177, 216, 80));
44 }
45 
47 {
48 
49 }
50 
52 {
53  if(!m_view)
54  return false;
55 
56  if(e->button() != Qt::LeftButton)
57  return false;
58 
59  m_origin = e->pos();
60  m_started = true;
61  m_rubberBand = new QRubberBand(QRubberBand::Rectangle, m_view->viewport());
62  m_rubberBand->setGeometry(QRect(m_origin, QSize()));
63  m_rubberBand->show();
64  return true;
65 }
66 
68 {
69  if(!m_view)
70  return false;
71 
72  if(!m_started)
73  return false;
74 
75  m_rect = QRect(m_origin, e->pos()).normalized();
76 
77  if (m_rubberBand)
78  {
79  m_rubberBand->setGeometry(m_rect.toRect());
80  }
81 
82  return true;
83 }
84 
86 {
87  m_started = false;
88 
89  if(!m_view)
90  return false;
91 
92  if(m_draft)
93  {
94  delete m_draft;
95  m_draft = 0;
96  }
97 
98  if(m_rubberBand)
99  {
100  m_rubberBand->hide();
101  delete m_rubberBand;
102  m_rubberBand= 0;
103  }
104 
105  // Roll back the default tool cursor
106  m_view->viewport()->setCursor(m_cursor);
107 
108  if(e->button() != Qt::LeftButton || m_origin.isNull())
109  return false;
110 
111  return true;
112 }
bool mouseMoveEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse move events for the...
QPen m_pen
The pen used to draw the rubber band shape.
Class representing the view. This view is child of QGraphicsView, part of Graphics View Framework...
Definition: View.h:89
QBrush m_brush
The brush used to draw the rubber band shape.
bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
ViewRubberBand(View *view, QObject *parent=0)
It constructs a rubber band associated with the given map display and with the specified cursor...
bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...