All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
BalloonItem.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 RectangleItem.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "BalloonItem.h"
30 #include "../../core/pattern/mvc/ItemController.h"
31 #include "../../core/AbstractScene.h"
32 #include "../../core/pattern/mvc/Observable.h"
33 #include "../../../color/RGBAColor.h"
34 #include "../../../qt/widgets/Utils.h"
35 #include "../../../geometry/Envelope.h"
36 #include "../../../common/STLUtils.h"
37 
38 // STL
39 #include <algorithm> // std::max and std::min
40 
41 // Qt
42 #include <QTextDocument>
43 #include <QStyleOptionGraphicsItem>
44 #include <QTextCursor>
45 #include <QAbstractTextDocumentLayout>
46 #include <QGraphicsSceneMouseEvent>
47 //
48 #include <QMessageBox>
49 
51  ObjectItem(controller, o)
52 {
53  m_nameClass = std::string(this->metaObject()->className());
54 }
55 
57 {
58 
59 }
60 
61 void te::layout::BalloonItem::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget /* = 0 */ )
62 {
63  Q_UNUSED( option );
64  Q_UNUSED( widget );
65  if ( !painter )
66  {
67  return;
68  }
69 
70  drawBackground(painter);
71 
72  drawBalloon(painter);
73 
74  //Draw Selection
75  if (option->state & QStyle::State_Selected)
76  {
77  drawSelection(painter);
78  }
79 }
80 
81 void te::layout::BalloonItem::drawBalloon( QPainter* painter )
82 {
83  QPointF centerBoundRect = boundingRect().center();
84  double xWidth = (boundingRect().width()/2) / 2;
85  double yHeight = (boundingRect().height()/2) / 2;
86 
87  QRectF boundRect(centerBoundRect.x() - xWidth, centerBoundRect.y() - yHeight, boundingRect().width()/2, boundingRect().height()/2);
88 
89  painter->save();
90 
91  painter->drawRect(boundRect);
92 
93  QPainterPath balloonPath;
94 
95  double arrowWidth = 25.;
96  double arrowHeight = 15;
97 
98  double x = m_endPoint.x();
99  double y = m_endPoint.y();
100 
101  double centerX = boundRect.center().x();
102  double centerY = boundRect.center().y();
103 
104  // to draw the point part that indicates who is speaking
105  QPolygonF poly;
106  poly.append(QPointF(x, y));
107  poly.append(QPointF(x - arrowWidth / 2, y - arrowHeight));
108  poly.append(QPointF(x + arrowWidth / 2, y - arrowHeight));
109  poly.append(QPointF(x, y));
110 
111  balloonPath.addPolygon(poly);
112 
113  //painter->drawPath(balloonPath);
114 
115  painter->restore();
116 }
117 
118 void te::layout::BalloonItem::mousePressEvent( QGraphicsSceneMouseEvent * event )
119 {
120  m_initPoint = QPointF(event->pos());
121  QGraphicsItem::mousePressEvent(event);
122 }
123 
124 void te::layout::BalloonItem::mouseMoveEvent( QGraphicsSceneMouseEvent * event )
125 {
126  QGraphicsItem::mouseMoveEvent(event);
127 }
128 
129 void te::layout::BalloonItem::mouseReleaseEvent( QGraphicsSceneMouseEvent * event )
130 {
131  m_endPoint = QPointF(event->pos());
132  QGraphicsItem::mouseReleaseEvent(event);
133 }
134 
135 
136 
137 
138 
Abstract class to represent an observable. "Model" part of MVC component.
Definition: Observable.h:56
virtual void drawBalloon(QPainter *painter)
Definition: BalloonItem.cpp:81
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Reimplemented from QGraphicsItem.
Abstract class to represent a controller. "Controller" part of MVC component. All classes representin...
Abstract class that represents a graphic item. This object is of type QGraphicsObject.
Definition: ObjectItem.h:61
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented from QGraphicsItem.
Definition: BalloonItem.cpp:61
std::string m_nameClass
Class name.
Definition: ItemObserver.h:201
BalloonItem(ItemController *controller, Observable *o)
Definition: BalloonItem.cpp:50
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
Reimplemented from QGraphicsItem.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Reimplemented from QGraphicsItem.