mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +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);
|
scene()->setSceneRect(0,0, viewport()->width()-50, viewport()->height()-50);
|
||||||
|
|
||||||
toolTip = new ToolTipItem();
|
toolTip = new ToolTipItem();
|
||||||
|
installEventFilter(toolTip);
|
||||||
scene()->addItem(toolTip);
|
scene()->addItem(toolTip);
|
||||||
|
|
||||||
// Fix this for printing / screen later.
|
// Fix this for printing / screen later.
|
||||||
|
@ -1355,12 +1356,9 @@ ToolTipItem::ToolTipItem(QGraphicsItem* parent): QGraphicsPathItem(parent), back
|
||||||
{
|
{
|
||||||
title = new QGraphicsSimpleTextItem(tr("Information"), this);
|
title = new QGraphicsSimpleTextItem(tr("Information"), this);
|
||||||
separator = new QGraphicsLineItem(this);
|
separator = new QGraphicsLineItem(this);
|
||||||
|
dragging = false;
|
||||||
setFlag(ItemIgnoresTransformations);
|
setFlag(ItemIgnoresTransformations);
|
||||||
setFlag(ItemIsMovable);
|
|
||||||
|
|
||||||
status = COLLAPSED;
|
status = COLLAPSED;
|
||||||
|
|
||||||
updateTitlePosition();
|
updateTitlePosition();
|
||||||
setZValue(99);
|
setZValue(99);
|
||||||
}
|
}
|
||||||
|
@ -1407,6 +1405,12 @@ bool ToolTipItem::isExpanded() {
|
||||||
void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
|
void ToolTipItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
|
||||||
{
|
{
|
||||||
persistPos();
|
persistPos();
|
||||||
|
dragging = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToolTipItem::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
||||||
|
{
|
||||||
|
dragging = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipItem::persistPos()
|
void ToolTipItem::persistPos()
|
||||||
|
@ -1417,7 +1421,6 @@ void ToolTipItem::persistPos()
|
||||||
s.setValue("tooltip_position", currentPos);
|
s.setValue("tooltip_position", currentPos);
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
s.sync();
|
s.sync();
|
||||||
qDebug() << "Salvou" << currentPos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToolTipItem::readPos()
|
void ToolTipItem::readPos()
|
||||||
|
@ -1430,6 +1433,15 @@ void ToolTipItem::readPos()
|
||||||
setPos(value);
|
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)
|
EventItem::EventItem(QGraphicsItem* parent): QGraphicsPolygonItem(parent)
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,11 +34,11 @@ public:
|
||||||
void removeToolTip(const QString& toolTip);
|
void removeToolTip(const QString& toolTip);
|
||||||
void refresh(struct graphics_context* gc, QPointF pos);
|
void refresh(struct graphics_context* gc, QPointF pos);
|
||||||
bool isExpanded();
|
bool isExpanded();
|
||||||
|
|
||||||
void persistPos();
|
void persistPos();
|
||||||
void readPos();
|
void readPos();
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent* event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
|
||||||
|
bool eventFilter(QObject* , QEvent* );
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void setRect(const QRectF& rect);
|
void setRect(const QRectF& rect);
|
||||||
|
|
||||||
|
@ -49,8 +49,8 @@ private:
|
||||||
QGraphicsLineItem *separator;
|
QGraphicsLineItem *separator;
|
||||||
QGraphicsSimpleTextItem *title;
|
QGraphicsSimpleTextItem *title;
|
||||||
Status status;
|
Status status;
|
||||||
|
|
||||||
QRectF rectangle;
|
QRectF rectangle;
|
||||||
|
bool dragging;
|
||||||
};
|
};
|
||||||
|
|
||||||
class EventItem : public QGraphicsPolygonItem
|
class EventItem : public QGraphicsPolygonItem
|
||||||
|
|
Loading…
Add table
Reference in a new issue