MCPcopy Create free account
hub / github.com/Gecode/gecode / centerCurrentNode

Method centerCurrentNode

gecode/gist/treecanvas.cpp:573–614  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

571 }
572
573 void
574 TreeCanvas::centerCurrentNode(void) {
575 QMutexLocker locker(&mutex);
576 int x=0;
577 int y=0;
578
579 VisualNode* c = currentNode;
580 while (c != nullptr) {
581 x += c->getOffset();
582 y += Layout::dist_y;
583 c = c->getParent(*na);
584 }
585
586 x = static_cast<int>((xtrans+x)*scale); y = static_cast<int>(y*scale);
587
588 QAbstractScrollArea* sa =
589 static_cast<QAbstractScrollArea*>(parentWidget()->parentWidget());
590
591 x -= sa->viewport()->width() / 2;
592 y -= sa->viewport()->height() / 2;
593
594 sourceX = sa->horizontalScrollBar()->value();
595 targetX = std::max(sa->horizontalScrollBar()->minimum(), x);
596 targetX = std::min(sa->horizontalScrollBar()->maximum(),
597 targetX);
598 sourceY = sa->verticalScrollBar()->value();
599 targetY = std::max(sa->verticalScrollBar()->minimum(), y);
600 targetY = std::min(sa->verticalScrollBar()->maximum(),
601 targetY);
602 if (!smoothScrollAndZoom) {
603 sa->horizontalScrollBar()->setValue(targetX);
604 sa->verticalScrollBar()->setValue(targetY);
605 } else {
606 scrollTimeLine.stop();
607 scrollTimeLine.setFrameRange(0,100);
608 scrollTimeLine.setDuration(std::max(200,
609 std::min(1000,
610 std::min(std::abs(sourceX-targetX),
611 std::abs(sourceY-targetY)))));
612 scrollTimeLine.start();
613 }
614 }
615
616 void
617 TreeCanvas::scroll(int i) {

Callers 1

selectBookmarkMethod · 0.80

Calls 10

getOffsetMethod · 0.80
getParentMethod · 0.80
maxFunction · 0.50
minFunction · 0.50
absFunction · 0.50
widthMethod · 0.45
heightMethod · 0.45
valueMethod · 0.45
stopMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected