comparison layer/Layer.cpp @ 272:87e4c880b4c8

* highlight the nearest measurement rect * fix rewind during playback
author Chris Cannam
date Fri, 29 Jun 2007 13:58:08 +0000
parents 61a704654497
children e954c00cbe55
comparison
equal deleted inserted replaced
271:1a49bd0d8375 272:87e4c880b4c8
23 #include <QMutexLocker> 23 #include <QMutexLocker>
24 #include <QMouseEvent> 24 #include <QMouseEvent>
25 25
26 #include "LayerFactory.h" 26 #include "LayerFactory.h"
27 #include "base/PlayParameterRepository.h" 27 #include "base/PlayParameterRepository.h"
28
29 #include <cmath>
28 30
29 Layer::Layer() : 31 Layer::Layer() :
30 m_haveDraggingRect(false) 32 m_haveDraggingRect(false)
31 { 33 {
32 } 34 }
252 254
253 m_haveDraggingRect = false; 255 m_haveDraggingRect = false;
254 } 256 }
255 257
256 void 258 void
257 Layer::paintMeasurementRects(View *v, QPainter &paint) const 259 Layer::paintMeasurementRects(View *v, QPainter &paint,
258 { 260 bool showFocus, QPoint focusPoint) const
261 {
262 updateMeasurementPixrects(v);
263
264 MeasureRectSet::const_iterator focusRectItr = m_measureRects.end();
265
259 if (m_haveDraggingRect) { 266 if (m_haveDraggingRect) {
267
260 paintMeasurementRect(v, paint, m_draggingRect, true); 268 paintMeasurementRect(v, paint, m_draggingRect, true);
269
270 } else if (showFocus) {
271
272 focusRectItr = findFocusedMeasureRect(focusPoint);
261 } 273 }
262 274
263 for (MeasureRectSet::const_iterator i = m_measureRects.begin(); 275 for (MeasureRectSet::const_iterator i = m_measureRects.begin();
264 i != m_measureRects.end(); ++i) { 276 i != m_measureRects.end(); ++i) {
265 paintMeasurementRect(v, paint, *i, true); 277 paintMeasurementRect(v, paint, *i, i == focusRectItr);
266 } 278 }
279 }
280
281 bool
282 Layer::nearestMeasurementRectChanged(View *v, QPoint prev, QPoint now) const
283 {
284 updateMeasurementPixrects(v);
285
286 MeasureRectSet::const_iterator i0 = findFocusedMeasureRect(prev);
287 MeasureRectSet::const_iterator i1 = findFocusedMeasureRect(now);
288
289 return (i0 != i1);
290 }
291
292 void
293 Layer::updateMeasurementPixrects(View *v) const
294 {
295 long sf = v->getStartFrame();
296 long ef = v->getEndFrame();
297
298 for (MeasureRectSet::const_iterator i = m_measureRects.begin();
299 i != m_measureRects.end(); ++i) {
300
301 if (!i->haveFrames) continue;
302
303 if (i->startFrame >= ef) break;
304 if (i->endFrame <= sf) continue;
305
306 int x0 = -1;
307 int x1 = v->width() + 1;
308
309 if (i->startFrame >= v->getStartFrame()) {
310 x0 = v->getXForFrame(i->startFrame);
311 }
312 if (i->endFrame <= long(v->getEndFrame())) {
313 x1 = v->getXForFrame(i->endFrame);
314 }
315
316 QRect pr = QRect(x0, i->pixrect.y(), x1 - x0, i->pixrect.height());
317
318 i->pixrect = pr;
319 }
320 }
321
322 Layer::MeasureRectSet::const_iterator
323 Layer::findFocusedMeasureRect(QPoint focusPoint) const
324 {
325 float frDist = 0;
326 MeasureRectSet::const_iterator focusRectItr = m_measureRects.end();
327
328 for (MeasureRectSet::const_iterator i = m_measureRects.begin();
329 i != m_measureRects.end(); ++i) {
330
331 if (!i->pixrect.adjusted(-2, -2, 2, 2).contains(focusPoint)) continue;
332
333 int cx = i->pixrect.x() + i->pixrect.width()/2;
334 int cy = i->pixrect.y() + i->pixrect.height()/2;
335 int xd = focusPoint.x() - cx;
336 int yd = focusPoint.y() - cy;
337
338 float d = sqrt(xd * xd + yd * yd);
339
340 if (focusRectItr == m_measureRects.end() || d < frDist) {
341 focusRectItr = i;
342 frDist = d;
343 }
344 }
345
346 return focusRectItr;
267 } 347 }
268 348
269 void 349 void
270 Layer::paintMeasurementRect(View *v, QPainter &paint, 350 Layer::paintMeasurementRect(View *v, QPainter &paint,
271 const MeasureRect &r, bool focus) const 351 const MeasureRect &r, bool focus) const
276 int x1 = v->width() + 1; 356 int x1 = v->width() + 1;
277 357
278 if (r.startFrame >= v->getStartFrame()) { 358 if (r.startFrame >= v->getStartFrame()) {
279 x0 = v->getXForFrame(r.startFrame); 359 x0 = v->getXForFrame(r.startFrame);
280 } 360 }
281 if (r.endFrame <= v->getEndFrame()) { 361 if (r.endFrame <= long(v->getEndFrame())) {
282 x1 = v->getXForFrame(r.endFrame); 362 x1 = v->getXForFrame(r.endFrame);
283 } 363 }
284 364
285 QRect pr = QRect(x0, r.pixrect.y(), 365 QRect pr = QRect(x0, r.pixrect.y(), x1 - x0, r.pixrect.height());
286 x1 - x0, r.pixrect.height());
287 366
288 r.pixrect = pr; 367 r.pixrect = pr;
289 } 368 }
290 369
291 v->drawMeasurementRect(paint, this, r.pixrect, focus); 370 v->drawMeasurementRect(paint, this, r.pixrect, focus);