Mercurial > hg > svgui
comparison 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 |
comparison
equal
deleted
inserted
replaced
551:c2ba2796cbee | 552:2e8194a30f40 |
---|---|
118 long frame1 = v->getFrameForX(v->width() + 150); | 118 long frame1 = v->getFrameForX(v->width() + 150); |
119 | 119 |
120 TextModel::PointList points(m_model->getPoints(frame0, frame1)); | 120 TextModel::PointList points(m_model->getPoints(frame0, frame1)); |
121 | 121 |
122 TextModel::PointList rv; | 122 TextModel::PointList rv; |
123 QFontMetrics metrics = QPainter().fontMetrics(); | 123 QFontMetrics metrics = QFontMetrics(QFont()); |
124 | 124 |
125 for (TextModel::PointList::iterator i = points.begin(); | 125 for (TextModel::PointList::iterator i = points.begin(); |
126 i != points.end(); ++i) { | 126 i != points.end(); ++i) { |
127 | 127 |
128 const TextModel::Point &p(*i); | 128 const TextModel::Point &p(*i); |
149 rv.insert(p); | 149 rv.insert(p); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 return rv; | 153 return rv; |
154 } | |
155 | |
156 bool | |
157 TextLayer::getPointToDrag(View *v, int x, int y, TextModel::Point &p) const | |
158 { | |
159 if (!m_model) return false; | |
160 | |
161 long a = v->getFrameForX(x - 120); | |
162 long b = v->getFrameForX(x + 10); | |
163 TextModel::PointList onPoints = m_model->getPoints(a, b); | |
164 if (onPoints.empty()) return false; | |
165 | |
166 float nearestDistance = -1; | |
167 | |
168 for (TextModel::PointList::const_iterator i = onPoints.begin(); | |
169 i != onPoints.end(); ++i) { | |
170 | |
171 int yd = getYForHeight(v, (*i).height) - y; | |
172 int xd = v->getXForFrame((*i).frame) - x; | |
173 float distance = sqrt(yd*yd + xd*xd); | |
174 | |
175 if (nearestDistance == -1 || distance < nearestDistance) { | |
176 nearestDistance = distance; | |
177 p = *i; | |
178 } | |
179 } | |
180 | |
181 return true; | |
154 } | 182 } |
155 | 183 |
156 QString | 184 QString |
157 TextLayer::getFeatureDescription(View *v, QPoint &pos) const | 185 TextLayer::getFeatureDescription(View *v, QPoint &pos) const |
158 { | 186 { |
305 | 333 |
306 // std::cerr << "TextLayer::paint: resolution is " | 334 // std::cerr << "TextLayer::paint: resolution is " |
307 // << m_model->getResolution() << " frames" << std::endl; | 335 // << m_model->getResolution() << " frames" << std::endl; |
308 | 336 |
309 QPoint localPos; | 337 QPoint localPos; |
310 long illuminateFrame = -1; | 338 TextModel::Point illuminatePoint(0); |
339 bool shouldIlluminate; | |
311 | 340 |
312 if (v->shouldIlluminateLocalFeatures(this, localPos)) { | 341 if (v->shouldIlluminateLocalFeatures(this, localPos)) { |
313 TextModel::PointList localPoints = getLocalPoints(v, localPos.x(), | 342 shouldIlluminate = getPointToDrag(v, localPos.x(), localPos.y(), |
314 localPos.y()); | 343 illuminatePoint); |
315 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame; | |
316 } | 344 } |
317 | 345 |
318 int boxMaxWidth = 150; | 346 int boxMaxWidth = 150; |
319 int boxMaxHeight = 200; | 347 int boxMaxHeight = 200; |
320 | 348 |
327 const TextModel::Point &p(*i); | 355 const TextModel::Point &p(*i); |
328 | 356 |
329 int x = v->getXForFrame(p.frame); | 357 int x = v->getXForFrame(p.frame); |
330 int y = getYForHeight(v, p.height); | 358 int y = getYForHeight(v, p.height); |
331 | 359 |
332 if (illuminateFrame == p.frame) { | 360 if (!shouldIlluminate || |
361 // "illuminatePoint != p" | |
362 TextModel::Point::Comparator()(illuminatePoint, p) || | |
363 TextModel::Point::Comparator()(p, illuminatePoint)) { | |
364 paint.setPen(penColour); | |
365 paint.setBrush(brushColour); | |
366 } else { | |
333 paint.setBrush(penColour); | 367 paint.setBrush(penColour); |
334 paint.setPen(v->getBackground()); | 368 paint.setPen(v->getBackground()); |
335 } else { | |
336 paint.setPen(penColour); | |
337 paint.setBrush(brushColour); | |
338 } | 369 } |
339 | 370 |
340 QString label = p.label; | 371 QString label = p.label; |
341 if (label == "") { | 372 if (label == "") { |
342 label = tr("<no text>"); | 373 label = tr("<no text>"); |
451 void | 482 void |
452 TextLayer::eraseStart(View *v, QMouseEvent *e) | 483 TextLayer::eraseStart(View *v, QMouseEvent *e) |
453 { | 484 { |
454 if (!m_model) return; | 485 if (!m_model) return; |
455 | 486 |
456 TextModel::PointList points = getLocalPoints(v, e->x(), e->y()); | 487 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; |
457 if (points.empty()) return; | |
458 | |
459 m_editingPoint = *points.begin(); | |
460 | 488 |
461 if (m_editingCommand) { | 489 if (m_editingCommand) { |
462 finish(m_editingCommand); | 490 finish(m_editingCommand); |
463 m_editingCommand = 0; | 491 m_editingCommand = 0; |
464 } | 492 } |
476 { | 504 { |
477 if (!m_model || !m_editing) return; | 505 if (!m_model || !m_editing) return; |
478 | 506 |
479 m_editing = false; | 507 m_editing = false; |
480 | 508 |
481 TextModel::PointList points = getLocalPoints(v, e->x(), e->y()); | 509 TextModel::Point p(0); |
482 if (points.empty()) return; | 510 if (!getPointToDrag(v, e->x(), e->y(), p)) return; |
483 if (points.begin()->frame != m_editingPoint.frame || | 511 if (p.frame != m_editingPoint.frame || p.height != m_editingPoint.height) return; |
484 points.begin()->height != m_editingPoint.height) return; | |
485 | 512 |
486 m_editingCommand = new TextModel::EditCommand | 513 m_editingCommand = new TextModel::EditCommand |
487 (m_model, tr("Erase Point")); | 514 (m_model, tr("Erase Point")); |
488 | 515 |
489 m_editingCommand->deletePoint(m_editingPoint); | 516 m_editingCommand->deletePoint(m_editingPoint); |
498 { | 525 { |
499 // std::cerr << "TextLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; | 526 // std::cerr << "TextLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; |
500 | 527 |
501 if (!m_model) return; | 528 if (!m_model) return; |
502 | 529 |
503 TextModel::PointList points = getLocalPoints(v, e->x(), e->y()); | 530 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) { |
504 if (points.empty()) return; | 531 return; |
532 } | |
505 | 533 |
506 m_editOrigin = e->pos(); | 534 m_editOrigin = e->pos(); |
507 m_editingPoint = *points.begin(); | |
508 m_originalPoint = m_editingPoint; | 535 m_originalPoint = m_editingPoint; |
509 | 536 |
510 if (m_editingCommand) { | 537 if (m_editingCommand) { |
511 finish(m_editingCommand); | 538 finish(m_editingCommand); |
512 m_editingCommand = 0; | 539 m_editingCommand = 0; |
573 bool | 600 bool |
574 TextLayer::editOpen(View *v, QMouseEvent *e) | 601 TextLayer::editOpen(View *v, QMouseEvent *e) |
575 { | 602 { |
576 if (!m_model) return false; | 603 if (!m_model) return false; |
577 | 604 |
578 TextModel::PointList points = getLocalPoints(v, e->x(), e->y()); | 605 TextModel::Point text(0); |
579 if (points.empty()) return false; | 606 if (!getPointToDrag(v, e->x(), e->y(), text)) return false; |
580 | 607 |
581 QString label = points.begin()->label; | 608 QString label = text.label; |
582 | 609 |
583 bool ok = false; | 610 bool ok = false; |
584 label = QInputDialog::getText(v, tr("Enter label"), | 611 label = QInputDialog::getText(v, tr("Enter label"), |
585 tr("Please enter a new label:"), | 612 tr("Please enter a new label:"), |
586 QLineEdit::Normal, label, &ok); | 613 QLineEdit::Normal, label, &ok); |
587 if (ok && label != points.begin()->label) { | 614 if (ok && label != text.label) { |
588 TextModel::RelabelCommand *command = | 615 TextModel::RelabelCommand *command = |
589 new TextModel::RelabelCommand(m_model, *points.begin(), label); | 616 new TextModel::RelabelCommand(m_model, text, label); |
590 CommandHistory::getInstance()->addCommand(command); | 617 CommandHistory::getInstance()->addCommand(command); |
591 } | 618 } |
592 | 619 |
593 return true; | 620 return true; |
594 } | 621 } |