comparison layer/RegionLayer.cpp @ 1266:a34a2a25907c

Untabify
author Chris Cannam
date Thu, 01 Mar 2018 18:02:22 +0000
parents ee01a4062747
children d79e21855aef
comparison
equal deleted inserted replaced
1265:6e724c81f18f 1266:a34a2a25907c
136 if (deflt) *deflt = 0; 136 if (deflt) *deflt = 0;
137 137
138 val = m_colourMap; 138 val = m_colourMap;
139 139
140 } else if (name == "Plot Type") { 140 } else if (name == "Plot Type") {
141 141
142 if (min) *min = 0; 142 if (min) *min = 0;
143 if (max) *max = 1; 143 if (max) *max = 1;
144 if (deflt) *deflt = 0; 144 if (deflt) *deflt = 0;
145 145
146 val = int(m_plotStyle); 146 val = int(m_plotStyle);
147 147
148 } else if (name == "Vertical Scale") { 148 } else if (name == "Vertical Scale") {
149 149
150 if (min) *min = 0; 150 if (min) *min = 0;
151 if (max) *max = 3; 151 if (max) *max = 3;
152 if (deflt) *deflt = int(EqualSpaced); 152 if (deflt) *deflt = int(EqualSpaced);
153 153
154 val = int(m_verticalScale); 154 val = int(m_verticalScale);
155 155
156 } else if (name == "Scale Units") { 156 } else if (name == "Scale Units") {
157 157
158 if (deflt) *deflt = 0; 158 if (deflt) *deflt = 0;
159 if (m_model) { 159 if (m_model) {
161 (getScaleUnits()); 161 (getScaleUnits());
162 } 162 }
163 163
164 } else { 164 } else {
165 165
166 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); 166 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
167 } 167 }
168 168
169 return val; 169 return val;
170 } 170 }
171 171
175 { 175 {
176 if (name == "Colour" && m_plotStyle == PlotSegmentation) { 176 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
177 return ColourMapper::getColourMapName(value); 177 return ColourMapper::getColourMapName(value);
178 } else if (name == "Plot Type") { 178 } else if (name == "Plot Type") {
179 179
180 switch (value) { 180 switch (value) {
181 default: 181 default:
182 case 0: return tr("Bars"); 182 case 0: return tr("Bars");
183 case 1: return tr("Segmentation"); 183 case 1: return tr("Segmentation");
184 } 184 }
185 185
186 } else if (name == "Vertical Scale") { 186 } else if (name == "Vertical Scale") {
187 switch (value) { 187 switch (value) {
188 default: 188 default:
189 case 0: return tr("Auto-Align"); 189 case 0: return tr("Auto-Align");
190 case 1: return tr("Equal Spaced"); 190 case 1: return tr("Equal Spaced");
191 case 2: return tr("Linear"); 191 case 2: return tr("Linear");
192 case 3: return tr("Log"); 192 case 3: return tr("Log");
193 } 193 }
194 } 194 }
195 return SingleColourLayer::getPropertyValueLabel(name, value); 195 return SingleColourLayer::getPropertyValueLabel(name, value);
196 } 196 }
197 197
198 void 198 void
199 RegionLayer::setProperty(const PropertyName &name, int value) 199 RegionLayer::setProperty(const PropertyName &name, int value)
200 { 200 {
201 if (name == "Colour" && m_plotStyle == PlotSegmentation) { 201 if (name == "Colour" && m_plotStyle == PlotSegmentation) {
202 setFillColourMap(value); 202 setFillColourMap(value);
203 } else if (name == "Plot Type") { 203 } else if (name == "Plot Type") {
204 setPlotStyle(PlotStyle(value)); 204 setPlotStyle(PlotStyle(value));
205 } else if (name == "Vertical Scale") { 205 } else if (name == "Vertical Scale") {
206 setVerticalScale(VerticalScale(value)); 206 setVerticalScale(VerticalScale(value));
207 } else if (name == "Scale Units") { 207 } else if (name == "Scale Units") {
208 if (m_model) { 208 if (m_model) {
209 m_model->setScaleUnits 209 m_model->setScaleUnits
210 (UnitDatabase::getInstance()->getUnitById(value)); 210 (UnitDatabase::getInstance()->getUnitById(value));
211 emit modelChanged(); 211 emit modelChanged();
308 if (!m_model) return RegionModel::PointList(); 308 if (!m_model) return RegionModel::PointList();
309 309
310 sv_frame_t frame = v->getFrameForX(x); 310 sv_frame_t frame = v->getFrameForX(x);
311 311
312 RegionModel::PointList onPoints = 312 RegionModel::PointList onPoints =
313 m_model->getPoints(frame); 313 m_model->getPoints(frame);
314 314
315 if (!onPoints.empty()) { 315 if (!onPoints.empty()) {
316 return onPoints; 316 return onPoints;
317 } 317 }
318 318
319 RegionModel::PointList prevPoints = 319 RegionModel::PointList prevPoints =
320 m_model->getPreviousPoints(frame); 320 m_model->getPreviousPoints(frame);
321 RegionModel::PointList nextPoints = 321 RegionModel::PointList nextPoints =
322 m_model->getNextPoints(frame); 322 m_model->getNextPoints(frame);
323 323
324 RegionModel::PointList usePoints = prevPoints; 324 RegionModel::PointList usePoints = prevPoints;
325 325
326 if (prevPoints.empty()) { 326 if (prevPoints.empty()) {
327 usePoints = nextPoints; 327 usePoints = nextPoints;
328 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() && 328 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() &&
329 !(nextPoints.begin()->frame > v->getEndFrame())) { 329 !(nextPoints.begin()->frame > v->getEndFrame())) {
330 usePoints = nextPoints; 330 usePoints = nextPoints;
331 } else if (long(nextPoints.begin()->frame) - frame < 331 } else if (long(nextPoints.begin()->frame) - frame <
332 frame - long(prevPoints.begin()->frame)) { 332 frame - long(prevPoints.begin()->frame)) {
333 usePoints = nextPoints; 333 usePoints = nextPoints;
334 } 334 }
335 335
336 if (!usePoints.empty()) { 336 if (!usePoints.empty()) {
337 int fuzz = 2; 337 int fuzz = 2;
338 int px = v->getXForFrame(usePoints.begin()->frame); 338 int px = v->getXForFrame(usePoints.begin()->frame);
339 if ((px > x && px - x > fuzz) || 339 if ((px > x && px - x > fuzz) ||
340 (px < x && x - px > fuzz + 1)) { 340 (px < x && x - px > fuzz + 1)) {
341 usePoints.clear(); 341 usePoints.clear();
342 } 342 }
343 } 343 }
344 344
345 return usePoints; 345 return usePoints;
346 } 346 }
347 347
391 if (!m_model || !m_model->getSampleRate()) return ""; 391 if (!m_model || !m_model->getSampleRate()) return "";
392 392
393 RegionModel::PointList points = getLocalPoints(v, x); 393 RegionModel::PointList points = getLocalPoints(v, x);
394 394
395 if (points.empty()) { 395 if (points.empty()) {
396 if (!m_model->isReady()) { 396 if (!m_model->isReady()) {
397 return tr("In progress"); 397 return tr("In progress");
398 } else { 398 } else {
399 return tr("No local points"); 399 return tr("No local points");
400 } 400 }
401 } 401 }
402 402
403 RegionRec region(0); 403 RegionRec region(0);
404 RegionModel::PointList::iterator i; 404 RegionModel::PointList::iterator i;
405 405
406 //!!! harmonise with whatever decision is made about point y 406 //!!! harmonise with whatever decision is made about point y
407 //!!! coords in paint method 407 //!!! coords in paint method
408 408
409 for (i = points.begin(); i != points.end(); ++i) { 409 for (i = points.begin(); i != points.end(); ++i) {
410 410
411 int y = getYForValue(v, i->value); 411 int y = getYForValue(v, i->value);
412 int h = 3; 412 int h = 3;
413 413
414 if (m_model->getValueQuantization() != 0.0) { 414 if (m_model->getValueQuantization() != 0.0) {
415 h = y - getYForValue(v, i->value + m_model->getValueQuantization()); 415 h = y - getYForValue(v, i->value + m_model->getValueQuantization());
416 if (h < 3) h = 3; 416 if (h < 3) h = 3;
417 } 417 }
418 418
419 if (pos.y() >= y - h && pos.y() <= y) { 419 if (pos.y() >= y - h && pos.y() <= y) {
420 region = *i; 420 region = *i;
421 break; 421 break;
422 } 422 }
423 } 423 }
424 424
425 if (i == points.end()) return tr("No local points"); 425 if (i == points.end()) return tr("No local points");
426 426
427 RealTime rt = RealTime::frame2RealTime(region.frame, 427 RealTime rt = RealTime::frame2RealTime(region.frame,
428 m_model->getSampleRate()); 428 m_model->getSampleRate());
429 RealTime rd = RealTime::frame2RealTime(region.duration, 429 RealTime rd = RealTime::frame2RealTime(region.duration,
430 m_model->getSampleRate()); 430 m_model->getSampleRate());
431 431
432 QString valueText; 432 QString valueText;
433 433
434 valueText = tr("%1 %2").arg(region.value).arg(getScaleUnits()); 434 valueText = tr("%1 %2").arg(region.value).arg(getScaleUnits());
435 435
436 QString text; 436 QString text;
437 437
438 if (region.label == "") { 438 if (region.label == "") {
439 text = QString(tr("Time:\t%1\nValue:\t%2\nDuration:\t%3\nNo label")) 439 text = QString(tr("Time:\t%1\nValue:\t%2\nDuration:\t%3\nNo label"))
440 .arg(rt.toText(true).c_str()) 440 .arg(rt.toText(true).c_str())
441 .arg(valueText) 441 .arg(valueText)
442 .arg(rd.toText(true).c_str()); 442 .arg(rd.toText(true).c_str());
443 } else { 443 } else {
444 text = QString(tr("Time:\t%1\nValue:\t%2\nDuration:\t%3\nLabel:\t%4")) 444 text = QString(tr("Time:\t%1\nValue:\t%2\nDuration:\t%3\nLabel:\t%4"))
445 .arg(rt.toText(true).c_str()) 445 .arg(rt.toText(true).c_str())
446 .arg(valueText) 446 .arg(valueText)
447 .arg(rd.toText(true).c_str()) 447 .arg(rd.toText(true).c_str())
448 .arg(region.label); 448 .arg(region.label);
449 } 449 }
450 450
451 pos = QPoint(v->getXForFrame(region.frame), 451 pos = QPoint(v->getXForFrame(region.frame),
452 getYForValue(v, region.value)); 452 getYForValue(v, region.value));
453 return text; 453 return text;
454 } 454 }
455 455
456 bool 456 bool
457 RegionLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, 457 RegionLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
458 int &resolution, 458 int &resolution,
459 SnapType snap) const 459 SnapType snap) const
460 { 460 {
461 if (!m_model) { 461 if (!m_model) {
462 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 462 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
463 } 463 }
464 464
465 resolution = m_model->getResolution(); 465 resolution = m_model->getResolution();
466 RegionModel::PointList points; 466 RegionModel::PointList points;
467 467
468 if (snap == SnapNeighbouring) { 468 if (snap == SnapNeighbouring) {
469 469
470 points = getLocalPoints(v, v->getXForFrame(frame)); 470 points = getLocalPoints(v, v->getXForFrame(frame));
471 if (points.empty()) return false; 471 if (points.empty()) return false;
472 frame = points.begin()->frame; 472 frame = points.begin()->frame;
473 return true; 473 return true;
474 } 474 }
475 475
476 points = m_model->getPoints(frame, frame); 476 points = m_model->getPoints(frame, frame);
477 sv_frame_t snapped = frame; 477 sv_frame_t snapped = frame;
478 bool found = false; 478 bool found = false;
479 479
480 for (RegionModel::PointList::const_iterator i = points.begin(); 480 for (RegionModel::PointList::const_iterator i = points.begin();
481 i != points.end(); ++i) { 481 i != points.end(); ++i) {
482 482
483 if (snap == SnapRight) { 483 if (snap == SnapRight) {
484 484
485 // The best frame to snap to is the end frame of whichever 485 // The best frame to snap to is the end frame of whichever
486 // feature we would have snapped to the start frame of if 486 // feature we would have snapped to the start frame of if
487 // we had been snapping left. 487 // we had been snapping left.
488 488
489 if (i->frame <= frame) { 489 if (i->frame <= frame) {
490 if (i->frame + i->duration > frame) { 490 if (i->frame + i->duration > frame) {
491 snapped = i->frame + i->duration; 491 snapped = i->frame + i->duration;
492 found = true; // don't break, as the next may be better 492 found = true; // don't break, as the next may be better
493 } 493 }
494 } else { 494 } else {
497 found = true; 497 found = true;
498 } 498 }
499 break; 499 break;
500 } 500 }
501 501
502 } else if (snap == SnapLeft) { 502 } else if (snap == SnapLeft) {
503 503
504 if (i->frame <= frame) { 504 if (i->frame <= frame) {
505 snapped = i->frame; 505 snapped = i->frame;
506 found = true; // don't break, as the next may be better 506 found = true; // don't break, as the next may be better
507 } else { 507 } else {
508 break; 508 break;
509 } 509 }
510 510
511 } else { // nearest 511 } else { // nearest
512 512
513 RegionModel::PointList::const_iterator j = i; 513 RegionModel::PointList::const_iterator j = i;
514 ++j; 514 ++j;
515 515
516 if (j == points.end()) { 516 if (j == points.end()) {
517 517
518 snapped = i->frame; 518 snapped = i->frame;
519 found = true; 519 found = true;
520 break; 520 break;
521 521
522 } else if (j->frame >= frame) { 522 } else if (j->frame >= frame) {
523 523
524 if (j->frame - frame < frame - i->frame) { 524 if (j->frame - frame < frame - i->frame) {
525 snapped = j->frame; 525 snapped = j->frame;
526 } else { 526 } else {
527 snapped = i->frame; 527 snapped = i->frame;
528 } 528 }
529 found = true; 529 found = true;
530 break; 530 break;
531 } 531 }
532 } 532 }
533 } 533 }
534 534
535 frame = snapped; 535 frame = snapped;
536 return found; 536 return found;
537 } 537 }
540 RegionLayer::snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame, 540 RegionLayer::snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame,
541 int &resolution, 541 int &resolution,
542 SnapType snap) const 542 SnapType snap) const
543 { 543 {
544 if (!m_model) { 544 if (!m_model) {
545 return Layer::snapToSimilarFeature(v, frame, resolution, snap); 545 return Layer::snapToSimilarFeature(v, frame, resolution, snap);
546 } 546 }
547 547
548 resolution = m_model->getResolution(); 548 resolution = m_model->getResolution();
549 549
550 const RegionModel::PointList &points = m_model->getPoints(); 550 const RegionModel::PointList &points = m_model->getPoints();
584 i = points.begin(); 584 i = points.begin();
585 distant = true; 585 distant = true;
586 } 586 }
587 } 587 }
588 588
589 if (snap == SnapRight) { 589 if (snap == SnapRight) {
590 590
591 if (i->frame > matchframe && 591 if (i->frame > matchframe &&
592 fabs(i->value - matchvalue) < epsilon) { 592 fabs(i->value - matchvalue) < epsilon) {
593 snapped = i->frame; 593 snapped = i->frame;
594 found = true; 594 found = true;
595 break; 595 break;
596 } 596 }
597 597
598 } else if (snap == SnapLeft) { 598 } else if (snap == SnapLeft) {
599 599
600 if (i->frame < matchframe) { 600 if (i->frame < matchframe) {
601 if (fabs(i->value - matchvalue) < epsilon) { 601 if (fabs(i->value - matchvalue) < epsilon) {
602 snapped = i->frame; 602 snapped = i->frame;
603 found = true; // don't break, as the next may be better 603 found = true; // don't break, as the next may be better
604 } 604 }
605 } else if (found || distant) { 605 } else if (found || distant) {
606 break; 606 break;
607 } 607 }
608 608
609 } else { 609 } else {
610 // no other snap types supported 610 // no other snap types supported
611 } 611 }
612 612
613 ++i; 613 ++i;
614 } 614 }
615 615
616 frame = snapped; 616 frame = snapped;
887 887
888 QColor brushColour(getBaseQColor()); 888 QColor brushColour(getBaseQColor());
889 brushColour.setAlpha(80); 889 brushColour.setAlpha(80);
890 890
891 // SVDEBUG << "RegionLayer::paint: resolution is " 891 // SVDEBUG << "RegionLayer::paint: resolution is "
892 // << m_model->getResolution() << " frames" << endl; 892 // << m_model->getResolution() << " frames" << endl;
893 893
894 double min = m_model->getValueMinimum(); 894 double min = m_model->getValueMinimum();
895 double max = m_model->getValueMaximum(); 895 double max = m_model->getValueMaximum();
896 if (max == min) max = min + 1.0; 896 if (max == min) max = min + 1.0;
897 897
914 //!!! coord is never completely flat on the top or bottom 914 //!!! coord is never completely flat on the top or bottom
915 915
916 int fontHeight = paint.fontMetrics().height(); 916 int fontHeight = paint.fontMetrics().height();
917 917
918 for (RegionModel::PointList::const_iterator i = points.begin(); 918 for (RegionModel::PointList::const_iterator i = points.begin();
919 i != points.end(); ++i) { 919 i != points.end(); ++i) {
920 920
921 const RegionModel::Point &p(*i); 921 const RegionModel::Point &p(*i);
922 922
923 int x = v->getXForFrame(p.frame); 923 int x = v->getXForFrame(p.frame);
924 int y = getYForValue(v, p.value); 924 int y = getYForValue(v, p.value);
925 int w = v->getXForFrame(p.frame + p.duration) - x; 925 int w = v->getXForFrame(p.frame + p.duration) - x;
926 int h = 9; 926 int h = 9;
927 int ex = x + w; 927 int ex = x + w;
928 928
929 RegionModel::PointList::const_iterator j = i; 929 RegionModel::PointList::const_iterator j = i;
930 ++j; 930 ++j;
931 931
932 if (j != points.end()) { 932 if (j != points.end()) {
933 const RegionModel::Point &q(*j); 933 const RegionModel::Point &q(*j);
934 int nx = v->getXForFrame(q.frame); 934 int nx = v->getXForFrame(q.frame);
935 if (nx < ex) ex = nx; 935 if (nx < ex) ex = nx;
936 } 936 }
937 937
938 if (m_model->getValueQuantization() != 0.0) { 938 if (m_model->getValueQuantization() != 0.0) {
939 h = y - getYForValue(v, p.value + m_model->getValueQuantization()); 939 h = y - getYForValue(v, p.value + m_model->getValueQuantization());
940 if (h < 3) h = 3; 940 if (h < 3) h = 3;
941 } 941 }
942 942
943 if (w < 1) w = 1; 943 if (w < 1) w = 1;
944 944
945 if (m_plotStyle == PlotSegmentation) { 945 if (m_plotStyle == PlotSegmentation) {
946 paint.setPen(getForegroundQColor(v->getView())); 946 paint.setPen(getForegroundQColor(v->getView()));
947 paint.setBrush(getColourForValue(v, p.value)); 947 paint.setBrush(getColourForValue(v, p.value));
948 } else { 948 } else {
949 paint.setPen(getBaseQColor()); 949 paint.setPen(getBaseQColor());
950 paint.setBrush(brushColour); 950 paint.setBrush(brushColour);
951 } 951 }
952 952
953 if (m_plotStyle == PlotSegmentation) { 953 if (m_plotStyle == PlotSegmentation) {
954 954
955 if (ex <= x) continue; 955 if (ex <= x) continue;
956 956
957 if (!shouldIlluminate || 957 if (!shouldIlluminate ||
958 // "illuminatePoint != p" 958 // "illuminatePoint != p"
959 RegionModel::Point::Comparator()(illuminatePoint, p) || 959 RegionModel::Point::Comparator()(illuminatePoint, p) ||
960 RegionModel::Point::Comparator()(p, illuminatePoint)) { 960 RegionModel::Point::Comparator()(p, illuminatePoint)) {
965 965
966 } else { 966 } else {
967 paint.setPen(QPen(getForegroundQColor(v->getView()), 2)); 967 paint.setPen(QPen(getForegroundQColor(v->getView()), 2));
968 } 968 }
969 969
970 paint.drawRect(x, -1, ex - x, v->getPaintHeight() + 2); 970 paint.drawRect(x, -1, ex - x, v->getPaintHeight() + 2);
971 971
972 } else { 972 } else {
973 973
974 if (shouldIlluminate && 974 if (shouldIlluminate &&
975 // "illuminatePoint == p" 975 // "illuminatePoint == p"
976 !RegionModel::Point::Comparator()(illuminatePoint, p) && 976 !RegionModel::Point::Comparator()(illuminatePoint, p) &&
977 !RegionModel::Point::Comparator()(p, illuminatePoint)) { 977 !RegionModel::Point::Comparator()(p, illuminatePoint)) {
1003 1003
1004 int nextLabelMinX = -100; 1004 int nextLabelMinX = -100;
1005 int lastLabelY = 0; 1005 int lastLabelY = 0;
1006 1006
1007 for (RegionModel::PointList::const_iterator i = points.begin(); 1007 for (RegionModel::PointList::const_iterator i = points.begin();
1008 i != points.end(); ++i) { 1008 i != points.end(); ++i) {
1009 1009
1010 const RegionModel::Point &p(*i); 1010 const RegionModel::Point &p(*i);
1011 1011
1012 int x = v->getXForFrame(p.frame); 1012 int x = v->getXForFrame(p.frame);
1013 int y = getYForValue(v, p.value); 1013 int y = getYForValue(v, p.value);
1014 1014
1015 bool illuminated = false; 1015 bool illuminated = false;
1016 1016
1017 if (m_plotStyle != PlotSegmentation) { 1017 if (m_plotStyle != PlotSegmentation) {
1018 1018
1019 if (shouldIlluminate && 1019 if (shouldIlluminate &&
1020 // "illuminatePoint == p" 1020 // "illuminatePoint == p"
1021 !RegionModel::Point::Comparator()(illuminatePoint, p) && 1021 !RegionModel::Point::Comparator()(illuminatePoint, p) &&
1022 !RegionModel::Point::Comparator()(p, illuminatePoint)) { 1022 !RegionModel::Point::Comparator()(p, illuminatePoint)) {
1192 if (!m_model) return; 1192 if (!m_model) return;
1193 1193
1194 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; 1194 if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return;
1195 1195
1196 if (m_editingCommand) { 1196 if (m_editingCommand) {
1197 finish(m_editingCommand); 1197 finish(m_editingCommand);
1198 m_editingCommand = 0; 1198 m_editingCommand = 0;
1199 } 1199 }
1200 1200
1201 m_editing = true; 1201 m_editing = true;
1202 recalcSpacing(); 1202 recalcSpacing();
1203 } 1203 }
1242 m_dragPointY = getYForValue(v, m_editingPoint.value); 1242 m_dragPointY = getYForValue(v, m_editingPoint.value);
1243 1243
1244 m_originalPoint = m_editingPoint; 1244 m_originalPoint = m_editingPoint;
1245 1245
1246 if (m_editingCommand) { 1246 if (m_editingCommand) {
1247 finish(m_editingCommand); 1247 finish(m_editingCommand);
1248 m_editingCommand = 0; 1248 m_editingCommand = 0;
1249 } 1249 }
1250 1250
1251 m_editing = true; 1251 m_editing = true;
1252 m_dragStartX = e->x(); 1252 m_dragStartX = e->x();
1253 m_dragStartY = e->y(); 1253 m_dragStartY = e->y();
1276 if (m_distributionMap[m_editingPoint.value] > 1) avoid = -1; 1276 if (m_distributionMap[m_editingPoint.value] > 1) avoid = -1;
1277 1277
1278 double value = getValueForY(v, newy, avoid); 1278 double value = getValueForY(v, newy, avoid);
1279 1279
1280 if (!m_editingCommand) { 1280 if (!m_editingCommand) {
1281 m_editingCommand = new RegionModel::EditCommand(m_model, 1281 m_editingCommand = new RegionModel::EditCommand(m_model,
1282 tr("Drag Region")); 1282 tr("Drag Region"));
1283 } 1283 }
1284 1284
1285 m_editingCommand->deletePoint(m_editingPoint); 1285 m_editingCommand->deletePoint(m_editingPoint);
1286 m_editingPoint.frame = frame; 1286 m_editingPoint.frame = frame;
1287 m_editingPoint.value = float(value); 1287 m_editingPoint.value = float(value);
1294 { 1294 {
1295 if (!m_model || !m_editing) return; 1295 if (!m_model || !m_editing) return;
1296 1296
1297 if (m_editingCommand) { 1297 if (m_editingCommand) {
1298 1298
1299 QString newName = m_editingCommand->getName(); 1299 QString newName = m_editingCommand->getName();
1300 1300
1301 if (m_editingPoint.frame != m_originalPoint.frame) { 1301 if (m_editingPoint.frame != m_originalPoint.frame) {
1302 if (m_editingPoint.value != m_originalPoint.value) { 1302 if (m_editingPoint.value != m_originalPoint.value) {
1303 newName = tr("Edit Region"); 1303 newName = tr("Edit Region");
1304 } else { 1304 } else {
1305 newName = tr("Relocate Region"); 1305 newName = tr("Relocate Region");
1306 } 1306 }
1307 } else { 1307 } else {
1308 newName = tr("Change Point Value"); 1308 newName = tr("Change Point Value");
1309 } 1309 }
1310 1310
1311 m_editingCommand->setName(newName); 1311 m_editingCommand->setName(newName);
1312 finish(m_editingCommand); 1312 finish(m_editingCommand);
1313 } 1313 }
1314 1314
1315 m_editingCommand = 0; 1315 m_editingCommand = 0;
1316 m_editing = false; 1316 m_editing = false;
1317 recalcSpacing(); 1317 recalcSpacing();
1362 RegionLayer::moveSelection(Selection s, sv_frame_t newStartFrame) 1362 RegionLayer::moveSelection(Selection s, sv_frame_t newStartFrame)
1363 { 1363 {
1364 if (!m_model) return; 1364 if (!m_model) return;
1365 1365
1366 RegionModel::EditCommand *command = 1366 RegionModel::EditCommand *command =
1367 new RegionModel::EditCommand(m_model, tr("Drag Selection")); 1367 new RegionModel::EditCommand(m_model, tr("Drag Selection"));
1368 1368
1369 RegionModel::PointList points = 1369 RegionModel::PointList points =
1370 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1370 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1371 1371
1372 for (RegionModel::PointList::iterator i = points.begin(); 1372 for (RegionModel::PointList::iterator i = points.begin();
1373 i != points.end(); ++i) { 1373 i != points.end(); ++i) {
1374 1374
1375 if (s.contains(i->frame)) { 1375 if (s.contains(i->frame)) {
1376 RegionModel::Point newPoint(*i); 1376 RegionModel::Point newPoint(*i);
1377 newPoint.frame = i->frame + newStartFrame - s.getStartFrame(); 1377 newPoint.frame = i->frame + newStartFrame - s.getStartFrame();
1378 command->deletePoint(*i); 1378 command->deletePoint(*i);
1379 command->addPoint(newPoint); 1379 command->addPoint(newPoint);
1380 } 1380 }
1381 } 1381 }
1382 1382
1383 finish(command); 1383 finish(command);
1384 recalcSpacing(); 1384 recalcSpacing();
1385 } 1385 }
1388 RegionLayer::resizeSelection(Selection s, Selection newSize) 1388 RegionLayer::resizeSelection(Selection s, Selection newSize)
1389 { 1389 {
1390 if (!m_model) return; 1390 if (!m_model) return;
1391 1391
1392 RegionModel::EditCommand *command = 1392 RegionModel::EditCommand *command =
1393 new RegionModel::EditCommand(m_model, tr("Resize Selection")); 1393 new RegionModel::EditCommand(m_model, tr("Resize Selection"));
1394 1394
1395 RegionModel::PointList points = 1395 RegionModel::PointList points =
1396 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1396 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1397 1397
1398 double ratio = 1398 double ratio =
1399 double(newSize.getEndFrame() - newSize.getStartFrame()) / 1399 double(newSize.getEndFrame() - newSize.getStartFrame()) /
1400 double(s.getEndFrame() - s.getStartFrame()); 1400 double(s.getEndFrame() - s.getStartFrame());
1401 1401
1402 for (RegionModel::PointList::iterator i = points.begin(); 1402 for (RegionModel::PointList::iterator i = points.begin();
1403 i != points.end(); ++i) { 1403 i != points.end(); ++i) {
1404 1404
1405 if (s.contains(i->frame)) { 1405 if (s.contains(i->frame)) {
1406 1406
1407 double targetStart = double(i->frame); 1407 double targetStart = double(i->frame);
1408 targetStart = double(newSize.getStartFrame()) + 1408 targetStart = double(newSize.getStartFrame()) +
1409 targetStart - double(s.getStartFrame()) * ratio; 1409 targetStart - double(s.getStartFrame()) * ratio;
1410 1410
1411 double targetEnd = double(i->frame + i->duration); 1411 double targetEnd = double(i->frame + i->duration);
1412 targetEnd = double(newSize.getStartFrame()) + 1412 targetEnd = double(newSize.getStartFrame()) +
1413 targetEnd - double(s.getStartFrame()) * ratio; 1413 targetEnd - double(s.getStartFrame()) * ratio;
1414 1414
1415 RegionModel::Point newPoint(*i); 1415 RegionModel::Point newPoint(*i);
1416 newPoint.frame = lrint(targetStart); 1416 newPoint.frame = lrint(targetStart);
1417 newPoint.duration = lrint(targetEnd - targetStart); 1417 newPoint.duration = lrint(targetEnd - targetStart);
1418 command->deletePoint(*i); 1418 command->deletePoint(*i);
1419 command->addPoint(newPoint); 1419 command->addPoint(newPoint);
1420 } 1420 }
1421 } 1421 }
1422 1422
1423 finish(command); 1423 finish(command);
1424 recalcSpacing(); 1424 recalcSpacing();
1425 } 1425 }
1428 RegionLayer::deleteSelection(Selection s) 1428 RegionLayer::deleteSelection(Selection s)
1429 { 1429 {
1430 if (!m_model) return; 1430 if (!m_model) return;
1431 1431
1432 RegionModel::EditCommand *command = 1432 RegionModel::EditCommand *command =
1433 new RegionModel::EditCommand(m_model, tr("Delete Selected Points")); 1433 new RegionModel::EditCommand(m_model, tr("Delete Selected Points"));
1434 1434
1435 RegionModel::PointList points = 1435 RegionModel::PointList points =
1436 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1436 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1437 1437
1438 for (RegionModel::PointList::iterator i = points.begin(); 1438 for (RegionModel::PointList::iterator i = points.begin();
1439 i != points.end(); ++i) { 1439 i != points.end(); ++i) {
1440 1440
1441 if (s.contains(i->frame)) { 1441 if (s.contains(i->frame)) {
1442 command->deletePoint(*i); 1442 command->deletePoint(*i);
1443 } 1443 }
1444 } 1444 }
1451 RegionLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) 1451 RegionLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to)
1452 { 1452 {
1453 if (!m_model) return; 1453 if (!m_model) return;
1454 1454
1455 RegionModel::PointList points = 1455 RegionModel::PointList points =
1456 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 1456 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
1457 1457
1458 for (RegionModel::PointList::iterator i = points.begin(); 1458 for (RegionModel::PointList::iterator i = points.begin();
1459 i != points.end(); ++i) { 1459 i != points.end(); ++i) {
1460 if (s.contains(i->frame)) { 1460 if (s.contains(i->frame)) {
1461 Clipboard::Point point(i->frame, i->value, i->duration, i->label); 1461 Clipboard::Point point(i->frame, i->value, i->duration, i->label);
1462 point.setReferenceFrame(alignToReference(v, i->frame)); 1462 point.setReferenceFrame(alignToReference(v, i->frame));
1463 to.addPoint(point); 1463 to.addPoint(point);
1464 } 1464 }
1465 } 1465 }
1490 realign = true; 1490 realign = true;
1491 } 1491 }
1492 } 1492 }
1493 1493
1494 RegionModel::EditCommand *command = 1494 RegionModel::EditCommand *command =
1495 new RegionModel::EditCommand(m_model, tr("Paste")); 1495 new RegionModel::EditCommand(m_model, tr("Paste"));
1496 1496
1497 for (Clipboard::PointList::const_iterator i = points.begin(); 1497 for (Clipboard::PointList::const_iterator i = points.begin();
1498 i != points.end(); ++i) { 1498 i != points.end(); ++i) {
1499 1499
1500 if (!i->haveFrame()) continue; 1500 if (!i->haveFrame()) continue;
1561 { 1561 {
1562 SingleColourLayer::setProperties(attributes); 1562 SingleColourLayer::setProperties(attributes);
1563 1563
1564 bool ok; 1564 bool ok;
1565 VerticalScale scale = (VerticalScale) 1565 VerticalScale scale = (VerticalScale)
1566 attributes.value("verticalScale").toInt(&ok); 1566 attributes.value("verticalScale").toInt(&ok);
1567 if (ok) setVerticalScale(scale); 1567 if (ok) setVerticalScale(scale);
1568 PlotStyle style = (PlotStyle) 1568 PlotStyle style = (PlotStyle)
1569 attributes.value("plotStyle").toInt(&ok); 1569 attributes.value("plotStyle").toInt(&ok);
1570 if (ok) setPlotStyle(style); 1570 if (ok) setPlotStyle(style);
1571 } 1571 }
1572 1572
1573 1573