Mercurial > hg > svgui
comparison layer/ScrollableImageCache.h @ 1118:175d4e15884d spectrogram-minor-refactor
Introduce ScrollableMagRangeCache, plus some tidying etc
author | Chris Cannam |
---|---|
date | Wed, 20 Jul 2016 08:30:20 +0100 |
parents | 261a00010918 |
children | a34a2a25907c |
comparison
equal
deleted
inserted
replaced
1117:64709d4d09ef | 1118:175d4e15884d |
---|---|
22 #include <QImage> | 22 #include <QImage> |
23 #include <QRect> | 23 #include <QRect> |
24 #include <QPainter> | 24 #include <QPainter> |
25 | 25 |
26 /** | 26 /** |
27 * A cached image for a view that scrolls horizontally, primarily the | 27 * A cached image for a view that scrolls horizontally, such as a |
28 * spectrogram. The cache object holds an image, reports the size of | 28 * spectrogram. The cache object holds an image, reports the size of |
29 * the image (likely the same as the underlying view, but it's the | 29 * the image (likely the same as the underlying view, but it's the |
30 * caller's responsibility to set the size appropriately), can scroll | 30 * caller's responsibility to set the size appropriately), can scroll |
31 * the image, and can report and update which contiguous horizontal | 31 * the image, and can report and update which contiguous horizontal |
32 * range of the image is valid. | 32 * range of the image is valid. |
36 */ | 36 */ |
37 class ScrollableImageCache | 37 class ScrollableImageCache |
38 { | 38 { |
39 public: | 39 public: |
40 ScrollableImageCache() : | 40 ScrollableImageCache() : |
41 m_left(0), | 41 m_validLeft(0), |
42 m_width(0), | 42 m_validWidth(0), |
43 m_startFrame(0), | 43 m_startFrame(0), |
44 m_zoomLevel(0) | 44 m_zoomLevel(0) |
45 {} | 45 {} |
46 | 46 |
47 void invalidate() { | 47 void invalidate() { |
48 m_width = 0; | 48 m_validWidth = 0; |
49 } | 49 } |
50 | 50 |
51 bool isValid() const { | 51 bool isValid() const { |
52 return m_width > 0; | 52 return m_validWidth > 0; |
53 } | 53 } |
54 | 54 |
55 QSize getSize() const { | 55 QSize getSize() const { |
56 return m_image.size(); | 56 return m_image.size(); |
57 } | 57 } |
58 | 58 |
59 /** | |
60 * Set the size of the cache. If the new size differs from the | |
61 * current size, the cache is invalidated. | |
62 */ | |
59 void resize(QSize newSize) { | 63 void resize(QSize newSize) { |
60 if (getSize() != newSize) { | 64 if (getSize() != newSize) { |
61 m_image = QImage(newSize, QImage::Format_ARGB32_Premultiplied); | 65 m_image = QImage(newSize, QImage::Format_ARGB32_Premultiplied); |
62 invalidate(); | 66 invalidate(); |
63 } | 67 } |
64 } | 68 } |
65 | 69 |
66 int getValidLeft() const { | 70 int getValidLeft() const { |
67 return m_left; | 71 return m_validLeft; |
68 } | 72 } |
69 | 73 |
70 int getValidWidth() const { | 74 int getValidWidth() const { |
71 return m_width; | 75 return m_validWidth; |
72 } | 76 } |
73 | 77 |
74 int getValidRight() const { | 78 int getValidRight() const { |
75 return m_left + m_width; | 79 return m_validLeft + m_validWidth; |
76 } | 80 } |
77 | 81 |
78 QRect getValidArea() const { | 82 QRect getValidArea() const { |
79 return QRect(m_left, 0, m_width, m_image.height()); | 83 return QRect(m_validLeft, 0, m_validWidth, m_image.height()); |
80 } | 84 } |
81 | 85 |
82 int getZoomLevel() const { | 86 int getZoomLevel() const { |
83 return m_zoomLevel; | 87 return m_zoomLevel; |
84 } | 88 } |
85 | 89 |
90 /** | |
91 * Set the zoom level. If the new zoom level differs from the | |
92 * current one, the cache is invalidated. (Determining whether to | |
93 * invalidate the cache here is the only thing the zoom level is | |
94 * used for.) | |
95 */ | |
86 void setZoomLevel(int zoom) { | 96 void setZoomLevel(int zoom) { |
87 if (m_zoomLevel != zoom) { | 97 if (m_zoomLevel != zoom) { |
88 m_zoomLevel = zoom; | 98 m_zoomLevel = zoom; |
89 invalidate(); | 99 invalidate(); |
90 } | 100 } |
93 sv_frame_t getStartFrame() const { | 103 sv_frame_t getStartFrame() const { |
94 return m_startFrame; | 104 return m_startFrame; |
95 } | 105 } |
96 | 106 |
97 /** | 107 /** |
98 * Set the start frame and invalidate the cache. To scroll, | 108 * Set the start frame. If the new start frame differs from the |
99 * i.e. to set the start frame while retaining cache validity | 109 * current one, the cache is invalidated. To scroll, i.e. to set |
100 * where possible, use scrollTo() instead. | 110 * the start frame while retaining cache validity where possible, |
111 * use scrollTo() instead. | |
101 */ | 112 */ |
102 void setStartFrame(sv_frame_t frame) { | 113 void setStartFrame(sv_frame_t frame) { |
103 if (m_startFrame != frame) { | 114 if (m_startFrame != frame) { |
104 m_startFrame = frame; | 115 m_startFrame = frame; |
105 invalidate(); | 116 invalidate(); |
141 int imageLeft, | 152 int imageLeft, |
142 int imageWidth); | 153 int imageWidth); |
143 | 154 |
144 private: | 155 private: |
145 QImage m_image; | 156 QImage m_image; |
146 int m_left; // of valid region | 157 int m_validLeft; |
147 int m_width; // of valid region | 158 int m_validWidth; |
148 sv_frame_t m_startFrame; | 159 sv_frame_t m_startFrame; |
149 int m_zoomLevel; | 160 int m_zoomLevel; |
150 }; | 161 }; |
151 | 162 |
152 #endif | 163 #endif |