30 #include "../../core/pattern/singleton/Context.h"
31 #include "../../core/pattern/mvc/ItemModelObservable.h"
32 #include "../../core/pattern/mvc/ItemController.h"
33 #include "../../../color/RGBAColor.h"
34 #include "../../../qt/widgets/Utils.h"
35 #include "../../../geometry/Envelope.h"
36 #include "../../../common/STLUtils.h"
37 #include "../../core/AbstractScene.h"
38 #include "../../core/pattern/mvc/ItemObserver.h"
41 #include <QGraphicsSceneMouseEvent>
42 #include <QStyleOptionGraphicsItem>
45 QGraphicsItemGroup(0),
48 this->setFlags(QGraphicsItem::ItemIsMovable
49 | QGraphicsItem::ItemIsSelectable
50 | QGraphicsItem::ItemSendsGeometryChanges);
52 QGraphicsItem* item =
this;
58 setAcceptHoverEvents(
true);
95 pixmp.fill(Qt::transparent);
96 pixmp = QPixmap::fromImage(*img);
114 QPointF posF = scenePos();
115 qreal valuex = posF.x();
116 qreal valuey = posF.y();
119 coordinate.
x = valuex;
120 coordinate.
y = valuey;
127 QGraphicsItemGroup::addToGroup(item);
129 QRectF chRect = childrenBoundingRect();
133 chRect.y() + childrenBoundingRect().height()));
138 QGraphicsItem::mouseMoveEvent(event);
143 QGraphicsItem::mousePressEvent(event);
145 QList<QGraphicsItem*> graphicsItems = childItems();
146 foreach( QGraphicsItem *item, graphicsItems)
150 if(item->contains(event->scenePos()))
160 QGraphicsItem::mouseReleaseEvent(event);
177 drawBackground( painter );
181 boundRect = boundingRect();
185 painter->translate( -boundRect.width() / 2.0, -boundRect.height() / 2.0 );
186 QRectF rtSource( 0, 0, m_pixmap.width(), m_pixmap.height() );
187 painter->drawPixmap(boundRect, m_pixmap, rtSource);
191 if (option->state & QStyle::State_Selected)
193 drawSelection(painter);
204 painter->setPen( Qt::NoPen );
205 painter->setRenderHint( QPainter::Antialiasing,
true );
217 qreal penWidth = painter->pen().widthF();
219 const qreal adj = penWidth / 2;
220 const QColor fgcolor(255,255,255);
221 const QColor backgroundColor(0,0,0);
224 painter->setBrush(Qt::NoBrush);
225 painter->drawRect(boundingRect().adjusted(adj, adj, -adj, -adj));
228 painter->setBrush(Qt::NoBrush);
229 painter->drawRect(boundingRect().adjusted(adj, adj, -adj, -adj));
235 return m_controller->contains(coord);
240 QGraphicsItem::setZValue(z);
246 return QGraphicsItem::zValue();
263 QPointF center = boundingRect().center();
265 double centerX = center.x();
266 double centerY = center.y();
268 setTransform(QTransform().translate(centerX, centerY).rotate(angle).translate(-centerX, -centerY));
273 QImage img = m_pixmap.toImage();
Abstract class to represent an observable. "Model" part of MVC component.
Class responsible for maintaining the drawing context of a MVC component. It is always used by the "M...
virtual void applyRotation()
Rotates the graphic component. Reimplement this function in a ItemObserver subclass to provide the it...
virtual te::color::RGBAColor ** getRGBAColorImage(int &w, int &h)
Returns a image of the graphic component. Reimplement this function in a ItemObserver subclass to pro...
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Abstract class to represent an observable. "Model" part of MVC component. All classes representing th...
double getWidth() const
It returns the envelope width.
ItemGroup(ItemController *controller, Observable *o)
Abstract class to represent an observer. "View" part of MVC component. All classes representing the g...
An utility struct for representing 2D coordinates.
Abstract class to represent a controller. "Controller" part of MVC component. All classes representin...
virtual int getZValueItem()
Return the Z value. Reimplement this function in a ItemObserver subclass to provide the item's getZVa...
virtual void updateObserver(ContextItem context)
Reimplemented from Observer.
virtual te::color::RGBAColor ** getPixmap()
Returns pixmap generated after drawing.
virtual double getAngle()
Returns the value of rotation.
void drawBackground(QPainter *painter)
void Free(std::vector< T * > *v)
This function can be applied to a pointer to a vector of pointers.
static Context & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
virtual Utils * getUtils()
Class that represents the grouping of objects of type QGraphicsItem, MVC components. Its coordinate system is the same of scene (millimeters). He is also the son of ItemObserver and ObjectItem, so it can become observer of a model (Observable).
void drawSelection(QPainter *painter)
std::string m_nameClass
Class name.
virtual te::gm::Envelope viewportBox(te::gm::Envelope box)
Converts the box world (mm) to screen coordinates (pixel).
virtual void addToGroup(QGraphicsItem *item)
virtual void setPosition(const double &x, const double &y)
void setPixmap(const QPixmap &pixmap)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
virtual te::gm::Envelope getBox()
Reimplemented from Observable.
virtual bool contains(const QPointF &point) const
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
Utility class with functions to manipulate the canvas and conversion between projections.
virtual double getOldAngle()
Returns the value of old rotation.
virtual void setBox(te::gm::Envelope box)
Change the bounding rectangle.
double getHeight() const
It returns the envelope height.
bool isValid() const
It tells if the rectangle is valid or not.
virtual te::gm::Coord2D getPosition()
Method that returns the position llx, lly Reimplement this function in a ItemObserver subclass to pro...