All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ImageItem.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 ImageItem.cpp
22 
23  \brief
24 
25  \ingroup layout
26 */
27 
28 // TerraLib
29 #include "ImageItem.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/ImageModel.h"
38 
39 // Qt
40 #include <QStyleOptionGraphicsItem>
41 
43  ObjectItem(controller, o)
44 {
45  m_nameClass = std::string(this->metaObject()->className());
46 }
47 
49 {
50 
51 }
52 
53 void te::layout::ImageItem::paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget /*= 0 */ )
54 {
55  Q_UNUSED( option );
56  Q_UNUSED( widget );
57  if ( !painter )
58  {
59  return;
60  }
61 
62  drawBackground(painter);
63 
64  drawImage(painter);
65 
66  drawBorder(painter);
67 
68  //Draw Selection
69  if (option->state & QStyle::State_Selected)
70  {
71  drawSelection(painter);
72  }
73 }
74 
75 void te::layout::ImageItem::drawImage( QPainter * painter )
76 {
77  ImageModel* model = dynamic_cast<ImageModel*>(m_model);
78  if(!model)
79  {
80  return;
81  }
82 
83  QRectF boundRect = boundingRect();
84  std::string fileName = model->getFileName();
85 
86  if(fileName.compare("") == 0)
87  return;
88 
89  painter->save();
90 
91  QImage img(fileName.c_str());
92  img = img.mirrored();
93 
94  QRectF sourceRect(0, 0, img.width(), img.height());
95 
96  painter->drawImage(boundRect, img, sourceRect);
97 
98  painter->restore();
99 }
100 
Abstract class to represent an observable. "Model" part of MVC component.
Definition: Observable.h:56
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Reimplemented from QGraphicsItem.
Definition: ImageItem.cpp:53
Class that represents a graphic Image. Its coordinate system is the same of scene (millimeters)...
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
std::string m_nameClass
Class name.
Definition: ItemObserver.h:201
Class that represents a "Model" part of Image MVC component. Its coordinate system is the same of sce...
Definition: ImageModel.h:55
virtual std::string getFileName()
Change file name.
Definition: ImageModel.cpp:66
virtual void drawImage(QPainter *painter)
Drawing method of a ellipse.
Definition: ImageItem.cpp:75
ImageItem(ItemController *controller, Observable *o)
Constructor.
Definition: ImageItem.cpp:42
virtual ~ImageItem()
Destructor.
Definition: ImageItem.cpp:48