2019-10-16 19:22:55 +02:00
|
|
|
#include <QGraphicsSceneHelpEvent>
|
|
|
|
#include <QGraphicsView>
|
|
|
|
#include "popup.h"
|
|
|
|
#include "graphicsscene.h"
|
|
|
|
|
|
|
|
|
2022-09-25 02:15:24 +02:00
|
|
|
bool GraphicsItem::_useStyle = false;
|
|
|
|
|
2019-10-16 19:22:55 +02:00
|
|
|
/* Standard GraphicsScene::items() is not pixel accurate, so we use the
|
|
|
|
following function which has the same logic as used in the original
|
|
|
|
QGraphicsScene::helpEvent() function. */
|
|
|
|
QList<QGraphicsItem *> GraphicsScene::itemsAtPosition(const QPoint &screenPos,
|
|
|
|
const QPointF &scenePos, QWidget *widget) const
|
|
|
|
{
|
|
|
|
QGraphicsView *view = widget
|
|
|
|
? qobject_cast<QGraphicsView *>(widget->parentWidget()) : 0;
|
|
|
|
|
|
|
|
if (!view)
|
|
|
|
return items(scenePos, Qt::IntersectsItemShape, Qt::DescendingOrder,
|
|
|
|
QTransform());
|
|
|
|
|
|
|
|
const QRectF pointRect(QPointF(widget->mapFromGlobal(screenPos)),
|
|
|
|
QSizeF(1, 1));
|
|
|
|
if (!view->isTransformed())
|
|
|
|
return items(pointRect, Qt::IntersectsItemShape, Qt::DescendingOrder);
|
|
|
|
|
|
|
|
const QTransform viewTransform = view->viewportTransform();
|
|
|
|
if (viewTransform.type() <= QTransform::TxScale)
|
|
|
|
return items(viewTransform.inverted().mapRect(pointRect),
|
|
|
|
Qt::IntersectsItemShape, Qt::DescendingOrder, viewTransform);
|
|
|
|
|
|
|
|
return items(viewTransform.inverted().map(pointRect),
|
|
|
|
Qt::IntersectsItemShape, Qt::DescendingOrder, viewTransform);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GraphicsScene::helpEvent(QGraphicsSceneHelpEvent *event)
|
|
|
|
{
|
|
|
|
QList<QGraphicsItem *> list = itemsAtPosition(event->screenPos(),
|
|
|
|
event->scenePos(), event->widget());
|
|
|
|
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
if (list.at(i)->type() == QGraphicsItem::UserType + 1) {
|
|
|
|
GraphicsItem *mi = static_cast<GraphicsItem*>(list.at(i));
|
|
|
|
Popup::show(event->screenPos(), mi->info(), event->widget());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No need to process QGraphicsScene::helpEvent() */
|
|
|
|
}
|
2019-12-23 16:16:15 +01:00
|
|
|
|
|
|
|
void GraphicsScene::clear()
|
|
|
|
{
|
|
|
|
Popup::clear();
|
|
|
|
QGraphicsScene::clear();
|
|
|
|
}
|