ui: Pan graph view to name of active symbol after activation

bug id = 80
This commit is contained in:
Eberhard Graether
2016-07-22 13:57:58 +02:00
parent b2cb95de1b
commit f4677a902d
7 changed files with 103 additions and 29 deletions
+37 -2
View File
@@ -4,6 +4,9 @@
#include <QScrollBar>
#include <QTimer>
#include <QPropertyAnimation>
#include <QParallelAnimationGroup>
QtGraphicsView::QtGraphicsView(QWidget* parent)
: QGraphicsView(parent)
, m_zoomFactor(1.0f)
@@ -17,7 +20,7 @@ QtGraphicsView::QtGraphicsView(QWidget* parent)
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
m_timer = std::make_shared<QTimer>(this);
connect(m_timer.get(), SIGNAL(timeout()), this, SLOT(update()));
connect(m_timer.get(), SIGNAL(timeout()), this, SLOT(updateTimer()));
m_timerStopper = std::make_shared<QTimer>(this);
m_timerStopper->setSingleShot(true);
@@ -35,6 +38,38 @@ void QtGraphicsView::setAppZoomFactor(float appZoomFactor)
updateTransform();
}
void QtGraphicsView::ensureVisibleAnimated(const QRectF& rect, int xmargin, int ymargin)
{
int xval = horizontalScrollBar()->value();
int yval = verticalScrollBar()->value();
ensureVisible(rect, xmargin, ymargin);
int xval2 = horizontalScrollBar()->value();
int yval2 = verticalScrollBar()->value();
horizontalScrollBar()->setValue(xval);
verticalScrollBar()->setValue(yval);
QParallelAnimationGroup* move = new QParallelAnimationGroup();
QPropertyAnimation* xanim = new QPropertyAnimation(horizontalScrollBar(), "value");
xanim->setDuration(150);
xanim->setStartValue(xval);
xanim->setEndValue(xval2);
xanim->setEasingCurve(QEasingCurve::InOutQuad);
move->addAnimation(xanim);
QPropertyAnimation* yanim = new QPropertyAnimation(verticalScrollBar(), "value");
yanim->setDuration(150);
yanim->setStartValue(yval);
yanim->setEndValue(yval2);
yanim->setEasingCurve(QEasingCurve::InOutQuad);
move->addAnimation(yanim);
move->start();
}
void QtGraphicsView::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton && !itemAt(event->pos()))
@@ -134,7 +169,7 @@ void QtGraphicsView::wheelEvent(QWheelEvent* event)
QGraphicsView::wheelEvent(event);
}
void QtGraphicsView::update()
void QtGraphicsView::updateTimer()
{
float ds = 30.0f;
float dz = 50.0f;
+3 -1
View File
@@ -20,6 +20,8 @@ public:
float getZoomFactor() const;
void setAppZoomFactor(float appZoomFactor);
void ensureVisibleAnimated(const QRectF& rect, int xmargin = 50, int ymargin = 50);
protected:
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
@@ -33,7 +35,7 @@ signals:
void emptySpaceClicked();
private slots:
void update();
void updateTimer();
void stopTimer();
private:
+35 -11
View File
@@ -84,9 +84,9 @@ void QtGraphView::rebuildGraph(
std::shared_ptr<Graph> graph,
const std::vector<std::shared_ptr<DummyNode>>& nodes,
const std::vector<std::shared_ptr<DummyEdge>>& edges,
bool animated
const GraphParams params
){
m_rebuildGraphFunctor(graph, nodes, edges, animated);
m_rebuildGraphFunctor(graph, nodes, edges, params);
}
void QtGraphView::clear()
@@ -166,7 +166,7 @@ void QtGraphView::switchToNewGraphData()
doResize();
// Manually hover the item below the mouse cursor.
QGraphicsView* view = getView();
QtGraphicsView* view = getView();
QPointF point = view->mapToScene(view->mapFromGlobal(QCursor::pos()));
QGraphicsItem* item = view->scene()->itemAt(point, QTransform());
if (item)
@@ -178,6 +178,22 @@ void QtGraphView::switchToNewGraphData()
}
}
if (m_activeNode)
{
Vec2i pos = m_activeNode->getPosition();
Vec2i size = m_activeNode->getSize();
QRectF rect(pos.x, pos.y, size.x, size.y);
if (rect.height() > view->height() - 200)
{
rect.setHeight(view->height() - 200);
}
view->ensureVisibleAnimated(rect, 100, 100);
m_activeNode.reset();
}
// Repaint to make sure all artifacts are removed
view->update();
}
@@ -200,7 +216,7 @@ void QtGraphView::doRebuildGraph(
std::shared_ptr<Graph> graph,
const std::vector<std::shared_ptr<DummyNode>>& nodes,
const std::vector<std::shared_ptr<DummyEdge>>& edges,
bool animated
const GraphParams params
){
if (m_transition && m_transition->currentTime() < m_transition->totalDuration())
{
@@ -217,6 +233,7 @@ void QtGraphView::doRebuildGraph(
}
m_nodes.clear();
m_activeNode.reset();
for (unsigned int i = 0; i < nodes.size(); i++)
{
std::shared_ptr<QtGraphNode> node = createNodeRecursive(view, NULL, nodes[i].get(), activeNodeCount > 1);
@@ -251,7 +268,7 @@ void QtGraphView::doRebuildGraph(
m_graph = graph;
}
if (animated)
if (params.animatedTransition)
{
createTransition();
}
@@ -259,6 +276,11 @@ void QtGraphView::doRebuildGraph(
{
switchToNewGraphData();
}
if (!params.centerActiveNode)
{
m_activeNode.reset();
}
}
void QtGraphView::doClear()
@@ -352,6 +374,11 @@ std::shared_ptr<QtGraphNode> QtGraphView::createNodeRecursive(
newNode->addComponent(std::make_shared<QtGraphNodeComponentMoveable>(newNode));
}
if (node->active && !m_activeNode)
{
m_activeNode = newNode;
}
for (unsigned int i = 0; i < node->subNodes.size(); i++)
{
std::shared_ptr<QtGraphNode> subNode = createNodeRecursive(view, newNode, node->subNodes[i].get(), multipleActive);
@@ -544,13 +571,10 @@ void QtGraphView::createTransition()
anim->setStartValue(view->sceneRect());
anim->setEndValue(getSceneRect(m_nodes));
if (remainingNodes.size())
anim->setDuration(300);
if (!remainingNodes.size())
{
anim->setDuration(300);
}
else
{
anim->setDuration(300);
connect(anim, SIGNAL(finished()), this, SLOT(centerScrollBars()));
}
+5 -3
View File
@@ -35,7 +35,7 @@ public:
std::shared_ptr<Graph> graph,
const std::vector<std::shared_ptr<DummyNode>>& nodes,
const std::vector<std::shared_ptr<DummyEdge>>& edges,
bool animated);
const GraphParams params);
virtual void clear();
virtual void focusTokenIds(const std::vector<Id>& focusedTokenIds);
@@ -59,7 +59,7 @@ private:
std::shared_ptr<Graph> graph,
const std::vector<std::shared_ptr<DummyNode>>& nodes,
const std::vector<std::shared_ptr<DummyEdge>>& edges,
bool animated);
const GraphParams params);
void doClear();
void doResize();
void doRefreshView();
@@ -89,7 +89,7 @@ private:
std::shared_ptr<Graph>,
const std::vector<std::shared_ptr<DummyNode>>&,
const std::vector<std::shared_ptr<DummyEdge>>&,
bool
const GraphParams
> m_rebuildGraphFunctor;
QtThreadedFunctor<void> m_clearFunctor;
QtThreadedFunctor<void> m_resizeFunctor;
@@ -106,6 +106,8 @@ private:
std::list<std::shared_ptr<QtGraphNode>> m_nodes;
std::list<std::shared_ptr<QtGraphNode>> m_oldNodes;
std::shared_ptr<QtGraphNode> m_activeNode;
std::shared_ptr<QSequentialAnimationGroup> m_transition;
QPointF m_sceneRectOffset;
};