# HG changeset patch # User gyorgyf # Date 1366443517 -3600 # Node ID 5c9dcec5f3e9985de305fd31d7d765f14ea54327 # Parent 4fa3951bbb05b65d792394e2bea6a780bc25bc4f splitting notes works but major cleanup needed diff -r 4fa3951bbb05 -r 5c9dcec5f3e9 layer/FlexiNoteLayer.cpp --- a/layer/FlexiNoteLayer.cpp Fri Apr 19 15:37:27 2013 +0100 +++ b/layer/FlexiNoteLayer.cpp Sat Apr 20 08:38:37 2013 +0100 @@ -625,13 +625,13 @@ max = Pitch::getFrequencyForPitch(lrintf(max + 1)); } - std::cerr << "FlexiNoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl; + // std::cerr << "FlexiNoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl; } else if (log) { LogRange::mapRange(min, max); - std::cerr << "FlexiNoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl; + // std::cerr << "FlexiNoteLayer[" << this << "]::getScaleExtents: min = " << min << ", max = " << max << ", log = " << log << std::endl; } @@ -908,6 +908,7 @@ FlexiNoteLayer::editStart(View *v, QMouseEvent *e) { // SVDEBUG << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; + std::cerr << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; if (!m_model) return; @@ -931,6 +932,7 @@ FlexiNoteLayer::editDrag(View *v, QMouseEvent *e) { // SVDEBUG << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl; + std::cerr << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl; if (!m_model || !m_editing) return; @@ -957,9 +959,11 @@ } void -FlexiNoteLayer::editEnd(View *, QMouseEvent *) +FlexiNoteLayer::editEnd(View *v, QMouseEvent *e) { // SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; + std::cerr << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; + if (!m_model || !m_editing) return; if (m_editingCommand) { @@ -984,6 +988,71 @@ m_editing = false; } +void +FlexiNoteLayer::splitStart(View *v, QMouseEvent *e) +{ + std::cerr << "splitStart" << std::endl; + if (!m_model) return; + + 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); + + if (m_editingCommand) { + finish(m_editingCommand); + m_editingCommand = 0; + } + + m_editing = true; + m_dragStartX = e->x(); + m_dragStartY = e->y(); + +} + +void +FlexiNoteLayer::splitEnd(View *v, QMouseEvent *e) +{ + std::cerr << "splitEnd" << std::endl; + if (!m_model || !m_editing) return; + + int xdist = e->x() - m_dragStartX; + int ydist = e->y() - m_dragStartY; + if (xdist != 0 || ydist != 0) { + std::cerr << "mouse moved" << std::endl; + return; + } + + FlexiNoteModel::Point note(0); + if (!getPointToDrag(v, e->x(), e->y(), note)) return; + + long frame = v->getFrameForX(e->x()); + + FlexiNoteModel::Point newNote1 = note; + newNote1.frame = note.frame; + newNote1.value = note.value; + // newNote1.duration = note.duration+10000; + newNote1.duration = frame - note.frame - 100; + newNote1.label = note.label; + + FlexiNoteModel::Point newNote2 = note; + newNote2.frame = frame + 100; + newNote2.value = note.value; + newNote2.duration = note.duration - (frame - note.frame - 100); + newNote2.label = note.label; + + + FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand + (m_model, tr("Edit Point")); + command->deletePoint(note); + command->addPoint(newNote1); + command->addPoint(newNote2); + finish(command); + +} + + bool FlexiNoteLayer::editOpen(View *v, QMouseEvent *e) { diff -r 4fa3951bbb05 -r 5c9dcec5f3e9 layer/FlexiNoteLayer.h --- a/layer/FlexiNoteLayer.h Fri Apr 19 15:37:27 2013 +0100 +++ b/layer/FlexiNoteLayer.h Sat Apr 20 08:38:37 2013 +0100 @@ -52,6 +52,9 @@ virtual void editDrag(View *v, QMouseEvent *); virtual void editEnd(View *v, QMouseEvent *); + virtual void splitStart(View *v, QMouseEvent *); + virtual void splitEnd(View *v, QMouseEvent *); + virtual bool editOpen(View *v, QMouseEvent *); virtual void moveSelection(Selection s, size_t newStartFrame); diff -r 4fa3951bbb05 -r 5c9dcec5f3e9 layer/Layer.h --- a/layer/Layer.h Fri Apr 19 15:37:27 2013 +0100 +++ b/layer/Layer.h Sat Apr 20 08:38:37 2013 +0100 @@ -229,6 +229,9 @@ virtual void editDrag(View *, QMouseEvent *) { } virtual void editEnd(View *, QMouseEvent *) { } + virtual void splitStart(View *, QMouseEvent *) { } + virtual void splitEnd(View *, QMouseEvent *) { } + // Measurement rectangle (or equivalent). Unlike draw and edit, // the base Layer class can provide working implementations of // these for most situations. diff -r 4fa3951bbb05 -r 5c9dcec5f3e9 view/Pane.cpp --- a/view/Pane.cpp Fri Apr 19 15:37:27 2013 +0100 +++ b/view/Pane.cpp Sat Apr 20 08:38:37 2013 +0100 @@ -1278,7 +1278,7 @@ return; } -// std::cerr << "mousePressEvent" << std::endl; + // std::cerr << "mousePressEvent" << std::endl; m_clickPos = e->pos(); m_mousePos = m_clickPos; @@ -1378,6 +1378,12 @@ } else if (mode == ViewManager::EditMode) { + std::cerr << "mouse pressed in edit mode" << std::endl; + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + layer->splitStart(this, e); + } + // Do nothing here -- we'll do it in mouseMoveEvent when the // drag threshold has been passed @@ -1473,6 +1479,12 @@ } } else if (mode == ViewManager::EditMode) { + + //GF: temporary + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + layer->splitEnd(this, e); + update(); } if (m_editing) { if (!editSelectionEnd(e)) { @@ -1482,7 +1494,7 @@ update(); } } - } + } } else if (mode == ViewManager::MeasureMode) { @@ -1615,7 +1627,7 @@ // dragging to be used most of the time } - if (m_shiftPressed) resist = false; + if (m_shiftPressed) resist = false; m_dragMode = updateDragMode (m_dragMode,