Mercurial > hg > svgui
comparison view/View.cpp @ 953:fe46201414c8 osx-retina
Fix rendering of selections
author | Chris Cannam |
---|---|
date | Wed, 29 Apr 2015 12:37:23 +0100 |
parents | b1aa74ce697e |
children | 76b5eabd816b |
comparison
equal
deleted
inserted
replaced
952:b1aa74ce697e | 953:fe46201414c8 |
---|---|
1702 #endif | 1702 #endif |
1703 } | 1703 } |
1704 | 1704 |
1705 QRect nonCacheRect(cacheRect); | 1705 QRect nonCacheRect(cacheRect); |
1706 | 1706 |
1707 int dpratio = devicePixelRatio(); | |
1708 | |
1707 // If not all layers are scrollable, but some of the back layers | 1709 // If not all layers are scrollable, but some of the back layers |
1708 // are, we should store only those in the cache. | 1710 // are, we should store only those in the cache. |
1709 | 1711 |
1710 bool layersChanged = false; | 1712 bool layersChanged = false; |
1711 LayerList scrollables = getScrollableBackLayers(true, layersChanged); | 1713 LayerList scrollables = getScrollableBackLayers(true, layersChanged); |
1713 bool selectionCacheable = nonScrollables.empty(); | 1715 bool selectionCacheable = nonScrollables.empty(); |
1714 bool haveSelections = m_manager && !m_manager->getSelections().empty(); | 1716 bool haveSelections = m_manager && !m_manager->getSelections().empty(); |
1715 | 1717 |
1716 // If all the non-scrollable layers are non-opaque, then we draw | 1718 // If all the non-scrollable layers are non-opaque, then we draw |
1717 // the selection rectangle behind them and cache it. If any are | 1719 // the selection rectangle behind them and cache it. If any are |
1718 // opaque, however, we can't cache. | 1720 // opaque, however, or if our device-pixel ratio is not 1 (so we |
1721 // need to paint direct to the widget), then we can't cache. | |
1719 // | 1722 // |
1720 if (!selectionCacheable) { | 1723 if (dpratio == 1) { |
1721 selectionCacheable = true; | 1724 |
1722 for (LayerList::const_iterator i = nonScrollables.begin(); | 1725 if (!selectionCacheable) { |
1723 i != nonScrollables.end(); ++i) { | 1726 selectionCacheable = true; |
1724 if ((*i)->isLayerOpaque()) { | 1727 for (LayerList::const_iterator i = nonScrollables.begin(); |
1725 selectionCacheable = false; | 1728 i != nonScrollables.end(); ++i) { |
1726 break; | 1729 if ((*i)->isLayerOpaque()) { |
1727 } | 1730 selectionCacheable = false; |
1728 } | 1731 break; |
1729 } | 1732 } |
1730 | 1733 } |
1731 if (selectionCacheable) { | 1734 } |
1732 QPoint localPos; | 1735 |
1733 bool closeToLeft, closeToRight; | 1736 if (selectionCacheable) { |
1734 if (shouldIlluminateLocalSelection(localPos, closeToLeft, closeToRight)) { | 1737 QPoint localPos; |
1735 selectionCacheable = false; | 1738 bool closeToLeft, closeToRight; |
1736 } | 1739 if (shouldIlluminateLocalSelection |
1740 (localPos, closeToLeft, closeToRight)) { | |
1741 selectionCacheable = false; | |
1742 } | |
1743 } | |
1744 | |
1745 } else { | |
1746 | |
1747 selectionCacheable = false; | |
1737 } | 1748 } |
1738 | 1749 |
1739 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1750 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1740 cerr << "View(" << this << ")::paintEvent: have " << scrollables.size() | 1751 cerr << "View(" << this << ")::paintEvent: have " << scrollables.size() |
1741 << " scrollable back layers and " << nonScrollables.size() | 1752 << " scrollable back layers and " << nonScrollables.size() |
1749 delete m_cache; | 1760 delete m_cache; |
1750 m_cache = 0; | 1761 m_cache = 0; |
1751 m_selectionCached = false; | 1762 m_selectionCached = false; |
1752 } | 1763 } |
1753 | 1764 |
1754 int dpratio = devicePixelRatio(); | |
1755 | |
1756 QSize scaledCacheSize(scaledSize(size(), dpratio)); | 1765 QSize scaledCacheSize(scaledSize(size(), dpratio)); |
1757 QRect scaledCacheRect(scaledRect(cacheRect, dpratio)); | 1766 QRect scaledCacheRect(scaledRect(cacheRect, dpratio)); |
1758 | 1767 |
1759 if (!m_buffer || scaledCacheSize != m_buffer->size()) { | 1768 if (!m_buffer || scaledCacheSize != m_buffer->size()) { |
1760 delete m_buffer; | 1769 delete m_buffer; |
1922 #endif | 1931 #endif |
1923 (*i)->paint(&proxy, paint, scaledNonCacheRect); | 1932 (*i)->paint(&proxy, paint, scaledNonCacheRect); |
1924 } | 1933 } |
1925 | 1934 |
1926 paint.end(); | 1935 paint.end(); |
1927 | 1936 |
1928 paint.begin(m_buffer); | 1937 paint.begin(this); |
1938 QRect finalPaintRect = e ? e->rect() : rect(); | |
1939 paint.drawPixmap(finalPaintRect, *m_buffer, scaledRect(finalPaintRect, dpratio)); | |
1940 paint.end(); | |
1941 | |
1942 paint.begin(this); | |
1929 setPaintFont(paint); | 1943 setPaintFont(paint); |
1930 if (e) paint.setClipRect(scaledRect(e->rect(), dpratio)); | 1944 if (e) paint.setClipRect(e->rect()); |
1931 if (!m_selectionCached) { | 1945 if (!m_selectionCached) { |
1932 drawSelections(paint); | 1946 drawSelections(paint); |
1933 } | 1947 } |
1934 paint.end(); | 1948 paint.end(); |
1935 | 1949 |
1946 // Don't show the play pointer when it is redundant with | 1960 // Don't show the play pointer when it is redundant with |
1947 // the centre line | 1961 // the centre line |
1948 showPlayPointer = false; | 1962 showPlayPointer = false; |
1949 } | 1963 } |
1950 } | 1964 } |
1951 | |
1952 paint.begin(this); | |
1953 QRect finalPaintRect = e ? e->rect() : rect(); | |
1954 paint.drawPixmap(finalPaintRect, *m_buffer, scaledRect(finalPaintRect, dpratio)); | |
1955 paint.end(); | |
1956 | 1965 |
1957 if (showPlayPointer) { | 1966 if (showPlayPointer) { |
1958 | 1967 |
1959 paint.begin(this); | 1968 paint.begin(this); |
1960 | 1969 |