All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RectangleItem.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 "RectangleItem.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/RectangleModel.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::RectangleItem::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  if(m_resizeMode)
60  {
61  ObjectItem::paint(painter, option, widget);
62  return;
63  }
64 
65  drawBackground(painter);
66 
67  drawRectangle(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::RectangleItem::drawRectangle( QPainter * painter )
79 {
80  RectangleModel* model = dynamic_cast<RectangleModel*>(m_model);
81  if(!model)
82  {
83  return;
84  }
85 
86  painter->save();
87 
88  QPainterPath rect_path;
89  rect_path.addRect(boundingRect());
90 
91  QColor cpen(0,0,0);
92  QPen pn(cpen, 0, Qt::SolidLine);
93  painter->setPen(pn);
94 
95  te::color::RGBAColor clrBack = model->getBackgroundColor();
96 
97  QColor cbrush;
98  cbrush.setRed(clrBack.getRed());
99  cbrush.setGreen(clrBack.getGreen());
100  cbrush.setBlue(clrBack.getBlue());
101  cbrush.setAlpha(clrBack.getAlpha());
102 
103  painter->setBrush(cbrush);
104  painter->drawPath(rect_path);
105 
106  painter->restore();
107 }
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
virtual ~RectangleItem()
Destructor.
virtual void drawRectangle(QPainter *painter)
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.
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 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented from QGraphicsItem.
virtual te::color::RGBAColor getBackgroundColor()
Returns the background color of the MVC component.
Class that represents a graphic Rectangle. Its coordinate system is the same of scene (millimeters)...
Class that represents a "Model" part of Rectangle MVC component. Its coordinate system is the same of...
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
RectangleItem(ItemController *controller, Observable *o)
Constructor.