Mercurial > hg > svgui
comparison layer/TimeInstantLayer.cpp @ 18:7c767d41bcee
* Add basic drag editing of time instants.
Plenty of tuning to do for both this and drawing.
author | Chris Cannam |
---|---|
date | Thu, 26 Jan 2006 18:01:38 +0000 |
parents | 0183ebb725ca |
children | 1deb5f87a18c |
comparison
equal
deleted
inserted
replaced
17:0183ebb725ca | 18:7c767d41bcee |
---|---|
22 #include <iostream> | 22 #include <iostream> |
23 | 23 |
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_editingPoint(0, tr("New Point")), | 28 m_editingPoint(0, tr("New Point")), |
28 m_colour(QColor(200, 50, 255)) | 29 m_colour(QColor(200, 50, 255)) |
29 { | 30 { |
30 m_view->addLayer(this); | 31 m_view->addLayer(this); |
31 } | 32 } |
353 | 354 |
354 long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); | 355 long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); |
355 if (frame < 0) frame = 0; | 356 if (frame < 0) frame = 0; |
356 m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point")); | 357 m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point")); |
357 m_model->addPoint(m_editingPoint); | 358 m_model->addPoint(m_editingPoint); |
359 m_editing = true; | |
358 } | 360 } |
359 | 361 |
360 void | 362 void |
361 TimeInstantLayer::drawDrag(QMouseEvent *e) | 363 TimeInstantLayer::drawDrag(QMouseEvent *e) |
362 { | 364 { |
363 std::cerr << "TimeInstantLayer::drawDrag(" << e->x() << ")" << std::endl; | 365 std::cerr << "TimeInstantLayer::drawDrag(" << e->x() << ")" << std::endl; |
364 | 366 |
365 if (!m_model) return; | 367 if (!m_model || !m_editing) return; |
366 | 368 |
367 long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); | 369 long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); |
368 if (frame < 0) frame = 0; | 370 if (frame < 0) frame = 0; |
369 m_model->deletePoint(m_editingPoint); | 371 m_model->deletePoint(m_editingPoint); |
370 m_editingPoint.frame = frame; | 372 m_editingPoint.frame = frame; |
373 | 375 |
374 void | 376 void |
375 TimeInstantLayer::drawEnd(QMouseEvent *e) | 377 TimeInstantLayer::drawEnd(QMouseEvent *e) |
376 { | 378 { |
377 std::cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << std::endl; | 379 std::cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << std::endl; |
380 if (!m_model || !m_editing) return; | |
381 m_editing = false; | |
382 } | |
383 | |
384 void | |
385 TimeInstantLayer::editStart(QMouseEvent *e) | |
386 { | |
387 std::cerr << "TimeInstantLayer::editStart(" << e->x() << ")" << std::endl; | |
388 | |
378 if (!m_model) return; | 389 if (!m_model) return; |
390 | |
391 SparseOneDimensionalModel::PointList points = getLocalPoints(e->x()); | |
392 if (points.empty()) return; | |
393 | |
394 m_editingPoint = *points.begin(); | |
395 m_editing = true; | |
396 } | |
397 | |
398 void | |
399 TimeInstantLayer::editDrag(QMouseEvent *e) | |
400 { | |
401 std::cerr << "TimeInstantLayer::editDrag(" << e->x() << ")" << std::endl; | |
402 | |
403 if (!m_model || !m_editing) return; | |
404 | |
405 long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); | |
406 if (frame < 0) frame = 0; | |
407 m_model->deletePoint(m_editingPoint); | |
408 m_editingPoint.frame = frame; | |
409 m_model->addPoint(m_editingPoint); | |
410 } | |
411 | |
412 void | |
413 TimeInstantLayer::editEnd(QMouseEvent *e) | |
414 { | |
415 std::cerr << "TimeInstantLayer::editEnd(" << e->x() << ")" << std::endl; | |
416 if (!m_model || !m_editing) return; | |
417 m_editing = false; | |
379 } | 418 } |
380 | 419 |
381 QString | 420 QString |
382 TimeInstantLayer::toXmlString(QString indent, QString extraAttributes) const | 421 TimeInstantLayer::toXmlString(QString indent, QString extraAttributes) const |
383 { | 422 { |