# HG changeset patch # User Chris Cannam # Date 1183125488 0 # Node ID 87e4c880b4c8791b70116186618737d560eb73e4 # Parent 1a49bd0d83754d36f0846f364f52241cc3f536f6 * highlight the nearest measurement rect * fix rewind during playback diff -r 1a49bd0d8375 -r 87e4c880b4c8 layer/Layer.cpp --- a/layer/Layer.cpp Thu Jun 28 14:50:58 2007 +0000 +++ b/layer/Layer.cpp Fri Jun 29 13:58:08 2007 +0000 @@ -26,6 +26,8 @@ #include "LayerFactory.h" #include "base/PlayParameterRepository.h" +#include + Layer::Layer() : m_haveDraggingRect(false) { @@ -254,18 +256,96 @@ } void -Layer::paintMeasurementRects(View *v, QPainter &paint) const +Layer::paintMeasurementRects(View *v, QPainter &paint, + bool showFocus, QPoint focusPoint) const { + updateMeasurementPixrects(v); + + MeasureRectSet::const_iterator focusRectItr = m_measureRects.end(); + if (m_haveDraggingRect) { + paintMeasurementRect(v, paint, m_draggingRect, true); + + } else if (showFocus) { + + focusRectItr = findFocusedMeasureRect(focusPoint); } for (MeasureRectSet::const_iterator i = m_measureRects.begin(); i != m_measureRects.end(); ++i) { - paintMeasurementRect(v, paint, *i, true); + paintMeasurementRect(v, paint, *i, i == focusRectItr); } } +bool +Layer::nearestMeasurementRectChanged(View *v, QPoint prev, QPoint now) const +{ + updateMeasurementPixrects(v); + + MeasureRectSet::const_iterator i0 = findFocusedMeasureRect(prev); + MeasureRectSet::const_iterator i1 = findFocusedMeasureRect(now); + + return (i0 != i1); +} + +void +Layer::updateMeasurementPixrects(View *v) const +{ + long sf = v->getStartFrame(); + long ef = v->getEndFrame(); + + for (MeasureRectSet::const_iterator i = m_measureRects.begin(); + i != m_measureRects.end(); ++i) { + + if (!i->haveFrames) continue; + + if (i->startFrame >= ef) break; + if (i->endFrame <= sf) continue; + + int x0 = -1; + int x1 = v->width() + 1; + + if (i->startFrame >= v->getStartFrame()) { + x0 = v->getXForFrame(i->startFrame); + } + if (i->endFrame <= long(v->getEndFrame())) { + x1 = v->getXForFrame(i->endFrame); + } + + QRect pr = QRect(x0, i->pixrect.y(), x1 - x0, i->pixrect.height()); + + i->pixrect = pr; + } +} + +Layer::MeasureRectSet::const_iterator +Layer::findFocusedMeasureRect(QPoint focusPoint) const +{ + float frDist = 0; + MeasureRectSet::const_iterator focusRectItr = m_measureRects.end(); + + for (MeasureRectSet::const_iterator i = m_measureRects.begin(); + i != m_measureRects.end(); ++i) { + + if (!i->pixrect.adjusted(-2, -2, 2, 2).contains(focusPoint)) continue; + + int cx = i->pixrect.x() + i->pixrect.width()/2; + int cy = i->pixrect.y() + i->pixrect.height()/2; + int xd = focusPoint.x() - cx; + int yd = focusPoint.y() - cy; + + float d = sqrt(xd * xd + yd * yd); + + if (focusRectItr == m_measureRects.end() || d < frDist) { + focusRectItr = i; + frDist = d; + } + } + + return focusRectItr; +} + void Layer::paintMeasurementRect(View *v, QPainter &paint, const MeasureRect &r, bool focus) const @@ -278,12 +358,11 @@ if (r.startFrame >= v->getStartFrame()) { x0 = v->getXForFrame(r.startFrame); } - if (r.endFrame <= v->getEndFrame()) { + if (r.endFrame <= long(v->getEndFrame())) { x1 = v->getXForFrame(r.endFrame); } - QRect pr = QRect(x0, r.pixrect.y(), - x1 - x0, r.pixrect.height()); + QRect pr = QRect(x0, r.pixrect.y(), x1 - x0, r.pixrect.height()); r.pixrect = pr; } diff -r 1a49bd0d8375 -r 87e4c880b4c8 layer/Layer.h --- a/layer/Layer.h Thu Jun 28 14:50:58 2007 +0000 +++ b/layer/Layer.h Fri Jun 29 13:58:08 2007 +0000 @@ -106,7 +106,11 @@ } virtual void paintCrosshairs(View *, QPainter &, QPoint) const { } - virtual void paintMeasurementRects(View *, QPainter &) const; + virtual void paintMeasurementRects(View *, QPainter &, + bool showFocus, QPoint focusPoint) const; + + virtual bool nearestMeasurementRectChanged(View *, QPoint prev, + QPoint now) const; virtual QString getFeatureDescription(View *, QPoint &) const { return ""; @@ -459,6 +463,14 @@ MeasureRectSet m_measureRects; MeasureRect m_draggingRect; bool m_haveDraggingRect; + + // Note that pixrects are only correct for a single view. + // So we should update them at the start of the paint procedure + // (painting is single threaded) and only use them after that. + void updateMeasurementPixrects(View *v) const; + + // This assumes updateMeasurementPixrects has been called + MeasureRectSet::const_iterator findFocusedMeasureRect(QPoint) const; void paintMeasurementRect(View *v, QPainter &paint, const MeasureRect &r, bool focus) const; diff -r 1a49bd0d8375 -r 87e4c880b4c8 layer/TimeRulerLayer.cpp --- a/layer/TimeRulerLayer.cpp Thu Jun 28 14:50:58 2007 +0000 +++ b/layer/TimeRulerLayer.cpp Fri Jun 29 13:58:08 2007 +0000 @@ -151,13 +151,17 @@ RealTime rt = RealTime::frame2RealTime(frame, rate); double ratio = rt / rtick; - int rounded = lrint(ratio); + int rounded = int(ratio); RealTime rdrt = rtick * rounded; int left = RealTime::realTime2Frame(rdrt, rate); resolution = RealTime::realTime2Frame(rtick, rate); int right = left + resolution; +// std::cerr << "TimeRulerLayer::snapToFeatureFrame: type " +// << int(snap) << ", frame " << frame << " (time " +// << rt << ", tick " << rtick << ", rounded " << rdrt << ") "; + switch (snap) { case SnapLeft: @@ -217,6 +221,8 @@ } } +// std::cerr << " -> " << frame << " (resolution = " << resolution << ")" << std::endl; + return true; } diff -r 1a49bd0d8375 -r 87e4c880b4c8 view/Pane.cpp --- a/view/Pane.cpp Thu Jun 28 14:50:58 2007 +0000 +++ b/view/Pane.cpp Fri Jun 29 13:58:08 2007 +0000 @@ -454,7 +454,9 @@ } if (toolMode == ViewManager::MeasureMode && topLayer) { - topLayer->paintMeasurementRects(this, paint); + bool showFocus = false; + if (!m_manager || !m_manager->isPlaying()) showFocus = true; + topLayer->paintMeasurementRects(this, paint, showFocus, m_identifyPoint); } if (selectionIsBeingEdited()) { @@ -1213,6 +1215,8 @@ if (!m_manager->isPlaying()) { + bool updating = false; + if (getSelectedLayer()) { bool previouslyIdentifying = m_identifyFeatures; @@ -1221,6 +1225,17 @@ if (m_identifyFeatures != previouslyIdentifying || m_identifyPoint != prevPoint) { update(); + updating = true; + } + } + + if (!updating && mode == ViewManager::MeasureMode && + m_manager && !m_manager->isPlaying()) { + + Layer *layer = getTopLayer(); + if (layer && layer->nearestMeasurementRectChanged + (this, prevPoint, m_identifyPoint)) { + update(); } } } diff -r 1a49bd0d8375 -r 87e4c880b4c8 view/View.cpp --- a/view/View.cpp Thu Jun 28 14:50:58 2007 +0000 +++ b/view/View.cpp Fri Jun 29 13:58:08 2007 +0000 @@ -1650,8 +1650,8 @@ paint.save(); if (focus) { paint.setPen(Qt::NoPen); - QColor brushColour(Qt::green); - brushColour.setAlpha(30); + QColor brushColour(Qt::black); + brushColour.setAlpha(hasLightBackground() ? 15 : 40); paint.setBrush(brushColour); if (r.x() > 0) { paint.drawRect(0, 0, r.x(), height());