35 #include "../../../color/RGBAColor.h"
36 #include "../../../../qt/widgets/Utils.h"
37 #include "../../../../geometry/Envelope.h"
38 #include "../../../../common/STLUtils.h"
41 #include <QGraphicsSceneHoverEvent>
42 #include <QGraphicsSceneMouseEvent>
44 #include <QStyleOptionGraphicsItem>
49 m_mousePressedCtrl(false),
50 m_hoverAboveItem(false),
51 m_toResizeItem(false),
54 QGraphicsItem* item =
this;
58 setAcceptHoverEvents(
true);
68 QPointF posF = scenePos();
69 qreal valuex = posF.x();
70 qreal valuey = posF.y();
73 coordinate.
x = valuex;
74 coordinate.
y = valuey;
81 QGraphicsItem::setPos(pos);
94 QPointF point = pos();
100 QGraphicsObject::prepareGeometryChange();
117 drawBackground( painter );
120 boundRect = boundingRect();
123 painter->translate( -boundRect.bottomLeft().x(), -boundRect.topRight().y() );
124 painter->drawPixmap(boundRect, m_pixmap, QRectF( 0, 0, m_pixmap.width(), m_pixmap.height() ));
128 if (option->state & QStyle::State_Selected)
130 drawSelection(painter);
139 painter->setPen(Qt::NoPen);
140 painter->setRenderHint( QPainter::Antialiasing,
true );
141 painter->drawRect(QRectF( 0, 0, boundingRect().width(), boundingRect().height()));
152 qreal penWidth = painter->pen().widthF();
154 const qreal adj = penWidth / 2;
155 const QColor fgcolor(255,255,255);
156 const QColor backgroundColor(0,0,0);
159 painter->setBrush(Qt::NoBrush);
160 painter->drawRect(boundingRect().adjusted(adj, adj, -adj, -adj));
163 painter->setBrush(Qt::NoBrush);
164 painter->drawRect(boundingRect().adjusted(adj, adj, -adj, -adj));
174 if (rect.isEmpty() && !rect.isNull())
183 QGraphicsItem::mousePressEvent(event);
185 if(event->modifiers() == Qt::AltModifier && m_toResizeItem)
187 m_clonePixmap = getPixmap();
188 m_mousePressedCtrl =
true;
194 QGraphicsItem::mouseReleaseEvent(event);
196 te::gm::Envelope boxScene = createNewBoxInCoordScene(event->scenePos().x(),
event->scenePos().y());
198 m_controller->setBox(boxScene);
200 m_mousePressedCtrl =
false;
202 if(m_toResizeItem && boxScene.
isValid())
204 m_toResizeItem =
false;
218 if(event->modifiers() == Qt::AltModifier &&
event->buttons() == Qt::LeftButton && m_toResizeItem)
220 m_mousePressedCtrl =
true;
223 QPixmap pix = calculateNewPixmap(event->scenePos().x(),
event->scenePos().y());
231 m_mousePressedCtrl =
false;
232 QGraphicsItem::mouseMoveEvent(event);
238 QGraphicsItem::hoverEnterEvent(event);
243 m_hoverAboveItem =
false;
244 setCursor(Qt::ArrowCursor);
245 QGraphicsItem::hoverLeaveEvent(event);
250 m_hoverAboveItem =
true;
251 m_toResizeItem = checkTouchesCorner(event->pos().x(),
event->pos().y());
252 QGraphicsItem::hoverMoveEvent(event);
258 QRectF bRect = boundingRect();
261 QPointF ll = bRect.bottomLeft();
262 QPointF lr = bRect.bottomRight();
263 QPointF tl = bRect.topLeft();
264 QPointF tr = bRect.topRight();
266 if((x >= (ll.x() - margin) && x <= (ll.x() + margin))
267 && (y >= (ll.y() - margin) && y <= (ll.y() + margin)))
269 setCursor(Qt::SizeBDiagCursor);
272 else if((x >= (lr.x() - margin) && x <= (lr.x() + margin))
273 && (y >= (lr.y() - margin) && y <= (lr.y() + margin)))
275 setCursor(Qt::SizeFDiagCursor);
278 else if((x >= (tl.x() - margin) && x <= (tl.x() + margin))
279 && (y >= (tl.y() - margin) && y <= (tl.y() + margin)))
281 setCursor(Qt::SizeFDiagCursor);
284 else if((x >= (tr.x() - margin) && x <= (tr.x() + margin))
285 && (y >= (tr.y() - margin) && y <= (tr.y() + margin)))
287 setCursor(Qt::SizeBDiagCursor);
292 setCursor(Qt::ArrowCursor);
315 QPointF posItem = this->scenePos();
316 QPointF posAtual(x, y);
318 double xTranslation = 0;
319 double yTranslation = 0;
321 double x1 = posItem.x() < posAtual.x() ? posItem.x() : posAtual.x();
322 double y1 = posItem.y() < posAtual.y() ? posItem.y() : posAtual.y();
323 double x2 = posItem.x() > posAtual.x() ? posItem.x() : posAtual.x();
324 double y2 = posItem.y() > posAtual.y() ? posItem.y() : posAtual.y();
329 if(m_mousePressedCtrl && m_toResizeItem)
335 boxScene =
te::gm::Envelope(posItem.x(), posItem.y() - dy, posItem.x() + dx, posItem.y());
340 dx = posItem.x() - posAtual.x();
341 dy = posItem.y() - posAtual.y();
343 QPointF pbxy2 = mapToScene(boundingRect().topRight());
344 if(posAtual.x() < pbxy2.x() && posAtual.y() < posItem.y())
346 boxScene =
te::gm::Envelope(posItem.x() - dx, posItem.y() - dy, pbxy2.x(), posItem.y());
348 QPointF p_f = mapFromScene(QPointF(posItem.x() - dx, posItem.y()));
349 QPointF p_ff = mapToParent(p_f);
350 xTranslation = p_ff.x();
351 yTranslation = p_ff.y();
354 setPos( QPointF(xTranslation, yTranslation) );
361 QRectF bond = boundingRect();
363 QPointF pbxy2 = mapToScene(boundingRect().topRight());
365 dx = posAtual.x() - pbxy2.x();
366 dy = posAtual.y() - pbxy2.y();
368 QPointF pbxy1 = mapToScene(boundingRect().bottomLeft());
369 if(posAtual.x() > posItem.x() && posAtual.y() < pbxy1.y())
374 QPointF p_f = mapFromScene(QPointF(posItem.x(), posItem.y() + dy));
375 QPointF p_ff = mapToParent(p_f);
376 xTranslation = p_ff.x();
377 yTranslation = p_ff.y();
380 setPos( QPointF(xTranslation, yTranslation) );
386 QPointF pbxy2 = mapToScene(boundingRect().topLeft());
388 dx = posAtual.x() - pbxy2.x();
389 dy = posAtual.y() - pbxy2.y();
391 QPointF pbxy1 = mapToScene(boundingRect().bottomRight());
392 if(posAtual.x() < pbxy1.x() && posAtual.y() > pbxy1.y())
394 boxScene =
te::gm::Envelope(posItem.x() + dx, pbxy1.y(), pbxy1.x(), posItem.y() + dy);
396 QPointF p_f = mapFromScene(QPointF(posItem.x() + dx, posItem.y() + dy));
397 QPointF p_ff = mapToParent(p_f);
398 xTranslation = p_ff.x();
399 yTranslation = p_ff.y();
402 setPos( QPointF(xTranslation, yTranslation) );
408 boxScene =
te::gm::Envelope(posItem.x(), posItem.y() - boundingRect().height(),
409 posItem.x() + boundingRect().width(), posItem.y());
430 QGraphicsItem::setZValue(z);
436 return QGraphicsItem::zValue();
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
virtual void setPixmap(const QPixmap &pixmap)
virtual QPixmap getPixmap()
virtual te::gm::Envelope getBox()=0
virtual void drawSelection(QPainter *painter)
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
double getWidth() const
It returns the envelope width.
virtual void drawBackground(QPainter *painter)
An utility struct for representing 2D coordinates.
virtual bool checkTouchesCorner(const double &x, const double &y)
virtual void setRect(QRectF rect)
An Envelope defines a 2D rectangular region.
virtual void insertItem(ItemObserver *item)=0
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
virtual te::gm::Envelope createNewBoxInCoordScene(const double &x, const double &y)
virtual int getZValueItem()
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
virtual QPixmap calculateNewPixmap(const double &x, const double &y)
virtual void setPos(const QPointF &pos)
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
AbstractScene * getScene()
ObjectItem(ItemController *controller=0, Observable *o=0)
virtual te::gm::Coord2D getPosition()
static Context * getInstance()
This function is called to create an instance of the class.
virtual bool contains(const QPointF &point) const
double getHeight() const
It returns the envelope height.
bool isValid() const
It tells if the rectangle is valid or not.
virtual QRectF boundingRect() const
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)