Mercurial > hg > svgui
comparison 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 |
comparison
equal
deleted
inserted
replaced
41:f2c416cbdaa9 | 42:1bdf285c4eac |
---|---|
39 } | 39 } |
40 | 40 |
41 bool | 41 bool |
42 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) | 42 Pane::shouldIlluminateLocalFeatures(const Layer *layer, QPoint &pos) |
43 { | 43 { |
44 if (layer == getSelectedLayer()) { | 44 QPoint discard; |
45 bool b0, b1; | |
46 | |
47 if (layer == getSelectedLayer() && | |
48 !shouldIlluminateLocalSelection(discard, b0, b1)) { | |
49 | |
45 pos = m_identifyPoint; | 50 pos = m_identifyPoint; |
46 return m_identifyFeatures; | 51 return m_identifyFeatures; |
47 } | 52 } |
48 | 53 |
54 return false; | |
55 } | |
56 | |
57 bool | |
58 Pane::shouldIlluminateLocalSelection(QPoint &pos, | |
59 bool &closeToLeft, | |
60 bool &closeToRight) | |
61 { | |
62 if (m_identifyFeatures && | |
63 m_manager && | |
64 m_manager->getToolMode() == ViewManager::EditMode && | |
65 !m_manager->getSelections().empty() && | |
66 !selectionIsBeingEdited()) { | |
67 | |
68 Selection s(getSelectionAt(m_identifyPoint.x(), | |
69 closeToLeft, closeToRight)); | |
70 | |
71 if (!s.isEmpty()) { | |
72 if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) { | |
73 | |
74 pos = m_identifyPoint; | |
75 return true; | |
76 } | |
77 } | |
78 } | |
79 | |
80 return false; | |
81 } | |
82 | |
83 bool | |
84 Pane::selectionIsBeingEdited() const | |
85 { | |
86 if (!m_editingSelection.isEmpty()) { | |
87 if (m_mousePos != m_clickPos && | |
88 getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) { | |
89 return true; | |
90 } | |
91 } | |
49 return false; | 92 return false; |
50 } | 93 } |
51 | 94 |
52 void | 95 void |
53 Pane::setCentreLineVisible(bool visible) | 96 Pane::setCentreLineVisible(bool visible) |
279 m_mousePos.x() - m_clickPos.x(), | 322 m_mousePos.x() - m_clickPos.x(), |
280 m_mousePos.y() - m_clickPos.y()); | 323 m_mousePos.y() - m_clickPos.y()); |
281 } | 324 } |
282 } | 325 } |
283 | 326 |
327 if (selectionIsBeingEdited()) { | |
328 | |
329 int offset = m_mousePos.x() - m_clickPos.x(); | |
330 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset; | |
331 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; | |
332 | |
333 if (m_editingSelectionEdge < 0) { | |
334 p1 = getXForFrame(m_editingSelection.getEndFrame()); | |
335 } else if (m_editingSelectionEdge > 0) { | |
336 p0 = getXForFrame(m_editingSelection.getStartFrame()); | |
337 } | |
338 | |
339 paint.save(); | |
340 if (hasLightBackground()) { | |
341 paint.setPen(QPen(Qt::black, 2)); | |
342 } else { | |
343 paint.setPen(QPen(Qt::white, 2)); | |
344 } | |
345 | |
346 //!!! duplicating display policy with View::drawSelections | |
347 | |
348 if (m_editingSelectionEdge < 0) { | |
349 paint.drawLine(p0, 1, p1, 1); | |
350 paint.drawLine(p0, 0, p0, height()); | |
351 paint.drawLine(p0, height() - 1, p1, height() - 1); | |
352 } else if (m_editingSelectionEdge > 0) { | |
353 paint.drawLine(p0, 1, p1, 1); | |
354 paint.drawLine(p1, 0, p1, height()); | |
355 paint.drawLine(p0, height() - 1, p1, height() - 1); | |
356 } else { | |
357 paint.setBrush(Qt::NoBrush); | |
358 paint.drawRect(p0, 1, p1 - p0, height() - 2); | |
359 } | |
360 paint.restore(); | |
361 } | |
362 | |
284 paint.end(); | 363 paint.end(); |
285 } | 364 } |
286 | 365 |
287 Selection | 366 Selection |
288 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) | 367 Pane::getSelectionAt(int x, bool &closeToLeftEdge, bool &closeToRightEdge) |
320 void | 399 void |
321 Pane::mousePressEvent(QMouseEvent *e) | 400 Pane::mousePressEvent(QMouseEvent *e) |
322 { | 401 { |
323 m_clickPos = e->pos(); | 402 m_clickPos = e->pos(); |
324 m_clickedInRange = true; | 403 m_clickedInRange = true; |
404 m_editingSelection = Selection(); | |
405 m_editingSelectionEdge = 0; | |
325 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier); | 406 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier); |
326 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier); | 407 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier); |
327 | 408 |
328 ViewManager::ToolMode mode = ViewManager::NavigateMode; | 409 ViewManager::ToolMode mode = ViewManager::NavigateMode; |
329 if (m_manager) mode = m_manager->getToolMode(); | 410 if (m_manager) mode = m_manager->getToolMode(); |
388 layer->drawStart(e); | 469 layer->drawStart(e); |
389 } | 470 } |
390 | 471 |
391 } else if (mode == ViewManager::EditMode) { | 472 } else if (mode == ViewManager::EditMode) { |
392 | 473 |
393 Layer *layer = getSelectedLayer(); | 474 if (!editSelectionStart(e)) { |
394 if (layer && layer->isLayerEditable()) { | 475 Layer *layer = getSelectedLayer(); |
395 layer->editStart(e); | 476 if (layer && layer->isLayerEditable()) { |
477 layer->editStart(e); | |
478 } | |
396 } | 479 } |
397 } | 480 } |
398 | 481 |
399 emit paneInteractedWith(); | 482 emit paneInteractedWith(); |
400 } | 483 } |
478 update(); | 561 update(); |
479 } | 562 } |
480 | 563 |
481 } else if (mode == ViewManager::EditMode) { | 564 } else if (mode == ViewManager::EditMode) { |
482 | 565 |
483 Layer *layer = getSelectedLayer(); | 566 if (!editSelectionEnd(e)) { |
484 if (layer && layer->isLayerEditable()) { | 567 Layer *layer = getSelectedLayer(); |
485 layer->editEnd(e); | 568 if (layer && layer->isLayerEditable()) { |
486 update(); | 569 layer->editEnd(e); |
570 update(); | |
571 } | |
487 } | 572 } |
488 } | 573 } |
489 | 574 |
490 m_clickedInRange = false; | 575 m_clickedInRange = false; |
491 | 576 |
624 layer->drawDrag(e); | 709 layer->drawDrag(e); |
625 } | 710 } |
626 | 711 |
627 } else if (mode == ViewManager::EditMode) { | 712 } else if (mode == ViewManager::EditMode) { |
628 | 713 |
629 Layer *layer = getSelectedLayer(); | 714 if (!editSelectionDrag(e)) { |
630 if (layer && layer->isLayerEditable()) { | 715 Layer *layer = getSelectedLayer(); |
631 layer->editDrag(e); | 716 if (layer && layer->isLayerEditable()) { |
717 layer->editDrag(e); | |
718 } | |
632 } | 719 } |
633 } | 720 } |
634 } | 721 } |
635 | 722 |
636 void | 723 void |
723 setZoomLevel(newZoomLevel); | 810 setZoomLevel(newZoomLevel); |
724 } | 811 } |
725 } | 812 } |
726 | 813 |
727 emit paneInteractedWith(); | 814 emit paneInteractedWith(); |
815 } | |
816 | |
817 bool | |
818 Pane::editSelectionStart(QMouseEvent *e) | |
819 { | |
820 bool closeToLeft, closeToRight; | |
821 Selection s(getSelectionAt(e->x(), closeToLeft, closeToRight)); | |
822 if (s.isEmpty()) return false; | |
823 m_editingSelection = s; | |
824 m_editingSelectionEdge = (closeToLeft ? -1 : closeToRight ? 1 : 0); | |
825 m_mousePos = e->pos(); | |
826 return true; | |
827 } | |
828 | |
829 bool | |
830 Pane::editSelectionDrag(QMouseEvent *e) | |
831 { | |
832 if (m_editingSelection.isEmpty()) return false; | |
833 m_mousePos = e->pos(); | |
834 update(); | |
835 return true; | |
836 } | |
837 | |
838 bool | |
839 Pane::editSelectionEnd(QMouseEvent *e) | |
840 { | |
841 if (m_editingSelection.isEmpty()) return false; | |
842 m_editingSelection = Selection(); | |
843 return true; | |
728 } | 844 } |
729 | 845 |
730 void | 846 void |
731 Pane::toolModeChanged() | 847 Pane::toolModeChanged() |
732 { | 848 { |