Mercurial > hg > svgui
comparison layer/ImageLayer.cpp @ 946:36cddc3de023 alignment_view
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 20 Apr 2015 09:19:52 +0100 |
parents | b66fb15de477 |
children | 94e4952a6774 |
comparison
equal
deleted
inserted
replaced
897:499b637f2a26 | 946:36cddc3de023 |
---|---|
108 { | 108 { |
109 Layer::setProperty(name, value); | 109 Layer::setProperty(name, value); |
110 } | 110 } |
111 | 111 |
112 bool | 112 bool |
113 ImageLayer::getValueExtents(float &, float &, bool &, QString &) const | 113 ImageLayer::getValueExtents(double &, double &, bool &, QString &) const |
114 { | 114 { |
115 return false; | 115 return false; |
116 } | 116 } |
117 | 117 |
118 bool | 118 bool |
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, int &frame, | 211 ImageLayer::snapToFeatureFrame(View *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); |
226 frame = points.begin()->frame; | 226 frame = points.begin()->frame; |
227 return true; | 227 return true; |
228 } | 228 } |
229 | 229 |
230 points = m_model->getPoints(frame, frame); | 230 points = m_model->getPoints(frame, frame); |
231 int snapped = frame; | 231 sv_frame_t snapped = frame; |
232 bool found = false; | 232 bool found = false; |
233 | 233 |
234 for (ImageModel::PointList::const_iterator i = points.begin(); | 234 for (ImageModel::PointList::const_iterator i = points.begin(); |
235 i != points.end(); ++i) { | 235 i != points.end(); ++i) { |
236 | 236 |
282 void | 282 void |
283 ImageLayer::paint(View *v, QPainter &paint, QRect rect) const | 283 ImageLayer::paint(View *v, QPainter &paint, QRect rect) const |
284 { | 284 { |
285 if (!m_model || !m_model->isOK()) return; | 285 if (!m_model || !m_model->isOK()) return; |
286 | 286 |
287 int sampleRate = m_model->getSampleRate(); | 287 sv_samplerate_t sampleRate = m_model->getSampleRate(); |
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->width(); |
294 | 294 |
295 int frame0 = v->getFrameForX(x0); | 295 sv_frame_t frame0 = v->getFrameForX(x0); |
296 int 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(); |
561 if (!m_model) { | 561 if (!m_model) { |
562 SVDEBUG << "ImageLayer::drawStart: no model" << endl; | 562 SVDEBUG << "ImageLayer::drawStart: no model" << endl; |
563 return; | 563 return; |
564 } | 564 } |
565 | 565 |
566 int frame = v->getFrameForX(e->x()); | 566 sv_frame_t frame = v->getFrameForX(e->x()); |
567 if (frame < 0) frame = 0; | 567 if (frame < 0) frame = 0; |
568 frame = frame / m_model->getResolution() * m_model->getResolution(); | 568 frame = frame / m_model->getResolution() * m_model->getResolution(); |
569 | 569 |
570 m_editingPoint = ImageModel::Point(frame, "", ""); | 570 m_editingPoint = ImageModel::Point(frame, "", ""); |
571 m_originalPoint = m_editingPoint; | 571 m_originalPoint = m_editingPoint; |
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 |
587 int frame = v->getFrameForX(e->x()); | 587 sv_frame_t frame = v->getFrameForX(e->x()); |
588 if (frame < 0) frame = 0; | 588 if (frame < 0) frame = 0; |
589 frame = frame / m_model->getResolution() * m_model->getResolution(); | 589 frame = frame / m_model->getResolution() * m_model->getResolution(); |
590 | 590 |
591 m_editingCommand->deletePoint(m_editingPoint); | 591 m_editingCommand->deletePoint(m_editingPoint); |
592 m_editingPoint.frame = frame; | 592 m_editingPoint.frame = frame; |
617 m_editingCommand = 0; | 617 m_editingCommand = 0; |
618 m_editing = false; | 618 m_editing = false; |
619 } | 619 } |
620 | 620 |
621 bool | 621 bool |
622 ImageLayer::addImage(int frame, QString url) | 622 ImageLayer::addImage(sv_frame_t frame, QString url) |
623 { | 623 { |
624 QImage image(getLocalFilename(url)); | 624 QImage image(getLocalFilename(url)); |
625 if (image.isNull()) { | 625 if (image.isNull()) { |
626 cerr << "Failed to open image from url \"" << url << "\" (local filename \"" << getLocalFilename(url) << "\"" << endl; | 626 cerr << "Failed to open image from url \"" << url << "\" (local filename \"" << getLocalFilename(url) << "\"" << endl; |
627 delete m_fileSources[url]; | 627 delete m_fileSources[url]; |
662 void | 662 void |
663 ImageLayer::editDrag(View *v, QMouseEvent *e) | 663 ImageLayer::editDrag(View *v, QMouseEvent *e) |
664 { | 664 { |
665 if (!m_model || !m_editing) return; | 665 if (!m_model || !m_editing) return; |
666 | 666 |
667 int 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 int frame = m_originalPoint.frame + frameDiff; | 668 sv_frame_t frame = m_originalPoint.frame + frameDiff; |
669 | 669 |
670 if (frame < 0) frame = 0; | 670 if (frame < 0) frame = 0; |
671 frame = (frame / m_model->getResolution()) * m_model->getResolution(); | 671 frame = (frame / m_model->getResolution()) * m_model->getResolution(); |
672 | 672 |
673 if (!m_editingCommand) { | 673 if (!m_editingCommand) { |
721 | 721 |
722 return true; | 722 return true; |
723 } | 723 } |
724 | 724 |
725 void | 725 void |
726 ImageLayer::moveSelection(Selection s, int newStartFrame) | 726 ImageLayer::moveSelection(Selection s, sv_frame_t newStartFrame) |
727 { | 727 { |
728 if (!m_model) return; | 728 if (!m_model) return; |
729 | 729 |
730 ImageModel::EditCommand *command = | 730 ImageModel::EditCommand *command = |
731 new ImageModel::EditCommand(m_model, tr("Drag Selection")); | 731 new ImageModel::EditCommand(m_model, tr("Drag Selection")); |
765 for (ImageModel::PointList::iterator i = points.begin(); | 765 for (ImageModel::PointList::iterator i = points.begin(); |
766 i != points.end(); ++i) { | 766 i != points.end(); ++i) { |
767 | 767 |
768 if (s.contains(i->frame)) { | 768 if (s.contains(i->frame)) { |
769 | 769 |
770 double target = i->frame; | 770 double target = double(i->frame); |
771 target = newSize.getStartFrame() + | 771 target = double(newSize.getStartFrame()) + |
772 double(target - s.getStartFrame()) * ratio; | 772 target - double(s.getStartFrame()) * ratio; |
773 | 773 |
774 ImageModel::Point newPoint(*i); | 774 ImageModel::Point newPoint(*i); |
775 newPoint.frame = lrint(target); | 775 newPoint.frame = lrint(target); |
776 command->deletePoint(*i); | 776 command->deletePoint(*i); |
777 command->addPoint(newPoint); | 777 command->addPoint(newPoint); |
817 } | 817 } |
818 } | 818 } |
819 } | 819 } |
820 | 820 |
821 bool | 821 bool |
822 ImageLayer::paste(View *v, const Clipboard &from, int /* frameOffset */, bool /* interactive */) | 822 ImageLayer::paste(View *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 |
850 for (Clipboard::PointList::const_iterator i = points.begin(); | 850 for (Clipboard::PointList::const_iterator i = points.begin(); |
851 i != points.end(); ++i) { | 851 i != points.end(); ++i) { |
852 | 852 |
853 if (!i->haveFrame()) continue; | 853 if (!i->haveFrame()) continue; |
854 | 854 |
855 int frame = 0; | 855 sv_frame_t frame = 0; |
856 | 856 |
857 if (!realign) { | 857 if (!realign) { |
858 | 858 |
859 frame = i->getFrame(); | 859 frame = i->getFrame(); |
860 | 860 |