mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Fix Tooltip Positions, code cleanup
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
93d3af768b
commit
2052e44ba1
2 changed files with 22 additions and 11 deletions
|
@ -142,6 +142,7 @@ void ProfileGraphicsView::wheelEvent(QWheelEvent* event)
|
||||||
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||||
|
|
||||||
// Scale the view / do the zoom
|
// Scale the view / do the zoom
|
||||||
|
QPoint toolTipPos = mapFromScene(toolTip->pos());
|
||||||
double scaleFactor = 1.15;
|
double scaleFactor = 1.15;
|
||||||
if(event->delta() > 0) {
|
if(event->delta() > 0) {
|
||||||
// Zoom in
|
// Zoom in
|
||||||
|
@ -150,23 +151,16 @@ void ProfileGraphicsView::wheelEvent(QWheelEvent* event)
|
||||||
// Zooming out
|
// Zooming out
|
||||||
scale(1.0 / scaleFactor, 1.0 / scaleFactor);
|
scale(1.0 / scaleFactor, 1.0 / scaleFactor);
|
||||||
}
|
}
|
||||||
|
toolTip->setPos(mapToScene(toolTipPos).x(), mapToScene(toolTipPos).y());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event)
|
void ProfileGraphicsView::mouseMoveEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
toolTip->clear();
|
toolTip->refresh(&gc, mapToScene(event->pos()));
|
||||||
int time = (mapToScene(event->pos()).x() * gc.maxtime) / scene()->sceneRect().width();
|
|
||||||
char buffer[500];
|
|
||||||
get_plot_details(&gc, time, buffer, 500);
|
|
||||||
toolTip->addToolTip(QString(buffer));
|
|
||||||
QList<QGraphicsItem*> items = scene()->items(mapToScene(event->pos()), Qt::IntersectsItemShape, Qt::DescendingOrder, transform());
|
|
||||||
Q_FOREACH(QGraphicsItem *item, items) {
|
|
||||||
if (!item->toolTip().isEmpty())
|
|
||||||
toolTip->addToolTip(item->toolTip());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pan on mouseMove code.
|
QPoint toolTipPos = mapFromScene(toolTip->pos());
|
||||||
ensureVisible(event->pos().x(), event->pos().y(), 10, 10, 100, 100);
|
ensureVisible(event->pos().x(), event->pos().y(), 10, 10, 100, 100);
|
||||||
|
toolTip->setPos(mapToScene(toolTipPos).x(), mapToScene(toolTipPos).y());
|
||||||
|
|
||||||
QGraphicsView::mouseMoveEvent(event);
|
QGraphicsView::mouseMoveEvent(event);
|
||||||
}
|
}
|
||||||
|
@ -1172,6 +1166,22 @@ void ToolTipItem::removeToolTip(const QString& toolTip)
|
||||||
expand();
|
expand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ToolTipItem::refresh(struct graphics_context *gc, QPointF pos)
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
int time = (pos.x() * gc->maxtime) / scene()->sceneRect().width();
|
||||||
|
char buffer[500];
|
||||||
|
get_plot_details(gc, time, buffer, 500);
|
||||||
|
addToolTip(QString(buffer));
|
||||||
|
|
||||||
|
QList<QGraphicsItem*> items = scene()->items(pos, Qt::IntersectsItemShape, Qt::DescendingOrder, transform());
|
||||||
|
Q_FOREACH(QGraphicsItem *item, items) {
|
||||||
|
if (!item->toolTip().isEmpty())
|
||||||
|
addToolTip(item->toolTip());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void ToolTipItem::clear()
|
void ToolTipItem::clear()
|
||||||
{
|
{
|
||||||
Q_FOREACH(ToolTip t, toolTips) {
|
Q_FOREACH(ToolTip t, toolTips) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
void clear();
|
void clear();
|
||||||
void addToolTip(const QString& toolTip, const QIcon& icon = QIcon());
|
void addToolTip(const QString& toolTip, const QIcon& icon = QIcon());
|
||||||
void removeToolTip(const QString& toolTip);
|
void removeToolTip(const QString& toolTip);
|
||||||
|
void refresh(struct graphics_context* gc, QPointF pos);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setRect(const QRectF& rect);
|
void setRect(const QRectF& rect);
|
||||||
|
|
Loading…
Add table
Reference in a new issue