All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PolygonItem.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 PolygonItemItem.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "PolygonItem.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/PolygonModel.h"
38 
39 // Qt
40 #include <QPointF>
41 #include <QGraphicsSceneMouseEvent>
42 #include <QStyleOptionGraphicsItem>
43 #include <QObject>
44 
46  LineItem(controller, o)
47 {
48  m_nameClass = std::string(this->metaObject()->className());
49 }
50 
52 {
53 
54 }
55 
56 void te::layout::PolygonItem::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget /*= 0 */ )
57 {
58  Q_UNUSED( option );
59  Q_UNUSED( widget );
60  if ( !painter )
61  {
62  return;
63  }
64 
65  drawBackground(painter);
66 
67  drawPolygon(painter);
68 
69  drawBorder(painter);
70 
71  //Draw Selection
72  if (option->state & QStyle::State_Selected)
73  {
74  drawSelection(painter);
75  }
76 }
77 
78 void te::layout::PolygonItem::drawPolygon( QPainter * painter )
79 {
80  LineModel* model = dynamic_cast<LineModel*>(m_model);
81  if(!model)
82  {
83  return;
84  }
85 
86  if(m_poly.empty())
87  return;
88 
89  te::color::RGBAColor clrLne = model->getLineColor();
90 
91  QColor cpen;
92  cpen.setRed(clrLne.getRed());
93  cpen.setGreen(clrLne.getGreen());
94  cpen.setBlue(clrLne.getBlue());
95  cpen.setAlpha(clrLne.getAlpha());
96 
97  QPen pn(cpen, 0, Qt::SolidLine);
98  painter->setPen(pn);
99 
100  painter->save();
101  painter->drawPolygon(m_poly);
102  painter->restore();
103 }
104 
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
Abstract class to represent a controller. "Controller" part of MVC component. All classes representin...
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented from QGraphicsItem.
Definition: PolygonItem.cpp:56
PolygonItem(ItemController *controller, Observable *o)
Definition: PolygonItem.cpp:45
virtual te::color::RGBAColor getLineColor()
Definition: LineModel.cpp:125
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 void drawPolygon(QPainter *painter)
Definition: PolygonItem.cpp:78
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57