comparison layer/LayerGeometryProvider.h @ 1216:dc2af6616c83

Merge from branch 3.0-integration
author Chris Cannam
date Fri, 13 Jan 2017 10:29:50 +0000
parents c8c747783110
children 57d192e26331
comparison
equal deleted inserted replaced
1048:e8102ff5573b 1216:dc2af6616c83
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 /**
29 * Interface for classes that provide geometry information (such as
30 * size, start frame, and a large number of other properties) about
31 * the disposition of a layer. The main implementor of this interface
32 * is the View class, but other implementations may be used in
33 * different circumstances, e.g. as a proxy to handle hi-dpi
34 * coordinate mapping.
35 *
36 * Note it is expected that some implementations of this may be
37 * disposable, created on-the-fly for a single use. Code that receives
38 * a LayerGeometryProvider pointer as an argument to something should
39 * not, in general, store that pointer as it may be invalidated before
40 * the next use. Use getId() to instead obtain a persistent identifier
41 * for a LayerGeometryProvider, for example to establish whether the
42 * same one is being provided in two separate calls.
43 */
44 class LayerGeometryProvider
45 {
46 protected:
47 static int getNextId() {
48 static QMutex idMutex;
49 static int nextId = 1;
50 static int maxId = INT_MAX;
51 QMutexLocker locker(&idMutex);
52 int id = nextId;
53 if (nextId == maxId) {
54 // we don't expect this to happen in the lifetime of a
55 // process, but it would be undefined behaviour if it did
56 // since we're using a signed int, so we should really
57 // guard for it...
58 nextId = 1;
59 } else {
60 nextId++;
61 }
62 return id;
63 }
64
65 public:
66 LayerGeometryProvider() { }
67
68 /**
69 * Retrieve the id of this object.
70 */
71 virtual int getId() const = 0;
72
73 /**
74 * Retrieve the first visible sample frame on the widget.
75 * This is a calculated value based on the centre-frame, widget
76 * width and zoom level. The result may be negative.
77 */
78 virtual sv_frame_t getStartFrame() const = 0;
79
80 /**
81 * Return the centre frame of the visible widget. This is an
82 * exact value that does not depend on the zoom block size. Other
83 * frame values (start, end) are calculated from this based on the
84 * zoom and other factors.
85 */
86 virtual sv_frame_t getCentreFrame() const = 0;
87
88 /**
89 * Retrieve the last visible sample frame on the widget.
90 * This is a calculated value based on the centre-frame, widget
91 * width and zoom level.
92 */
93 virtual sv_frame_t getEndFrame() const = 0;
94
95 /**
96 * Return the pixel x-coordinate corresponding to a given sample
97 * frame (which may be negative).
98 */
99 virtual int getXForFrame(sv_frame_t frame) const = 0;
100
101 /**
102 * Return the closest frame to the given pixel x-coordinate.
103 */
104 virtual sv_frame_t getFrameForX(int x) const = 0;
105
106 virtual sv_frame_t getModelsStartFrame() const = 0;
107 virtual sv_frame_t getModelsEndFrame() const = 0;
108
109 /**
110 * Return the closest pixel x-coordinate corresponding to a given
111 * view x-coordinate.
112 */
113 virtual int getXForViewX(int viewx) const = 0;
114
115 /**
116 * Return the closest view x-coordinate corresponding to a given
117 * pixel x-coordinate.
118 */
119 virtual int getViewXForX(int x) const = 0;
120
121 /**
122 * Return the (maybe fractional) pixel y-coordinate corresponding
123 * to a given frequency, if the frequency range is as specified.
124 * This does not imply any policy about layer frequency ranges,
125 * but it might be useful for layers to match theirs up if
126 * desired.
127 *
128 * Not thread-safe in logarithmic mode. Call only from GUI thread.
129 */
130 virtual double getYForFrequency(double frequency,
131 double minFreq, double maxFreq,
132 bool logarithmic) const = 0;
133
134 /**
135 * Return the closest frequency to the given (maybe fractional)
136 * pixel y-coordinate, if the frequency range is as specified.
137 *
138 * Not thread-safe in logarithmic mode. Call only from GUI thread.
139 */
140 virtual double getFrequencyForY(double y,
141 double minFreq, double maxFreq,
142 bool logarithmic) const = 0;
143
144 virtual int getTextLabelHeight(const Layer *layer, QPainter &) const = 0;
145
146 virtual bool getValueExtents(QString unit, double &min, double &max,
147 bool &log) const = 0;
148
149 /**
150 * Return the zoom level, i.e. the number of frames per pixel
151 */
152 virtual int getZoomLevel() const = 0;
153
154 /**
155 * To be called from a layer, to obtain the extent of the surface
156 * that the layer is currently painting to. This may be the extent
157 * of the view (if 1x display scaling is in effect) or of a larger
158 * cached pixmap (if greater display scaling is in effect).
159 */
160 virtual QRect getPaintRect() const = 0;
161
162 virtual QSize getPaintSize() const { return getPaintRect().size(); }
163 virtual int getPaintWidth() const { return getPaintRect().width(); }
164 virtual int getPaintHeight() const { return getPaintRect().height(); }
165
166 virtual bool hasLightBackground() const = 0;
167 virtual QColor getForeground() const = 0;
168 virtual QColor getBackground() const = 0;
169
170 virtual ViewManager *getViewManager() const = 0;
171
172 virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) const = 0;
173 virtual bool shouldShowFeatureLabels() const = 0;
174
175 virtual void drawMeasurementRect(QPainter &p, const Layer *,
176 QRect rect, bool focus) const = 0;
177
178 virtual void updatePaintRect(QRect r) = 0;
179
180 virtual View *getView() = 0;
181 virtual const View *getView() const = 0;
182 };
183
184 #endif