comparison layer/ImageLayer.cpp @ 1459:42c87368287c

Merge from branch single-point
author Chris Cannam
date Fri, 17 May 2019 10:02:52 +0100
parents 09d008b5c8f4
children 11a150e65ee1
comparison
equal deleted inserted replaced
1441:8d5bf4ab98ef 1459:42c87368287c
44 44
45 ImageLayer::ImageLayer() : 45 ImageLayer::ImageLayer() :
46 Layer(), 46 Layer(),
47 m_model(nullptr), 47 m_model(nullptr),
48 m_editing(false), 48 m_editing(false),
49 m_originalPoint(0, "", ""),
50 m_editingPoint(0, "", ""),
51 m_editingCommand(nullptr) 49 m_editingCommand(nullptr)
52 { 50 {
53 } 51 }
54 52
55 ImageLayer::~ImageLayer() 53 ImageLayer::~ImageLayer()
119 ImageLayer::isLayerScrollable(const LayerGeometryProvider *) const 117 ImageLayer::isLayerScrollable(const LayerGeometryProvider *) const
120 { 118 {
121 return true; 119 return true;
122 } 120 }
123 121
124 122 EventVector
125 ImageModel::PointList
126 ImageLayer::getLocalPoints(LayerGeometryProvider *v, int x, int ) const 123 ImageLayer::getLocalPoints(LayerGeometryProvider *v, int x, int ) const
127 { 124 {
128 if (!m_model) return ImageModel::PointList(); 125 if (!m_model) return {};
129 126
130 // SVDEBUG << "ImageLayer::getLocalPoints(" << x << "," << y << "):"; 127 // SVDEBUG << "ImageLayer::getLocalPoints(" << x << "," << y << "):";
131 const ImageModel::PointList &points(m_model->getPoints()); 128 EventVector points(m_model->getAllEvents());
132 129
133 ImageModel::PointList rv; 130 EventVector rv;
134 131
135 for (ImageModel::PointList::const_iterator i = points.begin(); 132 for (EventVector::const_iterator i = points.begin(); i != points.end(); ) {
136 i != points.end(); ) { 133
137 134 Event p(*i);
138 const ImageModel::Point &p(*i); 135 int px = v->getXForFrame(p.getFrame());
139 int px = v->getXForFrame(p.frame);
140 if (px > x) break; 136 if (px > x) break;
141 137
142 ++i; 138 ++i;
143 if (i != points.end()) { 139 if (i != points.end()) {
144 int nx = v->getXForFrame((*i).frame); 140 int nx = v->getXForFrame(i->getFrame());
145 if (nx < x) { 141 if (nx < x) {
146 // as we aim not to overlap the images, if the following 142 // as we aim not to overlap the images, if the following
147 // image begins to the left of a point then the current 143 // image begins to the left of a point then the current
148 // one may be assumed to end to the left of it as well. 144 // one may be assumed to end to the left of it as well.
149 continue; 145 continue;
151 } 147 }
152 148
153 // this image is a candidate, test it properly 149 // this image is a candidate, test it properly
154 150
155 int width = 32; 151 int width = 32;
156 if (m_scaled[v].find(p.image) != m_scaled[v].end()) { 152 if (m_scaled[v].find(p.getURI()) != m_scaled[v].end()) {
157 width = m_scaled[v][p.image].width(); 153 width = m_scaled[v][p.getURI()].width();
158 // SVDEBUG << "scaled width = " << width << endl; 154 // SVDEBUG << "scaled width = " << width << endl;
159 } 155 }
160 156
161 if (x >= px && x < px + width) { 157 if (x >= px && x < px + width) {
162 rv.insert(p); 158 rv.push_back(p);
163 } 159 }
164 } 160 }
165 161
166 // cerr << rv.size() << " point(s)" << endl; 162 // cerr << rv.size() << " point(s)" << endl;
167 163
173 { 169 {
174 int x = pos.x(); 170 int x = pos.x();
175 171
176 if (!m_model || !m_model->getSampleRate()) return ""; 172 if (!m_model || !m_model->getSampleRate()) return "";
177 173
178 ImageModel::PointList points = getLocalPoints(v, x, pos.y()); 174 EventVector points = getLocalPoints(v, x, pos.y());
179 175
180 if (points.empty()) { 176 if (points.empty()) {
181 if (!m_model->isReady()) { 177 if (!m_model->isReady()) {
182 return tr("In progress"); 178 return tr("In progress");
183 } else { 179 } else {
207 203
208 //!!! too much overlap with TimeValueLayer/TimeInstantLayer/TextLayer 204 //!!! too much overlap with TimeValueLayer/TimeInstantLayer/TextLayer
209 205
210 bool 206 bool
211 ImageLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, 207 ImageLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
212 int &resolution, 208 int &resolution,
213 SnapType snap) const 209 SnapType snap) const
214 { 210 {
215 if (!m_model) { 211 if (!m_model) {
216 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 212 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
217 } 213 }
218 214
219 resolution = m_model->getResolution(); 215 resolution = m_model->getResolution();
220 ImageModel::PointList points;
221 216
222 if (snap == SnapNeighbouring) { 217 if (snap == SnapNeighbouring) {
223 218 EventVector points = getLocalPoints(v, v->getXForFrame(frame), -1);
224 points = getLocalPoints(v, v->getXForFrame(frame), -1);
225 if (points.empty()) return false; 219 if (points.empty()) return false;
226 frame = points.begin()->frame; 220 frame = points.begin()->getFrame();
227 return true; 221 return true;
228 } 222 }
229 223
230 points = m_model->getPoints(frame, frame); 224 Event e;
231 sv_frame_t snapped = frame; 225 if (m_model->getNearestEventMatching
232 bool found = false; 226 (frame,
233 227 [](Event) { return true; },
234 for (ImageModel::PointList::const_iterator i = points.begin(); 228 snap == SnapLeft ? EventSeries::Backward : EventSeries::Forward,
235 i != points.end(); ++i) { 229 e)) {
236 230 frame = e.getFrame();
237 if (snap == SnapRight) { 231 return true;
238 232 }
239 if (i->frame > frame) { 233
240 snapped = i->frame; 234 return false;
241 found = true;
242 break;
243 }
244
245 } else if (snap == SnapLeft) {
246
247 if (i->frame <= frame) {
248 snapped = i->frame;
249 found = true; // don't break, as the next may be better
250 } else {
251 break;
252 }
253
254 } else { // nearest
255
256 ImageModel::PointList::const_iterator j = i;
257 ++j;
258
259 if (j == points.end()) {
260
261 snapped = i->frame;
262 found = true;
263 break;
264
265 } else if (j->frame >= frame) {
266
267 if (j->frame - frame < frame - i->frame) {
268 snapped = j->frame;
269 } else {
270 snapped = i->frame;
271 }
272 found = true;
273 break;
274 }
275 }
276 }
277
278 frame = snapped;
279 return found;
280 } 235 }
281 236
282 void 237 void
283 ImageLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const 238 ImageLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
284 { 239 {
293 int x0 = 0, x1 = v->getPaintWidth(); 248 int x0 = 0, x1 = v->getPaintWidth();
294 249
295 sv_frame_t frame0 = v->getFrameForX(x0); 250 sv_frame_t frame0 = v->getFrameForX(x0);
296 sv_frame_t frame1 = v->getFrameForX(x1); 251 sv_frame_t frame1 = v->getFrameForX(x1);
297 252
298 ImageModel::PointList points(m_model->getPoints(frame0, frame1)); 253 EventVector points(m_model->getEventsWithin(frame0, frame1 - frame0, 2));
299 if (points.empty()) return; 254 if (points.empty()) return;
300 255
301 paint.save(); 256 paint.save();
302 paint.setClipRect(rect.x(), 0, rect.width(), v->getPaintHeight()); 257 paint.setClipRect(rect.x(), 0, rect.width(), v->getPaintHeight());
303 258
313 268
314 paint.setPen(penColour); 269 paint.setPen(penColour);
315 paint.setBrush(brushColour); 270 paint.setBrush(brushColour);
316 paint.setRenderHint(QPainter::Antialiasing, true); 271 paint.setRenderHint(QPainter::Antialiasing, true);
317 272
318 for (ImageModel::PointList::const_iterator i = points.begin(); 273 for (EventVector::const_iterator i = points.begin();
319 i != points.end(); ++i) { 274 i != points.end(); ++i) {
320 275
321 const ImageModel::Point &p(*i); 276 Event p(*i);
322 277
323 int x = v->getXForFrame(p.frame); 278 int x = v->getXForFrame(p.getFrame());
324 279
325 int nx = x + 2000; 280 int nx = x + 2000;
326 ImageModel::PointList::const_iterator j = i; 281 EventVector::const_iterator j = i;
327 ++j; 282 ++j;
328 if (j != points.end()) { 283 if (j != points.end()) {
329 int jx = v->getXForFrame(j->frame); 284 int jx = v->getXForFrame(j->getFrame());
330 if (jx < nx) nx = jx; 285 if (jx < nx) nx = jx;
331 } 286 }
332 287
333 drawImage(v, paint, p, x, nx); 288 drawImage(v, paint, p, x, nx);
334 } 289 }
336 paint.setRenderHint(QPainter::Antialiasing, false); 291 paint.setRenderHint(QPainter::Antialiasing, false);
337 paint.restore(); 292 paint.restore();
338 } 293 }
339 294
340 void 295 void
341 ImageLayer::drawImage(LayerGeometryProvider *v, QPainter &paint, const ImageModel::Point &p, 296 ImageLayer::drawImage(LayerGeometryProvider *v, QPainter &paint, const Event &p,
342 int x, int nx) const 297 int x, int nx) const
343 { 298 {
344 QString label = p.label; 299 QString label = p.getLabel();
345 QString imageName = p.image; 300 QString imageName = p.getURI();
346 301
347 QImage image; 302 QImage image;
348 QString additionalText; 303 QString additionalText;
349 304
350 QSize imageSize; 305 QSize imageSize;
565 520
566 sv_frame_t frame = v->getFrameForX(e->x()); 521 sv_frame_t frame = v->getFrameForX(e->x());
567 if (frame < 0) frame = 0; 522 if (frame < 0) frame = 0;
568 frame = frame / m_model->getResolution() * m_model->getResolution(); 523 frame = frame / m_model->getResolution() * m_model->getResolution();
569 524
570 m_editingPoint = ImageModel::Point(frame, "", ""); 525 m_editingPoint = Event(frame);
571 m_originalPoint = m_editingPoint; 526 m_originalPoint = m_editingPoint;
572 527
573 if (m_editingCommand) finish(m_editingCommand); 528 if (m_editingCommand) finish(m_editingCommand);
574 m_editingCommand = new ImageModel::EditCommand(m_model, "Add Image"); 529 m_editingCommand = new ChangeEventsCommand(m_model, "Add Image");
575 m_editingCommand->addPoint(m_editingPoint); 530 m_editingCommand->add(m_editingPoint);
576 531
577 m_editing = true; 532 m_editing = true;
578 } 533 }
579 534
580 void 535 void
586 541
587 sv_frame_t frame = v->getFrameForX(e->x()); 542 sv_frame_t frame = v->getFrameForX(e->x());
588 if (frame < 0) frame = 0; 543 if (frame < 0) frame = 0;
589 frame = frame / m_model->getResolution() * m_model->getResolution(); 544 frame = frame / m_model->getResolution() * m_model->getResolution();
590 545
591 m_editingCommand->deletePoint(m_editingPoint); 546 m_editingCommand->remove(m_editingPoint);
592 m_editingPoint.frame = frame; 547 m_editingPoint = m_editingPoint
593 m_editingCommand->addPoint(m_editingPoint); 548 .withFrame(frame);
549 m_editingCommand->add(m_editingPoint);
594 } 550 }
595 551
596 void 552 void
597 ImageLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *) 553 ImageLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *)
598 { 554 {
599 // SVDEBUG << "ImageLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; 555 // SVDEBUG << "ImageLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl;
600 if (!m_model || !m_editing) return; 556 if (!m_model || !m_editing) return;
601 557
602 ImageDialog dialog(tr("Select image"), "", ""); 558 ImageDialog dialog(tr("Select image"), "", "");
603 559
560 m_editingCommand->remove(m_editingPoint);
561
604 if (dialog.exec() == QDialog::Accepted) { 562 if (dialog.exec() == QDialog::Accepted) {
605 563
606 checkAddSource(dialog.getImage()); 564 checkAddSource(dialog.getImage());
607 565
608 ImageModel::ChangeImageCommand *command = 566 m_editingPoint = m_editingPoint
609 new ImageModel::ChangeImageCommand 567 .withURI(dialog.getImage())
610 (m_model, m_editingPoint, dialog.getImage(), dialog.getLabel()); 568 .withLabel(dialog.getLabel());
611 m_editingCommand->addCommand(command); 569 m_editingCommand->add(m_editingPoint);
612 } else {
613 m_editingCommand->deletePoint(m_editingPoint);
614 } 570 }
615 571
616 finish(m_editingCommand); 572 finish(m_editingCommand);
617 m_editingCommand = nullptr; 573 m_editingCommand = nullptr;
618 m_editing = false; 574 m_editing = false;
627 delete m_fileSources[url]; 583 delete m_fileSources[url];
628 m_fileSources.erase(url); 584 m_fileSources.erase(url);
629 return false; 585 return false;
630 } 586 }
631 587
632 ImageModel::Point point(frame, url, ""); 588 Event point = Event(frame).withURI(url);
633 ImageModel::EditCommand *command = 589 ChangeEventsCommand *command =
634 new ImageModel::EditCommand(m_model, "Add Image"); 590 new ChangeEventsCommand(m_model, "Add Image");
635 command->addPoint(point); 591 command->add(point);
636 finish(command); 592 finish(command);
637 return true; 593 return true;
638 } 594 }
639 595
640 void 596 void
642 { 598 {
643 // SVDEBUG << "ImageLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; 599 // SVDEBUG << "ImageLayer::editStart(" << e->x() << "," << e->y() << ")" << endl;
644 600
645 if (!m_model) return; 601 if (!m_model) return;
646 602
647 ImageModel::PointList points = getLocalPoints(v, e->x(), e->y()); 603 EventVector points = getLocalPoints(v, e->x(), e->y());
648 if (points.empty()) return; 604 if (points.empty()) return;
649 605
650 m_editOrigin = e->pos(); 606 m_editOrigin = e->pos();
651 m_editingPoint = *points.begin(); 607 m_editingPoint = *points.begin();
652 m_originalPoint = m_editingPoint; 608 m_originalPoint = m_editingPoint;
663 ImageLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e) 619 ImageLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e)
664 { 620 {
665 if (!m_model || !m_editing) return; 621 if (!m_model || !m_editing) return;
666 622
667 sv_frame_t frameDiff = v->getFrameForX(e->x()) - v->getFrameForX(m_editOrigin.x()); 623 sv_frame_t frameDiff = v->getFrameForX(e->x()) - v->getFrameForX(m_editOrigin.x());
668 sv_frame_t frame = m_originalPoint.frame + frameDiff; 624 sv_frame_t frame = m_originalPoint.getFrame() + frameDiff;
669 625
670 if (frame < 0) frame = 0; 626 if (frame < 0) frame = 0;
671 frame = (frame / m_model->getResolution()) * m_model->getResolution(); 627 frame = (frame / m_model->getResolution()) * m_model->getResolution();
672 628
673 if (!m_editingCommand) { 629 if (!m_editingCommand) {
674 m_editingCommand = new ImageModel::EditCommand(m_model, tr("Move Image")); 630 m_editingCommand = new ChangeEventsCommand(m_model, tr("Move Image"));
675 } 631 }
676 632
677 m_editingCommand->deletePoint(m_editingPoint); 633 m_editingCommand->remove(m_editingPoint);
678 m_editingPoint.frame = frame; 634 m_editingPoint = m_editingPoint
679 m_editingCommand->addPoint(m_editingPoint); 635 .withFrame(frame);
636 m_editingCommand->add(m_editingPoint);
680 } 637 }
681 638
682 void 639 void
683 ImageLayer::editEnd(LayerGeometryProvider *, QMouseEvent *) 640 ImageLayer::editEnd(LayerGeometryProvider *, QMouseEvent *)
684 { 641 {
696 bool 653 bool
697 ImageLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) 654 ImageLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e)
698 { 655 {
699 if (!m_model) return false; 656 if (!m_model) return false;
700 657
701 ImageModel::PointList points = getLocalPoints(v, e->x(), e->y()); 658 EventVector points = getLocalPoints(v, e->x(), e->y());
702 if (points.empty()) return false; 659 if (points.empty()) return false;
703 660
704 QString image = points.begin()->image; 661 QString image = points.begin()->getURI();
705 QString label = points.begin()->label; 662 QString label = points.begin()->getLabel();
706 663
707 ImageDialog dialog(tr("Select image"), 664 ImageDialog dialog(tr("Select image"),
708 image, 665 image,
709 label); 666 label);
710 667
711 if (dialog.exec() == QDialog::Accepted) { 668 if (dialog.exec() == QDialog::Accepted) {
712 669
713 checkAddSource(dialog.getImage()); 670 checkAddSource(dialog.getImage());
714 671
715 ImageModel::ChangeImageCommand *command = 672 ChangeEventsCommand *command =
716 new ImageModel::ChangeImageCommand 673 new ChangeEventsCommand(m_model, tr("Edit Image"));
717 (m_model, *points.begin(), dialog.getImage(), dialog.getLabel()); 674 command->remove(*points.begin());
718 675 command->add(points.begin()->
719 CommandHistory::getInstance()->addCommand(command); 676 withURI(dialog.getImage()).withLabel(dialog.getLabel()));
677 finish(command);
720 } 678 }
721 679
722 return true; 680 return true;
723 } 681 }
724 682
725 void 683 void
726 ImageLayer::moveSelection(Selection s, sv_frame_t newStartFrame) 684 ImageLayer::moveSelection(Selection s, sv_frame_t newStartFrame)
727 { 685 {
728 if (!m_model) return; 686 if (!m_model) return;
729 687
730 ImageModel::EditCommand *command = 688 ChangeEventsCommand *command =
731 new ImageModel::EditCommand(m_model, tr("Drag Selection")); 689 new ChangeEventsCommand(m_model, tr("Drag Selection"));
732 690
733 ImageModel::PointList points = 691 EventVector points =
734 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 692 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration());
735 693
736 for (ImageModel::PointList::iterator i = points.begin(); 694 for (Event p: points) {
737 i != points.end(); ++i) { 695 command->remove(p);
738 696 Event moved = p.withFrame(p.getFrame() +
739 if (s.contains(i->frame)) { 697 newStartFrame - s.getStartFrame());
740 ImageModel::Point newPoint(*i); 698 command->add(moved);
741 newPoint.frame = i->frame + newStartFrame - s.getStartFrame();
742 command->deletePoint(*i);
743 command->addPoint(newPoint);
744 }
745 } 699 }
746 700
747 finish(command); 701 finish(command);
748 } 702 }
749 703
750 void 704 void
751 ImageLayer::resizeSelection(Selection s, Selection newSize) 705 ImageLayer::resizeSelection(Selection s, Selection newSize)
752 { 706 {
753 if (!m_model) return; 707 if (!m_model) return;
754 708
755 ImageModel::EditCommand *command = 709 ChangeEventsCommand *command =
756 new ImageModel::EditCommand(m_model, tr("Resize Selection")); 710 new ChangeEventsCommand(m_model, tr("Resize Selection"));
757 711
758 ImageModel::PointList points = 712 EventVector points =
759 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 713 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration());
760 714
761 double ratio = 715 double ratio = double(newSize.getDuration()) / double(s.getDuration());
762 double(newSize.getEndFrame() - newSize.getStartFrame()) / 716 double oldStart = double(s.getStartFrame());
763 double(s.getEndFrame() - s.getStartFrame()); 717 double newStart = double(newSize.getStartFrame());
764 718
765 for (ImageModel::PointList::iterator i = points.begin(); 719 for (Event p: points) {
766 i != points.end(); ++i) { 720
767 721 double newFrame = (double(p.getFrame()) - oldStart) * ratio + newStart;
768 if (s.contains(i->frame)) { 722
769 723 Event newPoint = p
770 double target = double(i->frame); 724 .withFrame(lrint(newFrame));
771 target = double(newSize.getStartFrame()) + 725 command->remove(p);
772 target - double(s.getStartFrame()) * ratio; 726 command->add(newPoint);
773
774 ImageModel::Point newPoint(*i);
775 newPoint.frame = lrint(target);
776 command->deletePoint(*i);
777 command->addPoint(newPoint);
778 }
779 } 727 }
780 728
781 finish(command); 729 finish(command);
782 } 730 }
783 731
784 void 732 void
785 ImageLayer::deleteSelection(Selection s) 733 ImageLayer::deleteSelection(Selection s)
786 { 734 {
787 if (!m_model) return; 735 if (!m_model) return;
788 736
789 ImageModel::EditCommand *command = 737 ChangeEventsCommand *command =
790 new ImageModel::EditCommand(m_model, tr("Delete Selection")); 738 new ChangeEventsCommand(m_model, tr("Delete Selection"));
791 739
792 ImageModel::PointList points = 740 EventVector points =
793 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 741 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration());
794 742
795 for (ImageModel::PointList::iterator i = points.begin(); 743 for (Event p: points) {
796 i != points.end(); ++i) { 744 command->remove(p);
797 if (s.contains(i->frame)) command->deletePoint(*i);
798 } 745 }
799 746
800 finish(command); 747 finish(command);
801 } 748 }
802 749
803 void 750 void
804 ImageLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) 751 ImageLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to)
805 { 752 {
806 if (!m_model) return; 753 if (!m_model) return;
807 754
808 ImageModel::PointList points = 755 EventVector points =
809 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 756 m_model->getEventsStartingWithin(s.getStartFrame(), s.getDuration());
810 757
811 for (ImageModel::PointList::iterator i = points.begin(); 758 for (Event p: points) {
812 i != points.end(); ++i) { 759 to.addPoint(p.withReferenceFrame(alignToReference(v, p.getFrame())));
813 if (s.contains(i->frame)) {
814 Clipboard::Point point(i->frame, i->label);
815 point.setReferenceFrame(alignToReference(v, i->frame));
816 to.addPoint(point);
817 }
818 } 760 }
819 } 761 }
820 762
821 bool 763 bool
822 ImageLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */) 764 ImageLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */)
823 { 765 {
824 if (!m_model) return false; 766 if (!m_model) return false;
825 767
826 const Clipboard::PointList &points = from.getPoints(); 768 const EventVector &points = from.getPoints();
827 769
828 bool realign = false; 770 bool realign = false;
829 771
830 if (clipboardHasDifferentAlignment(v, from)) { 772 if (clipboardHasDifferentAlignment(v, from)) {
831 773
842 if (button == QMessageBox::Yes) { 784 if (button == QMessageBox::Yes) {
843 realign = true; 785 realign = true;
844 } 786 }
845 } 787 }
846 788
847 ImageModel::EditCommand *command = 789 ChangeEventsCommand *command =
848 new ImageModel::EditCommand(m_model, tr("Paste")); 790 new ChangeEventsCommand(m_model, tr("Paste"));
849 791
850 for (Clipboard::PointList::const_iterator i = points.begin(); 792 for (EventVector::const_iterator i = points.begin();
851 i != points.end(); ++i) { 793 i != points.end(); ++i) {
852 794
853 if (!i->haveFrame()) continue;
854
855 sv_frame_t frame = 0; 795 sv_frame_t frame = 0;
856 796
857 if (!realign) { 797 if (!realign) {
858 798
859 frame = i->getFrame(); 799 frame = i->getFrame();
860 800
861 } else { 801 } else {
862 802
863 if (i->haveReferenceFrame()) { 803 if (i->hasReferenceFrame()) {
864 frame = i->getReferenceFrame(); 804 frame = i->getReferenceFrame();
865 frame = alignFromReference(v, frame); 805 frame = alignFromReference(v, frame);
866 } else { 806 } else {
867 frame = i->getFrame(); 807 frame = i->getFrame();
868 } 808 }
869 } 809 }
870 810
871 ImageModel::Point newPoint(frame); 811 Event p = *i;
812 Event newPoint = p;
872 813
873 //!!! inadequate 814 //!!! inadequate
874 815
875 if (i->haveLabel()) { 816 if (!p.hasLabel()) {
876 newPoint.label = i->getLabel(); 817 if (p.hasValue()) {
877 } else if (i->haveValue()) { 818 newPoint = newPoint.withLabel(QString("%1").arg(p.getValue()));
878 newPoint.label = QString("%1").arg(i->getValue()); 819 } else {
879 } else { 820 newPoint = newPoint.withLabel(tr("New Point"));
880 newPoint.label = tr("New Point"); 821 }
881 } 822 }
882 823
883 command->addPoint(newPoint); 824 command->add(newPoint);
884 } 825 }
885 826
886 finish(command); 827 finish(command);
887 return true; 828 return true;
888 } 829 }
920 } 861 }
921 862
922 void 863 void
923 ImageLayer::checkAddSources() 864 ImageLayer::checkAddSources()
924 { 865 {
925 const ImageModel::PointList &points(m_model->getPoints()); 866 const EventVector &points(m_model->getAllEvents());
926 867
927 for (ImageModel::PointList::const_iterator i = points.begin(); 868 for (EventVector::const_iterator i = points.begin();
928 i != points.end(); ++i) { 869 i != points.end(); ++i) {
929 870
930 checkAddSource((*i).image); 871 checkAddSource((*i).getURI());
931 } 872 }
932 } 873 }
933 874
934 void 875 void
935 ImageLayer::fileSourceReady() 876 ImageLayer::fileSourceReady()