Mercurial > hg > svgui
comparison view/View.cpp @ 682:1a0dfcbffaf1
Drop std:: from cout, cerr, endl -- pull these in through Debug.h
author | Chris Cannam |
---|---|
date | Tue, 26 Nov 2013 14:06:40 +0000 |
parents | 0aea4b9e4c3d |
children | 596414d20ef0 |
comparison
equal
deleted
inserted
replaced
681:eaf4446a1bef | 682:1a0dfcbffaf1 |
---|---|
41 | 41 |
42 #include <unistd.h> | 42 #include <unistd.h> |
43 | 43 |
44 //#define DEBUG_VIEW_WIDGET_PAINT 1 | 44 //#define DEBUG_VIEW_WIDGET_PAINT 1 |
45 | 45 |
46 using std::cerr; | 46 |
47 using std::endl; | 47 |
48 | 48 |
49 View::View(QWidget *w, bool showProgress) : | 49 View::View(QWidget *w, bool showProgress) : |
50 QFrame(w), | 50 QFrame(w), |
51 m_centreFrame(0), | 51 m_centreFrame(0), |
52 m_zoomLevel(1024), | 52 m_zoomLevel(1024), |
323 int newPixel = m_centreFrame / m_zoomLevel; | 323 int newPixel = m_centreFrame / m_zoomLevel; |
324 | 324 |
325 if (newPixel != formerPixel) { | 325 if (newPixel != formerPixel) { |
326 | 326 |
327 #ifdef DEBUG_VIEW_WIDGET_PAINT | 327 #ifdef DEBUG_VIEW_WIDGET_PAINT |
328 std::cout << "View(" << this << ")::setCentreFrame: newPixel " << newPixel << ", formerPixel " << formerPixel << std::endl; | 328 cout << "View(" << this << ")::setCentreFrame: newPixel " << newPixel << ", formerPixel " << formerPixel << endl; |
329 #endif | 329 #endif |
330 update(); | 330 update(); |
331 | 331 |
332 changeVisible = true; | 332 changeVisible = true; |
333 } | 333 } |
334 | 334 |
335 if (e) { | 335 if (e) { |
336 size_t rf = alignToReference(f); | 336 size_t rf = alignToReference(f); |
337 #ifdef DEBUG_VIEW_WIDGET_PAINT | 337 #ifdef DEBUG_VIEW_WIDGET_PAINT |
338 std::cerr << "View[" << this << "]::setCentreFrame(" << f | 338 cerr << "View[" << this << "]::setCentreFrame(" << f |
339 << "): emitting centreFrameChanged(" | 339 << "): emitting centreFrameChanged(" |
340 << rf << ")" << std::endl; | 340 << rf << ")" << endl; |
341 #endif | 341 #endif |
342 emit centreFrameChanged(rf, m_followPan, m_followPlay); | 342 emit centreFrameChanged(rf, m_followPan, m_followPlay); |
343 } | 343 } |
344 } | 344 } |
345 | 345 |
434 | 434 |
435 int | 435 int |
436 View::getZoomLevel() const | 436 View::getZoomLevel() const |
437 { | 437 { |
438 #ifdef DEBUG_VIEW_WIDGET_PAINT | 438 #ifdef DEBUG_VIEW_WIDGET_PAINT |
439 // std::cout << "zoom level: " << m_zoomLevel << std::endl; | 439 // cout << "zoom level: " << m_zoomLevel << endl; |
440 #endif | 440 #endif |
441 return m_zoomLevel; | 441 return m_zoomLevel; |
442 } | 442 } |
443 | 443 |
444 void | 444 void |
751 paint.setPen(Qt::NoPen); | 751 paint.setPen(Qt::NoPen); |
752 paint.setBrush(boxColour); | 752 paint.setBrush(boxColour); |
753 | 753 |
754 QRect r = paint.fontMetrics().boundingRect(text); | 754 QRect r = paint.fontMetrics().boundingRect(text); |
755 r.translate(QPoint(x, y)); | 755 r.translate(QPoint(x, y)); |
756 // std::cerr << "drawVisibleText: r = " << r.x() << "," <<r.y() << " " << r.width() << "x" << r.height() << std::endl; | 756 // cerr << "drawVisibleText: r = " << r.x() << "," <<r.y() << " " << r.width() << "x" << r.height() << endl; |
757 paint.drawRect(r); | 757 paint.drawRect(r); |
758 paint.setBrush(Qt::NoBrush); | 758 paint.setBrush(Qt::NoBrush); |
759 | 759 |
760 paint.setPen(surroundColour); | 760 paint.setPen(surroundColour); |
761 | 761 |
772 | 772 |
773 paint.restore(); | 773 paint.restore(); |
774 | 774 |
775 } else { | 775 } else { |
776 | 776 |
777 std::cerr << "ERROR: View::drawVisibleText: Boxed style not yet implemented!" << std::endl; | 777 cerr << "ERROR: View::drawVisibleText: Boxed style not yet implemented!" << endl; |
778 } | 778 } |
779 } | 779 } |
780 | 780 |
781 void | 781 void |
782 View::setPlaybackFollow(PlaybackFollowMode m) | 782 View::setPlaybackFollow(PlaybackFollowMode m) |
789 View::modelChanged() | 789 View::modelChanged() |
790 { | 790 { |
791 QObject *obj = sender(); | 791 QObject *obj = sender(); |
792 | 792 |
793 #ifdef DEBUG_VIEW_WIDGET_PAINT | 793 #ifdef DEBUG_VIEW_WIDGET_PAINT |
794 std::cerr << "View(" << this << ")::modelChanged()" << std::endl; | 794 cerr << "View(" << this << ")::modelChanged()" << endl; |
795 #endif | 795 #endif |
796 | 796 |
797 // If the model that has changed is not used by any of the cached | 797 // If the model that has changed is not used by any of the cached |
798 // layers, we won't need to recreate the cache | 798 // layers, we won't need to recreate the cache |
799 | 799 |
828 | 828 |
829 long myStartFrame = getStartFrame(); | 829 long myStartFrame = getStartFrame(); |
830 size_t myEndFrame = getEndFrame(); | 830 size_t myEndFrame = getEndFrame(); |
831 | 831 |
832 #ifdef DEBUG_VIEW_WIDGET_PAINT | 832 #ifdef DEBUG_VIEW_WIDGET_PAINT |
833 std::cerr << "View(" << this << ")::modelChanged(" << startFrame << "," << endFrame << ") [me " << myStartFrame << "," << myEndFrame << "]" << std::endl; | 833 cerr << "View(" << this << ")::modelChanged(" << startFrame << "," << endFrame << ") [me " << myStartFrame << "," << myEndFrame << "]" << endl; |
834 #endif | 834 #endif |
835 | 835 |
836 if (myStartFrame > 0 && endFrame < size_t(myStartFrame)) { | 836 if (myStartFrame > 0 && endFrame < size_t(myStartFrame)) { |
837 checkProgress(obj); | 837 checkProgress(obj); |
838 return; | 838 return; |
871 } | 871 } |
872 | 872 |
873 void | 873 void |
874 View::modelCompletionChanged() | 874 View::modelCompletionChanged() |
875 { | 875 { |
876 // std::cerr << "View(" << this << ")::modelCompletionChanged()" << std::endl; | 876 // cerr << "View(" << this << ")::modelCompletionChanged()" << endl; |
877 | 877 |
878 QObject *obj = sender(); | 878 QObject *obj = sender(); |
879 checkProgress(obj); | 879 checkProgress(obj); |
880 } | 880 } |
881 | 881 |
882 void | 882 void |
883 View::modelAlignmentCompletionChanged() | 883 View::modelAlignmentCompletionChanged() |
884 { | 884 { |
885 // std::cerr << "View(" << this << ")::modelAlignmentCompletionChanged()" << std::endl; | 885 // cerr << "View(" << this << ")::modelAlignmentCompletionChanged()" << endl; |
886 | 886 |
887 QObject *obj = sender(); | 887 QObject *obj = sender(); |
888 checkProgress(obj); | 888 checkProgress(obj); |
889 } | 889 } |
890 | 890 |
891 void | 891 void |
892 View::modelReplaced() | 892 View::modelReplaced() |
893 { | 893 { |
894 #ifdef DEBUG_VIEW_WIDGET_PAINT | 894 #ifdef DEBUG_VIEW_WIDGET_PAINT |
895 std::cerr << "View(" << this << ")::modelReplaced()" << std::endl; | 895 cerr << "View(" << this << ")::modelReplaced()" << endl; |
896 #endif | 896 #endif |
897 delete m_cache; | 897 delete m_cache; |
898 m_cache = 0; | 898 m_cache = 0; |
899 | 899 |
900 update(); | 900 update(); |
943 View::globalCentreFrameChanged(unsigned long rf) | 943 View::globalCentreFrameChanged(unsigned long rf) |
944 { | 944 { |
945 if (m_followPan) { | 945 if (m_followPan) { |
946 size_t f = alignFromReference(rf); | 946 size_t f = alignFromReference(rf); |
947 #ifdef DEBUG_VIEW_WIDGET_PAINT | 947 #ifdef DEBUG_VIEW_WIDGET_PAINT |
948 std::cerr << "View[" << this << "]::globalCentreFrameChanged(" << rf | 948 cerr << "View[" << this << "]::globalCentreFrameChanged(" << rf |
949 << "): setting centre frame to " << f << std::endl; | 949 << "): setting centre frame to " << f << endl; |
950 #endif | 950 #endif |
951 setCentreFrame(f, false); | 951 setCentreFrame(f, false); |
952 } | 952 } |
953 } | 953 } |
954 | 954 |
1012 } | 1012 } |
1013 } | 1013 } |
1014 } | 1014 } |
1015 | 1015 |
1016 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1016 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1017 std::cerr << "PlaybackScrollPage: f = " << m_playPointerFrame << ", sf = " << sf << ", start frame " | 1017 cerr << "PlaybackScrollPage: f = " << m_playPointerFrame << ", sf = " << sf << ", start frame " |
1018 << getStartFrame() << std::endl; | 1018 << getStartFrame() << endl; |
1019 #endif | 1019 #endif |
1020 | 1020 |
1021 // We don't consider scrolling unless the pointer is outside | 1021 // We don't consider scrolling unless the pointer is outside |
1022 // the clearly visible range already | 1022 // the clearly visible range already |
1023 | 1023 |
1024 int xnew = getXForFrame(m_playPointerFrame); | 1024 int xnew = getXForFrame(m_playPointerFrame); |
1025 | 1025 |
1026 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1026 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1027 std::cerr << "xnew = " << xnew << ", width = " << width() << std::endl; | 1027 cerr << "xnew = " << xnew << ", width = " << width() << endl; |
1028 #endif | 1028 #endif |
1029 | 1029 |
1030 if (xnew < width()/8 || xnew > (width()*7)/8) { | 1030 if (xnew < width()/8 || xnew > (width()*7)/8) { |
1031 if (!somethingGoingOn) { | 1031 if (!somethingGoingOn) { |
1032 long offset = getFrameForX(width()/2) - getStartFrame(); | 1032 long offset = getFrameForX(width()/2) - getStartFrame(); |
1055 | 1055 |
1056 void | 1056 void |
1057 View::viewZoomLevelChanged(View *p, unsigned long z, bool locked) | 1057 View::viewZoomLevelChanged(View *p, unsigned long z, bool locked) |
1058 { | 1058 { |
1059 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1059 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1060 std::cerr << "View[" << this << "]: viewZoomLevelChanged(" << p << ", " << z << ", " << locked << ")" << std::endl; | 1060 cerr << "View[" << this << "]: viewZoomLevelChanged(" << p << ", " << z << ", " << locked << ")" << endl; |
1061 #endif | 1061 #endif |
1062 if (m_followZoom && p != this && locked) { | 1062 if (m_followZoom && p != this && locked) { |
1063 setZoomLevel(z); | 1063 setZoomLevel(z); |
1064 } | 1064 } |
1065 } | 1065 } |
1243 Model *aligningModel = getAligningModel(); | 1243 Model *aligningModel = getAligningModel(); |
1244 if (!aligningModel) return pf; | 1244 if (!aligningModel) return pf; |
1245 /* | 1245 /* |
1246 Model *pm = m_manager->getPlaybackModel(); | 1246 Model *pm = m_manager->getPlaybackModel(); |
1247 | 1247 |
1248 // std::cerr << "View[" << this << "]::getAlignedPlaybackFrame: pf = " << pf; | 1248 // cerr << "View[" << this << "]::getAlignedPlaybackFrame: pf = " << pf; |
1249 | 1249 |
1250 if (pm) { | 1250 if (pm) { |
1251 pf = pm->alignToReference(pf); | 1251 pf = pm->alignToReference(pf); |
1252 // std::cerr << " -> " << pf; | 1252 // cerr << " -> " << pf; |
1253 } | 1253 } |
1254 */ | 1254 */ |
1255 int af = aligningModel->alignFromReference(pf); | 1255 int af = aligningModel->alignFromReference(pf); |
1256 | 1256 |
1257 // std::cerr << ", aligned = " << af << std::endl; | 1257 // cerr << ", aligned = " << af << endl; |
1258 return af; | 1258 return af; |
1259 } | 1259 } |
1260 | 1260 |
1261 bool | 1261 bool |
1262 View::areLayersScrollable() const | 1262 View::areLayersScrollable() const |
1279 LayerList scrollables; | 1279 LayerList scrollables; |
1280 bool metUnscrollable = false; | 1280 bool metUnscrollable = false; |
1281 | 1281 |
1282 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { | 1282 for (LayerList::const_iterator i = m_layers.begin(); i != m_layers.end(); ++i) { |
1283 // SVDEBUG << "View::getScrollableBackLayers: calling isLayerDormant on layer " << *i << endl; | 1283 // SVDEBUG << "View::getScrollableBackLayers: calling isLayerDormant on layer " << *i << endl; |
1284 // std::cerr << "(name is " << (*i)->objectName() << ")" | 1284 // cerr << "(name is " << (*i)->objectName() << ")" |
1285 // << std::endl; | 1285 // << endl; |
1286 // SVDEBUG << "View::getScrollableBackLayers: I am " << this << endl; | 1286 // SVDEBUG << "View::getScrollableBackLayers: I am " << this << endl; |
1287 if ((*i)->isLayerDormant(this)) continue; | 1287 if ((*i)->isLayerDormant(this)) continue; |
1288 if ((*i)->isLayerOpaque()) { | 1288 if ((*i)->isLayerOpaque()) { |
1289 // You can't see anything behind an opaque layer! | 1289 // You can't see anything behind an opaque layer! |
1290 scrollables.clear(); | 1290 scrollables.clear(); |
1483 pb->hide(); | 1483 pb->hide(); |
1484 timer->stop(); | 1484 timer->stop(); |
1485 | 1485 |
1486 } else { | 1486 } else { |
1487 | 1487 |
1488 // std::cerr << "progress = " << completion << std::endl; | 1488 // cerr << "progress = " << completion << endl; |
1489 | 1489 |
1490 if (!pb->isVisible()) { | 1490 if (!pb->isVisible()) { |
1491 i->second.lastCheck = 0; | 1491 i->second.lastCheck = 0; |
1492 timer->setInterval(2000); | 1492 timer->setInterval(2000); |
1493 timer->start(); | 1493 timer->start(); |
1576 QRect cacheRect(rect()); | 1576 QRect cacheRect(rect()); |
1577 | 1577 |
1578 if (e) { | 1578 if (e) { |
1579 cacheRect &= e->rect(); | 1579 cacheRect &= e->rect(); |
1580 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1580 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1581 std::cerr << "paint rect " << cacheRect.width() << "x" << cacheRect.height() | 1581 cerr << "paint rect " << cacheRect.width() << "x" << cacheRect.height() |
1582 << ", my rect " << width() << "x" << height() << std::endl; | 1582 << ", my rect " << width() << "x" << height() << endl; |
1583 #endif | 1583 #endif |
1584 } | 1584 } |
1585 | 1585 |
1586 QRect nonCacheRect(cacheRect); | 1586 QRect nonCacheRect(cacheRect); |
1587 | 1587 |
1617 selectionCacheable = false; | 1617 selectionCacheable = false; |
1618 } | 1618 } |
1619 } | 1619 } |
1620 | 1620 |
1621 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1621 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1622 std::cerr << "View(" << this << ")::paintEvent: have " << scrollables.size() | 1622 cerr << "View(" << this << ")::paintEvent: have " << scrollables.size() |
1623 << " scrollable back layers and " << nonScrollables.size() | 1623 << " scrollable back layers and " << nonScrollables.size() |
1624 << " non-scrollable front layers" << std::endl; | 1624 << " non-scrollable front layers" << endl; |
1625 std::cerr << "haveSelections " << haveSelections << ", selectionCacheable " | 1625 cerr << "haveSelections " << haveSelections << ", selectionCacheable " |
1626 << selectionCacheable << ", m_selectionCached " << m_selectionCached << std::endl; | 1626 << selectionCacheable << ", m_selectionCached " << m_selectionCached << endl; |
1627 #endif | 1627 #endif |
1628 | 1628 |
1629 if (layersChanged || scrollables.empty() || | 1629 if (layersChanged || scrollables.empty() || |
1630 (haveSelections && (selectionCacheable != m_selectionCached))) { | 1630 (haveSelections && (selectionCacheable != m_selectionCached))) { |
1631 delete m_cache; | 1631 delete m_cache; |
1634 } | 1634 } |
1635 | 1635 |
1636 if (!scrollables.empty()) { | 1636 if (!scrollables.empty()) { |
1637 | 1637 |
1638 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1638 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1639 std::cerr << "View(" << this << "): cache " << m_cache << ", cache zoom " | 1639 cerr << "View(" << this << "): cache " << m_cache << ", cache zoom " |
1640 << m_cacheZoomLevel << ", zoom " << m_zoomLevel << std::endl; | 1640 << m_cacheZoomLevel << ", zoom " << m_zoomLevel << endl; |
1641 #endif | 1641 #endif |
1642 | 1642 |
1643 if (!m_cache || | 1643 if (!m_cache || |
1644 m_cacheZoomLevel != m_zoomLevel || | 1644 m_cacheZoomLevel != m_zoomLevel || |
1645 width() != m_cache->width() || | 1645 width() != m_cache->width() || |
1649 | 1649 |
1650 if (cacheRect.width() < width()/10) { | 1650 if (cacheRect.width() < width()/10) { |
1651 delete m_cache; | 1651 delete m_cache; |
1652 m_cache = 0; | 1652 m_cache = 0; |
1653 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1653 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1654 std::cerr << "View(" << this << ")::paintEvent: small repaint, not bothering to recreate cache" << std::endl; | 1654 cerr << "View(" << this << ")::paintEvent: small repaint, not bothering to recreate cache" << endl; |
1655 #endif | 1655 #endif |
1656 } else { | 1656 } else { |
1657 delete m_cache; | 1657 delete m_cache; |
1658 m_cache = new QPixmap(width(), height()); | 1658 m_cache = new QPixmap(width(), height()); |
1659 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1659 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1660 std::cerr << "View(" << this << ")::paintEvent: recreated cache" << std::endl; | 1660 cerr << "View(" << this << ")::paintEvent: recreated cache" << endl; |
1661 #endif | 1661 #endif |
1662 cacheRect = rect(); | 1662 cacheRect = rect(); |
1663 repaintCache = true; | 1663 repaintCache = true; |
1664 } | 1664 } |
1665 | 1665 |
1700 cacheRect = QRect(width() + dx, 0, -dx, height()); | 1700 cacheRect = QRect(width() + dx, 0, -dx, height()); |
1701 } else { | 1701 } else { |
1702 cacheRect = QRect(0, 0, dx, height()); | 1702 cacheRect = QRect(0, 0, dx, height()); |
1703 } | 1703 } |
1704 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1704 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1705 std::cerr << "View(" << this << ")::paintEvent: scrolled cache by " << dx << std::endl; | 1705 cerr << "View(" << this << ")::paintEvent: scrolled cache by " << dx << endl; |
1706 #endif | 1706 #endif |
1707 } else { | 1707 } else { |
1708 cacheRect = rect(); | 1708 cacheRect = rect(); |
1709 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1709 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1710 std::cerr << "View(" << this << ")::paintEvent: scrolling too far" << std::endl; | 1710 cerr << "View(" << this << ")::paintEvent: scrolling too far" << endl; |
1711 #endif | 1711 #endif |
1712 } | 1712 } |
1713 repaintCache = true; | 1713 repaintCache = true; |
1714 | 1714 |
1715 } else { | 1715 } else { |
1716 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1716 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1717 std::cerr << "View(" << this << ")::paintEvent: cache is good" << std::endl; | 1717 cerr << "View(" << this << ")::paintEvent: cache is good" << endl; |
1718 #endif | 1718 #endif |
1719 paint.begin(this); | 1719 paint.begin(this); |
1720 paint.drawPixmap(cacheRect, *m_cache, cacheRect); | 1720 paint.drawPixmap(cacheRect, *m_cache, cacheRect); |
1721 paint.end(); | 1721 paint.end(); |
1722 QFrame::paintEvent(e); | 1722 QFrame::paintEvent(e); |
1726 m_cacheCentreFrame = m_centreFrame; | 1726 m_cacheCentreFrame = m_centreFrame; |
1727 m_cacheZoomLevel = m_zoomLevel; | 1727 m_cacheZoomLevel = m_zoomLevel; |
1728 } | 1728 } |
1729 | 1729 |
1730 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1730 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1731 // std::cerr << "View(" << this << ")::paintEvent: cacheRect " << cacheRect << ", nonCacheRect " << (nonCacheRect | cacheRect) << ", repaintCache " << repaintCache << ", paintedCacheRect " << paintedCacheRect << std::endl; | 1731 // cerr << "View(" << this << ")::paintEvent: cacheRect " << cacheRect << ", nonCacheRect " << (nonCacheRect | cacheRect) << ", repaintCache " << repaintCache << ", paintedCacheRect " << paintedCacheRect << endl; |
1732 #endif | 1732 #endif |
1733 | 1733 |
1734 // Scrollable (cacheable) items first | 1734 // Scrollable (cacheable) items first |
1735 | 1735 |
1736 if (!paintedCacheRect) { | 1736 if (!paintedCacheRect) { |
2307 paint.setRenderHint(QPainter::Antialiasing, false); | 2307 paint.setRenderHint(QPainter::Antialiasing, false); |
2308 | 2308 |
2309 paint.save(); | 2309 paint.save(); |
2310 paint.translate(xorigin + x, 0); | 2310 paint.translate(xorigin + x, 0); |
2311 | 2311 |
2312 std::cerr << "Centre frame now: " << m_centreFrame << " drawing to " << chunk.x() + x + xorigin << ", " << chunk.width() << std::endl; | 2312 cerr << "Centre frame now: " << m_centreFrame << " drawing to " << chunk.x() + x + xorigin << ", " << chunk.width() << endl; |
2313 | 2313 |
2314 (*i)->setSynchronousPainting(true); | 2314 (*i)->setSynchronousPainting(true); |
2315 | 2315 |
2316 (*i)->paint(this, paint, chunk); | 2316 (*i)->paint(this, paint, chunk); |
2317 | 2317 |