All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PaperItem.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 ItemGroup.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "PaperItem.h"
30 #include "../../core/pattern/mvc/ItemController.h"
31 #include "../core/Scene.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/PaperModel.h"
38 
40  ObjectItem(controller, o)
41 {
42 
43  this->setFlags(QGraphicsItem::ItemSendsGeometryChanges);
44 
46 
47  m_nameClass = std::string(this->metaObject()->className());
48 }
49 
51 {
52 
53 }
54 
55 void te::layout::PaperItem::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget /*= 0 */ )
56 {
57  Q_UNUSED( option );
58  Q_UNUSED( widget );
59  if ( !painter )
60  {
61  return;
62  }
63 
64  drawBackground( painter );
65 
66  drawPaper(painter);
67 
68  drawBorder(painter);
69 
70  //Draw Selection
71  if (option->state & QStyle::State_Selected)
72  {
73  drawSelection(painter);
74  }
75 }
76 
77 void te::layout::PaperItem::drawPaper( QPainter * painter )
78 {
79  PaperModel* model = dynamic_cast<PaperModel*>(m_model);
80  if(!model)
81  {
82  return;
83  }
84 
85  QRectF boundRect;
86  boundRect = boundingRect();
87 
88  painter->save();
89 
90  te::color::RGBAColor clrPaper = model->getPaperColor();
91  QColor cback;
92  cback.setRed(clrPaper.getRed());
93  cback.setGreen(clrPaper.getGreen());
94  cback.setBlue(clrPaper.getBlue());
95  cback.setAlpha(clrPaper.getAlpha());
96 
97  te::color::RGBAColor clrShadow = model->getShadowColor();
98  QColor cShadow;
99  cShadow.setRed(clrShadow.getRed());
100  cShadow.setGreen(clrShadow.getGreen());
101  cShadow.setBlue(clrShadow.getBlue());
102  cShadow.setAlpha(clrShadow.getAlpha());
103 
104  te::color::RGBAColor clrBorder = model->getBorderColor();
105  QColor cBorder;
106  cBorder.setRed(clrBorder.getRed());
107  cBorder.setGreen(clrBorder.getGreen());
108  cBorder.setBlue(clrBorder.getBlue());
109  cBorder.setAlpha(clrBorder.getAlpha());
110 
111  QBrush bsh(cShadow);
112  painter->setBrush(bsh);
113  QPen pen(cBorder);
114  painter->setPen(pen);
115 
116  if(!model->getPaperConfig())
117  return;
118 
119  double pw = 0.;
120  double ph = 0.;
121 
122  model->getPaperConfig()->getPaperSize(pw, ph);
123 
124  double shadowPadding = model->getShadowPadding();
125 
126  QRectF boxShadow(boundRect.x() + shadowPadding, boundRect.y(), boundRect.width() - shadowPadding, boundRect.height() - shadowPadding);
127  painter->drawRect(boxShadow);
128 
129  bsh.setColor(cback);
130  painter->setBrush(bsh);
131 
132  QRectF boxPaper = QRectF(boundRect.x(), boundRect.y() + shadowPadding, boundRect.width() - shadowPadding, boundRect.height() - shadowPadding);
133  painter->drawRect(boxPaper);
134 
135  painter->restore();
136 }
Abstract class to represent an observable. "Model" part of MVC component.
Definition: Observable.h:56
Class that represents a "Model" part of Paper MVC component. Its coordinate system is the same of sce...
Definition: PaperModel.h:54
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:295
PaperItem(ItemController *controller, Observable *o)
Constructor.
Definition: PaperItem.cpp:39
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 te::color::RGBAColor getBorderColor()
Returns the border color of the MVC component.
Abstract class that represents a graphic item. This object is of type QGraphicsObject.
Definition: ObjectItem.h:61
virtual ~PaperItem()
Destructor.
Definition: PaperItem.cpp:50
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Mandatory implementation from QGraphicsItem.
Definition: PaperItem.cpp:55
bool m_canChangeGraphicOrder
Define if item can send to back or bring to front.
Definition: ItemObserver.h:200
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
Definition: RGBAColor.h:310
virtual te::color::RGBAColor getPaperColor()
Definition: PaperModel.cpp:136
std::string m_nameClass
Class name.
Definition: ItemObserver.h:201
virtual double getShadowPadding()
Definition: PaperModel.cpp:119
virtual void drawPaper(QPainter *painter)
Definition: PaperItem.cpp:77
virtual void getPaperSize(double &w, double &h)
Returns paper size. Height and Width.
Definition: PaperConfig.cpp:61
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
virtual te::color::RGBAColor getShadowColor()
Definition: PaperModel.cpp:93
virtual PaperConfig * getPaperConfig() const
Definition: PaperModel.cpp:109
Class that represents a graphic sheet of paper. Its coordinate system is the same of scene (millimete...