Mercurial > hg > svgui
diff layer/TextLayer.cpp @ 552:2e8194a30f40 sv-v1.7.1
* Layer data editor window: fix sorting for columns in region model,
add Find feature
* RDF import: assign names to layers based on event types, if no suitable
labels are found in the RDF
* Add label to status bar showing the last text that was passed in current
layer (so e.g. counting 1, 2, 3, 4 if that's what beats are labelled)
* Better layout of text labels for region layers in segmentation mode when
they are close together
* Give text layer the same method for finding "nearest point" as region and
note layers, should improve its editability
author | Chris Cannam |
---|---|
date | Thu, 22 Oct 2009 15:54:21 +0000 |
parents | e1a9e478b7f2 |
children | 781feeb4d59f |
line wrap: on
line diff
--- a/layer/TextLayer.cpp Fri Oct 02 13:56:10 2009 +0000 +++ b/layer/TextLayer.cpp Thu Oct 22 15:54:21 2009 +0000 @@ -120,7 +120,7 @@ TextModel::PointList points(m_model->getPoints(frame0, frame1)); TextModel::PointList rv; - QFontMetrics metrics = QPainter().fontMetrics(); + QFontMetrics metrics = QFontMetrics(QFont()); for (TextModel::PointList::iterator i = points.begin(); i != points.end(); ++i) { @@ -153,6 +153,34 @@ return rv; } +bool +TextLayer::getPointToDrag(View *v, int x, int y, TextModel::Point &p) const +{ + if (!m_model) return false; + + long a = v->getFrameForX(x - 120); + long b = v->getFrameForX(x + 10); + TextModel::PointList onPoints = m_model->getPoints(a, b); + if (onPoints.empty()) return false; + + float nearestDistance = -1; + + for (TextModel::PointList::const_iterator i = onPoints.begin(); + i != onPoints.end(); ++i) { + + int yd = getYForHeight(v, (*i).height) - y; + int xd = v->getXForFrame((*i).frame) - x; + float distance = sqrt(yd*yd + xd*xd); + + if (nearestDistance == -1 || distance < nearestDistance) { + nearestDistance = distance; + p = *i; + } + } + + return true; +} + QString TextLayer::getFeatureDescription(View *v, QPoint &pos) const { @@ -307,12 +335,12 @@ // << m_model->getResolution() << " frames" << std::endl; QPoint localPos; - long illuminateFrame = -1; + TextModel::Point illuminatePoint(0); + bool shouldIlluminate; if (v->shouldIlluminateLocalFeatures(this, localPos)) { - TextModel::PointList localPoints = getLocalPoints(v, localPos.x(), - localPos.y()); - if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame; + shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(), + illuminatePoint); } int boxMaxWidth = 150; @@ -329,12 +357,15 @@ int x = v->getXForFrame(p.frame); int y = getYForHeight(v, p.height); - if (illuminateFrame == p.frame) { + if (!shouldIlluminate || + // "illuminatePoint != p" + TextModel::Point::Comparator()(illuminatePoint, p) || + TextModel::Point::Comparator()(p, illuminatePoint)) { + paint.setPen(penColour); + paint.setBrush(brushColour); + } else { paint.setBrush(penColour); paint.setPen(v->getBackground()); - } else { - paint.setPen(penColour); - paint.setBrush(brushColour); } QString label = p.label; @@ -453,10 +484,7 @@ { if (!m_model) return; - TextModel::PointList points = getLocalPoints(v, e->x(), e->y()); - if (points.empty()) return; - - m_editingPoint = *points.begin(); + if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; if (m_editingCommand) { finish(m_editingCommand); @@ -478,10 +506,9 @@ m_editing = false; - TextModel::PointList points = getLocalPoints(v, e->x(), e->y()); - if (points.empty()) return; - if (points.begin()->frame != m_editingPoint.frame || - points.begin()->height != m_editingPoint.height) return; + TextModel::Point p(0); + if (!getPointToDrag(v, e->x(), e->y(), p)) return; + if (p.frame != m_editingPoint.frame || p.height != m_editingPoint.height) return; m_editingCommand = new TextModel::EditCommand (m_model, tr("Erase Point")); @@ -500,11 +527,11 @@ if (!m_model) return; - TextModel::PointList points = getLocalPoints(v, e->x(), e->y()); - if (points.empty()) return; + if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) { + return; + } m_editOrigin = e->pos(); - m_editingPoint = *points.begin(); m_originalPoint = m_editingPoint; if (m_editingCommand) { @@ -575,18 +602,18 @@ { if (!m_model) return false; - TextModel::PointList points = getLocalPoints(v, e->x(), e->y()); - if (points.empty()) return false; + TextModel::Point text(0); + if (!getPointToDrag(v, e->x(), e->y(), text)) return false; - QString label = points.begin()->label; + QString label = text.label; bool ok = false; label = QInputDialog::getText(v, tr("Enter label"), tr("Please enter a new label:"), QLineEdit::Normal, label, &ok); - if (ok && label != points.begin()->label) { + if (ok && label != text.label) { TextModel::RelabelCommand *command = - new TextModel::RelabelCommand(m_model, *points.begin(), label); + new TextModel::RelabelCommand(m_model, text, label); CommandHistory::getInstance()->addCommand(command); }