Mercurial > hg > svgui
comparison layer/LayerGeometryProvider.h @ 1077:5144d7185fb5 spectrogram-minor-refactor
Move LayerGeometryProvider from view to layer
| author | Chris Cannam | 
|---|---|
| date | Thu, 30 Jun 2016 10:59:11 +0100 | 
| parents | view/LayerGeometryProvider.h@4e5c1c326794 | 
| children | ee01a4062747 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 1076:e536dfc6b250 | 1077:5144d7185fb5 | 
|---|---|
| 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
| 2 | |
| 3 /* | |
| 4 Sonic Visualiser | |
| 5 An audio file viewer and annotation editor. | |
| 6 Centre for Digital Music, Queen Mary, University of London. | |
| 7 | |
| 8 This program is free software; you can redistribute it and/or | |
| 9 modify it under the terms of the GNU General Public License as | |
| 10 published by the Free Software Foundation; either version 2 of the | |
| 11 License, or (at your option) any later version. See the file | |
| 12 COPYING included with this distribution for more information. | |
| 13 */ | |
| 14 | |
| 15 #ifndef LAYER_GEOMETRY_PROVIDER_H | |
| 16 #define LAYER_GEOMETRY_PROVIDER_H | |
| 17 | |
| 18 #include "base/BaseTypes.h" | |
| 19 | |
| 20 #include <QMutex> | |
| 21 #include <QMutexLocker> | |
| 22 #include <QPainter> | |
| 23 | |
| 24 class ViewManager; | |
| 25 class View; | |
| 26 class Layer; | |
| 27 | |
| 28 class LayerGeometryProvider | |
| 29 { | |
| 30 protected: | |
| 31 static int getNextId() { | |
| 32 static QMutex idMutex; | |
| 33 static int nextId = 1; | |
| 34 static int maxId = INT_MAX; | |
| 35 QMutexLocker locker(&idMutex); | |
| 36 int id = nextId; | |
| 37 if (nextId == maxId) { | |
| 38 // we don't expect this to happen in the lifetime of a | |
| 39 // process, but it would be undefined behaviour if it did | |
| 40 // since we're using a signed int, so we should really | |
| 41 // guard for it... | |
| 42 nextId = 1; | |
| 43 } else { | |
| 44 nextId++; | |
| 45 } | |
| 46 return id; | |
| 47 } | |
| 48 | |
| 49 public: | |
| 50 LayerGeometryProvider() { } | |
| 51 | |
| 52 /** | |
| 53 * Retrieve the id of this object. | |
| 54 */ | |
| 55 virtual int getId() const = 0; | |
| 56 | |
| 57 /** | |
| 58 * Retrieve the first visible sample frame on the widget. | |
| 59 * This is a calculated value based on the centre-frame, widget | |
| 60 * width and zoom level. The result may be negative. | |
| 61 */ | |
| 62 virtual sv_frame_t getStartFrame() const = 0; | |
| 63 | |
| 64 /** | |
| 65 * Return the centre frame of the visible widget. This is an | |
| 66 * exact value that does not depend on the zoom block size. Other | |
| 67 * frame values (start, end) are calculated from this based on the | |
| 68 * zoom and other factors. | |
| 69 */ | |
| 70 virtual sv_frame_t getCentreFrame() const = 0; | |
| 71 | |
| 72 /** | |
| 73 * Retrieve the last visible sample frame on the widget. | |
| 74 * This is a calculated value based on the centre-frame, widget | |
| 75 * width and zoom level. | |
| 76 */ | |
| 77 virtual sv_frame_t getEndFrame() const = 0; | |
| 78 | |
| 79 /** | |
| 80 * Return the pixel x-coordinate corresponding to a given sample | |
| 81 * frame (which may be negative). | |
| 82 */ | |
| 83 virtual int getXForFrame(sv_frame_t frame) const = 0; | |
| 84 | |
| 85 /** | |
| 86 * Return the closest frame to the given pixel x-coordinate. | |
| 87 */ | |
| 88 virtual sv_frame_t getFrameForX(int x) const = 0; | |
| 89 | |
| 90 virtual sv_frame_t getModelsStartFrame() const = 0; | |
| 91 virtual sv_frame_t getModelsEndFrame() const = 0; | |
| 92 | |
| 93 /** | |
| 94 * Return the closest pixel x-coordinate corresponding to a given | |
| 95 * view x-coordinate. | |
| 96 */ | |
| 97 virtual int getXForViewX(int viewx) const = 0; | |
| 98 | |
| 99 /** | |
| 100 * Return the closest view x-coordinate corresponding to a given | |
| 101 * pixel x-coordinate. | |
| 102 */ | |
| 103 virtual int getViewXForX(int x) const = 0; | |
| 104 | |
| 105 /** | |
| 106 * Return the pixel y-coordinate corresponding to a given | |
| 107 * frequency, if the frequency range is as specified. This does | |
| 108 * not imply any policy about layer frequency ranges, but it might | |
| 109 * be useful for layers to match theirs up if desired. | |
| 110 * | |
| 111 * Not thread-safe in logarithmic mode. Call only from GUI thread. | |
| 112 */ | |
| 113 virtual double getYForFrequency(double frequency, double minFreq, double maxFreq, | |
| 114 bool logarithmic) const = 0; | |
| 115 | |
| 116 /** | |
| 117 * Return the closest frequency to the given pixel y-coordinate, | |
| 118 * if the frequency range is as specified. | |
| 119 * | |
| 120 * Not thread-safe in logarithmic mode. Call only from GUI thread. | |
| 121 */ | |
| 122 virtual double getFrequencyForY(int y, double minFreq, double maxFreq, | |
| 123 bool logarithmic) const = 0; | |
| 124 | |
| 125 virtual int getTextLabelHeight(const Layer *layer, QPainter &) const = 0; | |
| 126 | |
| 127 virtual bool getValueExtents(QString unit, double &min, double &max, | |
| 128 bool &log) const = 0; | |
| 129 | |
| 130 /** | |
| 131 * Return the zoom level, i.e. the number of frames per pixel | |
| 132 */ | |
| 133 virtual int getZoomLevel() const = 0; | |
| 134 | |
| 135 /** | |
| 136 * To be called from a layer, to obtain the extent of the surface | |
| 137 * that the layer is currently painting to. This may be the extent | |
| 138 * of the view (if 1x display scaling is in effect) or of a larger | |
| 139 * cached pixmap (if greater display scaling is in effect). | |
| 140 */ | |
| 141 virtual QRect getPaintRect() const = 0; | |
| 142 | |
| 143 virtual QSize getPaintSize() const { return getPaintRect().size(); } | |
| 144 virtual int getPaintWidth() const { return getPaintRect().width(); } | |
| 145 virtual int getPaintHeight() const { return getPaintRect().height(); } | |
| 146 | |
| 147 virtual bool hasLightBackground() const = 0; | |
| 148 virtual QColor getForeground() const = 0; | |
| 149 virtual QColor getBackground() const = 0; | |
| 150 | |
| 151 virtual ViewManager *getViewManager() const = 0; | |
| 152 | |
| 153 virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) const = 0; | |
| 154 virtual bool shouldShowFeatureLabels() const = 0; | |
| 155 | |
| 156 enum TextStyle { | |
| 157 BoxedText, | |
| 158 OutlinedText, | |
| 159 OutlinedItalicText | |
| 160 }; | |
| 161 | |
| 162 virtual void drawVisibleText(QPainter &p, int x, int y, | |
| 163 QString text, TextStyle style) const = 0; | |
| 164 | |
| 165 virtual void drawMeasurementRect(QPainter &p, const Layer *, | |
| 166 QRect rect, bool focus) const = 0; | |
| 167 | |
| 168 virtual void updatePaintRect(QRect r) = 0; | |
| 169 | |
| 170 virtual View *getView() = 0; | |
| 171 virtual const View *getView() const = 0; | |
| 172 }; | |
| 173 | |
| 174 #endif | 
