Mercurial > hg > svgui
comparison view/View.cpp @ 952:b1aa74ce697e osx-retina
Always render to a buffer, then from that to the widget
author | Chris Cannam |
---|---|
date | Mon, 27 Apr 2015 11:38:01 +0100 |
parents | 53e039d99b5d |
children | fe46201414c8 |
comparison
equal
deleted
inserted
replaced
951:53e039d99b5d | 952:b1aa74ce697e |
---|---|
58 m_followPlay(PlaybackScrollPageWithCentre), | 58 m_followPlay(PlaybackScrollPageWithCentre), |
59 m_followPlayIsDetached(false), | 59 m_followPlayIsDetached(false), |
60 m_playPointerFrame(0), | 60 m_playPointerFrame(0), |
61 m_showProgress(showProgress), | 61 m_showProgress(showProgress), |
62 m_cache(0), | 62 m_cache(0), |
63 m_buffer(0), | |
63 m_cacheCentreFrame(0), | 64 m_cacheCentreFrame(0), |
64 m_cacheZoomLevel(1024), | 65 m_cacheZoomLevel(1024), |
65 m_selectionCached(false), | 66 m_selectionCached(false), |
66 m_deleting(false), | 67 m_deleting(false), |
67 m_haveSelectedLayer(false), | 68 m_haveSelectedLayer(false), |
1750 m_selectionCached = false; | 1751 m_selectionCached = false; |
1751 } | 1752 } |
1752 | 1753 |
1753 int dpratio = devicePixelRatio(); | 1754 int dpratio = devicePixelRatio(); |
1754 | 1755 |
1755 QSize scaledCacheSize(width() * dpratio, height() * dpratio); | 1756 QSize scaledCacheSize(scaledSize(size(), dpratio)); |
1756 QRect scaledCacheRect(cacheRect.x() * dpratio, cacheRect.y() * dpratio, | 1757 QRect scaledCacheRect(scaledRect(cacheRect, dpratio)); |
1757 cacheRect.width() * dpratio, cacheRect.height() * dpratio); | 1758 |
1758 | 1759 if (!m_buffer || scaledCacheSize != m_buffer->size()) { |
1760 delete m_buffer; | |
1761 m_buffer = new QPixmap(scaledCacheSize); | |
1762 } | |
1763 | |
1759 if (!scrollables.empty()) { | 1764 if (!scrollables.empty()) { |
1760 | 1765 |
1761 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1766 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1762 cerr << "View(" << this << "): cache " << m_cache << ", cache zoom " | 1767 cerr << "View(" << this << "): cache " << m_cache << ", cache zoom " |
1763 << m_cacheZoomLevel << ", zoom " << m_zoomLevel << endl; | 1768 << m_cacheZoomLevel << ", zoom " << m_zoomLevel << endl; |
1821 | 1826 |
1822 } else { | 1827 } else { |
1823 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1828 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1824 cerr << "View(" << this << ")::paintEvent: cache is good" << endl; | 1829 cerr << "View(" << this << ")::paintEvent: cache is good" << endl; |
1825 #endif | 1830 #endif |
1826 paint.begin(this); | 1831 paint.begin(m_buffer); |
1827 paint.drawPixmap(cacheRect, *m_cache, scaledCacheRect); | 1832 paint.drawPixmap(scaledCacheRect, *m_cache, scaledCacheRect); |
1828 paint.end(); | 1833 paint.end(); |
1829 QFrame::paintEvent(e); | 1834 QFrame::paintEvent(e); |
1830 paintedCacheRect = true; | 1835 paintedCacheRect = true; |
1831 } | 1836 } |
1832 | 1837 |
1848 | 1853 |
1849 if (repaintCache) { | 1854 if (repaintCache) { |
1850 paint.begin(m_cache); | 1855 paint.begin(m_cache); |
1851 rectToPaint = scaledCacheRect; | 1856 rectToPaint = scaledCacheRect; |
1852 } else { | 1857 } else { |
1853 paint.begin(this); | 1858 paint.begin(m_buffer); |
1854 rectToPaint = cacheRect; | 1859 rectToPaint = scaledCacheRect; |
1855 } | 1860 } |
1856 | 1861 |
1857 setPaintFont(paint); | 1862 setPaintFont(paint); |
1858 paint.setClipRect(rectToPaint); | 1863 paint.setClipRect(rectToPaint); |
1859 | 1864 |
1881 | 1886 |
1882 paint.end(); | 1887 paint.end(); |
1883 | 1888 |
1884 if (repaintCache) { | 1889 if (repaintCache) { |
1885 cacheRect |= (e ? e->rect() : rect()); | 1890 cacheRect |= (e ? e->rect() : rect()); |
1886 paint.begin(this); | 1891 scaledCacheRect = scaledRect(cacheRect, dpratio); |
1887 paint.drawPixmap(cacheRect, *m_cache, scaledCacheRect); | 1892 paint.begin(m_buffer); |
1893 paint.drawPixmap(scaledCacheRect, *m_cache, scaledCacheRect); | |
1888 paint.end(); | 1894 paint.end(); |
1889 } | 1895 } |
1890 } | 1896 } |
1891 | 1897 |
1892 // Now non-cacheable items. We always need to redraw the | 1898 // Now non-cacheable items. We always need to redraw the |
1893 // non-cacheable items across at least the area we drew of the | 1899 // non-cacheable items across at least the area we drew of the |
1894 // cacheable items. | 1900 // cacheable items. |
1895 | 1901 |
1896 nonCacheRect |= cacheRect; | 1902 nonCacheRect |= cacheRect; |
1897 | 1903 |
1898 paint.begin(this); | 1904 QRect scaledNonCacheRect = scaledRect(nonCacheRect, dpratio); |
1899 paint.setClipRect(nonCacheRect); | 1905 |
1906 paint.begin(m_buffer); | |
1907 paint.setClipRect(scaledNonCacheRect); | |
1900 setPaintFont(paint); | 1908 setPaintFont(paint); |
1901 if (scrollables.empty()) { | 1909 if (scrollables.empty()) { |
1902 paint.setPen(getBackground()); | 1910 paint.setPen(getBackground()); |
1903 paint.setBrush(getBackground()); | 1911 paint.setBrush(getBackground()); |
1904 paint.drawRect(nonCacheRect); | 1912 paint.drawRect(scaledNonCacheRect); |
1905 } | 1913 } |
1906 | 1914 |
1907 paint.setPen(getForeground()); | 1915 paint.setPen(getForeground()); |
1908 paint.setBrush(Qt::NoBrush); | 1916 paint.setBrush(Qt::NoBrush); |
1909 | 1917 |
1910 for (LayerList::iterator i = nonScrollables.begin(); i != nonScrollables.end(); ++i) { | 1918 for (LayerList::iterator i = nonScrollables.begin(); i != nonScrollables.end(); ++i) { |
1911 // Profiler profiler2("View::paintEvent non-cacheable"); | 1919 // Profiler profiler2("View::paintEvent non-cacheable"); |
1912 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1920 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1913 cerr << "Painting non-scrollable layer " << *i << " without proxy with repaintCache = " << repaintCache << ", dpratio = " << dpratio << ", rectToPaint = " << nonCacheRect.x() << "," << nonCacheRect.y() << " " << nonCacheRect.width() << "x" << nonCacheRect.height() << endl; | 1921 cerr << "Painting non-scrollable layer " << *i << " without proxy with repaintCache = " << repaintCache << ", dpratio = " << dpratio << ", rectToPaint = " << nonCacheRect.x() << "," << nonCacheRect.y() << " " << nonCacheRect.width() << "x" << nonCacheRect.height() << endl; |
1914 #endif | 1922 #endif |
1915 (*i)->paint(this, paint, nonCacheRect); | 1923 (*i)->paint(&proxy, paint, scaledNonCacheRect); |
1916 } | 1924 } |
1917 | 1925 |
1918 paint.end(); | 1926 paint.end(); |
1919 | 1927 |
1920 paint.begin(this); | 1928 paint.begin(m_buffer); |
1921 setPaintFont(paint); | 1929 setPaintFont(paint); |
1922 if (e) paint.setClipRect(e->rect()); | 1930 if (e) paint.setClipRect(scaledRect(e->rect(), dpratio)); |
1923 if (!m_selectionCached) { | 1931 if (!m_selectionCached) { |
1924 drawSelections(paint); | 1932 drawSelections(paint); |
1925 } | 1933 } |
1926 paint.end(); | 1934 paint.end(); |
1927 | 1935 |
1938 // Don't show the play pointer when it is redundant with | 1946 // Don't show the play pointer when it is redundant with |
1939 // the centre line | 1947 // the centre line |
1940 showPlayPointer = false; | 1948 showPlayPointer = false; |
1941 } | 1949 } |
1942 } | 1950 } |
1943 | 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 | |
1944 if (showPlayPointer) { | 1957 if (showPlayPointer) { |
1945 | 1958 |
1946 paint.begin(this); | 1959 paint.begin(this); |
1947 | 1960 |
1948 int playx = getXForFrame(m_playPointerFrame); | 1961 int playx = getXForFrame(m_playPointerFrame); |