Mercurial > hg > svgui
comparison layer/TimeValueLayer.cpp @ 21:3a506d25d95a
* Add command history class, and basic undo/redo menus. No actual commands
to undo/redo yet. Selecting the placeholders sometimes seems to cause
a crash, so this looks a little uncertain so far.
* Add Rename Layer
* Remove models from playback when their layers are removed (and ref counts
hit zero)
* Don't hang around waiting so much when there's work to be done in the audio
buffer fill thread
* Put more sensible names on layers generated from transforms
* Add basic editing to time-value layer like existing editing in time-instants
layer, and make both of them snap to the appropriate resolution during drag
author | Chris Cannam |
---|---|
date | Mon, 30 Jan 2006 17:51:56 +0000 |
parents | 1deb5f87a18c |
children | 179bf7b5ddea |
comparison
equal
deleted
inserted
replaced
20:1deb5f87a18c | 21:3a506d25d95a |
---|---|
16 | 16 |
17 #include "model/SparseTimeValueModel.h" | 17 #include "model/SparseTimeValueModel.h" |
18 | 18 |
19 #include <QPainter> | 19 #include <QPainter> |
20 #include <QPainterPath> | 20 #include <QPainterPath> |
21 #include <QMouseEvent> | |
21 | 22 |
22 #include <iostream> | 23 #include <iostream> |
23 #include <cmath> | 24 #include <cmath> |
24 | 25 |
25 TimeValueLayer::TimeValueLayer(View *w) : | 26 TimeValueLayer::TimeValueLayer(View *w) : |
26 Layer(w), | 27 Layer(w), |
27 m_model(0), | 28 m_model(0), |
29 m_editing(false), | |
30 m_editingPoint(0, 0.0, tr("New Point")), | |
28 m_colour(Qt::black), | 31 m_colour(Qt::black), |
29 m_plotStyle(PlotConnectedPoints) | 32 m_plotStyle(PlotConnectedPoints) |
30 { | 33 { |
31 m_view->addLayer(this); | 34 m_view->addLayer(this); |
32 } | 35 } |
295 } | 298 } |
296 | 299 |
297 return returnFrame; | 300 return returnFrame; |
298 } | 301 } |
299 | 302 |
303 int | |
304 TimeValueLayer::getYForValue(float value) const | |
305 { | |
306 float min = m_model->getValueMinimum(); | |
307 float max = m_model->getValueMaximum(); | |
308 if (max == min) max = min + 1.0; | |
309 | |
310 int h = m_view->height(); | |
311 | |
312 return int(h - ((value - min) * h) / (max - min)); | |
313 } | |
314 | |
315 float | |
316 TimeValueLayer::getValueForY(int y) const | |
317 { | |
318 float min = m_model->getValueMinimum(); | |
319 float max = m_model->getValueMaximum(); | |
320 if (max == min) max = min + 1.0; | |
321 | |
322 int h = m_view->height(); | |
323 | |
324 return min + (float(h - y) * float(max - min)) / h; | |
325 } | |
326 | |
300 void | 327 void |
301 TimeValueLayer::paint(QPainter &paint, QRect rect) const | 328 TimeValueLayer::paint(QPainter &paint, QRect rect) const |
302 { | 329 { |
303 if (!m_model || !m_model->isOK()) return; | 330 if (!m_model || !m_model->isOK()) return; |
304 | 331 |
357 i != points.end(); ++i) { | 384 i != points.end(); ++i) { |
358 | 385 |
359 const SparseTimeValueModel::Point &p(*i); | 386 const SparseTimeValueModel::Point &p(*i); |
360 | 387 |
361 int x = getXForFrame(p.frame); | 388 int x = getXForFrame(p.frame); |
362 int y = int(nearbyint(m_view->height() - | 389 int y = getYForValue(p.value); |
363 ((p.value - min) * m_view->height()) / | |
364 (max - min))); | |
365 | 390 |
366 if (w < 1) w = 1; | 391 if (w < 1) w = 1; |
367 | 392 |
368 if (m_plotStyle == PlotLines || | 393 if (m_plotStyle == PlotLines || |
369 m_plotStyle == PlotCurve) { | 394 m_plotStyle == PlotCurve) { |
414 | 439 |
415 if (j != points.end()) { | 440 if (j != points.end()) { |
416 | 441 |
417 const SparseTimeValueModel::Point &q(*j); | 442 const SparseTimeValueModel::Point &q(*j); |
418 int nx = getXForFrame(q.frame); | 443 int nx = getXForFrame(q.frame); |
419 int ny = int(nearbyint(m_view->height() - | 444 int ny = getYForValue(q.value); |
420 ((q.value - min) * m_view->height()) / | |
421 (max - min))); | |
422 | 445 |
423 if (m_plotStyle == PlotConnectedPoints) { | 446 if (m_plotStyle == PlotConnectedPoints) { |
424 | 447 |
425 paint.setPen(brushColour); | 448 paint.setPen(brushColour); |
426 paint.drawLine(x + w, y, nx, ny); | 449 paint.drawLine(x + w, y, nx, ny); |
457 | 480 |
458 // looks like save/restore doesn't deal with this: | 481 // looks like save/restore doesn't deal with this: |
459 paint.setRenderHint(QPainter::Antialiasing, false); | 482 paint.setRenderHint(QPainter::Antialiasing, false); |
460 } | 483 } |
461 | 484 |
485 void | |
486 TimeValueLayer::drawStart(QMouseEvent *e) | |
487 { | |
488 std::cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << std::endl; | |
489 | |
490 if (!m_model) return; | |
491 | |
492 long frame = getFrameForX(e->x()); | |
493 if (frame < 0) frame = 0; | |
494 frame = frame / m_model->getResolution() * m_model->getResolution(); | |
495 | |
496 float value = getValueForY(e->y()); | |
497 | |
498 m_editingPoint = SparseTimeValueModel::Point(frame, value, tr("New Point")); | |
499 m_model->addPoint(m_editingPoint); | |
500 m_editing = true; | |
501 } | |
502 | |
503 void | |
504 TimeValueLayer::drawDrag(QMouseEvent *e) | |
505 { | |
506 std::cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << std::endl; | |
507 | |
508 if (!m_model || !m_editing) return; | |
509 | |
510 long frame = getFrameForX(e->x()); | |
511 if (frame < 0) frame = 0; | |
512 frame = frame / m_model->getResolution() * m_model->getResolution(); | |
513 | |
514 float value = getValueForY(e->y()); | |
515 | |
516 m_model->deletePoint(m_editingPoint); | |
517 m_editingPoint.frame = frame; | |
518 m_editingPoint.value = value; | |
519 m_model->addPoint(m_editingPoint); | |
520 } | |
521 | |
522 void | |
523 TimeValueLayer::drawEnd(QMouseEvent *e) | |
524 { | |
525 std::cerr << "TimeValueLayer::drawEnd(" << e->x() << "," << e->y() << ")" << std::endl; | |
526 if (!m_model || !m_editing) return; | |
527 m_editing = false; | |
528 } | |
529 | |
530 void | |
531 TimeValueLayer::editStart(QMouseEvent *e) | |
532 { | |
533 std::cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; | |
534 | |
535 if (!m_model) return; | |
536 | |
537 SparseTimeValueModel::PointList points = getLocalPoints(e->x()); | |
538 if (points.empty()) return; | |
539 | |
540 m_editingPoint = *points.begin(); | |
541 m_editing = true; | |
542 } | |
543 | |
544 void | |
545 TimeValueLayer::editDrag(QMouseEvent *e) | |
546 { | |
547 std::cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl; | |
548 | |
549 if (!m_model || !m_editing) return; | |
550 | |
551 long frame = getFrameForX(e->x()); | |
552 if (frame < 0) frame = 0; | |
553 frame = frame / m_model->getResolution() * m_model->getResolution(); | |
554 | |
555 float value = getValueForY(e->y()); | |
556 | |
557 m_model->deletePoint(m_editingPoint); | |
558 m_editingPoint.frame = frame; | |
559 m_editingPoint.value = value; | |
560 m_model->addPoint(m_editingPoint); | |
561 } | |
562 | |
563 void | |
564 TimeValueLayer::editEnd(QMouseEvent *e) | |
565 { | |
566 std::cerr << "TimeValueLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; | |
567 if (!m_model || !m_editing) return; | |
568 m_editing = false; | |
569 } | |
570 | |
462 QString | 571 QString |
463 TimeValueLayer::toXmlString(QString indent, QString extraAttributes) const | 572 TimeValueLayer::toXmlString(QString indent, QString extraAttributes) const |
464 { | 573 { |
465 return Layer::toXmlString(indent, extraAttributes + | 574 return Layer::toXmlString(indent, extraAttributes + |
466 QString(" colour=\"%1\" plotStyle=\"%2\"") | 575 QString(" colour=\"%1\" plotStyle=\"%2\"") |