mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Implemented the movement of the ToolTip by Hand.
Reimplement the movement of the tooltip by hand, we were adding / removing childs of the tooltip quite often, wich broke the movement of the item using the default behavior, aparently Qt uses a cache of the transformation of the item, assuming that the bounding box of it will not get modified while dragging. wich in our particular case, is a falacy. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
34c6eec9ba
commit
ad5c186553
2 changed files with 21 additions and 9 deletions
|
@ -258,6 +258,7 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
|
|||
scene()->setSceneRect(0,0, viewport()->width()-50, viewport()->height()-50);
|
||||
|
||||
toolTip = new ToolTipItem();
|
||||
installEventFilter(toolTip);
|
||||
scene()->addItem(toolTip);
|
||||
|
||||
// Fix this for printing / screen later.
|
||||
|
@ -1355,12 +1356,9 @@ ToolTipItem::ToolTipItem(QGraphicsItem* parent): QGraphicsPathItem(parent), back
|
|||
{
|
||||
title = new QGraphicsSimpleTextItem(tr("Information"), this);
|
||||
separator = new QGraphicsLineItem(this);
|
||||
|
||||
dragging = false;
|
||||
setFlag(ItemIgnoresTransformations);
|
||||
setFlag(ItemIsMovable);
|
||||
|
||||
status = COLLAPSED;
|
||||
|
||||
updateTitlePosition();
|
||||
setZValue(99);
|
||||
}
|
||||
|
@ -1407,6 +1405,12 @@ bool ToolTipItem::isExpanded() {
|
|||
void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
|
||||
{
|
||||
persistPos();
|
||||
dragging = false;
|
||||
}
|
||||
|
||||
void ToolTipItem::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
||||
{
|
||||
dragging = true;
|
||||
}
|
||||
|
||||
void ToolTipItem::persistPos()
|
||||
|
@ -1417,7 +1421,6 @@ void ToolTipItem::persistPos()
|
|||
s.setValue("tooltip_position", currentPos);
|
||||
s.endGroup();
|
||||
s.sync();
|
||||
qDebug() << "Salvou" << currentPos;
|
||||
}
|
||||
|
||||
void ToolTipItem::readPos()
|
||||
|
@ -1430,6 +1433,15 @@ void ToolTipItem::readPos()
|
|||
setPos(value);
|
||||
}
|
||||
|
||||
bool ToolTipItem::eventFilter(QObject* view, QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::HoverMove && dragging){
|
||||
QHoverEvent *e = static_cast<QHoverEvent*>(event);
|
||||
QGraphicsView *v = scene()->views().at(0);
|
||||
setPos( v->mapToScene(e->pos()));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
EventItem::EventItem(QGraphicsItem* parent): QGraphicsPolygonItem(parent)
|
||||
{
|
||||
|
|
|
@ -34,11 +34,11 @@ public:
|
|||
void removeToolTip(const QString& toolTip);
|
||||
void refresh(struct graphics_context* gc, QPointF pos);
|
||||
bool isExpanded();
|
||||
|
||||
void persistPos();
|
||||
void readPos();
|
||||
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent* event);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
|
||||
bool eventFilter(QObject* , QEvent* );
|
||||
public Q_SLOTS:
|
||||
void setRect(const QRectF& rect);
|
||||
|
||||
|
@ -49,8 +49,8 @@ private:
|
|||
QGraphicsLineItem *separator;
|
||||
QGraphicsSimpleTextItem *title;
|
||||
Status status;
|
||||
|
||||
QRectF rectangle;
|
||||
bool dragging;
|
||||
};
|
||||
|
||||
class EventItem : public QGraphicsPolygonItem
|
||||
|
|
Loading…
Reference in a new issue