| 535 | } |
| 536 | |
| 537 | void |
| 538 | TreeCanvas::zoomToFit(void) { |
| 539 | QMutexLocker locker(&layoutMutex); |
| 540 | if (root != nullptr) { |
| 541 | BoundingBox bb; |
| 542 | bb = root->getBoundingBox(); |
| 543 | QWidget* p = parentWidget(); |
| 544 | if (p) { |
| 545 | double newXScale = |
| 546 | static_cast<double>(p->width()) / (bb.right - bb.left + |
| 547 | Layout::extent); |
| 548 | double newYScale = |
| 549 | static_cast<double>(p->height()) / (root->getShape()->depth() * |
| 550 | Layout::dist_y + |
| 551 | 2*Layout::extent); |
| 552 | int scale0 = static_cast<int>(std::min(newXScale, newYScale)*100); |
| 553 | if (scale0<LayoutConfig::minScale) |
| 554 | scale0 = LayoutConfig::minScale; |
| 555 | if (scale0>LayoutConfig::maxAutoZoomScale) |
| 556 | scale0 = LayoutConfig::maxAutoZoomScale; |
| 557 | |
| 558 | if (!smoothScrollAndZoom) { |
| 559 | scaleTree(scale0); |
| 560 | } else { |
| 561 | zoomTimeLine.stop(); |
| 562 | int zoomCurrent = static_cast<int>(scale*100); |
| 563 | int targetZoom = scale0; |
| 564 | targetZoom = std::min(std::max(targetZoom, LayoutConfig::minScale), |
| 565 | LayoutConfig::maxAutoZoomScale); |
| 566 | zoomTimeLine.setFrameRange(zoomCurrent,targetZoom); |
| 567 | zoomTimeLine.start(); |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | void |
| 574 | TreeCanvas::centerCurrentNode(void) { |