void PhotoGraphicsItem::mousePressEvent ( QGraphicsSceneMouseEvent * event ) { if (isEnabled() && deleteRect().contains(event->pos())) { if (scene()) { if (scene()->views().count()) { bool vResult = question(scene()->views().at(0)->parentWidget() , TRANSLATE("Удалить фото") , TRANSLATE("Вы действительно хотите удалить фотографию?") ); if (vResult) { ((GalleryGrapicsScene*)scene())->remove(id()); } } } } else { setActive(); } }
/** * \brief When we press a button on the mouse * left click : begin the draw of a boundingbox * right cick : remove the rectangles we clicked * \author Jules Gorny - ALCoV team, ISIT, UMR 6284 UdA – CNRS **/ void QImageLabel::mousePressEvent(QMouseEvent * event) { if(event->button() == Qt::LeftButton) mousePress(event->pos().x(), event->pos().y()); else if(event->button() == Qt::RightButton) deleteRect(event->pos().x(), event->pos().y()); }
void PhotoGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { if (isSelected()) { QBrush vOld = painter->brush(); QBrush vBackground = vOld; vBackground.setColor(Qt::gray); vBackground.setStyle(Qt::SolidPattern); painter->fillRect(boundingRect(), vBackground); painter->setBrush(vOld); } QRectF vRectImage = imageRect(); painter->drawImage(vRectImage, mImage); if (isHover && isEnabled()) { QRectF vRectDelete = deleteRect(); painter->drawImage(vRectDelete, mDeleteImage.scaled(vRectDelete.width(), vRectDelete.height())); } GeneralGraphicsItem::paint(painter, option, widget); }
void PhotoGraphicsItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ) { Q_UNUSED(event); isHover = false; update(deleteRect()); }