Mercurial > hg > svgui
changeset 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 | 46d8f5add6f0 |
files | layer/TimeInstantLayer.cpp layer/TimeInstantLayer.h widgets/Pane.cpp |
diffstat | 3 files changed, 67 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/TimeInstantLayer.cpp Thu Jan 26 16:15:40 2006 +0000 +++ b/layer/TimeInstantLayer.cpp Thu Jan 26 18:01:38 2006 +0000 @@ -24,6 +24,7 @@ TimeInstantLayer::TimeInstantLayer(View *w) : Layer(w), m_model(0), + m_editing(false), m_editingPoint(0, tr("New Point")), m_colour(QColor(200, 50, 255)) { @@ -355,6 +356,7 @@ if (frame < 0) frame = 0; m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point")); m_model->addPoint(m_editingPoint); + m_editing = true; } void @@ -362,7 +364,7 @@ { std::cerr << "TimeInstantLayer::drawDrag(" << e->x() << ")" << std::endl; - if (!m_model) return; + if (!m_model || !m_editing) return; long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); if (frame < 0) frame = 0; @@ -375,7 +377,44 @@ TimeInstantLayer::drawEnd(QMouseEvent *e) { std::cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << std::endl; + if (!m_model || !m_editing) return; + m_editing = false; +} + +void +TimeInstantLayer::editStart(QMouseEvent *e) +{ + std::cerr << "TimeInstantLayer::editStart(" << e->x() << ")" << std::endl; + if (!m_model) return; + + SparseOneDimensionalModel::PointList points = getLocalPoints(e->x()); + if (points.empty()) return; + + m_editingPoint = *points.begin(); + m_editing = true; +} + +void +TimeInstantLayer::editDrag(QMouseEvent *e) +{ + std::cerr << "TimeInstantLayer::editDrag(" << e->x() << ")" << std::endl; + + if (!m_model || !m_editing) return; + + long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); + if (frame < 0) frame = 0; + m_model->deletePoint(m_editingPoint); + m_editingPoint.frame = frame; + m_model->addPoint(m_editingPoint); +} + +void +TimeInstantLayer::editEnd(QMouseEvent *e) +{ + std::cerr << "TimeInstantLayer::editEnd(" << e->x() << ")" << std::endl; + if (!m_model || !m_editing) return; + m_editing = false; } QString
--- a/layer/TimeInstantLayer.h Thu Jan 26 16:15:40 2006 +0000 +++ b/layer/TimeInstantLayer.h Thu Jan 26 18:01:38 2006 +0000 @@ -39,6 +39,10 @@ virtual void drawDrag(QMouseEvent *); virtual void drawEnd(QMouseEvent *); + virtual void editStart(QMouseEvent *); + virtual void editDrag(QMouseEvent *); + virtual void editEnd(QMouseEvent *); + virtual const Model *getModel() const { return m_model; } void setModel(SparseOneDimensionalModel *model); @@ -66,6 +70,7 @@ SparseOneDimensionalModel::PointList getLocalPoints(int) const; SparseOneDimensionalModel *m_model; + bool m_editing; SparseOneDimensionalModel::Point m_editingPoint; QColor m_colour; };
--- a/widgets/Pane.cpp Thu Jan 26 16:15:40 2006 +0000 +++ b/widgets/Pane.cpp Thu Jan 26 18:01:38 2006 +0000 @@ -342,6 +342,13 @@ if (layer) { layer->drawStart(e); } + + } else if (mode == ViewManager::EditMode) { + + Layer *layer = getSelectedLayer(); + if (layer) { + layer->editStart(e); + } } emit paneInteractedWith(); @@ -424,6 +431,14 @@ layer->drawEnd(e); update(); } + + } else if (mode == ViewManager::EditMode) { + + Layer *layer = getSelectedLayer(); + if (layer) { + layer->editEnd(e); + update(); + } } m_clickedInRange = false; @@ -564,6 +579,13 @@ if (layer) { layer->drawDrag(e); } + + } else if (mode == ViewManager::EditMode) { + + Layer *layer = getSelectedLayer(); + if (layer) { + layer->editDrag(e); + } } }