LayerGeometryProvider.h
Go to the documentation of this file.
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 SV_LAYER_GEOMETRY_PROVIDER_H
16 #define SV_LAYER_GEOMETRY_PROVIDER_H
17 
18 #include "base/BaseTypes.h"
19 #include "base/ZoomLevel.h"
20 
21 #include <QMutex>
22 #include <QMutexLocker>
23 #include <QPainter>
24 
25 class ViewManager;
26 class View;
27 class Layer;
28 
46 {
47 protected:
48  static int getNextId() {
49  static QMutex idMutex;
50  static int nextId = 1;
51  static int maxId = INT_MAX;
52  QMutexLocker locker(&idMutex);
53  int id = nextId;
54  if (nextId == maxId) {
55  // we don't expect this to happen in the lifetime of a
56  // process, but it would be undefined behaviour if it did
57  // since we're using a signed int, so we should really
58  // guard for it...
59  nextId = 1;
60  } else {
61  nextId++;
62  }
63  return id;
64  }
65 
66 public:
68 
72  virtual int getId() const = 0;
73 
79  virtual sv_frame_t getStartFrame() const = 0;
80 
87  virtual sv_frame_t getCentreFrame() const = 0;
88 
94  virtual sv_frame_t getEndFrame() const = 0;
95 
100  virtual int getXForFrame(sv_frame_t frame) const = 0;
101 
105  virtual sv_frame_t getFrameForX(int x) const = 0;
106 
107  virtual sv_frame_t getModelsStartFrame() const = 0;
108  virtual sv_frame_t getModelsEndFrame() const = 0;
109 
114  virtual int getXForViewX(int viewx) const = 0;
115 
120  virtual int getViewXForX(int x) const = 0;
121 
131  virtual double getYForFrequency(double frequency,
132  double minFreq, double maxFreq,
133  bool logarithmic) const = 0;
134 
141  virtual double getFrequencyForY(double y,
142  double minFreq, double maxFreq,
143  bool logarithmic) const = 0;
144 
153  virtual int getTextLabelYCoord(const Layer *layer, QPainter &) const = 0;
154 
168  virtual bool getVisibleExtentsForUnit(QString unit,
169  double &min, double &max,
170  bool &log) const = 0;
171 
176  virtual ZoomLevel getZoomLevel() const = 0;
177 
184  virtual QRect getPaintRect() const = 0;
185 
186  virtual QSize getPaintSize() const { return getPaintRect().size(); }
187  virtual int getPaintWidth() const { return getPaintRect().width(); }
188  virtual int getPaintHeight() const { return getPaintRect().height(); }
189 
190  virtual bool hasLightBackground() const = 0;
191  virtual QColor getForeground() const = 0;
192  virtual QColor getBackground() const = 0;
193 
194  virtual ViewManager *getViewManager() const = 0;
195 
196  virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) const = 0;
197  virtual bool shouldShowFeatureLabels() const = 0;
198 
199  virtual void drawMeasurementRect(QPainter &p, const Layer *,
200  QRect rect, bool focus) const = 0;
201 
202  virtual void updatePaintRect(QRect r) = 0;
203 
204  virtual double scaleSize(double size) const = 0;
205  virtual int scalePixelSize(int size) const = 0;
206  virtual double scalePenWidth(double width) const = 0;
207  virtual QPen scalePen(QPen pen) const = 0;
208 
209  virtual View *getView() = 0;
210  virtual const View *getView() const = 0;
211 };
212 
213 #endif
virtual int scalePixelSize(int size) const =0
virtual int getXForViewX(int viewx) const =0
Return the closest pixel x-coordinate corresponding to a given view x-coordinate. ...
The base class for visual representations of the data found in a Model.
Definition: Layer.h:54
virtual QColor getForeground() const =0
virtual QColor getBackground() const =0
virtual QSize getPaintSize() const
virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) const =0
virtual ZoomLevel getZoomLevel() const =0
Return the zoom level, i.e.
virtual double getFrequencyForY(double y, double minFreq, double maxFreq, bool logarithmic) const =0
Return the closest frequency to the given (maybe fractional) pixel y-coordinate, if the frequency ran...
virtual sv_frame_t getFrameForX(int x) const =0
Return the closest frame to the given pixel x-coordinate.
virtual double scaleSize(double size) const =0
Interface for classes that provide geometry information (such as size, start frame, and a large number of other properties) about the disposition of a layer.
virtual double getYForFrequency(double frequency, double minFreq, double maxFreq, bool logarithmic) const =0
Return the (maybe fractional) pixel y-coordinate corresponding to a given frequency, if the frequency range is as specified.
virtual QRect getPaintRect() const =0
To be called from a layer, to obtain the extent of the surface that the layer is currently painting t...
virtual sv_frame_t getStartFrame() const =0
Retrieve the first visible sample frame on the widget.
virtual double scalePenWidth(double width) const =0
virtual bool shouldShowFeatureLabels() const =0
virtual int getPaintHeight() const
virtual sv_frame_t getModelsStartFrame() const =0
virtual sv_frame_t getModelsEndFrame() const =0
virtual QPen scalePen(QPen pen) const =0
virtual int getViewXForX(int x) const =0
Return the closest view x-coordinate corresponding to a given pixel x-coordinate. ...
virtual void updatePaintRect(QRect r)=0
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:55
virtual void drawMeasurementRect(QPainter &p, const Layer *, QRect rect, bool focus) const =0
virtual ViewManager * getViewManager() const =0
The ViewManager manages properties that may need to be synchronised between separate Views...
Definition: ViewManager.h:78
virtual int getId() const =0
Retrieve the id of this object.
virtual int getTextLabelYCoord(const Layer *layer, QPainter &) const =0
Return a y-coordinate at which text labels for individual items in a layer may be drawn...
virtual bool getVisibleExtentsForUnit(QString unit, double &min, double &max, bool &log) const =0
Return the visible vertical extents for the given unit, if any.
virtual sv_frame_t getCentreFrame() const =0
Return the centre frame of the visible widget.
virtual sv_frame_t getEndFrame() const =0
Retrieve the last visible sample frame on the widget.
virtual bool hasLightBackground() const =0
virtual int getXForFrame(sv_frame_t frame) const =0
Return the pixel x-coordinate corresponding to a given sample frame (which may be negative)...
virtual int getPaintWidth() const
virtual View * getView()=0