summaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-10 14:48:31 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-10 14:48:31 -0300
commitad5c18655365d5f8adad9397d7dc0e52d2522fdd (patch)
tree71e186526a16c1cf507084c05981b990493c4816 /qt-ui
parent34c6eec9bac57846da042aac546578bdb5dcb1af (diff)
downloadsubsurface-ad5c18655365d5f8adad9397d7dc0e52d2522fdd.tar.gz
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>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/profilegraphics.cpp22
-rw-r--r--qt-ui/profilegraphics.h8
2 files changed, 21 insertions, 9 deletions
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index 9c73e1fdc..1c6f76209 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -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)
{
diff --git a/qt-ui/profilegraphics.h b/qt-ui/profilegraphics.h
index 8f83deabb..2e4f0d596 100644
--- a/qt-ui/profilegraphics.h
+++ b/qt-ui/profilegraphics.h
@@ -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