Mercurial > hg > svgui
comparison layer/ImageLayer.cpp @ 1266:a34a2a25907c
Untabify
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2018 18:02:22 +0000 |
parents | 4fe7a09be0fe |
children | c8a6fd3f9dff |
comparison
equal
deleted
inserted
replaced
1265:6e724c81f18f | 1266:a34a2a25907c |
---|---|
89 return Layer::getPropertyType(name); | 89 return Layer::getPropertyType(name); |
90 } | 90 } |
91 | 91 |
92 int | 92 int |
93 ImageLayer::getPropertyRangeAndValue(const PropertyName &name, | 93 ImageLayer::getPropertyRangeAndValue(const PropertyName &name, |
94 int *min, int *max, int *deflt) const | 94 int *min, int *max, int *deflt) const |
95 { | 95 { |
96 return Layer::getPropertyRangeAndValue(name, min, max, deflt); | 96 return Layer::getPropertyRangeAndValue(name, min, max, deflt); |
97 } | 97 } |
98 | 98 |
99 QString | 99 QString |
100 ImageLayer::getPropertyValueLabel(const PropertyName &name, | 100 ImageLayer::getPropertyValueLabel(const PropertyName &name, |
101 int value) const | 101 int value) const |
102 { | 102 { |
103 return Layer::getPropertyValueLabel(name, value); | 103 return Layer::getPropertyValueLabel(name, value); |
104 } | 104 } |
105 | 105 |
106 void | 106 void |
131 const ImageModel::PointList &points(m_model->getPoints()); | 131 const ImageModel::PointList &points(m_model->getPoints()); |
132 | 132 |
133 ImageModel::PointList rv; | 133 ImageModel::PointList rv; |
134 | 134 |
135 for (ImageModel::PointList::const_iterator i = points.begin(); | 135 for (ImageModel::PointList::const_iterator i = points.begin(); |
136 i != points.end(); ) { | 136 i != points.end(); ) { |
137 | 137 |
138 const ImageModel::Point &p(*i); | 138 const ImageModel::Point &p(*i); |
139 int px = v->getXForFrame(p.frame); | 139 int px = v->getXForFrame(p.frame); |
140 if (px > x) break; | 140 if (px > x) break; |
141 | 141 |
142 ++i; | 142 ++i; |
143 if (i != points.end()) { | 143 if (i != points.end()) { |
144 int nx = v->getXForFrame((*i).frame); | 144 int nx = v->getXForFrame((*i).frame); |
176 if (!m_model || !m_model->getSampleRate()) return ""; | 176 if (!m_model || !m_model->getSampleRate()) return ""; |
177 | 177 |
178 ImageModel::PointList points = getLocalPoints(v, x, pos.y()); | 178 ImageModel::PointList points = getLocalPoints(v, x, pos.y()); |
179 | 179 |
180 if (points.empty()) { | 180 if (points.empty()) { |
181 if (!m_model->isReady()) { | 181 if (!m_model->isReady()) { |
182 return tr("In progress"); | 182 return tr("In progress"); |
183 } else { | 183 } else { |
184 return ""; | 184 return ""; |
185 } | 185 } |
186 } | 186 } |
187 | 187 |
188 // int useFrame = points.begin()->frame; | 188 // int useFrame = points.begin()->frame; |
189 | 189 |
190 // RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate()); | 190 // RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate()); |
191 | 191 |
192 QString text; | 192 QString text; |
193 /* | 193 /* |
194 if (points.begin()->label == "") { | 194 if (points.begin()->label == "") { |
195 text = QString(tr("Time:\t%1\nHeight:\t%2\nLabel:\t%3")) | 195 text = QString(tr("Time:\t%1\nHeight:\t%2\nLabel:\t%3")) |
196 .arg(rt.toText(true).c_str()) | 196 .arg(rt.toText(true).c_str()) |
197 .arg(points.begin()->height) | 197 .arg(points.begin()->height) |
198 .arg(points.begin()->label); | 198 .arg(points.begin()->label); |
199 } | 199 } |
200 | 200 |
201 pos = QPoint(v->getXForFrame(useFrame), | 201 pos = QPoint(v->getXForFrame(useFrame), |
202 getYForHeight(v, points.begin()->height)); | 202 getYForHeight(v, points.begin()->height)); |
203 */ | 203 */ |
204 return text; | 204 return text; |
205 } | 205 } |
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(LayerGeometryProvider *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); |
217 } | 217 } |
218 | 218 |
219 resolution = m_model->getResolution(); | 219 resolution = m_model->getResolution(); |
220 ImageModel::PointList points; | 220 ImageModel::PointList points; |
221 | 221 |
222 if (snap == SnapNeighbouring) { | 222 if (snap == SnapNeighbouring) { |
223 | 223 |
224 points = getLocalPoints(v, v->getXForFrame(frame), -1); | 224 points = getLocalPoints(v, v->getXForFrame(frame), -1); |
225 if (points.empty()) return false; | 225 if (points.empty()) return false; |
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 sv_frame_t 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 |
237 if (snap == SnapRight) { | 237 if (snap == SnapRight) { |
238 | 238 |
239 if (i->frame > frame) { | 239 if (i->frame > frame) { |
240 snapped = i->frame; | 240 snapped = i->frame; |
241 found = true; | 241 found = true; |
242 break; | 242 break; |
243 } | 243 } |
244 | 244 |
245 } else if (snap == SnapLeft) { | 245 } else if (snap == SnapLeft) { |
246 | 246 |
247 if (i->frame <= frame) { | 247 if (i->frame <= frame) { |
248 snapped = i->frame; | 248 snapped = i->frame; |
249 found = true; // don't break, as the next may be better | 249 found = true; // don't break, as the next may be better |
250 } else { | 250 } else { |
251 break; | 251 break; |
252 } | 252 } |
253 | 253 |
254 } else { // nearest | 254 } else { // nearest |
255 | 255 |
256 ImageModel::PointList::const_iterator j = i; | 256 ImageModel::PointList::const_iterator j = i; |
257 ++j; | 257 ++j; |
258 | 258 |
259 if (j == points.end()) { | 259 if (j == points.end()) { |
260 | 260 |
261 snapped = i->frame; | 261 snapped = i->frame; |
262 found = true; | 262 found = true; |
263 break; | 263 break; |
264 | 264 |
265 } else if (j->frame >= frame) { | 265 } else if (j->frame >= frame) { |
266 | 266 |
267 if (j->frame - frame < frame - i->frame) { | 267 if (j->frame - frame < frame - i->frame) { |
268 snapped = j->frame; | 268 snapped = j->frame; |
269 } else { | 269 } else { |
270 snapped = i->frame; | 270 snapped = i->frame; |
271 } | 271 } |
272 found = true; | 272 found = true; |
273 break; | 273 break; |
274 } | 274 } |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 frame = snapped; | 278 frame = snapped; |
279 return found; | 279 return found; |
280 } | 280 } |
314 paint.setPen(penColour); | 314 paint.setPen(penColour); |
315 paint.setBrush(brushColour); | 315 paint.setBrush(brushColour); |
316 paint.setRenderHint(QPainter::Antialiasing, true); | 316 paint.setRenderHint(QPainter::Antialiasing, true); |
317 | 317 |
318 for (ImageModel::PointList::const_iterator i = points.begin(); | 318 for (ImageModel::PointList::const_iterator i = points.begin(); |
319 i != points.end(); ++i) { | 319 i != points.end(); ++i) { |
320 | 320 |
321 const ImageModel::Point &p(*i); | 321 const ImageModel::Point &p(*i); |
322 | 322 |
323 int x = v->getXForFrame(p.frame); | 323 int x = v->getXForFrame(p.frame); |
324 | 324 |
325 int nx = x + 2000; | 325 int nx = x + 2000; |
326 ImageModel::PointList::const_iterator j = i; | 326 ImageModel::PointList::const_iterator j = i; |
327 ++j; | 327 ++j; |
328 if (j != points.end()) { | 328 if (j != points.end()) { |
557 ImageLayer::drawStart(LayerGeometryProvider *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; |
563 return; | 563 return; |
564 } | 564 } |
565 | 565 |
566 sv_frame_t 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(); |
603 | 603 |
604 if (dialog.exec() == QDialog::Accepted) { | 604 if (dialog.exec() == QDialog::Accepted) { |
605 | 605 |
606 checkAddSource(dialog.getImage()); | 606 checkAddSource(dialog.getImage()); |
607 | 607 |
608 ImageModel::ChangeImageCommand *command = | 608 ImageModel::ChangeImageCommand *command = |
609 new ImageModel::ChangeImageCommand | 609 new ImageModel::ChangeImageCommand |
610 (m_model, m_editingPoint, dialog.getImage(), dialog.getLabel()); | 610 (m_model, m_editingPoint, dialog.getImage(), dialog.getLabel()); |
611 m_editingCommand->addCommand(command); | 611 m_editingCommand->addCommand(command); |
612 } else { | 612 } else { |
613 m_editingCommand->deletePoint(m_editingPoint); | 613 m_editingCommand->deletePoint(m_editingPoint); |
614 } | 614 } |
615 | 615 |
616 finish(m_editingCommand); | 616 finish(m_editingCommand); |
650 m_editOrigin = e->pos(); | 650 m_editOrigin = e->pos(); |
651 m_editingPoint = *points.begin(); | 651 m_editingPoint = *points.begin(); |
652 m_originalPoint = m_editingPoint; | 652 m_originalPoint = m_editingPoint; |
653 | 653 |
654 if (m_editingCommand) { | 654 if (m_editingCommand) { |
655 finish(m_editingCommand); | 655 finish(m_editingCommand); |
656 m_editingCommand = 0; | 656 m_editingCommand = 0; |
657 } | 657 } |
658 | 658 |
659 m_editing = true; | 659 m_editing = true; |
660 } | 660 } |
661 | 661 |
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) { |
674 m_editingCommand = new ImageModel::EditCommand(m_model, tr("Move Image")); | 674 m_editingCommand = new ImageModel::EditCommand(m_model, tr("Move Image")); |
675 } | 675 } |
676 | 676 |
677 m_editingCommand->deletePoint(m_editingPoint); | 677 m_editingCommand->deletePoint(m_editingPoint); |
678 m_editingPoint.frame = frame; | 678 m_editingPoint.frame = frame; |
679 m_editingCommand->addPoint(m_editingPoint); | 679 m_editingCommand->addPoint(m_editingPoint); |
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) { |
689 finish(m_editingCommand); | 689 finish(m_editingCommand); |
690 } | 690 } |
691 | 691 |
692 m_editingCommand = 0; | 692 m_editingCommand = 0; |
693 m_editing = false; | 693 m_editing = false; |
694 } | 694 } |
710 | 710 |
711 if (dialog.exec() == QDialog::Accepted) { | 711 if (dialog.exec() == QDialog::Accepted) { |
712 | 712 |
713 checkAddSource(dialog.getImage()); | 713 checkAddSource(dialog.getImage()); |
714 | 714 |
715 ImageModel::ChangeImageCommand *command = | 715 ImageModel::ChangeImageCommand *command = |
716 new ImageModel::ChangeImageCommand | 716 new ImageModel::ChangeImageCommand |
717 (m_model, *points.begin(), dialog.getImage(), dialog.getLabel()); | 717 (m_model, *points.begin(), dialog.getImage(), dialog.getLabel()); |
718 | 718 |
719 CommandHistory::getInstance()->addCommand(command); | 719 CommandHistory::getInstance()->addCommand(command); |
720 } | 720 } |
721 | 721 |
726 ImageLayer::moveSelection(Selection s, sv_frame_t 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")); |
732 | 732 |
733 ImageModel::PointList points = | 733 ImageModel::PointList points = |
734 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 734 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
735 | 735 |
736 for (ImageModel::PointList::iterator i = points.begin(); | 736 for (ImageModel::PointList::iterator i = points.begin(); |
737 i != points.end(); ++i) { | 737 i != points.end(); ++i) { |
738 | 738 |
739 if (s.contains(i->frame)) { | 739 if (s.contains(i->frame)) { |
740 ImageModel::Point newPoint(*i); | 740 ImageModel::Point newPoint(*i); |
741 newPoint.frame = i->frame + newStartFrame - s.getStartFrame(); | 741 newPoint.frame = i->frame + newStartFrame - s.getStartFrame(); |
742 command->deletePoint(*i); | 742 command->deletePoint(*i); |
743 command->addPoint(newPoint); | 743 command->addPoint(newPoint); |
744 } | 744 } |
745 } | 745 } |
746 | 746 |
747 finish(command); | 747 finish(command); |
748 } | 748 } |
749 | 749 |
751 ImageLayer::resizeSelection(Selection s, Selection newSize) | 751 ImageLayer::resizeSelection(Selection s, Selection newSize) |
752 { | 752 { |
753 if (!m_model) return; | 753 if (!m_model) return; |
754 | 754 |
755 ImageModel::EditCommand *command = | 755 ImageModel::EditCommand *command = |
756 new ImageModel::EditCommand(m_model, tr("Resize Selection")); | 756 new ImageModel::EditCommand(m_model, tr("Resize Selection")); |
757 | 757 |
758 ImageModel::PointList points = | 758 ImageModel::PointList points = |
759 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 759 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
760 | 760 |
761 double ratio = | 761 double ratio = |
762 double(newSize.getEndFrame() - newSize.getStartFrame()) / | 762 double(newSize.getEndFrame() - newSize.getStartFrame()) / |
763 double(s.getEndFrame() - s.getStartFrame()); | 763 double(s.getEndFrame() - s.getStartFrame()); |
764 | 764 |
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 = double(i->frame); | 770 double target = double(i->frame); |
771 target = double(newSize.getStartFrame()) + | 771 target = double(newSize.getStartFrame()) + |
772 target - double(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); |
778 } | 778 } |
779 } | 779 } |
780 | 780 |
781 finish(command); | 781 finish(command); |
782 } | 782 } |
783 | 783 |
785 ImageLayer::deleteSelection(Selection s) | 785 ImageLayer::deleteSelection(Selection s) |
786 { | 786 { |
787 if (!m_model) return; | 787 if (!m_model) return; |
788 | 788 |
789 ImageModel::EditCommand *command = | 789 ImageModel::EditCommand *command = |
790 new ImageModel::EditCommand(m_model, tr("Delete Selection")); | 790 new ImageModel::EditCommand(m_model, tr("Delete Selection")); |
791 | 791 |
792 ImageModel::PointList points = | 792 ImageModel::PointList points = |
793 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); | 793 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); |
794 | 794 |
795 for (ImageModel::PointList::iterator i = points.begin(); | 795 for (ImageModel::PointList::iterator i = points.begin(); |
796 i != points.end(); ++i) { | 796 i != points.end(); ++i) { |
797 if (s.contains(i->frame)) command->deletePoint(*i); | 797 if (s.contains(i->frame)) command->deletePoint(*i); |
798 } | 798 } |
799 | 799 |
800 finish(command); | 800 finish(command); |
801 } | 801 } |
802 | 802 |
804 ImageLayer::copy(LayerGeometryProvider *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()); |
810 | 810 |
811 for (ImageModel::PointList::iterator i = points.begin(); | 811 for (ImageModel::PointList::iterator i = points.begin(); |
812 i != points.end(); ++i) { | 812 i != points.end(); ++i) { |
813 if (s.contains(i->frame)) { | 813 if (s.contains(i->frame)) { |
814 Clipboard::Point point(i->frame, i->label); | 814 Clipboard::Point point(i->frame, i->label); |
815 point.setReferenceFrame(alignToReference(v, i->frame)); | 815 point.setReferenceFrame(alignToReference(v, i->frame)); |
816 to.addPoint(point); | 816 to.addPoint(point); |
817 } | 817 } |
818 } | 818 } |
843 realign = true; | 843 realign = true; |
844 } | 844 } |
845 } | 845 } |
846 | 846 |
847 ImageModel::EditCommand *command = | 847 ImageModel::EditCommand *command = |
848 new ImageModel::EditCommand(m_model, tr("Paste")); | 848 new ImageModel::EditCommand(m_model, tr("Paste")); |
849 | 849 |
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; |
923 ImageLayer::checkAddSources() | 923 ImageLayer::checkAddSources() |
924 { | 924 { |
925 const ImageModel::PointList &points(m_model->getPoints()); | 925 const ImageModel::PointList &points(m_model->getPoints()); |
926 | 926 |
927 for (ImageModel::PointList::const_iterator i = points.begin(); | 927 for (ImageModel::PointList::const_iterator i = points.begin(); |
928 i != points.end(); ++i) { | 928 i != points.end(); ++i) { |
929 | 929 |
930 checkAddSource((*i).image); | 930 checkAddSource((*i).image); |
931 } | 931 } |
932 } | 932 } |
933 | 933 |