Mercurial > hg > svgui
comparison view/View.cpp @ 914:59e51842cf39 osx-retina
First steps toward high-res rendering on retina Mac -- quite a bit more to be done
author | Chris Cannam |
---|---|
date | Wed, 11 Mar 2015 13:54:01 +0000 |
parents | 4a578a360011 |
children | f6d9f28f37cb |
comparison
equal
deleted
inserted
replaced
913:50be12cf2802 | 914:59e51842cf39 |
---|---|
1739 delete m_cache; | 1739 delete m_cache; |
1740 m_cache = 0; | 1740 m_cache = 0; |
1741 m_selectionCached = false; | 1741 m_selectionCached = false; |
1742 } | 1742 } |
1743 | 1743 |
1744 int dpratio = devicePixelRatio(); | |
1745 | |
1746 QSize scaledCacheSize(width() * dpratio, height() * dpratio); | |
1747 QRect scaledCacheRect(cacheRect.x() * dpratio, cacheRect.y() * dpratio, | |
1748 cacheRect.width() * dpratio, cacheRect.height() * dpratio); | |
1749 | |
1744 if (!scrollables.empty()) { | 1750 if (!scrollables.empty()) { |
1745 | 1751 |
1746 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1752 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1747 cerr << "View(" << this << "): cache " << m_cache << ", cache zoom " | 1753 cerr << "View(" << this << "): cache " << m_cache << ", cache zoom " |
1748 << m_cacheZoomLevel << ", zoom " << m_zoomLevel << endl; | 1754 << m_cacheZoomLevel << ", zoom " << m_zoomLevel << endl; |
1749 #endif | 1755 #endif |
1750 | 1756 |
1751 if (!m_cache || | 1757 if (!m_cache || |
1752 m_cacheZoomLevel != m_zoomLevel || | 1758 m_cacheZoomLevel != m_zoomLevel || |
1753 width() != m_cache->width() || | 1759 scaledCacheSize != m_cache->size()) { |
1754 height() != m_cache->height()) { | |
1755 | 1760 |
1756 // cache is not valid | 1761 // cache is not valid |
1757 | 1762 |
1758 if (cacheRect.width() < width()/10) { | 1763 if (cacheRect.width() < width()/10) { |
1759 delete m_cache; | 1764 delete m_cache; |
1761 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1766 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1762 cerr << "View(" << this << ")::paintEvent: small repaint, not bothering to recreate cache" << endl; | 1767 cerr << "View(" << this << ")::paintEvent: small repaint, not bothering to recreate cache" << endl; |
1763 #endif | 1768 #endif |
1764 } else { | 1769 } else { |
1765 delete m_cache; | 1770 delete m_cache; |
1766 m_cache = new QPixmap(width(), height()); | 1771 m_cache = new QPixmap(scaledCacheSize); |
1767 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1772 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1768 cerr << "View(" << this << ")::paintEvent: recreated cache" << endl; | 1773 cerr << "View(" << this << ")::paintEvent: recreated cache" << endl; |
1769 #endif | 1774 #endif |
1770 cacheRect = rect(); | 1775 cacheRect = rect(); |
1771 repaintCache = true; | 1776 repaintCache = true; |
1776 int dx = | 1781 int dx = |
1777 getXForFrame(m_cacheCentreFrame) - | 1782 getXForFrame(m_cacheCentreFrame) - |
1778 getXForFrame(m_centreFrame); | 1783 getXForFrame(m_centreFrame); |
1779 | 1784 |
1780 if (dx > -width() && dx < width()) { | 1785 if (dx > -width() && dx < width()) { |
1781 #ifdef PIXMAP_COPY_TO_SELF | |
1782 // This is not normally defined. Copying a pixmap to | |
1783 // itself doesn't work properly on Windows, Mac, or | |
1784 // X11 with the raster backend (it only works when | |
1785 // moving in one direction and then presumably only by | |
1786 // accident). It does actually seem to be fine on X11 | |
1787 // with the native backend, but we prefer not to use | |
1788 // that anyway | |
1789 paint.begin(m_cache); | |
1790 paint.drawPixmap(dx, 0, *m_cache); | |
1791 paint.end(); | |
1792 #else | |
1793 static QPixmap *tmpPixmap = 0; | 1786 static QPixmap *tmpPixmap = 0; |
1794 if (!tmpPixmap || | 1787 if (!tmpPixmap || tmpPixmap->size() != scaledCacheSize) { |
1795 tmpPixmap->width() != width() || | |
1796 tmpPixmap->height() != height()) { | |
1797 delete tmpPixmap; | 1788 delete tmpPixmap; |
1798 tmpPixmap = new QPixmap(width(), height()); | 1789 tmpPixmap = new QPixmap(scaledCacheSize); |
1799 } | 1790 } |
1800 paint.begin(tmpPixmap); | 1791 paint.begin(tmpPixmap); |
1801 paint.drawPixmap(0, 0, *m_cache); | 1792 paint.drawPixmap(0, 0, *m_cache); |
1802 paint.end(); | 1793 paint.end(); |
1803 paint.begin(m_cache); | 1794 paint.begin(m_cache); |
1804 paint.drawPixmap(dx, 0, *tmpPixmap); | 1795 paint.drawPixmap(dx, 0, *tmpPixmap); |
1805 paint.end(); | 1796 paint.end(); |
1806 #endif | |
1807 if (dx < 0) { | 1797 if (dx < 0) { |
1808 cacheRect = QRect(width() + dx, 0, -dx, height()); | 1798 cacheRect = QRect(width() + dx, 0, -dx, height()); |
1809 } else { | 1799 } else { |
1810 cacheRect = QRect(0, 0, dx, height()); | 1800 cacheRect = QRect(0, 0, dx, height()); |
1811 } | 1801 } |
1823 } else { | 1813 } else { |
1824 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1814 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1825 cerr << "View(" << this << ")::paintEvent: cache is good" << endl; | 1815 cerr << "View(" << this << ")::paintEvent: cache is good" << endl; |
1826 #endif | 1816 #endif |
1827 paint.begin(this); | 1817 paint.begin(this); |
1828 paint.drawPixmap(cacheRect, *m_cache, cacheRect); | 1818 paint.drawPixmap(cacheRect, *m_cache, scaledCacheRect); |
1829 paint.end(); | 1819 paint.end(); |
1830 QFrame::paintEvent(e); | 1820 QFrame::paintEvent(e); |
1831 paintedCacheRect = true; | 1821 paintedCacheRect = true; |
1832 } | 1822 } |
1833 | 1823 |
1841 | 1831 |
1842 // Scrollable (cacheable) items first | 1832 // Scrollable (cacheable) items first |
1843 | 1833 |
1844 if (!paintedCacheRect) { | 1834 if (!paintedCacheRect) { |
1845 | 1835 |
1846 if (repaintCache) paint.begin(m_cache); | 1836 QRect rectToPaint; |
1847 else paint.begin(this); | 1837 |
1838 if (repaintCache) { | |
1839 paint.begin(m_cache); | |
1840 rectToPaint = scaledCacheRect; | |
1841 } else { | |
1842 paint.begin(this); | |
1843 rectToPaint = cacheRect; | |
1844 } | |
1845 | |
1848 setPaintFont(paint); | 1846 setPaintFont(paint); |
1849 paint.setClipRect(cacheRect); | 1847 paint.setClipRect(rectToPaint); |
1850 | 1848 |
1851 paint.setPen(getBackground()); | 1849 paint.setPen(getBackground()); |
1852 paint.setBrush(getBackground()); | 1850 paint.setBrush(getBackground()); |
1853 paint.drawRect(cacheRect); | 1851 paint.drawRect(rectToPaint); |
1854 | 1852 |
1855 paint.setPen(getForeground()); | 1853 paint.setPen(getForeground()); |
1856 paint.setBrush(Qt::NoBrush); | 1854 paint.setBrush(Qt::NoBrush); |
1857 | 1855 |
1858 for (LayerList::iterator i = scrollables.begin(); i != scrollables.end(); ++i) { | 1856 for (LayerList::iterator i = scrollables.begin(); i != scrollables.end(); ++i) { |
1859 paint.setRenderHint(QPainter::Antialiasing, false); | 1857 paint.setRenderHint(QPainter::Antialiasing, false); |
1860 paint.save(); | 1858 paint.save(); |
1861 (*i)->paint(this, paint, cacheRect); | 1859 (*i)->paint(this, paint, rectToPaint); |
1862 paint.restore(); | 1860 paint.restore(); |
1863 } | 1861 } |
1864 | 1862 |
1865 if (haveSelections && selectionCacheable) { | 1863 if (haveSelections && selectionCacheable) { |
1866 drawSelections(paint); | 1864 drawSelections(paint); |
1870 paint.end(); | 1868 paint.end(); |
1871 | 1869 |
1872 if (repaintCache) { | 1870 if (repaintCache) { |
1873 cacheRect |= (e ? e->rect() : rect()); | 1871 cacheRect |= (e ? e->rect() : rect()); |
1874 paint.begin(this); | 1872 paint.begin(this); |
1875 paint.drawPixmap(cacheRect, *m_cache, cacheRect); | 1873 paint.drawPixmap(cacheRect, *m_cache, scaledCacheRect); |
1876 paint.end(); | 1874 paint.end(); |
1877 } | 1875 } |
1878 } | 1876 } |
1879 | 1877 |
1880 // Now non-cacheable items. We always need to redraw the | 1878 // Now non-cacheable items. We always need to redraw the |