All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EllipseItem.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 EllipseItem.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "EllipseItem.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 #include "../../item/EllipseModel.h"
38 
40  ObjectItem(controller, o)
41 {
42  m_nameClass = std::string(this->metaObject()->className());
43 }
44 
46 {
47 
48 }
49 
50 void te::layout::EllipseItem::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget /*= 0 */ )
51 {
52  Q_UNUSED( option );
53  Q_UNUSED( widget );
54  if ( !painter )
55  {
56  return;
57  }
58 
59  drawBackground(painter);
60 
61  drawEllipse(painter);
62 
63  drawBorder(painter);
64 
65  //Draw Selection
66  if (option->state & QStyle::State_Selected)
67  {
68  drawSelection(painter);
69  }
70 }
71 
72 void te::layout::EllipseItem::drawEllipse( QPainter * painter )
73 {
74  EllipseModel* model = dynamic_cast<EllipseModel*>(m_model);
75  if(!model)
76  {
77  return;
78  }
79 
80  painter->save();
81 
82  QPainterPath circle_path;
83  circle_path.addEllipse(boundingRect());
84 
85  QColor cpen(0,0,0);
86  QPen pn(cpen, 0, Qt::SolidLine);
87  painter->setPen(pn);
88 
89  te::color::RGBAColor clrBack = model->getBackgroundColor();
90 
91  QColor cbrush;
92  cbrush.setRed(clrBack.getRed());
93  cbrush.setGreen(clrBack.getGreen());
94  cbrush.setBlue(clrBack.getBlue());
95  cbrush.setAlpha(clrBack.getAlpha());
96 
97  painter->setBrush(cbrush);
98  painter->drawPath(circle_path);
99 
100  painter->restore();
101 }
102 
Abstract class to represent an observable. "Model" part of MVC component.
Definition: Observable.h:56
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:295
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
Definition: RGBAColor.h:305
int getGreen() const
It returns the green component color value (a value from 0 to 255).
Definition: RGBAColor.h:300
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented from QGraphicsItem.
Definition: EllipseItem.cpp:50
Abstract class to represent a controller. "Controller" part of MVC component. All classes representin...
Class that represents a graphic Ellipse. Its coordinate system is the same of scene (millimeters)...
virtual ~EllipseItem()
Destructor.
Definition: EllipseItem.cpp:45
Abstract class that represents a graphic item. This object is of type QGraphicsObject.
Definition: ObjectItem.h:61
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
Definition: RGBAColor.h:310
std::string m_nameClass
Class name.
Definition: ItemObserver.h:201
virtual te::color::RGBAColor getBackgroundColor()
Returns the background color of the MVC component.
Class that represents a "Model" part of Ellipse MVC component. Its coordinate system is the same of s...
Definition: EllipseModel.h:51
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
virtual void drawEllipse(QPainter *painter)
Drawing method of a ellipse.
Definition: EllipseItem.cpp:72
EllipseItem(ItemController *controller, Observable *o)
Constructor.
Definition: EllipseItem.cpp:39