comparison layer/TimeInstantLayer.cpp @ 1324:13d9b422f7fe zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:31 +0100
parents 61418c112281
children c39f2d439d59
comparison
equal deleted inserted replaced
1183:57d192e26331 1324:13d9b422f7fe
99 int *min, int *max, int *deflt) const 99 int *min, int *max, int *deflt) const
100 { 100 {
101 int val = 0; 101 int val = 0;
102 102
103 if (name == "Plot Type") { 103 if (name == "Plot Type") {
104 104
105 if (min) *min = 0; 105 if (min) *min = 0;
106 if (max) *max = 1; 106 if (max) *max = 1;
107 if (deflt) *deflt = 0; 107 if (deflt) *deflt = 0;
108 108
109 val = int(m_plotStyle); 109 val = int(m_plotStyle);
110 110
111 } else { 111 } else {
112 112
113 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); 113 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
114 } 114 }
115 115
116 return val; 116 return val;
117 } 117 }
118 118
119 QString 119 QString
120 TimeInstantLayer::getPropertyValueLabel(const PropertyName &name, 120 TimeInstantLayer::getPropertyValueLabel(const PropertyName &name,
121 int value) const 121 int value) const
122 { 122 {
123 if (name == "Plot Type") { 123 if (name == "Plot Type") {
124 switch (value) { 124 switch (value) {
125 default: 125 default:
126 case 0: return tr("Instants"); 126 case 0: return tr("Instants");
127 case 1: return tr("Segmentation"); 127 case 1: return tr("Segmentation");
128 } 128 }
129 } 129 }
130 return SingleColourLayer::getPropertyValueLabel(name, value); 130 return SingleColourLayer::getPropertyValueLabel(name, value);
131 } 131 }
132 132
133 void 133 void
134 TimeInstantLayer::setProperty(const PropertyName &name, int value) 134 TimeInstantLayer::setProperty(const PropertyName &name, int value)
135 { 135 {
136 if (name == "Plot Type") { 136 if (name == "Plot Type") {
137 setPlotStyle(PlotStyle(value)); 137 setPlotStyle(PlotStyle(value));
138 } else { 138 } else {
139 SingleColourLayer::setProperty(name, value); 139 SingleColourLayer::setProperty(name, value);
140 } 140 }
141 } 141 }
142 142
165 if (!m_model) return SparseOneDimensionalModel::PointList(); 165 if (!m_model) return SparseOneDimensionalModel::PointList();
166 166
167 sv_frame_t frame = v->getFrameForX(x); 167 sv_frame_t frame = v->getFrameForX(x);
168 168
169 SparseOneDimensionalModel::PointList onPoints = 169 SparseOneDimensionalModel::PointList onPoints =
170 m_model->getPoints(frame); 170 m_model->getPoints(frame);
171 171
172 if (!onPoints.empty()) { 172 if (!onPoints.empty()) {
173 return onPoints; 173 return onPoints;
174 } 174 }
175 175
176 SparseOneDimensionalModel::PointList prevPoints = 176 SparseOneDimensionalModel::PointList prevPoints =
177 m_model->getPreviousPoints(frame); 177 m_model->getPreviousPoints(frame);
178 SparseOneDimensionalModel::PointList nextPoints = 178 SparseOneDimensionalModel::PointList nextPoints =
179 m_model->getNextPoints(frame); 179 m_model->getNextPoints(frame);
180 180
181 SparseOneDimensionalModel::PointList usePoints = prevPoints; 181 SparseOneDimensionalModel::PointList usePoints = prevPoints;
182 182
183 if (prevPoints.empty()) { 183 if (prevPoints.empty()) {
184 usePoints = nextPoints; 184 usePoints = nextPoints;
185 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() && 185 } else if (long(prevPoints.begin()->frame) < v->getStartFrame() &&
186 !(nextPoints.begin()->frame > v->getEndFrame())) { 186 !(nextPoints.begin()->frame > v->getEndFrame())) {
187 usePoints = nextPoints; 187 usePoints = nextPoints;
188 } else if (nextPoints.begin()->frame - frame < 188 } else if (nextPoints.begin()->frame - frame <
189 frame - prevPoints.begin()->frame) { 189 frame - prevPoints.begin()->frame) {
190 usePoints = nextPoints; 190 usePoints = nextPoints;
191 } 191 }
192 192
193 if (!usePoints.empty()) { 193 if (!usePoints.empty()) {
194 int fuzz = 2; 194 int fuzz = 2;
195 int px = v->getXForFrame(usePoints.begin()->frame); 195 int px = v->getXForFrame(usePoints.begin()->frame);
196 if ((px > x && px - x > fuzz) || 196 if ((px > x && px - x > fuzz) ||
197 (px < x && x - px > fuzz + 1)) { 197 (px < x && x - px > fuzz + 1)) {
198 usePoints.clear(); 198 usePoints.clear();
199 } 199 }
200 } 200 }
201 201
202 return usePoints; 202 return usePoints;
203 } 203 }
204 204
222 if (!m_model || !m_model->getSampleRate()) return ""; 222 if (!m_model || !m_model->getSampleRate()) return "";
223 223
224 SparseOneDimensionalModel::PointList points = getLocalPoints(v, x); 224 SparseOneDimensionalModel::PointList points = getLocalPoints(v, x);
225 225
226 if (points.empty()) { 226 if (points.empty()) {
227 if (!m_model->isReady()) { 227 if (!m_model->isReady()) {
228 return tr("In progress"); 228 return tr("In progress");
229 } else { 229 } else {
230 return tr("No local points"); 230 return tr("No local points");
231 } 231 }
232 } 232 }
233 233
234 sv_frame_t useFrame = points.begin()->frame; 234 sv_frame_t useFrame = points.begin()->frame;
235 235
236 RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate()); 236 RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate());
237 237
238 QString text; 238 QString text;
239 239
240 if (points.begin()->label == "") { 240 if (points.begin()->label == "") {
241 text = QString(tr("Time:\t%1\nNo label")) 241 text = QString(tr("Time:\t%1\nNo label"))
242 .arg(rt.toText(true).c_str()); 242 .arg(rt.toText(true).c_str());
243 } else { 243 } else {
244 text = QString(tr("Time:\t%1\nLabel:\t%2")) 244 text = QString(tr("Time:\t%1\nLabel:\t%2"))
245 .arg(rt.toText(true).c_str()) 245 .arg(rt.toText(true).c_str())
246 .arg(points.begin()->label); 246 .arg(points.begin()->label);
247 } 247 }
248 248
249 pos = QPoint(v->getXForFrame(useFrame), pos.y()); 249 pos = QPoint(v->getXForFrame(useFrame), pos.y());
250 return text; 250 return text;
251 } 251 }
252 252
253 bool 253 bool
254 TimeInstantLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, 254 TimeInstantLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
255 int &resolution, 255 int &resolution,
256 SnapType snap) const 256 SnapType snap) const
257 { 257 {
258 if (!m_model) { 258 if (!m_model) {
259 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 259 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
260 } 260 }
261 261
262 resolution = m_model->getResolution(); 262 resolution = m_model->getResolution();
263 SparseOneDimensionalModel::PointList points; 263 SparseOneDimensionalModel::PointList points;
264 264
265 if (snap == SnapNeighbouring) { 265 if (snap == SnapNeighbouring) {
266 266
267 points = getLocalPoints(v, v->getXForFrame(frame)); 267 points = getLocalPoints(v, v->getXForFrame(frame));
268 if (points.empty()) return false; 268 if (points.empty()) return false;
269 frame = points.begin()->frame; 269 frame = points.begin()->frame;
270 return true; 270 return true;
271 } 271 }
272 272
273 points = m_model->getPoints(frame, frame); 273 points = m_model->getPoints(frame, frame);
274 sv_frame_t snapped = frame; 274 sv_frame_t snapped = frame;
275 bool found = false; 275 bool found = false;
276 276
277 for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin(); 277 for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin();
278 i != points.end(); ++i) { 278 i != points.end(); ++i) {
279 279
280 if (snap == SnapRight) { 280 if (snap == SnapRight) {
281 281
282 if (i->frame >= frame) { 282 if (i->frame >= frame) {
283 snapped = i->frame; 283 snapped = i->frame;
284 found = true; 284 found = true;
285 break; 285 break;
286 } 286 }
287 287
288 } else if (snap == SnapLeft) { 288 } else if (snap == SnapLeft) {
289 289
290 if (i->frame <= frame) { 290 if (i->frame <= frame) {
291 snapped = i->frame; 291 snapped = i->frame;
292 found = true; // don't break, as the next may be better 292 found = true; // don't break, as the next may be better
293 } else { 293 } else {
294 break; 294 break;
295 } 295 }
296 296
297 } else { // nearest 297 } else { // nearest
298 298
299 SparseOneDimensionalModel::PointList::const_iterator j = i; 299 SparseOneDimensionalModel::PointList::const_iterator j = i;
300 ++j; 300 ++j;
301 301
302 if (j == points.end()) { 302 if (j == points.end()) {
303 303
304 snapped = i->frame; 304 snapped = i->frame;
305 found = true; 305 found = true;
306 break; 306 break;
307 307
308 } else if (j->frame >= frame) { 308 } else if (j->frame >= frame) {
309 309
310 if (j->frame - frame < frame - i->frame) { 310 if (j->frame - frame < frame - i->frame) {
311 snapped = j->frame; 311 snapped = j->frame;
312 } else { 312 } else {
313 snapped = i->frame; 313 snapped = i->frame;
314 } 314 }
315 found = true; 315 found = true;
316 break; 316 break;
317 } 317 }
318 } 318 }
319 } 319 }
320 320
321 frame = snapped; 321 frame = snapped;
322 return found; 322 return found;
323 } 323 }
333 333
334 sv_frame_t frame0 = v->getFrameForX(x0); 334 sv_frame_t frame0 = v->getFrameForX(x0);
335 sv_frame_t frame1 = v->getFrameForX(x1); 335 sv_frame_t frame1 = v->getFrameForX(x1);
336 336
337 SparseOneDimensionalModel::PointList points(m_model->getPoints 337 SparseOneDimensionalModel::PointList points(m_model->getPoints
338 (frame0, frame1)); 338 (frame0, frame1));
339 339
340 bool odd = false; 340 bool odd = false;
341 if (m_plotStyle == PlotSegmentation && !points.empty()) { 341 if (m_plotStyle == PlotSegmentation && !points.empty()) {
342 int index = m_model->getIndexOf(*points.begin()); 342 int index = m_model->getIndexOf(*points.begin());
343 odd = ((index % 2) == 1); 343 odd = ((index % 2) == 1);
344 } 344 }
345 345
346 paint.setPen(getBaseQColor()); 346 paint.setPen(getBaseQColor());
347 347
348 QColor brushColour(getBaseQColor()); 348 QColor brushColour(getBaseQColor());
349 brushColour.setAlpha(100); 349 brushColour.setAlpha(100);
350 paint.setBrush(brushColour); 350 paint.setBrush(brushColour);
351 351
352 QColor oddBrushColour(brushColour); 352 QColor oddBrushColour(brushColour);
353 if (m_plotStyle == PlotSegmentation) { 353 if (m_plotStyle == PlotSegmentation) {
354 if (getBaseQColor() == Qt::black) { 354 if (getBaseQColor() == Qt::black) {
355 oddBrushColour = Qt::gray; 355 oddBrushColour = Qt::gray;
356 } else if (getBaseQColor() == Qt::darkRed) { 356 } else if (getBaseQColor() == Qt::darkRed) {
357 oddBrushColour = Qt::red; 357 oddBrushColour = Qt::red;
358 } else if (getBaseQColor() == Qt::darkBlue) { 358 } else if (getBaseQColor() == Qt::darkBlue) {
359 oddBrushColour = Qt::blue; 359 oddBrushColour = Qt::blue;
360 } else if (getBaseQColor() == Qt::darkGreen) { 360 } else if (getBaseQColor() == Qt::darkGreen) {
361 oddBrushColour = Qt::green; 361 oddBrushColour = Qt::green;
362 } else { 362 } else {
363 oddBrushColour = oddBrushColour.light(150); 363 oddBrushColour = oddBrushColour.light(150);
364 } 364 }
365 oddBrushColour.setAlpha(100); 365 oddBrushColour.setAlpha(100);
366 } 366 }
367 367
368 // SVDEBUG << "TimeInstantLayer::paint: resolution is " 368 // SVDEBUG << "TimeInstantLayer::paint: resolution is "
369 // << m_model->getResolution() << " frames" << endl; 369 // << m_model->getResolution() << " frames" << endl;
370 370
371 QPoint localPos; 371 QPoint localPos;
372 sv_frame_t illuminateFrame = -1; 372 sv_frame_t illuminateFrame = -1;
373 373
374 if (v->shouldIlluminateLocalFeatures(this, localPos)) { 374 if (v->shouldIlluminateLocalFeatures(this, localPos)) {
375 SparseOneDimensionalModel::PointList localPoints = 375 SparseOneDimensionalModel::PointList localPoints =
376 getLocalPoints(v, localPos.x()); 376 getLocalPoints(v, localPos.x());
377 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame; 377 if (!localPoints.empty()) illuminateFrame = localPoints.begin()->frame;
378 } 378 }
379 379
380 int prevX = -1; 380 int prevX = -1;
381 int textY = v->getTextLabelHeight(this, paint); 381 int textY = v->getTextLabelHeight(this, paint);
382 382
383 for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin(); 383 for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin();
384 i != points.end(); ++i) { 384 i != points.end(); ++i) {
385 385
386 const SparseOneDimensionalModel::Point &p(*i); 386 const SparseOneDimensionalModel::Point &p(*i);
387 SparseOneDimensionalModel::PointList::const_iterator j = i; 387 SparseOneDimensionalModel::PointList::const_iterator j = i;
388 ++j; 388 ++j;
389 389
390 int x = v->getXForFrame(p.frame); 390 int x = v->getXForFrame(p.frame);
391 if (x == prevX && m_plotStyle == PlotInstants && 391 if (x == prevX && m_plotStyle == PlotInstants &&
392 p.frame != illuminateFrame) continue; 392 p.frame != illuminateFrame) continue;
393 393
394 int iw = v->getXForFrame(p.frame + m_model->getResolution()) - x; 394 int iw = v->getXForFrame(p.frame + m_model->getResolution()) - x;
395 if (iw < 2) { 395 if (iw < 2) {
396 if (iw < 1) { 396 if (iw < 1) {
397 iw = 2; 397 iw = 2;
398 if (j != points.end()) { 398 if (j != points.end()) {
399 int nx = v->getXForFrame(j->frame); 399 int nx = v->getXForFrame(j->frame);
400 if (nx < x + 3) iw = 1; 400 if (nx < x + 3) iw = 1;
401 } 401 }
402 } else { 402 } else {
403 iw = 2; 403 iw = 2;
404 } 404 }
405 } 405 }
406 406
407 if (p.frame == illuminateFrame) { 407 if (p.frame == illuminateFrame) {
408 paint.setPen(getForegroundQColor(v->getView())); 408 paint.setPen(getForegroundQColor(v->getView()));
409 } else { 409 } else {
410 paint.setPen(brushColour); 410 paint.setPen(brushColour);
411 } 411 }
412 412
413 if (m_plotStyle == PlotInstants) { 413 if (m_plotStyle == PlotInstants) {
414 if (iw > 1) { 414 if (iw > 1) {
415 paint.drawRect(x, 0, iw - 1, v->getPaintHeight() - 1); 415 paint.drawRect(x, 0, iw - 1, v->getPaintHeight() - 1);
416 } else { 416 } else {
417 paint.drawLine(x, 0, x, v->getPaintHeight() - 1); 417 paint.drawLine(x, 0, x, v->getPaintHeight() - 1);
418 } 418 }
419 } else { 419 } else {
420 420
421 if (odd) paint.setBrush(oddBrushColour); 421 if (odd) paint.setBrush(oddBrushColour);
422 else paint.setBrush(brushColour); 422 else paint.setBrush(brushColour);
423 423
424 int nx; 424 int nx;
425 425
426 if (j != points.end()) { 426 if (j != points.end()) {
427 const SparseOneDimensionalModel::Point &q(*j); 427 const SparseOneDimensionalModel::Point &q(*j);
428 nx = v->getXForFrame(q.frame); 428 nx = v->getXForFrame(q.frame);
429 } else { 429 } else {
430 nx = v->getXForFrame(m_model->getEndFrame()); 430 nx = v->getXForFrame(m_model->getEndFrame());
431 } 431 }
432 432
433 if (nx >= x) { 433 if (nx >= x) {
434 434
435 if (illuminateFrame != p.frame && 435 if (illuminateFrame != p.frame &&
436 (nx < x + 5 || x >= v->getPaintWidth() - 1)) { 436 (nx < x + 5 || x >= v->getPaintWidth() - 1)) {
437 paint.setPen(Qt::NoPen); 437 paint.setPen(Qt::NoPen);
438 } 438 }
439 439
440 paint.drawRect(x, -1, nx - x, v->getPaintHeight() + 1); 440 paint.drawRect(x, -1, nx - x, v->getPaintHeight() + 1);
441 } 441 }
442 442
443 odd = !odd; 443 odd = !odd;
444 } 444 }
445 445
446 paint.setPen(getBaseQColor()); 446 paint.setPen(getBaseQColor());
447 447
448 if (p.label != "") { 448 if (p.label != "") {
449 449
450 // only draw if there's enough room from here to the next point 450 // only draw if there's enough room from here to the next point
451 451
452 int lw = paint.fontMetrics().width(p.label); 452 int lw = paint.fontMetrics().width(p.label);
453 bool good = true; 453 bool good = true;
454 454
455 if (j != points.end()) { 455 if (j != points.end()) {
456 int nx = v->getXForFrame(j->frame); 456 int nx = v->getXForFrame(j->frame);
457 if (nx >= x && nx - x - iw - 3 <= lw) good = false; 457 if (nx >= x && nx - x - iw - 3 <= lw) good = false;
458 } 458 }
459 459
460 if (good) { 460 if (good) {
461 PaintAssistant::drawVisibleText(v, paint, x + iw + 2, textY, p.label, PaintAssistant::OutlinedText); 461 PaintAssistant::drawVisibleText(v, paint,
462 // paint.drawText(x + iw + 2, textY, p.label); 462 x + iw + 2, textY,
463 } 463 p.label,
464 } 464 PaintAssistant::OutlinedText);
465 465 }
466 prevX = x; 466 }
467
468 prevX = x;
467 } 469 }
468 } 470 }
469 471
470 void 472 void
471 TimeInstantLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) 473 TimeInstantLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e)
482 484
483 m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point")); 485 m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point"));
484 486
485 if (m_editingCommand) finish(m_editingCommand); 487 if (m_editingCommand) finish(m_editingCommand);
486 m_editingCommand = new SparseOneDimensionalModel::EditCommand(m_model, 488 m_editingCommand = new SparseOneDimensionalModel::EditCommand(m_model,
487 tr("Draw Point")); 489 tr("Draw Point"));
488 m_editingCommand->addPoint(m_editingPoint); 490 m_editingCommand->addPoint(m_editingPoint);
489 491
490 m_editing = true; 492 m_editing = true;
491 } 493 }
492 494
513 #ifdef DEBUG_TIME_INSTANT_LAYER 515 #ifdef DEBUG_TIME_INSTANT_LAYER
514 cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << endl; 516 cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << endl;
515 #endif 517 #endif
516 if (!m_model || !m_editing) return; 518 if (!m_model || !m_editing) return;
517 QString newName = tr("Add Point at %1 s") 519 QString newName = tr("Add Point at %1 s")
518 .arg(RealTime::frame2RealTime(m_editingPoint.frame, 520 .arg(RealTime::frame2RealTime(m_editingPoint.frame,
519 m_model->getSampleRate()) 521 m_model->getSampleRate())
520 .toText(false).c_str()); 522 .toText(false).c_str());
521 m_editingCommand->setName(newName); 523 m_editingCommand->setName(newName);
522 finish(m_editingCommand); 524 finish(m_editingCommand);
523 m_editingCommand = 0; 525 m_editingCommand = 0;
524 m_editing = false; 526 m_editing = false;
525 } 527 }
533 if (points.empty()) return; 535 if (points.empty()) return;
534 536
535 m_editingPoint = *points.begin(); 537 m_editingPoint = *points.begin();
536 538
537 if (m_editingCommand) { 539 if (m_editingCommand) {
538 finish(m_editingCommand); 540 finish(m_editingCommand);
539 m_editingCommand = 0; 541 m_editingCommand = 0;
540 } 542 }
541 543
542 m_editing = true; 544 m_editing = true;
543 } 545 }
544 546
581 if (points.empty()) return; 583 if (points.empty()) return;
582 584
583 m_editingPoint = *points.begin(); 585 m_editingPoint = *points.begin();
584 586
585 if (m_editingCommand) { 587 if (m_editingCommand) {
586 finish(m_editingCommand); 588 finish(m_editingCommand);
587 m_editingCommand = 0; 589 m_editingCommand = 0;
588 } 590 }
589 591
590 m_editing = true; 592 m_editing = true;
591 } 593 }
592 594
602 sv_frame_t frame = v->getFrameForX(e->x()); 604 sv_frame_t frame = v->getFrameForX(e->x());
603 if (frame < 0) frame = 0; 605 if (frame < 0) frame = 0;
604 frame = frame / m_model->getResolution() * m_model->getResolution(); 606 frame = frame / m_model->getResolution() * m_model->getResolution();
605 607
606 if (!m_editingCommand) { 608 if (!m_editingCommand) {
607 m_editingCommand = new SparseOneDimensionalModel::EditCommand(m_model, 609 m_editingCommand = new SparseOneDimensionalModel::EditCommand(m_model,
608 tr("Drag Point")); 610 tr("Drag Point"));
609 } 611 }
610 612
611 m_editingCommand->deletePoint(m_editingPoint); 613 m_editingCommand->deletePoint(m_editingPoint);
612 m_editingPoint.frame = frame; 614 m_editingPoint.frame = frame;
613 m_editingCommand->addPoint(m_editingPoint); 615 m_editingCommand->addPoint(m_editingPoint);
619 #ifdef DEBUG_TIME_INSTANT_LAYER 621 #ifdef DEBUG_TIME_INSTANT_LAYER
620 cerr << "TimeInstantLayer::editEnd(" << e->x() << ")" << endl; 622 cerr << "TimeInstantLayer::editEnd(" << e->x() << ")" << endl;
621 #endif 623 #endif
622 if (!m_model || !m_editing) return; 624 if (!m_model || !m_editing) return;
623 if (m_editingCommand) { 625 if (m_editingCommand) {
624 QString newName = tr("Move Point to %1 s") 626 QString newName = tr("Move Point to %1 s")
625 .arg(RealTime::frame2RealTime(m_editingPoint.frame, 627 .arg(RealTime::frame2RealTime(m_editingPoint.frame,
626 m_model->getSampleRate()) 628 m_model->getSampleRate())
627 .toText(false).c_str()); 629 .toText(false).c_str());
628 m_editingCommand->setName(newName); 630 m_editingCommand->setName(newName);
629 finish(m_editingCommand); 631 finish(m_editingCommand);
630 } 632 }
631 m_editingCommand = 0; 633 m_editingCommand = 0;
632 m_editing = false; 634 m_editing = false;
633 } 635 }
634 636
671 TimeInstantLayer::moveSelection(Selection s, sv_frame_t newStartFrame) 673 TimeInstantLayer::moveSelection(Selection s, sv_frame_t newStartFrame)
672 { 674 {
673 if (!m_model) return; 675 if (!m_model) return;
674 676
675 SparseOneDimensionalModel::EditCommand *command = 677 SparseOneDimensionalModel::EditCommand *command =
676 new SparseOneDimensionalModel::EditCommand(m_model, 678 new SparseOneDimensionalModel::EditCommand(m_model,
677 tr("Drag Selection")); 679 tr("Drag Selection"));
678 680
679 SparseOneDimensionalModel::PointList points = 681 SparseOneDimensionalModel::PointList points =
680 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 682 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
681 683
682 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); 684 for (SparseOneDimensionalModel::PointList::iterator i = points.begin();
683 i != points.end(); ++i) { 685 i != points.end(); ++i) {
684 686
685 if (s.contains(i->frame)) { 687 if (s.contains(i->frame)) {
686 SparseOneDimensionalModel::Point newPoint(*i); 688 SparseOneDimensionalModel::Point newPoint(*i);
687 newPoint.frame = i->frame + newStartFrame - s.getStartFrame(); 689 newPoint.frame = i->frame + newStartFrame - s.getStartFrame();
688 command->deletePoint(*i); 690 command->deletePoint(*i);
689 command->addPoint(newPoint); 691 command->addPoint(newPoint);
690 } 692 }
691 } 693 }
692 694
693 finish(command); 695 finish(command);
694 } 696 }
695 697
697 TimeInstantLayer::resizeSelection(Selection s, Selection newSize) 699 TimeInstantLayer::resizeSelection(Selection s, Selection newSize)
698 { 700 {
699 if (!m_model) return; 701 if (!m_model) return;
700 702
701 SparseOneDimensionalModel::EditCommand *command = 703 SparseOneDimensionalModel::EditCommand *command =
702 new SparseOneDimensionalModel::EditCommand(m_model, 704 new SparseOneDimensionalModel::EditCommand(m_model,
703 tr("Resize Selection")); 705 tr("Resize Selection"));
704 706
705 SparseOneDimensionalModel::PointList points = 707 SparseOneDimensionalModel::PointList points =
706 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 708 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
707 709
708 double ratio = 710 double ratio =
709 double(newSize.getEndFrame() - newSize.getStartFrame()) / 711 double(newSize.getEndFrame() - newSize.getStartFrame()) /
710 double(s.getEndFrame() - s.getStartFrame()); 712 double(s.getEndFrame() - s.getStartFrame());
711 713
712 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); 714 for (SparseOneDimensionalModel::PointList::iterator i = points.begin();
713 i != points.end(); ++i) { 715 i != points.end(); ++i) {
714 716
715 if (s.contains(i->frame)) { 717 if (s.contains(i->frame)) {
716 718
717 double target = double(i->frame); 719 double target = double(i->frame);
718 target = double(newSize.getStartFrame()) + 720 target = double(newSize.getStartFrame()) +
719 target - double(s.getStartFrame()) * ratio; 721 target - double(s.getStartFrame()) * ratio;
720 722
721 SparseOneDimensionalModel::Point newPoint(*i); 723 SparseOneDimensionalModel::Point newPoint(*i);
722 newPoint.frame = lrint(target); 724 newPoint.frame = lrint(target);
723 command->deletePoint(*i); 725 command->deletePoint(*i);
724 command->addPoint(newPoint); 726 command->addPoint(newPoint);
725 } 727 }
726 } 728 }
727 729
728 finish(command); 730 finish(command);
729 } 731 }
730 732
732 TimeInstantLayer::deleteSelection(Selection s) 734 TimeInstantLayer::deleteSelection(Selection s)
733 { 735 {
734 if (!m_model) return; 736 if (!m_model) return;
735 737
736 SparseOneDimensionalModel::EditCommand *command = 738 SparseOneDimensionalModel::EditCommand *command =
737 new SparseOneDimensionalModel::EditCommand(m_model, 739 new SparseOneDimensionalModel::EditCommand(m_model,
738 tr("Delete Selection")); 740 tr("Delete Selection"));
739 741
740 SparseOneDimensionalModel::PointList points = 742 SparseOneDimensionalModel::PointList points =
741 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 743 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
742 744
743 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); 745 for (SparseOneDimensionalModel::PointList::iterator i = points.begin();
744 i != points.end(); ++i) { 746 i != points.end(); ++i) {
745 if (s.contains(i->frame)) command->deletePoint(*i); 747 if (s.contains(i->frame)) command->deletePoint(*i);
746 } 748 }
747 749
748 finish(command); 750 finish(command);
749 } 751 }
750 752
752 TimeInstantLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) 754 TimeInstantLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to)
753 { 755 {
754 if (!m_model) return; 756 if (!m_model) return;
755 757
756 SparseOneDimensionalModel::PointList points = 758 SparseOneDimensionalModel::PointList points =
757 m_model->getPoints(s.getStartFrame(), s.getEndFrame()); 759 m_model->getPoints(s.getStartFrame(), s.getEndFrame());
758 760
759 for (SparseOneDimensionalModel::PointList::iterator i = points.begin(); 761 for (SparseOneDimensionalModel::PointList::iterator i = points.begin();
760 i != points.end(); ++i) { 762 i != points.end(); ++i) {
761 if (s.contains(i->frame)) { 763 if (s.contains(i->frame)) {
762 Clipboard::Point point(i->frame, i->label); 764 Clipboard::Point point(i->frame, i->label);
763 point.setReferenceFrame(alignToReference(v, i->frame)); 765 point.setReferenceFrame(alignToReference(v, i->frame));
764 to.addPoint(point); 766 to.addPoint(point);
765 } 767 }
766 } 768 }
791 realign = true; 793 realign = true;
792 } 794 }
793 } 795 }
794 796
795 SparseOneDimensionalModel::EditCommand *command = 797 SparseOneDimensionalModel::EditCommand *command =
796 new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste")); 798 new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste"));
797 799
798 for (Clipboard::PointList::const_iterator i = points.begin(); 800 for (Clipboard::PointList::const_iterator i = points.begin();
799 i != points.end(); ++i) { 801 i != points.end(); ++i) {
800 802
801 if (!i->haveFrame()) continue; 803 if (!i->haveFrame()) continue;
859 { 861 {
860 SingleColourLayer::setProperties(attributes); 862 SingleColourLayer::setProperties(attributes);
861 863
862 bool ok; 864 bool ok;
863 PlotStyle style = (PlotStyle) 865 PlotStyle style = (PlotStyle)
864 attributes.value("plotStyle").toInt(&ok); 866 attributes.value("plotStyle").toInt(&ok);
865 if (ok) setPlotStyle(style); 867 if (ok) setPlotStyle(style);
866 } 868 }
867 869