comparison layer/TimeInstantLayer.cpp @ 22:179bf7b5ddea

* Update some copyright notice dates * Add commands for basic editing operations in time-instants and time-value layers
author Chris Cannam
date Tue, 31 Jan 2006 15:57:25 +0000
parents 3a506d25d95a
children ca57f70b0e48
comparison
equal deleted inserted replaced
21:3a506d25d95a 22:179bf7b5ddea
24 TimeInstantLayer::TimeInstantLayer(View *w) : 24 TimeInstantLayer::TimeInstantLayer(View *w) :
25 Layer(w), 25 Layer(w),
26 m_model(0), 26 m_model(0),
27 m_editing(false), 27 m_editing(false),
28 m_editingPoint(0, tr("New Point")), 28 m_editingPoint(0, tr("New Point")),
29 m_editingCommand(0),
29 m_colour(QColor(200, 50, 255)) 30 m_colour(QColor(200, 50, 255))
30 { 31 {
31 m_view->addLayer(this); 32 m_view->addLayer(this);
32 } 33 }
33 34
347 if (!m_model) return; 348 if (!m_model) return;
348 349
349 long frame = getFrameForX(e->x()); 350 long frame = getFrameForX(e->x());
350 if (frame < 0) frame = 0; 351 if (frame < 0) frame = 0;
351 frame = frame / m_model->getResolution() * m_model->getResolution(); 352 frame = frame / m_model->getResolution() * m_model->getResolution();
353
352 m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point")); 354 m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point"));
353 m_model->addPoint(m_editingPoint); 355
356 if (m_editingCommand) m_editingCommand->finish();
357 m_editingCommand = new SparseOneDimensionalModel::EditCommand(m_model,
358 tr("Draw Point"));
359 m_editingCommand->addPoint(m_editingPoint);
360
354 m_editing = true; 361 m_editing = true;
355 } 362 }
356 363
357 void 364 void
358 TimeInstantLayer::drawDrag(QMouseEvent *e) 365 TimeInstantLayer::drawDrag(QMouseEvent *e)
362 if (!m_model || !m_editing) return; 369 if (!m_model || !m_editing) return;
363 370
364 long frame = getFrameForX(e->x()); 371 long frame = getFrameForX(e->x());
365 if (frame < 0) frame = 0; 372 if (frame < 0) frame = 0;
366 frame = frame / m_model->getResolution() * m_model->getResolution(); 373 frame = frame / m_model->getResolution() * m_model->getResolution();
367 m_model->deletePoint(m_editingPoint); 374 m_editingCommand->deletePoint(m_editingPoint);
368 m_editingPoint.frame = frame; 375 m_editingPoint.frame = frame;
369 m_model->addPoint(m_editingPoint); 376 m_editingCommand->addPoint(m_editingPoint);
370 } 377 }
371 378
372 void 379 void
373 TimeInstantLayer::drawEnd(QMouseEvent *e) 380 TimeInstantLayer::drawEnd(QMouseEvent *e)
374 { 381 {
375 std::cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << std::endl; 382 std::cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << std::endl;
376 if (!m_model || !m_editing) return; 383 if (!m_model || !m_editing) return;
384 m_editingCommand->finish();
385 m_editingCommand = 0;
377 m_editing = false; 386 m_editing = false;
378 } 387 }
379 388
380 void 389 void
381 TimeInstantLayer::editStart(QMouseEvent *e) 390 TimeInstantLayer::editStart(QMouseEvent *e)
386 395
387 SparseOneDimensionalModel::PointList points = getLocalPoints(e->x()); 396 SparseOneDimensionalModel::PointList points = getLocalPoints(e->x());
388 if (points.empty()) return; 397 if (points.empty()) return;
389 398
390 m_editingPoint = *points.begin(); 399 m_editingPoint = *points.begin();
400
401 if (m_editingCommand) {
402 m_editingCommand->finish();
403 m_editingCommand = 0;
404 }
405
391 m_editing = true; 406 m_editing = true;
392 } 407 }
393 408
394 void 409 void
395 TimeInstantLayer::editDrag(QMouseEvent *e) 410 TimeInstantLayer::editDrag(QMouseEvent *e)
399 if (!m_model || !m_editing) return; 414 if (!m_model || !m_editing) return;
400 415
401 long frame = getFrameForX(e->x()); 416 long frame = getFrameForX(e->x());
402 if (frame < 0) frame = 0; 417 if (frame < 0) frame = 0;
403 frame = frame / m_model->getResolution() * m_model->getResolution(); 418 frame = frame / m_model->getResolution() * m_model->getResolution();
404 m_model->deletePoint(m_editingPoint); 419
420 if (!m_editingCommand) {
421 m_editingCommand = new SparseOneDimensionalModel::EditCommand(m_model,
422 tr("Drag Point"));
423 }
424
425 m_editingCommand->deletePoint(m_editingPoint);
405 m_editingPoint.frame = frame; 426 m_editingPoint.frame = frame;
406 m_model->addPoint(m_editingPoint); 427 m_editingCommand->addPoint(m_editingPoint);
407 } 428 }
408 429
409 void 430 void
410 TimeInstantLayer::editEnd(QMouseEvent *e) 431 TimeInstantLayer::editEnd(QMouseEvent *e)
411 { 432 {
412 std::cerr << "TimeInstantLayer::editEnd(" << e->x() << ")" << std::endl; 433 std::cerr << "TimeInstantLayer::editEnd(" << e->x() << ")" << std::endl;
413 if (!m_model || !m_editing) return; 434 if (!m_model || !m_editing) return;
435 if (m_editingCommand) m_editingCommand->finish();
436 m_editingCommand = 0;
414 m_editing = false; 437 m_editing = false;
415 } 438 }
416 439
417 QString 440 QString
418 TimeInstantLayer::toXmlString(QString indent, QString extraAttributes) const 441 TimeInstantLayer::toXmlString(QString indent, QString extraAttributes) const