Mercurial > hg > svgui
diff layer/FlexiNoteLayer.cpp @ 650:12d570c27d85 tonioni
split drag delete
author | matthiasm |
---|---|
date | Sun, 16 Jun 2013 00:16:37 +0100 |
parents | f61a54364d1d |
children |
line wrap: on
line diff
--- a/layer/FlexiNoteLayer.cpp Sat Jun 15 19:52:06 2013 +0100 +++ b/layer/FlexiNoteLayer.cpp Sun Jun 16 00:16:37 2013 +0100 @@ -472,6 +472,34 @@ return true; } +bool +FlexiNoteLayer::getLeftNeighbour(View *v, FlexiNote note, FlexiNote &leftNeighbour) const { + // MM: this is necessary (I think) to restrict the movement of notes to the left + if (!m_model) return false; + + FlexiNoteModel::PointList onPoints = m_model->getPoints(0, note.frame - 1); + if (!onPoints.empty()) + { + leftNeighbour = *onPoints.end(); + return true; + } + return false; +} + +bool +FlexiNoteLayer::getRightNeighbour(View *v, FlexiNote note, FlexiNote &rightNeighbour) const { + // MM: this is necessary (I think) to restrict the movement of notes to the right + if (!m_model) return false; + + FlexiNoteModel::PointList onPoints = m_model->getPoints(note.frame + note.duration); + if (!onPoints.empty()) + { + rightNeighbour = *onPoints.begin(); + return true; + } + return false; +} + QString FlexiNoteLayer::getFeatureDescription(View *v, QPoint &pos) const { @@ -1019,68 +1047,161 @@ } void -FlexiNoteLayer::splitStart(View *v, QMouseEvent *e) +FlexiNoteLayer::multiStart(View *v, QMouseEvent *e) { - // GF: note splitting starts (!! remove printing soon) - std::cerr << "splitStart" << std::endl; + std::cerr << "multiStart" << std::endl; if (!m_model) return; + if (m_editingCommand) { + finish(m_editingCommand); + m_editingCommand = 0; + } + if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; - // m_originalPoint = m_editingPoint; - // - // m_dragPointX = v->getXForFrame(m_editingPoint.frame); - // m_dragPointY = getYForValue(v, m_editingPoint.value); + bool closeToLeft = false, closeToRight = false, closeToTop = false, closeToBottom = false; + getRelativeMousePosition(v, m_editingPoint, e->x(), e->y(), closeToLeft, closeToRight, closeToTop, closeToBottom); - if (m_editingCommand) { - finish(m_editingCommand); - m_editingCommand = 0; + std::cerr << closeToLeft << " " << closeToRight << " " << closeToTop << " " << closeToBottom << std::endl; + + if (closeToLeft) + { + std::cerr << "... move left boundary" << std::endl; + + if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; + m_originalPoint = m_editingPoint; + + m_editing = true; + m_multiEditMode = MoveLeftBoundary; + m_dragStartX = e->x(); + m_dragStartY = e->y(); + + } else if (closeToTop) + { + // MM: note delete starts + std::cerr << "... delete" << std::endl; + if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; + FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand + (m_model, tr("Edit Point")); + command->deletePoint(m_editingPoint); + finish(command); + m_editing = false; + m_editingPoint = 0; + + } else if (closeToBottom) + { + // GF: note splitting starts (!! remove printing soon) + std::cerr << "... split" << std::endl; + m_editing = true; + m_multiEditMode = Split; + m_dragStartX = e->x(); + m_dragStartY = e->y(); } + return; +} - m_editing = true; - m_dragStartX = e->x(); - m_dragStartY = e->y(); + +void +FlexiNoteLayer::multiDrag(View *v, QMouseEvent *e) +{ + // GF: note splitting ends. (!! remove printing soon) + std::cerr << "multiDrag" << std::endl; + if (!m_model || !m_editing) return; + switch (m_multiEditMode) + { + case MoveLeftBoundary : + { + long frame = v->getFrameForX(e->x()); + long duration = m_originalPoint.duration - (frame - m_originalPoint.frame); + + if (!m_editingCommand) { + m_editingCommand = new FlexiNoteModel::EditCommand(m_model, + tr("Drag Point")); + } + + m_editingCommand->deletePoint(m_editingPoint); + m_editingPoint.frame = frame; + m_editingPoint.duration = duration; + m_editingCommand->addPoint(m_editingPoint); + + } + default : return; + } + return; } void -FlexiNoteLayer::splitEnd(View *v, QMouseEvent *e) +FlexiNoteLayer::multiEnd(View *v, QMouseEvent *e) { // GF: note splitting ends. (!! remove printing soon) - std::cerr << "splitEnd" << std::endl; + std::cerr << "multiEnd" << std::endl; if (!m_model || !m_editing) return; + m_editing = false; + + switch (m_multiEditMode) + { + case MoveLeftBoundary : + { + std::cerr << "... move left boundary" << std::endl; - int xdist = e->x() - m_dragStartX; - int ydist = e->y() - m_dragStartY; - if (xdist != 0 || ydist != 0) { - std::cerr << "mouse moved" << std::endl; - return; + + if (m_editingCommand) { + + QString newName = m_editingCommand->getName(); + + if (m_editingPoint.frame != m_originalPoint.frame) { + newName = tr("Relocate Point"); + } + + m_editingCommand->setName(newName); + finish(m_editingCommand); + } + + m_editingCommand = 0; + m_editing = false; + + } + case Split : + { + + // MM simpler declaration + FlexiNote note(0); + if (!getNoteToEdit(v, m_dragStartX, m_dragStartY, note)) return; + + long frame = v->getFrameForX(e->x()); + + int gap = 100; // MM: I prefer a gap of 0, but we can decide later + + // MM: changed this a bit, to make it slightly clearer + FlexiNote newNote1(note.frame, note.value, + frame - note.frame - gap, + note.level, note.label); + + FlexiNote newNote2(frame, note.value, + note.duration - newNote1.duration, + note.level, note.label); + FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand + (m_model, tr("Edit Point")); + + command->deletePoint(note); + command->addPoint(newNote1); + command->addPoint(newNote2); + finish(command); + } } - // MM simpler declaration - FlexiNote note(0); - if (!getPointToDrag(v, e->x(), e->y(), note)) return; + return; +} - long frame = v->getFrameForX(e->x()); - - int gap = 0; // MM: I prefer a gap of 0, but we can decide later - - // MM: changed this a bit, to make it slightly clearer - FlexiNote newNote1(note.frame, note.value, - frame - note.frame - gap, - note.level, note.label); - - FlexiNote newNote2(frame, note.value, - note.duration - newNote1.duration, - note.level, note.label); - - FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand - (m_model, tr("Edit Point")); - command->deletePoint(note); - command->addPoint(newNote1); - command->addPoint(newNote2); - finish(command); - -} +// void +// FlexiNoteLayer::moveBoundaryStart(View *v, QMouseEvent *e) +// { +// } +// +// void +// FlexiNoteLayer::moveBoundaryEnd(View *v, QMouseEvent *e) +// { +// } void FlexiNoteLayer::mouseMoveEvent(View *v, QMouseEvent *e)