All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
47 }
48 
50 {
51  m_origin = e->pos();
52  return true;
53 }
54 
56 {
57  m_rect = QRect(m_origin, e->pos()).normalized();
58 
59  QPixmap* draft = m_display->getDraftPixmap();
60  draft->fill(Qt::transparent);
61 
62  QPainter painter(draft);
63  painter.setPen(m_pen);
64  painter.setBrush(m_brush);
65  painter.drawRect(m_rect);
66 
67  m_display->repaint();
68 
69  return true;
70 }
71 
73 {
74  QPixmap* draft = m_display->getDraftPixmap();
75  draft->fill(Qt::transparent);
76 
77  m_display->repaint();
78 
79  return true;
80 }
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:55
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:72
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:49
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.
Definition: MapDisplay.h:66
This class defines an interface for objects that can receive application events and respond to them...
Definition: AbstractTool.h:62
QBrush m_brush
The brush used to draw the rubber band shape.
Definition: RubberBand.h:95
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.
Definition: RubberBand.cpp:45