Mercurial > hg > svgui
comparison layer/ScrollableImageCache.h @ 1324:13d9b422f7fe zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 17 Sep 2018 13:51:31 +0100 |
parents | a34a2a25907c |
children | bc2cb82050a0 |
comparison
equal
deleted
inserted
replaced
1183:57d192e26331 | 1324:13d9b422f7fe |
---|---|
36 */ | 36 */ |
37 class ScrollableImageCache | 37 class ScrollableImageCache |
38 { | 38 { |
39 public: | 39 public: |
40 ScrollableImageCache() : | 40 ScrollableImageCache() : |
41 m_validLeft(0), | 41 m_validLeft(0), |
42 m_validWidth(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_validWidth = 0; | 48 m_validWidth = 0; |
49 } | 49 } |
50 | 50 |
51 bool isValid() const { | 51 bool isValid() const { |
52 return m_validWidth > 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 /** | 59 /** |
60 * Set the size of the cache. If the new size differs from the | 60 * Set the size of the cache. If the new size differs from the |
61 * current size, the cache is invalidated. | 61 * current size, the cache is invalidated. |
64 if (getSize() != newSize) { | 64 if (getSize() != newSize) { |
65 m_image = QImage(newSize, QImage::Format_ARGB32_Premultiplied); | 65 m_image = QImage(newSize, QImage::Format_ARGB32_Premultiplied); |
66 invalidate(); | 66 invalidate(); |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 int getValidLeft() const { | 70 int getValidLeft() const { |
71 return m_validLeft; | 71 return m_validLeft; |
72 } | 72 } |
73 | 73 |
74 int getValidWidth() const { | 74 int getValidWidth() const { |
75 return m_validWidth; | 75 return m_validWidth; |
76 } | 76 } |
77 | 77 |
78 int getValidRight() const { | 78 int getValidRight() const { |
79 return m_validLeft + m_validWidth; | 79 return m_validLeft + m_validWidth; |
80 } | 80 } |
81 | 81 |
82 QRect getValidArea() const { | 82 QRect getValidArea() const { |
83 return QRect(m_validLeft, 0, m_validWidth, m_image.height()); | 83 return QRect(m_validLeft, 0, m_validWidth, m_image.height()); |
84 } | 84 } |
85 | 85 |
86 int getZoomLevel() const { | 86 int getZoomLevel() const { |
87 return m_zoomLevel; | 87 return m_zoomLevel; |
88 } | 88 } |
89 | 89 |
90 /** | 90 /** |
91 * Set the zoom level. If the new zoom level differs from the | 91 * Set the zoom level. If the new zoom level differs from the |
92 * current one, the cache is invalidated. (Determining whether to | 92 * current one, the cache is invalidated. (Determining whether to |
99 invalidate(); | 99 invalidate(); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 sv_frame_t getStartFrame() const { | 103 sv_frame_t getStartFrame() const { |
104 return m_startFrame; | 104 return m_startFrame; |
105 } | 105 } |
106 | 106 |
107 /** | 107 /** |
108 * Set the start frame. If the new start frame differs from the | 108 * Set the start frame. If the new start frame differs from the |
109 * current one, the cache is invalidated. To scroll, i.e. to set | 109 * current one, the cache is invalidated. To scroll, i.e. to set |
116 invalidate(); | 116 invalidate(); |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 const QImage &getImage() const { | 120 const QImage &getImage() const { |
121 return m_image; | 121 return m_image; |
122 } | 122 } |
123 | 123 |
124 /** | 124 /** |
125 * Set the new start frame for the cache, according to the | 125 * Set the new start frame for the cache, according to the |
126 * geometry of the supplied LayerGeometryProvider, if possible | 126 * geometry of the supplied LayerGeometryProvider, if possible |
135 * region and so that the union of the adjusted region with the | 135 * region and so that the union of the adjusted region with the |
136 * cache valid region contains the supplied region. Does not | 136 * cache valid region contains the supplied region. Does not |
137 * modify anything about the cache, only about the arguments. | 137 * modify anything about the cache, only about the arguments. |
138 */ | 138 */ |
139 void adjustToTouchValidArea(int &left, int &width, | 139 void adjustToTouchValidArea(int &left, int &width, |
140 bool &isLeftOfValidArea) const; | 140 bool &isLeftOfValidArea) const; |
141 | 141 |
142 /** | 142 /** |
143 * Draw from an image onto the cache. The supplied image must have | 143 * Draw from an image onto the cache. The supplied image must have |
144 * the same height as the cache and the full height is always | 144 * the same height as the cache and the full height is always |
145 * drawn. The left and width parameters determine the target | 145 * drawn. The left and width parameters determine the target |
146 * region of the cache, the imageLeft and imageWidth parameters | 146 * region of the cache, the imageLeft and imageWidth parameters |
147 * the source region of the image. | 147 * the source region of the image. |
148 */ | 148 */ |
149 void drawImage(int left, | 149 void drawImage(int left, |
150 int width, | 150 int width, |
151 QImage image, | 151 QImage image, |
152 int imageLeft, | 152 int imageLeft, |
153 int imageWidth); | 153 int imageWidth); |
154 | 154 |
155 private: | 155 private: |
156 QImage m_image; | 156 QImage m_image; |
157 int m_validLeft; | 157 int m_validLeft; |
158 int m_validWidth; | 158 int m_validWidth; |