annotate view/ViewProxy.h @ 1431:af824022bffd single-point

Begin fixing the various snap operations. Also remove SnapNearest, which is never used and seems to consume more lines of code than the rest!
author Chris Cannam
date Wed, 20 Mar 2019 14:59:34 +0000
parents a18e78b9c78b
children c83504eb2649
rev   line source
Chris@919 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@919 2
Chris@919 3 /*
Chris@919 4 Sonic Visualiser
Chris@919 5 An audio file viewer and annotation editor.
Chris@919 6 Centre for Digital Music, Queen Mary, University of London.
Chris@919 7
Chris@919 8 This program is free software; you can redistribute it and/or
Chris@919 9 modify it under the terms of the GNU General Public License as
Chris@919 10 published by the Free Software Foundation; either version 2 of the
Chris@919 11 License, or (at your option) any later version. See the file
Chris@919 12 COPYING included with this distribution for more information.
Chris@919 13 */
Chris@919 14
Chris@919 15 #ifndef VIEW_PROXY_H
Chris@919 16 #define VIEW_PROXY_H
Chris@919 17
Chris@1077 18 #include "layer/LayerGeometryProvider.h"
Chris@919 19
Chris@919 20 class ViewProxy : public LayerGeometryProvider
Chris@919 21 {
Chris@919 22 public:
Chris@919 23 ViewProxy(View *view, int scaleFactor) :
Chris@1266 24 m_view(view), m_scaleFactor(scaleFactor) { }
Chris@919 25
Chris@1406 26 int getId() const override {
Chris@1044 27 return m_view->getId();
Chris@1044 28 }
Chris@1406 29 sv_frame_t getStartFrame() const override {
Chris@1266 30 return m_view->getStartFrame();
Chris@919 31 }
Chris@1406 32 sv_frame_t getCentreFrame() const override {
Chris@1266 33 return m_view->getCentreFrame();
Chris@919 34 }
Chris@1406 35 sv_frame_t getEndFrame() const override {
Chris@1266 36 return m_view->getEndFrame();
Chris@919 37 }
Chris@1406 38 int getXForFrame(sv_frame_t frame) const override {
Chris@950 39 //!!! not actually correct, if frame lies between view's pixels
Chris@1266 40 return m_scaleFactor * m_view->getXForFrame(frame);
Chris@919 41 }
Chris@1406 42 sv_frame_t getFrameForX(int x) const override {
Chris@950 43 sv_frame_t f0 = m_view->getFrameForX(x / m_scaleFactor);
Chris@950 44 if (m_scaleFactor == 1) return f0;
Chris@950 45 sv_frame_t f1 = m_view->getFrameForX((x / m_scaleFactor) + 1);
Chris@950 46 return f0 + ((f1 - f0) * (x % m_scaleFactor)) / m_scaleFactor;
Chris@919 47 }
Chris@1406 48 int getXForViewX(int viewx) const override {
Chris@1030 49 return viewx * m_scaleFactor;
Chris@1030 50 }
Chris@1406 51 int getViewXForX(int x) const override {
Chris@1030 52 return x / m_scaleFactor;
Chris@1030 53 }
Chris@1406 54 sv_frame_t getModelsStartFrame() const override {
Chris@1266 55 return m_view->getModelsStartFrame();
Chris@919 56 }
Chris@1406 57 sv_frame_t getModelsEndFrame() const override {
Chris@1266 58 return m_view->getModelsEndFrame();
Chris@919 59 }
Chris@1406 60 double getYForFrequency(double frequency,
Chris@1266 61 double minFreq, double maxFreq,
Chris@1406 62 bool logarithmic) const override {
Chris@1266 63 return m_scaleFactor *
Chris@1266 64 m_view->getYForFrequency(frequency, minFreq, maxFreq, logarithmic);
Chris@919 65 }
Chris@1406 66 double getFrequencyForY(double y, double minFreq, double maxFreq,
Chris@1406 67 bool logarithmic) const override {
Chris@1085 68 return m_view->getFrequencyForY
Chris@950 69 (y / m_scaleFactor, minFreq, maxFreq, logarithmic);
Chris@919 70 }
Chris@1406 71 int getTextLabelHeight(const Layer *layer, QPainter &paint) const override {
Chris@1266 72 return m_scaleFactor * m_view->getTextLabelHeight(layer, paint);
Chris@919 73 }
Chris@1406 74 bool getValueExtents(QString unit, double &min, double &max,
Chris@1406 75 bool &log) const override {
Chris@1266 76 return m_view->getValueExtents(unit, min, max, log);
Chris@919 77 }
Chris@1406 78 ZoomLevel getZoomLevel() const override {
Chris@1326 79 ZoomLevel z = m_view->getZoomLevel();
Chris@1326 80 //!!!
Chris@1329 81 // cerr << "getZoomLevel: from " << z << " to ";
Chris@1326 82 if (z.zone == ZoomLevel::FramesPerPixel) {
Chris@1326 83 z.level /= m_scaleFactor;
Chris@1326 84 if (z.level < 1) {
Chris@1326 85 z.level = 1;
Chris@1326 86 }
Chris@1326 87 } else {
Chris@1326 88 //!!!???
Chris@1326 89 z.level *= m_scaleFactor;
Chris@1326 90 }
Chris@1329 91 // cerr << z << endl;
Chris@1266 92 return z;
Chris@919 93 }
Chris@1406 94 QRect getPaintRect() const override {
Chris@1266 95 QRect r = m_view->getPaintRect();
Chris@1266 96 return QRect(r.x() * m_scaleFactor,
Chris@1266 97 r.y() * m_scaleFactor,
Chris@1266 98 r.width() * m_scaleFactor,
Chris@1266 99 r.height() * m_scaleFactor);
Chris@919 100 }
Chris@1406 101 QSize getPaintSize() const override {
Chris@954 102 return getPaintRect().size();
Chris@954 103 }
Chris@1406 104 int getPaintWidth() const override {
Chris@954 105 return getPaintRect().width();
Chris@954 106 }
Chris@1406 107 int getPaintHeight() const override {
Chris@954 108 return getPaintRect().height();
Chris@954 109 }
Chris@1406 110 bool hasLightBackground() const override {
Chris@1266 111 return m_view->hasLightBackground();
Chris@919 112 }
Chris@1406 113 QColor getForeground() const override {
Chris@1266 114 return m_view->getForeground();
Chris@919 115 }
Chris@1406 116 QColor getBackground() const override {
Chris@1266 117 return m_view->getBackground();
Chris@919 118 }
Chris@1406 119 ViewManager *getViewManager() const override {
Chris@1266 120 return m_view->getViewManager();
Chris@919 121 }
Chris@1266 122
Chris@1406 123 bool shouldIlluminateLocalFeatures(const Layer *layer,
Chris@1406 124 QPoint &point) const override {
Chris@954 125 QPoint p;
Chris@1266 126 bool should = m_view->shouldIlluminateLocalFeatures(layer, p);
Chris@954 127 point = QPoint(p.x() * m_scaleFactor, p.y() * m_scaleFactor);
Chris@954 128 return should;
Chris@919 129 }
Chris@954 130
Chris@1406 131 bool shouldShowFeatureLabels() const override {
Chris@1266 132 return m_view->shouldShowFeatureLabels();
Chris@919 133 }
Chris@919 134
Chris@1406 135 void drawMeasurementRect(QPainter &p, const Layer *layer,
Chris@1406 136 QRect rect, bool focus) const override {
Chris@1266 137 m_view->drawMeasurementRect(p, layer, rect, focus);
Chris@919 138 }
Chris@919 139
Chris@1406 140 void updatePaintRect(QRect r) override {
Chris@1030 141 m_view->update(r.x() / m_scaleFactor,
Chris@1030 142 r.y() / m_scaleFactor,
Chris@1030 143 r.width() / m_scaleFactor,
Chris@1030 144 r.height() / m_scaleFactor);
Chris@1030 145 }
Chris@1401 146
Chris@1401 147 /**
Chris@1401 148 * Scale up a size in pixels for a hi-dpi display without pixel
Chris@1401 149 * doubling. This is like ViewManager::scalePixelSize, but taking
Chris@1401 150 * and returning floating-point values rather than integer
Chris@1401 151 * pixels. It is also a little more conservative - it never
Chris@1401 152 * shrinks the size, it can only increase or leave it unchanged.
Chris@1401 153 */
Chris@1406 154 double scaleSize(double size) const override {
Chris@1401 155 return m_view->scaleSize(size * m_scaleFactor);
Chris@1401 156 }
Chris@1401 157
Chris@1401 158 /**
Chris@1402 159 * Integer version of scaleSize.
Chris@1402 160 */
Chris@1406 161 int scalePixelSize(int size) const override {
Chris@1402 162 return m_view->scalePixelSize(size * m_scaleFactor);
Chris@1402 163 }
Chris@1402 164
Chris@1402 165 /**
Chris@1401 166 * Scale up pen width for a hi-dpi display without pixel doubling.
Chris@1401 167 * This is like scaleSize except that it also scales the
Chris@1401 168 * zero-width case.
Chris@1401 169 */
Chris@1406 170 double scalePenWidth(double width) const override {
Chris@1401 171 if (width <= 0) { // zero-width pen, produce a scaled one-pixel pen
Chris@1401 172 width = 1;
Chris@1401 173 }
Chris@1401 174 width *= sqrt(double(m_scaleFactor));
Chris@1401 175 return m_view->scalePenWidth(width);
Chris@1401 176 }
Chris@1401 177
Chris@1401 178 /**
Chris@1401 179 * Apply scalePenWidth to a pen.
Chris@1401 180 */
Chris@1406 181 QPen scalePen(QPen pen) const override {
Chris@1401 182 return QPen(pen.color(), scalePenWidth(pen.width()));
Chris@1401 183 }
Chris@1030 184
Chris@1406 185 View *getView() override { return m_view; }
Chris@1406 186 const View *getView() const override { return m_view; }
Chris@919 187
Chris@919 188 private:
Chris@919 189 View *m_view;
Chris@919 190 int m_scaleFactor;
Chris@919 191 };
Chris@919 192
Chris@919 193 #endif