Mercurial > hg > svgui
diff view/Pane.cpp @ 645:c8f45afb83d5 tonioni
added NoteEdit tool mode
author | gyorgyf |
---|---|
date | Sat, 15 Jun 2013 16:16:24 +0100 |
parents | 5c9dcec5f3e9 |
children | ba76130ed7e5 |
line wrap: on
line diff
--- a/view/Pane.cpp Sat Apr 20 08:38:37 2013 +0100 +++ b/view/Pane.cpp Sat Jun 15 16:16:24 2013 +0100 @@ -167,7 +167,7 @@ } m_reset = new NotifyingPushButton; - m_reset->setFlat(true); + m_reset->setFlat(true); m_reset->setCursor(Qt::ArrowCursor); m_reset->setFixedHeight(16); m_reset->setFixedWidth(16); @@ -336,10 +336,10 @@ } if (layer == getSelectedLayer() && - !shouldIlluminateLocalSelection(discard, b0, b1)) { - - pos = m_identifyPoint; - return m_identifyFeatures; + !shouldIlluminateLocalSelection(discard, b0, b1)) { + + pos = m_identifyPoint; + return m_identifyFeatures; } return false; @@ -347,25 +347,25 @@ bool Pane::shouldIlluminateLocalSelection(QPoint &pos, - bool &closeToLeft, - bool &closeToRight) const + bool &closeToLeft, + bool &closeToRight) const { if (m_identifyFeatures && - m_manager && - m_manager->getToolMode() == ViewManager::EditMode && - !m_manager->getSelections().empty() && - !selectionIsBeingEdited()) { - - Selection s(getSelectionAt(m_identifyPoint.x(), - closeToLeft, closeToRight)); - - if (!s.isEmpty()) { - if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) { - - pos = m_identifyPoint; - return true; - } - } + m_manager && + m_manager->getToolMode() == ViewManager::EditMode && + !m_manager->getSelections().empty() && + !selectionIsBeingEdited()) { + + Selection s(getSelectionAt(m_identifyPoint.x(), + closeToLeft, closeToRight)); + + if (!s.isEmpty()) { + if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) { + + pos = m_identifyPoint; + return true; + } + } } return false; @@ -375,10 +375,10 @@ Pane::selectionIsBeingEdited() const { if (!m_editingSelection.isEmpty()) { - if (m_mousePos != m_clickPos && - getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) { - return true; - } + if (m_mousePos != m_clickPos && + getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) { + return true; + } } return false; } @@ -625,9 +625,9 @@ if (m_scaleWidth > 0 && r.left() < m_scaleWidth) { -// Profiler profiler("Pane::paintEvent - painting vertical scale", true); - -// SVDEBUG << "Pane::paintEvent: calling paint.save() in vertical scale block" << endl; +// Profiler profiler("Pane::paintEvent - painting vertical scale", true); + +// SVDEBUG << "Pane::paintEvent: calling paint.save() in vertical scale block" << endl; paint.save(); paint.setPen(getForeground()); @@ -648,7 +648,7 @@ { QPoint pos = m_identifyPoint; QString desc = topLayer->getFeatureDescription(this, pos); - + if (desc != "") { paint.save(); @@ -725,7 +725,7 @@ LayerList::iterator vi = m_layers.end(); if (vi != m_layers.begin()) { - + switch ((*--vi)->getPreferredFrameCountPosition()) { case Layer::PositionTop: @@ -892,7 +892,7 @@ } if (r.x() + r.width() >= llx - fontAscent - 3) { - + for (size_t i = 0; i < texts.size(); ++i) { // std::cerr << "Pane "<< this << ": text " << i << ": " << texts[i] << std::endl; @@ -1147,8 +1147,8 @@ long testFrame = getFrameForX(x - 5); if (testFrame < 0) { - testFrame = getFrameForX(x); - if (testFrame < 0) return Selection(); + testFrame = getFrameForX(x); + if (testFrame < 0) return Selection(); } Selection selection = m_manager->getContainingSelection(testFrame, true); @@ -1303,12 +1303,12 @@ (mode == ViewManager::MeasureMode && (e->buttons() & Qt::LeftButton) && m_shiftPressed)) { - if (mode != ViewManager::NavigateMode) { - setCursor(Qt::PointingHandCursor); - } - - m_navigating = true; - m_dragCentreFrame = m_centreFrame; + if (mode != ViewManager::NavigateMode) { + setCursor(Qt::PointingHandCursor); + } + + m_navigating = true; + m_dragCentreFrame = m_centreFrame; m_dragStartMinValue = 0; float vmin, vmax, dmin, dmax; @@ -1320,70 +1320,73 @@ if (!hasTopLayerTimeXAxis()) return; - bool closeToLeft = false, closeToRight = false; - Selection selection = getSelectionAt(e->x(), closeToLeft, closeToRight); - - if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) { - - m_manager->removeSelection(selection); - - if (closeToLeft) { - m_selectionStartFrame = selection.getEndFrame(); - } else { - m_selectionStartFrame = selection.getStartFrame(); - } - - m_manager->setInProgressSelection(selection, false); - m_resizing = true; - - } else { - - int mouseFrame = getFrameForX(e->x()); - size_t resolution = 1; - int snapFrame = mouseFrame; - - Layer *layer = getSelectedLayer(); - if (layer && !m_shiftPressed) { - layer->snapToFeatureFrame(this, snapFrame, - resolution, Layer::SnapLeft); - } - - if (snapFrame < 0) snapFrame = 0; - m_selectionStartFrame = snapFrame; - if (m_manager) { - m_manager->setInProgressSelection + bool closeToLeft = false, closeToRight = false; + Selection selection = getSelectionAt(e->x(), closeToLeft, closeToRight); + + if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) { + + m_manager->removeSelection(selection); + + if (closeToLeft) { + m_selectionStartFrame = selection.getEndFrame(); + } else { + m_selectionStartFrame = selection.getStartFrame(); + } + + m_manager->setInProgressSelection(selection, false); + m_resizing = true; + + } else { + + int mouseFrame = getFrameForX(e->x()); + size_t resolution = 1; + int snapFrame = mouseFrame; + + Layer *layer = getSelectedLayer(); + if (layer && !m_shiftPressed) { + layer->snapToFeatureFrame(this, snapFrame, + resolution, Layer::SnapLeft); + } + + if (snapFrame < 0) snapFrame = 0; + m_selectionStartFrame = snapFrame; + if (m_manager) { + m_manager->setInProgressSelection (Selection(alignToReference(snapFrame), alignToReference(snapFrame + resolution)), !m_ctrlPressed); - } - - m_resizing = false; - } - - update(); + } + + m_resizing = false; + } + + update(); } else if (mode == ViewManager::DrawMode) { - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { - layer->drawStart(this, e); - } + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + layer->drawStart(this, e); + } } else if (mode == ViewManager::EraseMode) { - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { - layer->eraseStart(this, e); - } - - } else if (mode == ViewManager::EditMode) { - - std::cerr << "mouse pressed in edit mode" << std::endl; + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + layer->eraseStart(this, e); + } + + // GF: handle mouse press for NoteEditMode + } else if (mode == ViewManager::NoteEditMode) { + + std::cerr << "mouse pressed in note edit mode" << std::endl; Layer *layer = getSelectedLayer(); if (layer && layer->isLayerEditable()) { layer->splitStart(this, e); } + } else if (mode == ViewManager::EditMode) { + // Do nothing here -- we'll do it in mouseMoveEvent when the // drag threshold has been passed @@ -1412,28 +1415,28 @@ m_releasing = true; if (m_clickedInRange) { - mouseMoveEvent(e); + mouseMoveEvent(e); } if (m_navigating || mode == ViewManager::NavigateMode) { - m_navigating = false; - - if (mode != ViewManager::NavigateMode) { - // restore cursor - toolModeChanged(); - } - - if (m_shiftPressed) { - - int x0 = std::min(m_clickPos.x(), m_mousePos.x()); - int x1 = std::max(m_clickPos.x(), m_mousePos.x()); - - int y0 = std::min(m_clickPos.y(), m_mousePos.y()); - int y1 = std::max(m_clickPos.y(), m_mousePos.y()); + m_navigating = false; + + if (mode != ViewManager::NavigateMode) { + // restore cursor + toolModeChanged(); + } + + if (m_shiftPressed) { + + int x0 = std::min(m_clickPos.x(), m_mousePos.x()); + int x1 = std::max(m_clickPos.x(), m_mousePos.x()); + + int y0 = std::min(m_clickPos.y(), m_mousePos.y()); + int y1 = std::max(m_clickPos.y(), m_mousePos.y()); zoomToRegion(x0, y0, x1, y1); - } + } } else if (mode == ViewManager::SelectMode) { @@ -1442,45 +1445,45 @@ return; } - if (m_manager && m_manager->haveInProgressSelection()) { - - bool exclusive; - Selection selection = m_manager->getInProgressSelection(exclusive); - - if (selection.getEndFrame() < selection.getStartFrame() + 2) { - selection = Selection(); - } - - m_manager->clearInProgressSelection(); - - if (exclusive) { - m_manager->setSelection(selection); - } else { - m_manager->addSelection(selection); - } - } - - update(); + if (m_manager && m_manager->haveInProgressSelection()) { + + bool exclusive; + Selection selection = m_manager->getInProgressSelection(exclusive); + + if (selection.getEndFrame() < selection.getStartFrame() + 2) { + selection = Selection(); + } + + m_manager->clearInProgressSelection(); + + if (exclusive) { + m_manager->setSelection(selection); + } else { + m_manager->addSelection(selection); + } + } + + update(); } else if (mode == ViewManager::DrawMode) { - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { - layer->drawEnd(this, e); - update(); - } + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + layer->drawEnd(this, e); + update(); + } } else if (mode == ViewManager::EraseMode) { - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { - layer->eraseEnd(this, e); - update(); - } - - } else if (mode == ViewManager::EditMode) { - - //GF: temporary + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + layer->eraseEnd(this, e); + update(); + } + + } else if (mode == ViewManager::NoteEditMode) { + + //GF: handle mouse release for NoteEditMode (note: works but will need to re-think this a bit later) Layer *layer = getSelectedLayer(); if (layer && layer->isLayerEditable()) { layer->splitEnd(this, e); @@ -1496,6 +1499,19 @@ } } + } else if (mode == ViewManager::EditMode) { + + // GF: edited this previously, but restored to original state + if (m_editing) { + if (!editSelectionEnd(e)) { + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + layer->editEnd(this, e); + update(); + } + } + } + } else if (mode == ViewManager::MeasureMode) { Layer *layer = getTopLayer(); @@ -1542,16 +1558,16 @@ m_identifyPoint = e->pos(); if (!m_clickedInRange) { - - if (mode == ViewManager::SelectMode && hasTopLayerTimeXAxis()) { - bool closeToLeft = false, closeToRight = false; - getSelectionAt(e->x(), closeToLeft, closeToRight); - if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) { - setCursor(Qt::SizeHorCursor); - } else { - setCursor(Qt::ArrowCursor); - } - } + + if (mode == ViewManager::SelectMode && hasTopLayerTimeXAxis()) { + bool closeToLeft = false, closeToRight = false; + getSelectionAt(e->x(), closeToLeft, closeToRight); + if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) { + setCursor(Qt::SizeHorCursor); + } else { + setCursor(Qt::ArrowCursor); + } + } if (!m_manager->isPlaying()) { @@ -1581,17 +1597,17 @@ } } - return; + return; } if (m_navigating || mode == ViewManager::NavigateMode) { - if (m_shiftPressed) { - - m_mousePos = e->pos(); - update(); - - } else { + if (m_shiftPressed) { + + m_mousePos = e->pos(); + update(); + + } else { dragTopLayer(e); } @@ -1604,17 +1620,17 @@ } else if (mode == ViewManager::DrawMode) { - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { - layer->drawDrag(this, e); - } + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + layer->drawDrag(this, e); + } } else if (mode == ViewManager::EraseMode) { - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { - layer->eraseDrag(this, e); - } + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + layer->eraseDrag(this, e); + } } else if (mode == ViewManager::EditMode) { @@ -1627,7 +1643,7 @@ // dragging to be used most of the time } - if (m_shiftPressed) resist = false; + if (m_shiftPressed) resist = false; m_dragMode = updateDragMode (m_dragMode, @@ -1700,24 +1716,24 @@ Pane::zoomToRegion(int x0, int y0, int x1, int y1) { int w = x1 - x0; - + long newStartFrame = getFrameForX(x0); - + long visibleFrames = getEndFrame() - getStartFrame(); if (newStartFrame <= -visibleFrames) { newStartFrame = -visibleFrames + 1; } - + if (newStartFrame >= long(getModelsEndFrame())) { newStartFrame = getModelsEndFrame() - 1; } - + float ratio = float(w) / float(width()); -// std::cerr << "ratio: " << ratio << std::endl; +// std::cerr << "ratio: " << ratio << std::endl; size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio); if (newZoomLevel < 1) newZoomLevel = 1; -// std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl; +// std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl; setZoomLevel(getZoomConstraintBlockSize(newZoomLevel)); setStartFrame(newStartFrame); @@ -1796,7 +1812,7 @@ long frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x()); size_t newCentreFrame = m_dragCentreFrame; - + if (frameOff < 0) { newCentreFrame -= frameOff; } else if (newCentreFrame >= size_t(frameOff)) { @@ -1805,7 +1821,7 @@ newCentreFrame = 0; } -#ifdef DEBUG_PANE +#ifdef DEBUG_PANE SVDEBUG << "Pane::dragTopLayer: newCentreFrame = " << newCentreFrame << ", models end frame = " << getModelsEndFrame() << endl; #endif @@ -1924,7 +1940,7 @@ size_t resolution = 1; int snapFrameLeft = mouseFrame; int snapFrameRight = mouseFrame; - + Layer *layer = getSelectedLayer(); if (layer && !m_shiftPressed) { layer->snapToFeatureFrame(this, snapFrameLeft, @@ -1932,14 +1948,14 @@ layer->snapToFeatureFrame(this, snapFrameRight, resolution, Layer::SnapRight); } - -// std::cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << std::endl; + +// std::cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << std::endl; if (snapFrameLeft < 0) snapFrameLeft = 0; if (snapFrameRight < 0) snapFrameRight = 0; - + size_t min, max; - + if (m_selectionStartFrame > size_t(snapFrameLeft)) { min = snapFrameLeft; max = m_selectionStartFrame; @@ -2013,10 +2029,10 @@ if (mode == ViewManager::NavigateMode || mode == ViewManager::EditMode) { - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { - if (layer->editOpen(this, e)) relocate = false; - } + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + if (layer->editOpen(this, e)) relocate = false; + } } else if (mode == ViewManager::MeasureMode) { @@ -2074,31 +2090,31 @@ int count = e->delta(); if (count > 0) { - if (count >= 120) count /= 120; - else count = 1; + if (count >= 120) count /= 120; + else count = 1; } if (count < 0) { - if (count <= -120) count /= 120; - else count = -1; + if (count <= -120) count /= 120; + else count = -1; } if (e->modifiers() & Qt::ControlModifier) { - // Scroll left or right, rapidly - - if (getStartFrame() < 0 && - getEndFrame() >= getModelsEndFrame()) return; - - long delta = ((width() / 2) * count * m_zoomLevel); - - if (int(m_centreFrame) < delta) { - setCentreFrame(0); - } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) { - setCentreFrame(getModelsEndFrame()); - } else { - setCentreFrame(m_centreFrame - delta); - } + // Scroll left or right, rapidly + + if (getStartFrame() < 0 && + getEndFrame() >= getModelsEndFrame()) return; + + long delta = ((width() / 2) * count * m_zoomLevel); + + if (int(m_centreFrame) < delta) { + setCentreFrame(0); + } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) { + setCentreFrame(getModelsEndFrame()); + } else { + setCentreFrame(m_centreFrame - delta); + } } else if (e->modifiers() & Qt::ShiftModifier) { @@ -2118,29 +2134,29 @@ } else { - // Zoom in or out - - int newZoomLevel = m_zoomLevel; + // Zoom in or out + + int newZoomLevel = m_zoomLevel; - while (count > 0) { - if (newZoomLevel <= 2) { - newZoomLevel = 1; - break; - } - newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1, - ZoomConstraint::RoundDown); - --count; - } - - while (count < 0) { - newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1, - ZoomConstraint::RoundUp); - ++count; - } - - if (newZoomLevel != m_zoomLevel) { - setZoomLevel(newZoomLevel); - } + while (count > 0) { + if (newZoomLevel <= 2) { + newZoomLevel = 1; + break; + } + newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1, + ZoomConstraint::RoundDown); + --count; + } + + while (count < 0) { + newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1, + ZoomConstraint::RoundUp); + ++count; + } + + if (newZoomLevel != m_zoomLevel) { + setZoomLevel(newZoomLevel); + } } emit paneInteractedWith(); @@ -2316,9 +2332,9 @@ Pane::editSelectionStart(QMouseEvent *e) { if (!m_identifyFeatures || - !m_manager || - m_manager->getToolMode() != ViewManager::EditMode) { - return false; + !m_manager || + m_manager->getToolMode() != ViewManager::EditMode) { + return false; } bool closeToLeft, closeToRight; @@ -2348,8 +2364,8 @@ Layer *layer = getSelectedLayer(); if (offset == 0 || !layer) { - m_editingSelection = Selection(); - return true; + m_editingSelection = Selection(); + return true; } int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset; @@ -2361,25 +2377,25 @@ Selection newSelection(f0, f1); if (m_editingSelectionEdge == 0) { - + CommandHistory::getInstance()->startCompoundOperation (tr("Drag Selection"), true); - layer->moveSelection(m_editingSelection, f0); - + layer->moveSelection(m_editingSelection, f0); + } else { - + CommandHistory::getInstance()->startCompoundOperation (tr("Resize Selection"), true); - if (m_editingSelectionEdge < 0) { - f1 = m_editingSelection.getEndFrame(); - } else { - f0 = m_editingSelection.getStartFrame(); - } - - newSelection = Selection(f0, f1); - layer->resizeSelection(m_editingSelection, newSelection); + if (m_editingSelectionEdge < 0) { + f1 = m_editingSelection.getEndFrame(); + } else { + f0 = m_editingSelection.getStartFrame(); + } + + newSelection = Selection(f0, f1); + layer->resizeSelection(m_editingSelection, newSelection); } m_manager->removeSelection(m_editingSelection); @@ -2409,33 +2425,38 @@ switch (mode) { case ViewManager::NavigateMode: - setCursor(Qt::PointingHandCursor); - break; - + setCursor(Qt::PointingHandCursor); + break; + case ViewManager::SelectMode: - setCursor(Qt::ArrowCursor); - break; - + setCursor(Qt::ArrowCursor); + break; + case ViewManager::EditMode: - setCursor(Qt::UpArrowCursor); - break; - + setCursor(Qt::UpArrowCursor); + break; + case ViewManager::DrawMode: - setCursor(Qt::CrossCursor); - break; - + setCursor(Qt::CrossCursor); + break; + case ViewManager::EraseMode: - setCursor(Qt::CrossCursor); - break; + setCursor(Qt::CrossCursor); + break; case ViewManager::MeasureMode: if (m_measureCursor1) setCursor(*m_measureCursor1); - break; - -/* + break; + + // GF: NoteEditMode uses the same default cursor as EditMode, but it will change in a context sensitive manner. + case ViewManager::NoteEditMode: + setCursor(Qt::UpArrowCursor); + break; + +/* case ViewManager::TextMode: - setCursor(Qt::IBeamCursor); - break; + setCursor(Qt::IBeamCursor); + break; */ } } @@ -2571,21 +2592,21 @@ } else if (mode == ViewManager::DrawMode) { //!!! could call through to a layer function to find out exact meaning - if (editable) { + if (editable) { help = tr("Click to add a new item in the active layer"); } } else if (mode == ViewManager::EraseMode) { //!!! could call through to a layer function to find out exact meaning - if (editable) { + if (editable) { help = tr("Click to erase an item from the active layer"); } } else if (mode == ViewManager::EditMode) { //!!! could call through to layer - if (editable) { + if (editable) { help = tr("Click and drag an item in the active layer to move it; hold Shift to override initial resistance"); if (pos) { bool closeToLeft = false, closeToRight = false; @@ -2629,8 +2650,8 @@ { View::toXml (stream, indent, - QString("type=\"pane\" centreLineVisible=\"%1\" height=\"%2\" %3") - .arg(m_centreLineVisible).arg(height()).arg(extraAttributes)); + QString("type=\"pane\" centreLineVisible=\"%1\" height=\"%2\" %3") + .arg(m_centreLineVisible).arg(height()).arg(extraAttributes)); }