aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--historygraph.cpp30
-rw-r--r--historygraph.h4
2 files changed, 32 insertions, 2 deletions
diff --git a/historygraph.cpp b/historygraph.cpp
index 0aeec20..66249e5 100644
--- a/historygraph.cpp
+++ b/historygraph.cpp
@@ -126,11 +126,13 @@ HistoryGraph::HistoryGraph(QQuickItem *parent)
: QQuickItem(parent)
, m_firstNode(0)
, m_currentNode(0)
+ , m_currentWidth(0.0f)
, m_needsUpdate(false)
{
setClip(true);
setFlag(QQuickItem::ItemHasContents);
setAcceptedMouseButtons(Qt::LeftButton);
+ setAcceptHoverEvents(true);
}
HistoryGraph::~HistoryGraph()
@@ -193,7 +195,7 @@ QSGNode *HistoryGraph::createNodeTree()
//int breadth = m_firstNode->breadth();
//int depth = m_firstNode->depth();
- QSGNode *sceneGraphRoot = new QSGNode;
+ QSGTransformNode *sceneGraphRoot = new QSGTransformNode;
HistoryItemNode *histNode = m_firstNode;
float margin = height()*MARGIN;
float padding = height()*PADDING;
@@ -234,7 +236,12 @@ QSGNode *HistoryGraph::createNodeTree()
histNode = children[0];
} while (true);
- // setWidth(xPos + radius + margin);
+ m_currentWidth = x - 2.0f*margin;
+
+ if (m_currentWidth > width()) {
+ m_viewportTransform.setToIdentity();
+ m_viewportTransform.translate(-(m_currentWidth - width() + margin), 0);
+ }
return sceneGraphRoot;
}
@@ -274,6 +281,8 @@ QSGNode *HistoryGraph::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
updateNodeTree(root);
}
+ static_cast<QSGTransformNode *>(root->firstChild())->setMatrix(m_viewportTransform);
+
return root;
}
@@ -309,6 +318,23 @@ HistoryGraph::HistoryItemNode *HistoryGraph::nodeAt(const QPointF &pos, HistoryG
return 0;
}
+void HistoryGraph::hoverMoveEvent(QHoverEvent *event)
+{
+ if (m_currentWidth < width()) {
+ return;
+ }
+
+ const QPointF &pos = event->posF();
+ float margin = MARGIN * height();
+ float prop = (pos.x() - margin) / (width() - 2*margin);
+ float displ = m_currentWidth - width() + margin;
+
+ m_viewportTransform.setToIdentity();
+ m_viewportTransform.translate(-displ * prop, 0);
+
+ update();
+}
+
void HistoryGraph::mousePressEvent(QMouseEvent *event)
{
HistoryGraph::HistoryItemNode *node = nodeAt(event->localPos());
diff --git a/historygraph.h b/historygraph.h
index 60cce94..6c5bd9a 100644
--- a/historygraph.h
+++ b/historygraph.h
@@ -2,6 +2,7 @@
#define HISTORYGRAPH_H
#include <QtQuick>
+#include <QMatrix4x4>
#include <armadillo>
class HistoryGraph : public QQuickItem
@@ -19,6 +20,7 @@ public slots:
protected:
QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *);
+ void hoverMoveEvent(QHoverEvent *event);
void mousePressEvent(QMouseEvent *event);
private:
@@ -32,6 +34,8 @@ private:
void addScatterplot(QSGNode *node, const HistoryItemNode *historyItemNode, float x, float y, float w, float h);
HistoryItemNode *m_firstNode, *m_currentNode;
+ QMatrix4x4 m_viewportTransform;
+ float m_currentWidth;
bool m_needsUpdate;
};