Mercurial > hg > svgui
diff widgets/Pane.cpp @ 42:1bdf285c4eac
* Add "Export Audio File" option
* Make note layer align in frequency with any spectrogram layer on the same
view (if it's set to frequency mode)
* Start to implement mouse editing for ranges of points by dragging the
selection
* First scrappy attempt at a vertical scale for time value layer
author | Chris Cannam |
---|---|
date | Mon, 27 Feb 2006 17:34:41 +0000 |
parents | f2c416cbdaa9 |
children | 78515b1e29eb |
line wrap: on
line diff
--- a/widgets/Pane.cpp Fri Feb 24 17:26:11 2006 +0000 +++ b/widgets/Pane.cpp Mon Feb 27 17:34:41 2006 +0000 @@ -41,7 +41,12 @@ bool Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) { - if (layer == getSelectedLayer()) { + QPoint discard; + bool b0, b1; + + if (layer == getSelectedLayer() && + !shouldIlluminateLocalSelection(discard, b0, b1)) { + pos = m_identifyPoint; return m_identifyFeatures; } @@ -49,6 +54,44 @@ return false; } +bool +Pane::shouldIlluminateLocalSelection(QPoint &pos, + bool &closeToLeft, + bool &closeToRight) +{ + 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; + } + } + } + + return false; +} + +bool +Pane::selectionIsBeingEdited() const +{ + if (!m_editingSelection.isEmpty()) { + if (m_mousePos != m_clickPos && + getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) { + return true; + } + } + return false; +} + void Pane::setCentreLineVisible(bool visible) { @@ -281,6 +324,42 @@ } } + if (selectionIsBeingEdited()) { + + int offset = m_mousePos.x() - m_clickPos.x(); + int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset; + int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; + + if (m_editingSelectionEdge < 0) { + p1 = getXForFrame(m_editingSelection.getEndFrame()); + } else if (m_editingSelectionEdge > 0) { + p0 = getXForFrame(m_editingSelection.getStartFrame()); + } + + paint.save(); + if (hasLightBackground()) { + paint.setPen(QPen(Qt::black, 2)); + } else { + paint.setPen(QPen(Qt::white, 2)); + } + + //!!! duplicating display policy with View::drawSelections + + if (m_editingSelectionEdge < 0) { + paint.drawLine(p0, 1, p1, 1); + paint.drawLine(p0, 0, p0, height()); + paint.drawLine(p0, height() - 1, p1, height() - 1); + } else if (m_editingSelectionEdge > 0) { + paint.drawLine(p0, 1, p1, 1); + paint.drawLine(p1, 0, p1, height()); + paint.drawLine(p0, height() - 1, p1, height() - 1); + } else { + paint.setBrush(Qt::NoBrush); + paint.drawRect(p0, 1, p1 - p0, height() - 2); + } + paint.restore(); + } + paint.end(); } @@ -322,6 +401,8 @@ { m_clickPos = e->pos(); m_clickedInRange = true; + m_editingSelection = Selection(); + m_editingSelectionEdge = 0; m_shiftPressed = (e->modifiers() & Qt::ShiftModifier); m_ctrlPressed = (e->modifiers() & Qt::ControlModifier); @@ -390,9 +471,11 @@ } else if (mode == ViewManager::EditMode) { - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { - layer->editStart(e); + if (!editSelectionStart(e)) { + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + layer->editStart(e); + } } } @@ -480,10 +563,12 @@ } else if (mode == ViewManager::EditMode) { - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { - layer->editEnd(e); - update(); + if (!editSelectionEnd(e)) { + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + layer->editEnd(e); + update(); + } } } @@ -626,9 +711,11 @@ } else if (mode == ViewManager::EditMode) { - Layer *layer = getSelectedLayer(); - if (layer && layer->isLayerEditable()) { - layer->editDrag(e); + if (!editSelectionDrag(e)) { + Layer *layer = getSelectedLayer(); + if (layer && layer->isLayerEditable()) { + layer->editDrag(e); + } } } } @@ -727,6 +814,35 @@ emit paneInteractedWith(); } +bool +Pane::editSelectionStart(QMouseEvent *e) +{ + bool closeToLeft, closeToRight; + Selection s(getSelectionAt(e->x(), closeToLeft, closeToRight)); + if (s.isEmpty()) return false; + m_editingSelection = s; + m_editingSelectionEdge = (closeToLeft ? -1 : closeToRight ? 1 : 0); + m_mousePos = e->pos(); + return true; +} + +bool +Pane::editSelectionDrag(QMouseEvent *e) +{ + if (m_editingSelection.isEmpty()) return false; + m_mousePos = e->pos(); + update(); + return true; +} + +bool +Pane::editSelectionEnd(QMouseEvent *e) +{ + if (m_editingSelection.isEmpty()) return false; + m_editingSelection = Selection(); + return true; +} + void Pane::toolModeChanged() {