# HG changeset patch # User Chris Cannam # Date 1426686727 0 # Node ID a5488775f880403a96687771c68489795fd5049a # Parent 4fe7a09be0fe5f7f75393e822f0d7c931fb23a7e Pass proxy to layer for painting diff -r 4fe7a09be0fe -r a5488775f880 layer/SingleColourLayer.cpp --- a/layer/SingleColourLayer.cpp Tue Mar 17 16:56:03 2015 +0000 +++ b/layer/SingleColourLayer.cpp Wed Mar 18 13:52:07 2015 +0000 @@ -137,7 +137,7 @@ } void -SingleColourLayer::setDefaultColourFor(View *v) +SingleColourLayer::setDefaultColourFor(LayerGeometryProvider *v) { #ifdef DEBUG_COLOUR_SELECTION SVDEBUG << "SingleColourLayer::setDefaultColourFor: m_colourExplicitlySet = " << m_colourExplicitlySet << ", m_defaultColourSet " << m_defaultColourSet << endl; @@ -244,19 +244,19 @@ } QColor -SingleColourLayer::getBackgroundQColor(View *v) const +SingleColourLayer::getBackgroundQColor(LayerGeometryProvider *v) const { return v->getBackground(); } QColor -SingleColourLayer::getForegroundQColor(View *v) const +SingleColourLayer::getForegroundQColor(LayerGeometryProvider *v) const { return v->getForeground(); } std::vector -SingleColourLayer::getPartialShades(View *v) const +SingleColourLayer::getPartialShades(LayerGeometryProvider *v) const { std::vector s; QColor base = getBaseQColor(); diff -r 4fe7a09be0fe -r a5488775f880 layer/SingleColourLayer.h --- a/layer/SingleColourLayer.h Tue Mar 17 16:56:03 2015 +0000 +++ b/layer/SingleColourLayer.h Wed Mar 18 13:52:07 2015 +0000 @@ -71,16 +71,16 @@ virtual void setProperties(const QXmlAttributes &attributes); - virtual void setDefaultColourFor(View *v); + virtual void setDefaultColourFor(LayerGeometryProvider *v); protected: SingleColourLayer(); virtual ~SingleColourLayer(); virtual QColor getBaseQColor() const; - virtual QColor getBackgroundQColor(View *v) const; - virtual QColor getForegroundQColor(View *v) const; - std::vector getPartialShades(View *v) const; + virtual QColor getBackgroundQColor(LayerGeometryProvider *v) const; + virtual QColor getForegroundQColor(LayerGeometryProvider *v) const; + std::vector getPartialShades(LayerGeometryProvider *v) const; virtual void flagBaseColourChanged() { } virtual int getDefaultColourHint(bool /* darkBackground */, diff -r 4fe7a09be0fe -r a5488775f880 layer/TimeRulerLayer.cpp --- a/layer/TimeRulerLayer.cpp Tue Mar 17 16:56:03 2015 +0000 +++ b/layer/TimeRulerLayer.cpp Wed Mar 18 13:52:07 2015 +0000 @@ -309,7 +309,7 @@ if (v->getViewManager() && v->getViewManager()->getOverlayMode() != ViewManager::NoOverlays) { - if (v->getLayer(0) == this) { + if (v->getView()->getLayer(0) == this) { // backmost layer, don't worry about outlining the text paint.drawText(x+2 - tw/2, y, text); } else { diff -r 4fe7a09be0fe -r a5488775f880 layer/TimeValueLayer.cpp --- a/layer/TimeValueLayer.cpp Tue Mar 17 16:56:03 2015 +0000 +++ b/layer/TimeValueLayer.cpp Wed Mar 18 13:52:07 2015 +0000 @@ -1703,7 +1703,7 @@ if (clipboardHasDifferentAlignment(v, from)) { QMessageBox::StandardButton button = - QMessageBox::question(v, tr("Re-align pasted items?"), + QMessageBox::question(v->getView(), tr("Re-align pasted items?"), tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes); diff -r 4fe7a09be0fe -r a5488775f880 svgui.pro --- a/svgui.pro Tue Mar 17 16:56:03 2015 +0000 +++ b/svgui.pro Wed Mar 18 13:52:07 2015 +0000 @@ -93,7 +93,8 @@ view/Pane.h \ view/PaneStack.h \ view/View.h \ - view/ViewManager.h + view/ViewManager.h \ + view/ViewProxy.h SOURCES += view/Overview.cpp \ view/Pane.cpp \ view/PaneStack.cpp \ diff -r 4fe7a09be0fe -r a5488775f880 view/LayerGeometryProvider.h --- a/view/LayerGeometryProvider.h Tue Mar 17 16:56:03 2015 +0000 +++ b/view/LayerGeometryProvider.h Wed Mar 18 13:52:07 2015 +0000 @@ -57,6 +57,9 @@ */ virtual sv_frame_t getFrameForX(int x) const = 0; + virtual sv_frame_t getModelsStartFrame() const = 0; + virtual sv_frame_t getModelsEndFrame() const = 0; + /** * Return the pixel y-coordinate corresponding to a given * frequency, if the frequency range is as specified. This does @@ -106,6 +109,7 @@ virtual ViewManager *getViewManager() const = 0; virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) const = 0; + virtual bool shouldShowFeatureLabels() const = 0; enum TextStyle { BoxedText, diff -r 4fe7a09be0fe -r a5488775f880 view/View.cpp --- a/view/View.cpp Tue Mar 17 16:56:03 2015 +0000 +++ b/view/View.cpp Wed Mar 18 13:52:07 2015 +0000 @@ -20,6 +20,7 @@ #include "base/Profiler.h" #include "base/Pitch.h" #include "base/Preferences.h" +#include "ViewProxy.h" #include "layer/TimeRulerLayer.h" #include "layer/SingleColourLayer.h" @@ -58,7 +59,6 @@ m_followPlayIsDetached(false), m_playPointerFrame(0), m_showProgress(showProgress), - m_paintScale(1), m_cache(0), m_cacheCentreFrame(0), m_cacheZoomLevel(1024), @@ -1662,9 +1662,7 @@ QRect View::getPaintRect() const { - QRect r(rect()); - return QRect(r.x() * m_paintScale, r.y() * m_paintScale, - r.width() * m_paintScale, r.height() * m_paintScale); + return rect(); } void @@ -1840,6 +1838,8 @@ // Scrollable (cacheable) items first + ViewProxy proxy(this, dpratio); + if (!paintedCacheRect) { QRect rectToPaint; @@ -1847,11 +1847,9 @@ if (repaintCache) { paint.begin(m_cache); rectToPaint = scaledCacheRect; - m_paintScale = dpratio; } else { paint.begin(this); rectToPaint = cacheRect; - m_paintScale = 1; } setPaintFont(paint); @@ -1867,7 +1865,7 @@ for (LayerList::iterator i = scrollables.begin(); i != scrollables.end(); ++i) { paint.setRenderHint(QPainter::Antialiasing, false); paint.save(); - (*i)->paint(this, paint, rectToPaint); + (*i)->paint(&proxy, paint, rectToPaint); paint.restore(); } @@ -1906,7 +1904,7 @@ for (LayerList::iterator i = nonScrollables.begin(); i != nonScrollables.end(); ++i) { // Profiler profiler2("View::paintEvent non-cacheable"); - (*i)->paint(this, paint, nonCacheRect); + (*i)->paint(&proxy, paint, nonCacheRect); } paint.end(); @@ -2421,23 +2419,23 @@ for (LayerList::iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { - if(!((*i)->isLayerDormant(this))){ - - paint.setRenderHint(QPainter::Antialiasing, false); - - paint.save(); - paint.translate(xorigin + x, 0); - - cerr << "Centre frame now: " << m_centreFrame << " drawing to " << chunk.x() + x + xorigin << ", " << chunk.width() << endl; - - (*i)->setSynchronousPainting(true); - - (*i)->paint(this, paint, chunk); - - (*i)->setSynchronousPainting(false); - - paint.restore(); - } + if (!((*i)->isLayerDormant(this))){ + + paint.setRenderHint(QPainter::Antialiasing, false); + + paint.save(); + paint.translate(xorigin + x, 0); + + cerr << "Centre frame now: " << m_centreFrame << " drawing to " << chunk.x() + x + xorigin << ", " << chunk.width() << endl; + + (*i)->setSynchronousPainting(true); + + (*i)->paint(this, paint, chunk); + + (*i)->setSynchronousPainting(false); + + paint.restore(); + } } } diff -r 4fe7a09be0fe -r a5488775f880 view/View.h --- a/view/View.h Tue Mar 17 16:56:03 2015 +0000 +++ b/view/View.h Wed Mar 18 13:52:07 2015 +0000 @@ -427,7 +427,6 @@ sv_frame_t m_playPointerFrame; bool m_lightBackground; bool m_showProgress; - int m_paintScale; QPixmap *m_cache; sv_frame_t m_cacheCentreFrame; diff -r 4fe7a09be0fe -r a5488775f880 view/ViewProxy.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/view/ViewProxy.h Wed Mar 18 13:52:07 2015 +0000 @@ -0,0 +1,122 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef VIEW_PROXY_H +#define VIEW_PROXY_H + +#include "LayerGeometryProvider.h" + +class ViewProxy : public LayerGeometryProvider +{ +public: + ViewProxy(View *view, int scaleFactor) : + m_view(view), m_scaleFactor(scaleFactor) { } + + virtual sv_frame_t getStartFrame() const { + return m_view->getStartFrame(); + } + virtual sv_frame_t getCentreFrame() const { + return m_view->getCentreFrame(); + } + virtual sv_frame_t getEndFrame() const { + return m_view->getEndFrame(); + } + virtual int getXForFrame(sv_frame_t frame) const { + return m_scaleFactor * m_view->getXForFrame(frame); + } + virtual sv_frame_t getFrameForX(int x) const { + //!!! todo: interpolate + return m_view->getFrameForX(x / m_scaleFactor); + } + virtual sv_frame_t getModelsStartFrame() const { + return m_view->getModelsStartFrame(); + } + virtual sv_frame_t getModelsEndFrame() const { + return m_view->getModelsEndFrame(); + } + virtual double getYForFrequency(double frequency, + double minFreq, double maxFreq, + bool logarithmic) const { + return m_scaleFactor * + m_view->getYForFrequency(frequency, minFreq, maxFreq, logarithmic); + } + virtual double getFrequencyForY(int y, double minFreq, double maxFreq, + bool logarithmic) const { + //!!! todo: interpolate + return m_view->getFrequencyForY(y / m_scaleFactor, minFreq, maxFreq, logarithmic); + } + virtual int getTextLabelHeight(const Layer *layer, QPainter &paint) const { + return m_scaleFactor * m_view->getTextLabelHeight(layer, paint); + } + virtual bool getValueExtents(QString unit, double &min, double &max, + bool &log) const { + return m_view->getValueExtents(unit, min, max, log); + } + virtual int getZoomLevel() const { + //!!! aarg, what if it's already 1? + int z = m_view->getZoomLevel(); + cerr << "getZoomLevel: from " << z << " to "; + z = z / m_scaleFactor; + cerr << z << endl; + return z; + } + virtual QRect getPaintRect() const { + QRect r = m_view->getPaintRect(); + return QRect(r.x() * m_scaleFactor, + r.y() * m_scaleFactor, + r.width() * m_scaleFactor, + r.height() * m_scaleFactor); + } + virtual QSize getPaintSize() const { return getPaintRect().size(); } + virtual int getPaintWidth() const { return getPaintRect().width(); } + virtual int getPaintHeight() const { return getPaintRect().height(); } + virtual bool hasLightBackground() const { + return m_view->hasLightBackground(); + } + virtual QColor getForeground() const { + return m_view->getForeground(); + } + virtual QColor getBackground() const { + return m_view->getBackground(); + } + virtual ViewManager *getViewManager() const { + return m_view->getViewManager(); + } + + virtual bool shouldIlluminateLocalFeatures(const Layer *layer, QPoint &point) const { + return m_view->shouldIlluminateLocalFeatures(layer, point); + } + virtual bool shouldShowFeatureLabels() const { + return m_view->shouldShowFeatureLabels(); + } + + virtual void drawVisibleText(QPainter &p, int x, int y, + QString text, TextStyle style) const { + m_view->drawVisibleText(p, x, y, text, style); + } + + virtual void drawMeasurementRect(QPainter &p, const Layer *layer, + QRect rect, bool focus) const { + m_view->drawMeasurementRect(p, layer, rect, focus); + } + + virtual View *getView() { return m_view; } + virtual const View *getView() const { return m_view; } + +private: + View *m_view; + int m_scaleFactor; +}; + +#endif