Mercurial > hg > svgui
comparison layer/TextLayer.cpp @ 997:296ccd36f626 tony-2.0-integration
Merge through to branch for Tony 2.0
author | Chris Cannam |
---|---|
date | Thu, 20 Aug 2015 14:54:21 +0100 |
parents | 4fe7a09be0fe |
children | c02c51ae5238 a34a2a25907c |
comparison
equal
deleted
inserted
replaced
943:788b7623bfca | 997:296ccd36f626 |
---|---|
100 { | 100 { |
101 return false; | 101 return false; |
102 } | 102 } |
103 | 103 |
104 bool | 104 bool |
105 TextLayer::isLayerScrollable(const View *v) const | 105 TextLayer::isLayerScrollable(const LayerGeometryProvider *v) const |
106 { | 106 { |
107 QPoint discard; | 107 QPoint discard; |
108 return !v->shouldIlluminateLocalFeatures(this, discard); | 108 return !v->shouldIlluminateLocalFeatures(this, discard); |
109 } | 109 } |
110 | 110 |
111 | 111 |
112 TextModel::PointList | 112 TextModel::PointList |
113 TextLayer::getLocalPoints(View *v, int x, int y) const | 113 TextLayer::getLocalPoints(LayerGeometryProvider *v, int x, int y) const |
114 { | 114 { |
115 if (!m_model) return TextModel::PointList(); | 115 if (!m_model) return TextModel::PointList(); |
116 | 116 |
117 sv_frame_t frame0 = v->getFrameForX(-150); | 117 sv_frame_t frame0 = v->getFrameForX(-150); |
118 sv_frame_t frame1 = v->getFrameForX(v->width() + 150); | 118 sv_frame_t frame1 = v->getFrameForX(v->getPaintWidth() + 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 = QFontMetrics(QFont()); | 123 QFontMetrics metrics = QFontMetrics(QFont()); |
137 | 137 |
138 QRect rect = metrics.boundingRect | 138 QRect rect = metrics.boundingRect |
139 (QRect(0, 0, 150, 200), | 139 (QRect(0, 0, 150, 200), |
140 Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, label); | 140 Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, label); |
141 | 141 |
142 if (py + rect.height() > v->height()) { | 142 if (py + rect.height() > v->getPaintHeight()) { |
143 if (rect.height() > v->height()) py = 0; | 143 if (rect.height() > v->getPaintHeight()) py = 0; |
144 else py = v->height() - rect.height() - 1; | 144 else py = v->getPaintHeight() - rect.height() - 1; |
145 } | 145 } |
146 | 146 |
147 if (x >= px && x < px + rect.width() && | 147 if (x >= px && x < px + rect.width() && |
148 y >= py && y < py + rect.height()) { | 148 y >= py && y < py + rect.height()) { |
149 rv.insert(p); | 149 rv.insert(p); |
152 | 152 |
153 return rv; | 153 return rv; |
154 } | 154 } |
155 | 155 |
156 bool | 156 bool |
157 TextLayer::getPointToDrag(View *v, int x, int y, TextModel::Point &p) const | 157 TextLayer::getPointToDrag(LayerGeometryProvider *v, int x, int y, TextModel::Point &p) const |
158 { | 158 { |
159 if (!m_model) return false; | 159 if (!m_model) return false; |
160 | 160 |
161 sv_frame_t a = v->getFrameForX(x - 120); | 161 sv_frame_t a = v->getFrameForX(x - 120); |
162 sv_frame_t b = v->getFrameForX(x + 10); | 162 sv_frame_t b = v->getFrameForX(x + 10); |
180 | 180 |
181 return true; | 181 return true; |
182 } | 182 } |
183 | 183 |
184 QString | 184 QString |
185 TextLayer::getFeatureDescription(View *v, QPoint &pos) const | 185 TextLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const |
186 { | 186 { |
187 int x = pos.x(); | 187 int x = pos.x(); |
188 | 188 |
189 if (!m_model || !m_model->getSampleRate()) return ""; | 189 if (!m_model || !m_model->getSampleRate()) return ""; |
190 | 190 |
218 | 218 |
219 | 219 |
220 //!!! too much overlap with TimeValueLayer/TimeInstantLayer | 220 //!!! too much overlap with TimeValueLayer/TimeInstantLayer |
221 | 221 |
222 bool | 222 bool |
223 TextLayer::snapToFeatureFrame(View *v, sv_frame_t &frame, | 223 TextLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, |
224 int &resolution, | 224 int &resolution, |
225 SnapType snap) const | 225 SnapType snap) const |
226 { | 226 { |
227 if (!m_model) { | 227 if (!m_model) { |
228 return Layer::snapToFeatureFrame(v, frame, resolution, snap); | 228 return Layer::snapToFeatureFrame(v, frame, resolution, snap); |
290 frame = snapped; | 290 frame = snapped; |
291 return found; | 291 return found; |
292 } | 292 } |
293 | 293 |
294 int | 294 int |
295 TextLayer::getYForHeight(View *v, double height) const | 295 TextLayer::getYForHeight(LayerGeometryProvider *v, double height) const |
296 { | 296 { |
297 int h = v->height(); | 297 int h = v->getPaintHeight(); |
298 return h - int(height * h); | 298 return h - int(height * h); |
299 } | 299 } |
300 | 300 |
301 double | 301 double |
302 TextLayer::getHeightForY(View *v, int y) const | 302 TextLayer::getHeightForY(LayerGeometryProvider *v, int y) const |
303 { | 303 { |
304 int h = v->height(); | 304 int h = v->getPaintHeight(); |
305 return double(h - y) / h; | 305 return double(h - y) / h; |
306 } | 306 } |
307 | 307 |
308 void | 308 void |
309 TextLayer::paint(View *v, QPainter &paint, QRect rect) const | 309 TextLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const |
310 { | 310 { |
311 if (!m_model || !m_model->isOK()) return; | 311 if (!m_model || !m_model->isOK()) return; |
312 | 312 |
313 sv_samplerate_t sampleRate = m_model->getSampleRate(); | 313 sv_samplerate_t sampleRate = m_model->getSampleRate(); |
314 if (!sampleRate) return; | 314 if (!sampleRate) return; |
345 | 345 |
346 int boxMaxWidth = 150; | 346 int boxMaxWidth = 150; |
347 int boxMaxHeight = 200; | 347 int boxMaxHeight = 200; |
348 | 348 |
349 paint.save(); | 349 paint.save(); |
350 paint.setClipRect(rect.x(), 0, rect.width() + boxMaxWidth, v->height()); | 350 paint.setClipRect(rect.x(), 0, rect.width() + boxMaxWidth, v->getPaintHeight()); |
351 | 351 |
352 for (TextModel::PointList::const_iterator i = points.begin(); | 352 for (TextModel::PointList::const_iterator i = points.begin(); |
353 i != points.end(); ++i) { | 353 i != points.end(); ++i) { |
354 | 354 |
355 const TextModel::Point &p(*i); | 355 const TextModel::Point &p(*i); |
378 Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, label); | 378 Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, label); |
379 | 379 |
380 QRect textRect = QRect(3, 2, boxRect.width(), boxRect.height()); | 380 QRect textRect = QRect(3, 2, boxRect.width(), boxRect.height()); |
381 boxRect = QRect(0, 0, boxRect.width() + 6, boxRect.height() + 2); | 381 boxRect = QRect(0, 0, boxRect.width() + 6, boxRect.height() + 2); |
382 | 382 |
383 if (y + boxRect.height() > v->height()) { | 383 if (y + boxRect.height() > v->getPaintHeight()) { |
384 if (boxRect.height() > v->height()) y = 0; | 384 if (boxRect.height() > v->getPaintHeight()) y = 0; |
385 else y = v->height() - boxRect.height() - 1; | 385 else y = v->getPaintHeight() - boxRect.height() - 1; |
386 } | 386 } |
387 | 387 |
388 boxRect = QRect(x, y, boxRect.width(), boxRect.height()); | 388 boxRect = QRect(x, y, boxRect.width(), boxRect.height()); |
389 textRect = QRect(x + 3, y + 2, textRect.width(), textRect.height()); | 389 textRect = QRect(x + 3, y + 2, textRect.width(), textRect.height()); |
390 | 390 |
409 // looks like save/restore doesn't deal with this: | 409 // looks like save/restore doesn't deal with this: |
410 paint.setRenderHint(QPainter::Antialiasing, false); | 410 paint.setRenderHint(QPainter::Antialiasing, false); |
411 } | 411 } |
412 | 412 |
413 void | 413 void |
414 TextLayer::drawStart(View *v, QMouseEvent *e) | 414 TextLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) |
415 { | 415 { |
416 // SVDEBUG << "TextLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; | 416 // SVDEBUG << "TextLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; |
417 | 417 |
418 if (!m_model) { | 418 if (!m_model) { |
419 SVDEBUG << "TextLayer::drawStart: no model" << endl; | 419 SVDEBUG << "TextLayer::drawStart: no model" << endl; |
435 | 435 |
436 m_editing = true; | 436 m_editing = true; |
437 } | 437 } |
438 | 438 |
439 void | 439 void |
440 TextLayer::drawDrag(View *v, QMouseEvent *e) | 440 TextLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e) |
441 { | 441 { |
442 // SVDEBUG << "TextLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; | 442 // SVDEBUG << "TextLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; |
443 | 443 |
444 if (!m_model || !m_editing) return; | 444 if (!m_model || !m_editing) return; |
445 | 445 |
454 m_editingPoint.height = float(height); | 454 m_editingPoint.height = float(height); |
455 m_editingCommand->addPoint(m_editingPoint); | 455 m_editingCommand->addPoint(m_editingPoint); |
456 } | 456 } |
457 | 457 |
458 void | 458 void |
459 TextLayer::drawEnd(View *v, QMouseEvent *) | 459 TextLayer::drawEnd(LayerGeometryProvider *v, QMouseEvent *) |
460 { | 460 { |
461 // SVDEBUG << "TextLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; | 461 // SVDEBUG << "TextLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; |
462 if (!m_model || !m_editing) return; | 462 if (!m_model || !m_editing) return; |
463 | 463 |
464 bool ok = false; | 464 bool ok = false; |
465 QString label = QInputDialog::getText(v, tr("Enter label"), | 465 QString label = QInputDialog::getText(v->getView(), tr("Enter label"), |
466 tr("Please enter a new label:"), | 466 tr("Please enter a new label:"), |
467 QLineEdit::Normal, "", &ok); | 467 QLineEdit::Normal, "", &ok); |
468 | 468 |
469 if (ok) { | 469 if (ok) { |
470 TextModel::RelabelCommand *command = | 470 TextModel::RelabelCommand *command = |
478 m_editingCommand = 0; | 478 m_editingCommand = 0; |
479 m_editing = false; | 479 m_editing = false; |
480 } | 480 } |
481 | 481 |
482 void | 482 void |
483 TextLayer::eraseStart(View *v, QMouseEvent *e) | 483 TextLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e) |
484 { | 484 { |
485 if (!m_model) return; | 485 if (!m_model) return; |
486 | 486 |
487 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; | 487 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; |
488 | 488 |
493 | 493 |
494 m_editing = true; | 494 m_editing = true; |
495 } | 495 } |
496 | 496 |
497 void | 497 void |
498 TextLayer::eraseDrag(View *, QMouseEvent *) | 498 TextLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *) |
499 { | 499 { |
500 } | 500 } |
501 | 501 |
502 void | 502 void |
503 TextLayer::eraseEnd(View *v, QMouseEvent *e) | 503 TextLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e) |
504 { | 504 { |
505 if (!m_model || !m_editing) return; | 505 if (!m_model || !m_editing) return; |
506 | 506 |
507 m_editing = false; | 507 m_editing = false; |
508 | 508 |
519 m_editingCommand = 0; | 519 m_editingCommand = 0; |
520 m_editing = false; | 520 m_editing = false; |
521 } | 521 } |
522 | 522 |
523 void | 523 void |
524 TextLayer::editStart(View *v, QMouseEvent *e) | 524 TextLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e) |
525 { | 525 { |
526 // SVDEBUG << "TextLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; | 526 // SVDEBUG << "TextLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; |
527 | 527 |
528 if (!m_model) return; | 528 if (!m_model) return; |
529 | 529 |
541 | 541 |
542 m_editing = true; | 542 m_editing = true; |
543 } | 543 } |
544 | 544 |
545 void | 545 void |
546 TextLayer::editDrag(View *v, QMouseEvent *e) | 546 TextLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e) |
547 { | 547 { |
548 if (!m_model || !m_editing) return; | 548 if (!m_model || !m_editing) return; |
549 | 549 |
550 sv_frame_t frameDiff = v->getFrameForX(e->x()) - v->getFrameForX(m_editOrigin.x()); | 550 sv_frame_t frameDiff = v->getFrameForX(e->x()) - v->getFrameForX(m_editOrigin.x()); |
551 double heightDiff = getHeightForY(v, e->y()) - getHeightForY(v, m_editOrigin.y()); | 551 double heightDiff = getHeightForY(v, e->y()) - getHeightForY(v, m_editOrigin.y()); |
568 m_editingPoint.height = float(height); | 568 m_editingPoint.height = float(height); |
569 m_editingCommand->addPoint(m_editingPoint); | 569 m_editingCommand->addPoint(m_editingPoint); |
570 } | 570 } |
571 | 571 |
572 void | 572 void |
573 TextLayer::editEnd(View *, QMouseEvent *) | 573 TextLayer::editEnd(LayerGeometryProvider *, QMouseEvent *) |
574 { | 574 { |
575 // SVDEBUG << "TextLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; | 575 // SVDEBUG << "TextLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; |
576 if (!m_model || !m_editing) return; | 576 if (!m_model || !m_editing) return; |
577 | 577 |
578 if (m_editingCommand) { | 578 if (m_editingCommand) { |
596 m_editingCommand = 0; | 596 m_editingCommand = 0; |
597 m_editing = false; | 597 m_editing = false; |
598 } | 598 } |
599 | 599 |
600 bool | 600 bool |
601 TextLayer::editOpen(View *v, QMouseEvent *e) | 601 TextLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) |
602 { | 602 { |
603 if (!m_model) return false; | 603 if (!m_model) return false; |
604 | 604 |
605 TextModel::Point text(0); | 605 TextModel::Point text(0); |
606 if (!getPointToDrag(v, e->x(), e->y(), text)) return false; | 606 if (!getPointToDrag(v, e->x(), e->y(), text)) return false; |
607 | 607 |
608 QString label = text.label; | 608 QString label = text.label; |
609 | 609 |
610 bool ok = false; | 610 bool ok = false; |
611 label = QInputDialog::getText(v, tr("Enter label"), | 611 label = QInputDialog::getText(v->getView(), tr("Enter label"), |
612 tr("Please enter a new label:"), | 612 tr("Please enter a new label:"), |
613 QLineEdit::Normal, label, &ok); | 613 QLineEdit::Normal, label, &ok); |
614 if (ok && label != text.label) { | 614 if (ok && label != text.label) { |
615 TextModel::RelabelCommand *command = | 615 TextModel::RelabelCommand *command = |
616 new TextModel::RelabelCommand(m_model, text, label); | 616 new TextModel::RelabelCommand(m_model, text, label); |
697 | 697 |
698 finish(command); | 698 finish(command); |
699 } | 699 } |
700 | 700 |
701 void | 701 void |
702 TextLayer::copy(View *v, Selection s, Clipboard &to) | 702 TextLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) |
703 { | 703 { |
704 if (!m_model) return; | 704 if (!m_model) return; |
705 | 705 |
706 TextModel::PointList points = | 706 TextModel::PointList points = |
707 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 707 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
715 } | 715 } |
716 } | 716 } |
717 } | 717 } |
718 | 718 |
719 bool | 719 bool |
720 TextLayer::paste(View *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */) | 720 TextLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */) |
721 { | 721 { |
722 if (!m_model) return false; | 722 if (!m_model) return false; |
723 | 723 |
724 const Clipboard::PointList &points = from.getPoints(); | 724 const Clipboard::PointList &points = from.getPoints(); |
725 | 725 |
726 bool realign = false; | 726 bool realign = false; |
727 | 727 |
728 if (clipboardHasDifferentAlignment(v, from)) { | 728 if (clipboardHasDifferentAlignment(v, from)) { |
729 | 729 |
730 QMessageBox::StandardButton button = | 730 QMessageBox::StandardButton button = |
731 QMessageBox::question(v, tr("Re-align pasted items?"), | 731 QMessageBox::question(v->getView(), tr("Re-align pasted items?"), |
732 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), | 732 tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), |
733 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, | 733 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, |
734 QMessageBox::Yes); | 734 QMessageBox::Yes); |
735 | 735 |
736 if (button == QMessageBox::Cancel) { | 736 if (button == QMessageBox::Cancel) { |