Mercurial > hg > svgui
comparison view/View.cpp @ 1354:40b9a495a0e0
Use zoom constraints more consistently, including the new RelativelyFine one
author | Chris Cannam |
---|---|
date | Wed, 10 Oct 2018 14:33:10 +0100 |
parents | 86429ff00f05 |
children | b9bfcb8cd5a1 |
comparison
equal
deleted
inserted
replaced
1353:86429ff00f05 | 1354:40b9a495a0e0 |
---|---|
24 | 24 |
25 #include "layer/TimeRulerLayer.h" | 25 #include "layer/TimeRulerLayer.h" |
26 #include "layer/SingleColourLayer.h" | 26 #include "layer/SingleColourLayer.h" |
27 #include "layer/PaintAssistant.h" | 27 #include "layer/PaintAssistant.h" |
28 | 28 |
29 #include "data/model/PowerOfSqrtTwoZoomConstraint.h" | 29 #include "data/model/RelativelyFineZoomConstraint.h" |
30 #include "data/model/RangeSummarisableTimeValueModel.h" | 30 #include "data/model/RangeSummarisableTimeValueModel.h" |
31 | 31 |
32 #include "widgets/IconLoader.h" | 32 #include "widgets/IconLoader.h" |
33 | 33 |
34 #include <QPainter> | 34 #include <QPainter> |
1467 ZoomConstraint::RoundingDirection dir) | 1467 ZoomConstraint::RoundingDirection dir) |
1468 const | 1468 const |
1469 { | 1469 { |
1470 using namespace std::rel_ops; | 1470 using namespace std::rel_ops; |
1471 | 1471 |
1472 ZoomLevel candidate = zoomLevel; | 1472 ZoomLevel candidate = |
1473 bool haveCandidate = false; | 1473 RelativelyFineZoomConstraint().getNearestZoomLevel(zoomLevel, dir); |
1474 | 1474 |
1475 PowerOfSqrtTwoZoomConstraint defaultZoomConstraint; | 1475 for (auto i : m_layerStack) { |
1476 | 1476 |
1477 for (auto i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { | 1477 if (i->supportsOtherZoomLevels() || !(i->getZoomConstraint())) { |
1478 | 1478 continue; |
1479 const ZoomConstraint *zoomConstraint = (*i)->getZoomConstraint(); | 1479 } |
1480 if (!zoomConstraint) zoomConstraint = &defaultZoomConstraint; | 1480 |
1481 | |
1482 ZoomLevel thisLevel = | 1481 ZoomLevel thisLevel = |
1483 zoomConstraint->getNearestZoomLevel(zoomLevel, dir); | 1482 i->getZoomConstraint()->getNearestZoomLevel(zoomLevel, dir); |
1484 | 1483 |
1485 // Go for the block size that's furthest from the one | 1484 // Go for the block size that's furthest from the one |
1486 // passed in. Most of the time, that's what we want. | 1485 // passed in. Most of the time, that's what we want. |
1487 if (!haveCandidate || | 1486 if ((thisLevel > zoomLevel && thisLevel > candidate) || |
1488 (thisLevel > zoomLevel && thisLevel > candidate) || | |
1489 (thisLevel < zoomLevel && thisLevel < candidate)) { | 1487 (thisLevel < zoomLevel && thisLevel < candidate)) { |
1490 candidate = thisLevel; | 1488 candidate = thisLevel; |
1491 haveCandidate = true; | |
1492 } | 1489 } |
1493 } | 1490 } |
1494 | 1491 |
1495 return candidate; | 1492 return candidate; |
1493 } | |
1494 | |
1495 int | |
1496 View::countZoomLevels() const | |
1497 { | |
1498 int n = 0; | |
1499 ZoomLevel min = ZoomConstraint().getMinZoomLevel(); | |
1500 ZoomLevel max = ZoomConstraint().getMaxZoomLevel(); | |
1501 ZoomLevel level = min; | |
1502 while (true) { | |
1503 ++n; | |
1504 if (level == max) { | |
1505 break; | |
1506 } | |
1507 level = getZoomConstraintLevel | |
1508 (level.incremented(), ZoomConstraint::RoundUp); | |
1509 } | |
1510 cerr << "View::countZoomLevels: " << n << endl; | |
1511 return n; | |
1512 } | |
1513 | |
1514 ZoomLevel | |
1515 View::getZoomLevelByIndex(int ix) const | |
1516 { | |
1517 int n = 0; | |
1518 ZoomLevel min = ZoomConstraint().getMinZoomLevel(); | |
1519 ZoomLevel max = ZoomConstraint().getMaxZoomLevel(); | |
1520 ZoomLevel level = min; | |
1521 while (true) { | |
1522 if (n == ix) { | |
1523 cerr << "View::getZoomLevelByIndex: " << ix << " -> " << level | |
1524 << endl; | |
1525 return level; | |
1526 } | |
1527 ++n; | |
1528 if (level == max) { | |
1529 break; | |
1530 } | |
1531 level = getZoomConstraintLevel | |
1532 (level.incremented(), ZoomConstraint::RoundUp); | |
1533 } | |
1534 cerr << "View::getZoomLevelByIndex: " << ix << " -> " << max << " (max)" | |
1535 << endl; | |
1536 return max; | |
1537 } | |
1538 | |
1539 int | |
1540 View::getZoomLevelIndex(ZoomLevel z) const | |
1541 { | |
1542 int n = 0; | |
1543 ZoomLevel min = ZoomConstraint().getMinZoomLevel(); | |
1544 ZoomLevel max = ZoomConstraint().getMaxZoomLevel(); | |
1545 ZoomLevel level = min; | |
1546 while (true) { | |
1547 if (z == level) { | |
1548 cerr << "View::getZoomLevelIndex: " << z << " -> " << n | |
1549 << endl; | |
1550 return n; | |
1551 } | |
1552 ++n; | |
1553 if (level == max) { | |
1554 break; | |
1555 } | |
1556 level = getZoomConstraintLevel | |
1557 (level.incremented(), ZoomConstraint::RoundUp); | |
1558 } | |
1559 cerr << "View::getZoomLevelIndex: " << z << " -> " << n << " (max)" | |
1560 << endl; | |
1561 return n; | |
1496 } | 1562 } |
1497 | 1563 |
1498 bool | 1564 bool |
1499 View::areLayerColoursSignificant() const | 1565 View::areLayerColoursSignificant() const |
1500 { | 1566 { |
1732 QFrame::paintEvent(e); | 1798 QFrame::paintEvent(e); |
1733 return; | 1799 return; |
1734 } | 1800 } |
1735 | 1801 |
1736 // ensure our constraints are met | 1802 // ensure our constraints are met |
1737 | 1803 m_zoomLevel = getZoomConstraintLevel |
1738 /*!!! Should we do this only if we have layers that can't support other | 1804 (m_zoomLevel, ZoomConstraint::RoundNearest); |
1739 zoom levels? | |
1740 | |
1741 m_zoomLevel = getZoomConstraintBlockSize(m_zoomLevel, | |
1742 ZoomConstraint::RoundUp); | |
1743 */ | |
1744 | 1805 |
1745 QPainter paint; | 1806 QPainter paint; |
1746 bool repaintCache = false; | 1807 bool repaintCache = false; |
1747 bool paintedCacheRect = false; | 1808 bool paintedCacheRect = false; |
1748 | 1809 |