mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
Handle the tooltips pixel accurate
This commit is contained in:
parent
9c96e7124a
commit
0c1a123cd9
@ -320,7 +320,8 @@ SOURCES += src/main.cpp \
|
|||||||
src/GUI/pathtickitem.cpp \
|
src/GUI/pathtickitem.cpp \
|
||||||
src/map/IMG/textitem.cpp \
|
src/map/IMG/textitem.cpp \
|
||||||
src/data/csv.cpp \
|
src/data/csv.cpp \
|
||||||
src/data/cupparser.cpp
|
src/data/cupparser.cpp \
|
||||||
|
src/GUI/graphicsscene.cpp
|
||||||
|
|
||||||
greaterThan(QT_MAJOR_VERSION, 4) {
|
greaterThan(QT_MAJOR_VERSION, 4) {
|
||||||
HEADERS += src/data/geojsonparser.h
|
HEADERS += src/data/geojsonparser.h
|
||||||
|
48
src/GUI/graphicsscene.cpp
Normal file
48
src/GUI/graphicsscene.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include <QGraphicsSceneHelpEvent>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
#include "popup.h"
|
||||||
|
#include "graphicsscene.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* 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() */
|
||||||
|
}
|
@ -3,9 +3,6 @@
|
|||||||
|
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
#include <QGraphicsSceneHelpEvent>
|
|
||||||
#include <QWidget>
|
|
||||||
#include "popup.h"
|
|
||||||
|
|
||||||
class GraphicsItem : public QGraphicsItem
|
class GraphicsItem : public QGraphicsItem
|
||||||
{
|
{
|
||||||
@ -22,15 +19,11 @@ public:
|
|||||||
GraphicsScene(QObject *parent = 0) : QGraphicsScene(parent) {}
|
GraphicsScene(QObject *parent = 0) : QGraphicsScene(parent) {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void helpEvent(QGraphicsSceneHelpEvent *event)
|
void helpEvent(QGraphicsSceneHelpEvent *event);
|
||||||
{
|
|
||||||
QGraphicsItem *item = itemAt(event->scenePos(), QTransform());
|
private:
|
||||||
if (item && item->type() == QGraphicsItem::UserType + 1) {
|
QList<QGraphicsItem *> itemsAtPosition(const QPoint &screenPos,
|
||||||
GraphicsItem *mi = static_cast<GraphicsItem*>(item);
|
const QPointF &scenePos, QWidget *widget) const;
|
||||||
Popup::show(event->screenPos(), mi->info(),
|
|
||||||
static_cast<QWidget*>(parent()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GRAPHICSSCENE_H
|
#endif // GRAPHICSSCENE_H
|
||||||
|
Loading…
Reference in New Issue
Block a user