annotate view/LayerGeometryProvider.h @ 1035:6d084d6d5015 spectrogram-minor-refactor

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