Mercurial > hg > svgui
comparison view/Overview.cpp @ 1324:13d9b422f7fe zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 17 Sep 2018 13:51:31 +0100 |
parents | 57d192e26331 a34a2a25907c |
children | bc2cb82050a0 |
comparison
equal
deleted
inserted
replaced
1183:57d192e26331 | 1324:13d9b422f7fe |
---|---|
115 { | 115 { |
116 #ifdef DEBUG_OVERVIEW | 116 #ifdef DEBUG_OVERVIEW |
117 cerr << "Overview[" << this << "]::viewCentreFrameChanged(" << v << "): " << f << endl; | 117 cerr << "Overview[" << this << "]::viewCentreFrameChanged(" << v << "): " << f << endl; |
118 #endif | 118 #endif |
119 if (m_views.find(v) != m_views.end()) { | 119 if (m_views.find(v) != m_views.end()) { |
120 update(); | 120 update(); |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
124 void | 124 void |
125 Overview::viewZoomLevelChanged(View *v, int, bool) | 125 Overview::viewZoomLevelChanged(View *v, int, bool) |
126 { | 126 { |
127 if (v == this) return; | 127 if (v == this) return; |
128 if (m_views.find(v) != m_views.end()) { | 128 if (m_views.find(v) != m_views.end()) { |
129 update(); | 129 update(); |
130 } | 130 } |
131 } | 131 } |
132 | 132 |
133 void | 133 void |
134 Overview::viewManagerPlaybackFrameChanged(sv_frame_t f) | 134 Overview::viewManagerPlaybackFrameChanged(sv_frame_t f) |
179 sv_frame_t startFrame = getModelsStartFrame(); | 179 sv_frame_t startFrame = getModelsStartFrame(); |
180 sv_frame_t frameCount = getModelsEndFrame() - getModelsStartFrame(); | 180 sv_frame_t frameCount = getModelsEndFrame() - getModelsStartFrame(); |
181 int zoomLevel = int(frameCount / width()); | 181 int zoomLevel = int(frameCount / width()); |
182 if (zoomLevel < 1) zoomLevel = 1; | 182 if (zoomLevel < 1) zoomLevel = 1; |
183 zoomLevel = getZoomConstraintBlockSize(zoomLevel, | 183 zoomLevel = getZoomConstraintBlockSize(zoomLevel, |
184 ZoomConstraint::RoundUp); | 184 ZoomConstraint::RoundUp); |
185 if (zoomLevel != m_zoomLevel) { | 185 if (zoomLevel != m_zoomLevel) { |
186 m_zoomLevel = zoomLevel; | 186 m_zoomLevel = zoomLevel; |
187 emit zoomLevelChanged(m_zoomLevel, m_followZoom); | 187 emit zoomLevelChanged(m_zoomLevel, m_followZoom); |
188 } | 188 } |
189 | 189 |
190 sv_frame_t centreFrame = startFrame + m_zoomLevel * (width() / 2); | 190 sv_frame_t centreFrame = startFrame + m_zoomLevel * (width() / 2); |
191 if (centreFrame > (startFrame + getModelsEndFrame())/2) { | 191 if (centreFrame > (startFrame + getModelsEndFrame())/2) { |
192 centreFrame = (startFrame + getModelsEndFrame())/2; | 192 centreFrame = (startFrame + getModelsEndFrame())/2; |
193 } | 193 } |
194 if (centreFrame != m_centreFrame) { | 194 if (centreFrame != m_centreFrame) { |
195 #ifdef DEBUG_OVERVIEW | 195 #ifdef DEBUG_OVERVIEW |
196 cerr << "Overview::paintEvent: Centre frame changed from " | 196 cerr << "Overview::paintEvent: Centre frame changed from " |
197 << m_centreFrame << " to " << centreFrame << " and thus start frame from " << getStartFrame(); | 197 << m_centreFrame << " to " << centreFrame << " and thus start frame from " << getStartFrame(); |
198 #endif | 198 #endif |
199 m_centreFrame = centreFrame; | 199 m_centreFrame = centreFrame; |
200 #ifdef DEBUG_OVERVIEW | 200 #ifdef DEBUG_OVERVIEW |
201 cerr << " to " << getStartFrame() << endl; | 201 cerr << " to " << getStartFrame() << endl; |
202 #endif | 202 #endif |
203 emit centreFrameChanged(m_centreFrame, false, PlaybackIgnore); | 203 emit centreFrameChanged(m_centreFrame, false, PlaybackIgnore); |
204 } | 204 } |
205 | 205 |
206 View::paintEvent(e); | 206 View::paintEvent(e); |
207 | 207 |
208 QPainter paint; | 208 QPainter paint; |
209 paint.begin(this); | 209 paint.begin(this); |
210 paint.setClipRegion(e->region()); | 210 paint.setClipRegion(e->region()); |
211 paint.setRenderHints(QPainter::Antialiasing); | 211 paint.setRenderHints(QPainter::Antialiasing); |
212 | 212 |
213 QRect r(rect()); | |
214 | |
215 // We paint a rounded rect for each distinct set of view extents, | 213 // We paint a rounded rect for each distinct set of view extents, |
216 // and we colour in the inside and outside of the rect that | 214 // and we colour in the inside and outside of the rect that |
217 // corresponds to the current view. (One small caveat -- we don't | 215 // corresponds to the current view. (One small caveat -- we don't |
218 // know which rect that is yet. We'll have to figure it out | 216 // know which rect that is yet. We'll have to figure it out |
219 // somehow...) | 217 // somehow...) |
223 QRect primary; | 221 QRect primary; |
224 | 222 |
225 int y = 0; | 223 int y = 0; |
226 | 224 |
227 for (ViewSet::iterator i = m_views.begin(); i != m_views.end(); ++i) { | 225 for (ViewSet::iterator i = m_views.begin(); i != m_views.end(); ++i) { |
228 if (!*i) continue; | 226 if (!*i) continue; |
229 | 227 |
230 View *w = (View *)*i; | 228 View *w = (View *)*i; |
231 | 229 |
232 sv_frame_t f0 = w->getFrameForX(0); | 230 sv_frame_t f0 = w->getFrameForX(0); |
233 sv_frame_t f1 = w->getFrameForX(w->width()); | 231 sv_frame_t f1 = w->getFrameForX(w->width()); |
234 | 232 |
235 if (f0 >= 0) { | 233 if (f0 >= 0) { |
236 sv_frame_t rf0 = w->alignToReference(f0); | 234 sv_frame_t rf0 = w->alignToReference(f0); |
237 f0 = alignFromReference(rf0); | 235 f0 = alignFromReference(rf0); |
238 } | 236 } |
239 if (f1 >= 0) { | 237 if (f1 >= 0) { |
240 sv_frame_t rf1 = w->alignToReference(f1); | 238 sv_frame_t rf1 = w->alignToReference(f1); |
241 f1 = alignFromReference(rf1); | 239 f1 = alignFromReference(rf1); |
242 } | 240 } |
243 | 241 |
244 int x0 = getXForFrame(f0); | 242 int x0 = getXForFrame(f0); |
245 int x1 = getXForFrame(f1); | 243 int x1 = getXForFrame(f1); |
246 | 244 |
247 | 245 if (x1 <= x0) x1 = x0 + 1; |
248 if (x1 <= x0) x1 = x0 + 1; | |
249 | 246 |
250 std::pair<int, int> extent(x0, x1); | 247 std::pair<int, int> extent(x0, x1); |
251 | 248 |
252 if (extents.find(extent) == extents.end()) { | 249 if (extents.find(extent) == extents.end()) { |
253 | 250 |
254 y += height() / 10 + 1; | 251 y += height() / 10 + 1; |
255 extents.insert(extent); | 252 extents.insert(extent); |
256 | 253 |
257 QRect vr(x0, y, x1 - x0, height() - 2 * y); | 254 QRect vr(x0, y, x1 - x0, height() - 2 * y); |
258 rects.push_back(vr); | 255 rects.push_back(vr); |
259 primary = vr; //!!! for now | 256 primary = vr; //!!! for now |
287 if (clickFrame > 0) m_dragCentreFrame = clickFrame; | 284 if (clickFrame > 0) m_dragCentreFrame = clickFrame; |
288 else m_dragCentreFrame = 0; | 285 else m_dragCentreFrame = 0; |
289 m_clickedInRange = true; | 286 m_clickedInRange = true; |
290 | 287 |
291 for (ViewSet::iterator i = m_views.begin(); i != m_views.end(); ++i) { | 288 for (ViewSet::iterator i = m_views.begin(); i != m_views.end(); ++i) { |
292 if (*i && (*i)->getAligningModel() == getAligningModel()) { | 289 if (*i && (*i)->getAligningModel() == getAligningModel()) { |
293 m_dragCentreFrame = (*i)->getCentreFrame(); | 290 m_dragCentreFrame = (*i)->getCentreFrame(); |
294 break; | 291 break; |
295 } | 292 } |
296 } | 293 } |
297 } | 294 } |
298 | 295 |
299 void | 296 void |
300 Overview::mouseReleaseEvent(QMouseEvent *e) | 297 Overview::mouseReleaseEvent(QMouseEvent *e) |
301 { | 298 { |
302 if (m_clickedInRange) { | 299 if (m_clickedInRange) { |
303 mouseMoveEvent(e); | 300 mouseMoveEvent(e); |
304 } | 301 } |
305 m_clickedInRange = false; | 302 m_clickedInRange = false; |
306 } | 303 } |
307 | 304 |
308 void | 305 void |
313 int xoff = int(e->x()) - int(m_clickPos.x()); | 310 int xoff = int(e->x()) - int(m_clickPos.x()); |
314 sv_frame_t frameOff = xoff * m_zoomLevel; | 311 sv_frame_t frameOff = xoff * m_zoomLevel; |
315 | 312 |
316 sv_frame_t newCentreFrame = m_dragCentreFrame; | 313 sv_frame_t newCentreFrame = m_dragCentreFrame; |
317 if (frameOff > 0) { | 314 if (frameOff > 0) { |
318 newCentreFrame += frameOff; | 315 newCentreFrame += frameOff; |
319 } else if (newCentreFrame >= -frameOff) { | 316 } else if (newCentreFrame >= -frameOff) { |
320 newCentreFrame += frameOff; | 317 newCentreFrame += frameOff; |
321 } else { | 318 } else { |
322 newCentreFrame = 0; | 319 newCentreFrame = 0; |
323 } | 320 } |
324 | 321 |
325 if (newCentreFrame >= getModelsEndFrame()) { | 322 if (newCentreFrame >= getModelsEndFrame()) { |
326 newCentreFrame = getModelsEndFrame(); | 323 newCentreFrame = getModelsEndFrame(); |
327 if (newCentreFrame > 0) --newCentreFrame; | 324 if (newCentreFrame > 0) --newCentreFrame; |
328 } | 325 } |
329 | 326 |
330 if (std::max(m_centreFrame, newCentreFrame) - | 327 if (std::max(m_centreFrame, newCentreFrame) - |
331 std::min(m_centreFrame, newCentreFrame) > m_zoomLevel) { | 328 std::min(m_centreFrame, newCentreFrame) > m_zoomLevel) { |
332 sv_frame_t rf = alignToReference(newCentreFrame); | 329 sv_frame_t rf = alignToReference(newCentreFrame); |
333 #ifdef DEBUG_OVERVIEW | 330 #ifdef DEBUG_OVERVIEW |
334 cerr << "Overview::mouseMoveEvent: x " << e->x() << " and click x " << m_clickPos.x() << " -> frame " << newCentreFrame << " -> rf " << rf << endl; | 331 cerr << "Overview::mouseMoveEvent: x " << e->x() << " and click x " << m_clickPos.x() << " -> frame " << newCentreFrame << " -> rf " << rf << endl; |
335 #endif | 332 #endif |
336 if (m_followPlay == PlaybackScrollContinuous || | 333 if (m_followPlay == PlaybackScrollContinuous || |