Mercurial > hg > svgui
comparison layer/ImageLayer.cpp @ 918:4fe7a09be0fe osx-retina
Many fixes for the previous stuff
author | Chris Cannam |
---|---|
date | Tue, 17 Mar 2015 16:56:03 +0000 |
parents | 94e4952a6774 |
children | a34a2a25907c |
comparison
equal
deleted
inserted
replaced
917:77a1d42353ce | 918:4fe7a09be0fe |
---|---|
114 { | 114 { |
115 return false; | 115 return false; |
116 } | 116 } |
117 | 117 |
118 bool | 118 bool |
119 ImageLayer::isLayerScrollable(const View *) const | 119 ImageLayer::isLayerScrollable(const LayerGeometryProvider *) const |
120 { | 120 { |
121 return true; | 121 return true; |
122 } | 122 } |
123 | 123 |
124 | 124 |
125 ImageModel::PointList | 125 ImageModel::PointList |
126 ImageLayer::getLocalPoints(View *v, int x, int ) const | 126 ImageLayer::getLocalPoints(LayerGeometryProvider *v, int x, int ) const |
127 { | 127 { |
128 if (!m_model) return ImageModel::PointList(); | 128 if (!m_model) return ImageModel::PointList(); |
129 | 129 |
130 // SVDEBUG << "ImageLayer::getLocalPoints(" << x << "," << y << "):"; | 130 // SVDEBUG << "ImageLayer::getLocalPoints(" << x << "," << y << "):"; |
131 const ImageModel::PointList &points(m_model->getPoints()); | 131 const ImageModel::PointList &points(m_model->getPoints()); |
167 | 167 |
168 return rv; | 168 return rv; |
169 } | 169 } |
170 | 170 |
171 QString | 171 QString |
172 ImageLayer::getFeatureDescription(View *v, QPoint &pos) const | 172 ImageLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const |
173 { | 173 { |
174 int x = pos.x(); | 174 int x = pos.x(); |
175 | 175 |
176 if (!m_model || !m_model->getSampleRate()) return ""; | 176 if (!m_model || !m_model->getSampleRate()) return ""; |
177 | 177 |
206 | 206 |
207 | 207 |
208 //!!! too much overlap with TimeValueLayer/TimeInstantLayer/TextLayer | 208 //!!! too much overlap with TimeValueLayer/TimeInstantLayer/TextLayer |
209 | 209 |
210 bool | 210 bool |
211 ImageLayer::snapToFeatureFrame(View *v, sv_frame_t &frame, | 211 ImageLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, |
212 int &resolution, | 212 int &resolution, |
213 SnapType snap) const | 213 SnapType snap) const |
214 { | 214 { |
215 if (!m_model) { | 215 if (!m_model) { |
216 return Layer::snapToFeatureFrame(v, frame, resolution, snap); | 216 return Layer::snapToFeatureFrame(v, frame, resolution, snap); |
288 if (!sampleRate) return; | 288 if (!sampleRate) return; |
289 | 289 |
290 // Profiler profiler("ImageLayer::paint", true); | 290 // Profiler profiler("ImageLayer::paint", true); |
291 | 291 |
292 // int x0 = rect.left(), x1 = rect.right(); | 292 // int x0 = rect.left(), x1 = rect.right(); |
293 int x0 = 0, x1 = v->width(); | 293 int x0 = 0, x1 = v->getPaintWidth(); |
294 | 294 |
295 sv_frame_t frame0 = v->getFrameForX(x0); | 295 sv_frame_t frame0 = v->getFrameForX(x0); |
296 sv_frame_t frame1 = v->getFrameForX(x1); | 296 sv_frame_t frame1 = v->getFrameForX(x1); |
297 | 297 |
298 ImageModel::PointList points(m_model->getPoints(frame0, frame1)); | 298 ImageModel::PointList points(m_model->getPoints(frame0, frame1)); |
299 if (points.empty()) return; | 299 if (points.empty()) return; |
300 | 300 |
301 paint.save(); | 301 paint.save(); |
302 paint.setClipRect(rect.x(), 0, rect.width(), v->height()); | 302 paint.setClipRect(rect.x(), 0, rect.width(), v->getPaintHeight()); |
303 | 303 |
304 QColor penColour; | 304 QColor penColour; |
305 penColour = v->getForeground(); | 305 penColour = v->getForeground(); |
306 | 306 |
307 QColor brushColour; | 307 QColor brushColour; |
336 paint.setRenderHint(QPainter::Antialiasing, false); | 336 paint.setRenderHint(QPainter::Antialiasing, false); |
337 paint.restore(); | 337 paint.restore(); |
338 } | 338 } |
339 | 339 |
340 void | 340 void |
341 ImageLayer::drawImage(View *v, QPainter &paint, const ImageModel::Point &p, | 341 ImageLayer::drawImage(LayerGeometryProvider *v, QPainter &paint, const ImageModel::Point &p, |
342 int x, int nx) const | 342 int x, int nx) const |
343 { | 343 { |
344 QString label = p.label; | 344 QString label = p.label; |
345 QString imageName = p.image; | 345 QString imageName = p.image; |
346 | 346 |
356 | 356 |
357 int topMargin = 10; | 357 int topMargin = 10; |
358 int bottomMargin = 10; | 358 int bottomMargin = 10; |
359 int spacing = 5; | 359 int spacing = 5; |
360 | 360 |
361 if (v->height() < 100) { | 361 if (v->getPaintHeight() < 100) { |
362 topMargin = 5; | 362 topMargin = 5; |
363 bottomMargin = 5; | 363 bottomMargin = 5; |
364 } | 364 } |
365 | 365 |
366 int maxBoxHeight = v->height() - topMargin - bottomMargin; | 366 int maxBoxHeight = v->getPaintHeight() - topMargin - bottomMargin; |
367 | 367 |
368 int availableWidth = nx - x - 3; | 368 int availableWidth = nx - x - 3; |
369 if (availableWidth < 20) availableWidth = 20; | 369 if (availableWidth < 20) availableWidth = 20; |
370 | 370 |
371 QRect labelRect; | 371 QRect labelRect; |
372 | 372 |
373 if (label != "") { | 373 if (label != "") { |
374 | 374 |
375 int likelyHeight = v->height() / 4; | 375 int likelyHeight = v->getPaintHeight() / 4; |
376 | 376 |
377 int likelyWidth = // available height times image aspect | 377 int likelyWidth = // available height times image aspect |
378 ((maxBoxHeight - likelyHeight) * imageSize.width()) | 378 ((maxBoxHeight - likelyHeight) * imageSize.width()) |
379 / imageSize.height(); | 379 / imageSize.height(); |
380 | 380 |
433 } | 433 } |
434 boxHeight += paint.fontMetrics().height(); | 434 boxHeight += paint.fontMetrics().height(); |
435 division += paint.fontMetrics().height(); | 435 division += paint.fontMetrics().height(); |
436 } | 436 } |
437 | 437 |
438 bottomMargin = v->height() - topMargin - boxHeight; | 438 bottomMargin = v->getPaintHeight() - topMargin - boxHeight; |
439 if (bottomMargin > topMargin + v->height()/7) { | 439 if (bottomMargin > topMargin + v->getPaintHeight()/7) { |
440 topMargin += v->height()/8; | 440 topMargin += v->getPaintHeight()/8; |
441 bottomMargin -= v->height()/8; | 441 bottomMargin -= v->getPaintHeight()/8; |
442 } | 442 } |
443 | 443 |
444 paint.drawRect(x - 1, | 444 paint.drawRect(x - 1, |
445 topMargin - 1, | 445 topMargin - 1, |
446 boxWidth + 2, | 446 boxWidth + 2, |
478 label); | 478 label); |
479 } | 479 } |
480 } | 480 } |
481 | 481 |
482 void | 482 void |
483 ImageLayer::setLayerDormant(const View *v, bool dormant) | 483 ImageLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant) |
484 { | 484 { |
485 if (dormant) { | 485 if (dormant) { |
486 // Delete the images named in the view's scaled map from the | 486 // Delete the images named in the view's scaled map from the |
487 // general image map as well. They can always be re-loaded | 487 // general image map as well. They can always be re-loaded |
488 // if it turns out another view still needs them. | 488 // if it turns out another view still needs them. |
515 return true; | 515 return true; |
516 } | 516 } |
517 } | 517 } |
518 | 518 |
519 QImage | 519 QImage |
520 ImageLayer::getImage(View *v, QString name, QSize maxSize) const | 520 ImageLayer::getImage(LayerGeometryProvider *v, QString name, QSize maxSize) const |
521 { | 521 { |
522 // SVDEBUG << "ImageLayer::getImage(" << v << ", " << name << ", (" | 522 // SVDEBUG << "ImageLayer::getImage(" << v << ", " << name << ", (" |
523 // << maxSize.width() << "x" << maxSize.height() << "))" << endl; | 523 // << maxSize.width() << "x" << maxSize.height() << "))" << endl; |
524 | 524 |
525 if (!m_scaled[v][name].isNull() && | 525 if (!m_scaled[v][name].isNull() && |
552 | 552 |
553 return m_scaled[v][name]; | 553 return m_scaled[v][name]; |
554 } | 554 } |
555 | 555 |
556 void | 556 void |
557 ImageLayer::drawStart(View *v, QMouseEvent *e) | 557 ImageLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) |
558 { | 558 { |
559 // SVDEBUG << "ImageLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; | 559 // SVDEBUG << "ImageLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; |
560 | 560 |
561 if (!m_model) { | 561 if (!m_model) { |
562 SVDEBUG << "ImageLayer::drawStart: no model" << endl; | 562 SVDEBUG << "ImageLayer::drawStart: no model" << endl; |
576 | 576 |
577 m_editing = true; | 577 m_editing = true; |
578 } | 578 } |
579 | 579 |
580 void | 580 void |
581 ImageLayer::drawDrag(View *v, QMouseEvent *e) | 581 ImageLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e) |
582 { | 582 { |
583 // SVDEBUG << "ImageLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; | 583 // SVDEBUG << "ImageLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; |
584 | 584 |
585 if (!m_model || !m_editing) return; | 585 if (!m_model || !m_editing) return; |
586 | 586 |
592 m_editingPoint.frame = frame; | 592 m_editingPoint.frame = frame; |
593 m_editingCommand->addPoint(m_editingPoint); | 593 m_editingCommand->addPoint(m_editingPoint); |
594 } | 594 } |
595 | 595 |
596 void | 596 void |
597 ImageLayer::drawEnd(View *, QMouseEvent *) | 597 ImageLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *) |
598 { | 598 { |
599 // SVDEBUG << "ImageLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; | 599 // SVDEBUG << "ImageLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; |
600 if (!m_model || !m_editing) return; | 600 if (!m_model || !m_editing) return; |
601 | 601 |
602 ImageDialog dialog(tr("Select image"), "", ""); | 602 ImageDialog dialog(tr("Select image"), "", ""); |
636 finish(command); | 636 finish(command); |
637 return true; | 637 return true; |
638 } | 638 } |
639 | 639 |
640 void | 640 void |
641 ImageLayer::editStart(View *v, QMouseEvent *e) | 641 ImageLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e) |
642 { | 642 { |
643 // SVDEBUG << "ImageLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; | 643 // SVDEBUG << "ImageLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; |
644 | 644 |
645 if (!m_model) return; | 645 if (!m_model) return; |
646 | 646 |
658 | 658 |
659 m_editing = true; | 659 m_editing = true; |
660 } | 660 } |
661 | 661 |
662 void | 662 void |
663 ImageLayer::editDrag(View *v, QMouseEvent *e) | 663 ImageLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e) |
664 { | 664 { |
665 if (!m_model || !m_editing) return; | 665 if (!m_model || !m_editing) return; |
666 | 666 |
667 sv_frame_t frameDiff = v->getFrameForX(e->x()) - v->getFrameForX(m_editOrigin.x()); | 667 sv_frame_t frameDiff = v->getFrameForX(e->x()) - v->getFrameForX(m_editOrigin.x()); |
668 sv_frame_t frame = m_originalPoint.frame + frameDiff; | 668 sv_frame_t frame = m_originalPoint.frame + frameDiff; |
678 m_editingPoint.frame = frame; | 678 m_editingPoint.frame = frame; |
679 m_editingCommand->addPoint(m_editingPoint); | 679 m_editingCommand->addPoint(m_editingPoint); |
680 } | 680 } |
681 | 681 |
682 void | 682 void |
683 ImageLayer::editEnd(View *, QMouseEvent *) | 683 ImageLayer::editEnd(LayerGeometryProvider *, QMouseEvent *) |
684 { | 684 { |
685 // SVDEBUG << "ImageLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; | 685 // SVDEBUG << "ImageLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; |
686 if (!m_model || !m_editing) return; | 686 if (!m_model || !m_editing) return; |
687 | 687 |
688 if (m_editingCommand) { | 688 if (m_editingCommand) { |
692 m_editingCommand = 0; | 692 m_editingCommand = 0; |
693 m_editing = false; | 693 m_editing = false; |
694 } | 694 } |
695 | 695 |
696 bool | 696 bool |
697 ImageLayer::editOpen(View *v, QMouseEvent *e) | 697 ImageLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) |
698 { | 698 { |
699 if (!m_model) return false; | 699 if (!m_model) return false; |
700 | 700 |
701 ImageModel::PointList points = getLocalPoints(v, e->x(), e->y()); | 701 ImageModel::PointList points = getLocalPoints(v, e->x(), e->y()); |
702 if (points.empty()) return false; | 702 if (points.empty()) return false; |
799 | 799 |
800 finish(command); | 800 finish(command); |
801 } | 801 } |
802 | 802 |
803 void | 803 void |
804 ImageLayer::copy(View *v, Selection s, Clipboard &to) | 804 ImageLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) |
805 { | 805 { |
806 if (!m_model) return; | 806 if (!m_model) return; |
807 | 807 |
808 ImageModel::PointList points = | 808 ImageModel::PointList points = |
809 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 809 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
817 } | 817 } |
818 } | 818 } |
819 } | 819 } |
820 | 820 |
821 bool | 821 bool |
822 ImageLayer::paste(View *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */) | 822 ImageLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */) |
823 { | 823 { |
824 if (!m_model) return false; | 824 if (!m_model) return false; |
825 | 825 |
826 const Clipboard::PointList &points = from.getPoints(); | 826 const Clipboard::PointList &points = from.getPoints(); |
827 | 827 |
828 bool realign = false; | 828 bool realign = false; |
829 | 829 |
830 if (clipboardHasDifferentAlignment(v, from)) { | 830 if (clipboardHasDifferentAlignment(v, from)) { |
831 | 831 |
832 QMessageBox::StandardButton button = | 832 QMessageBox::StandardButton button = |
833 QMessageBox::question(v, tr("Re-align pasted items?"), | 833 QMessageBox::question(v->getView(), tr("Re-align pasted items?"), |
834 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?"), | 834 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?"), |
835 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, | 835 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, |
836 QMessageBox::Yes); | 836 QMessageBox::Yes); |
837 | 837 |
838 if (button == QMessageBox::Cancel) { | 838 if (button == QMessageBox::Cancel) { |