RubberBand.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/RubberBand.cpp
22 
23  \brief This is a utility class tool that provides a rectangle that can indicate a boundary.
24 */
25 
26 // TerraLib
27 #include "../canvas/MapDisplay.h"
28 #include "RubberBand.h"
29 
30 // Qt
31 #include <QMouseEvent>
32 #include <QPainter>
33 #include <QPixmap>
34 
36  : AbstractTool(display, parent)
37 {
38  // Setups the rubber band style
39  m_pen.setStyle(Qt::SolidLine);
40  m_pen.setColor(QColor(100, 177, 216));
41  m_pen.setWidth(2);
42  m_brush = QColor(100, 177, 216, 80);
43 }
44 
46 
48 {
49  m_origin = e->pos();
50  return true;
51 }
52 
54 {
55  m_rect = QRect(m_origin, e->pos()).normalized();
56 
57  QPixmap* draft = m_display->getDraftPixmap();
58  draft->fill(Qt::transparent);
59 
60  QPainter painter(draft);
61  painter.setPen(m_pen);
62  painter.setBrush(m_brush);
63  painter.drawRect(m_rect);
64 
65  m_display->repaint();
66 
67  return true;
68 }
69 
71 {
72  QPixmap* draft = m_display->getDraftPixmap();
73  draft->fill(Qt::transparent);
74 
75  m_display->repaint();
76 
77  return true;
78 }
virtual bool mouseMoveEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse move events for the...
Definition: RubberBand.cpp:53
virtual bool mouseReleaseEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse release events for ...
Definition: RubberBand.cpp:70
QPoint m_origin
Origin point on mouse pressed.
Definition: RubberBand.h:92
virtual bool mousePressEvent(QMouseEvent *e)
This event handler can be reimplemented in a concrete tool class to receive mouse press events for th...
Definition: RubberBand.cpp:47
This is a utility class tool that provides a rectangle that can indicate a boundary.
QPen m_pen
The pen used to draw the rubber band shape.
Definition: RubberBand.h:94
A widget to control the display of a set of layers.
This class defines an interface for objects that can receive application events and respond to them...
Definition: AbstractTool.h:63
QBrush m_brush
The brush used to draw the rubber band shape.
Definition: RubberBand.h:95
QRectF m_rect
The boundary rectangle managed by the rubber band.
Definition: RubberBand.h:93
virtual QPixmap * getDraftPixmap() const
It returns the map display draft pixmap.
RubberBand(MapDisplay *display, QObject *parent=0)
It constructs a rubber band associated with the given map display and with the specified cursor...
Definition: RubberBand.cpp:35
virtual ~RubberBand()
Destructor.
MapDisplay * m_display
The map display associated with the tool.
Definition: AbstractTool.h:171