# HG changeset patch # User Chris Cannam # Date 1389285715 0 # Node ID 084fd76deb89a36708fabd732dc04e578d75df78 # Parent c65826b5e980005bbecb3da5b8d2fc1d2f7c4195 Allow per-pane overrides for tool mode diff -r c65826b5e980 -r 084fd76deb89 view/Pane.cpp --- a/view/Pane.cpp Thu Jan 09 09:18:17 2014 +0000 +++ b/view/Pane.cpp Thu Jan 09 16:41:55 2014 +0000 @@ -333,7 +333,7 @@ QPoint discard; bool b0, b1; - if (m_manager && m_manager->getToolMode() == ViewManager::MeasureMode) { + if (m_manager && m_manager->getToolModeFor(this) == ViewManager::MeasureMode) { return false; } @@ -358,7 +358,7 @@ { if (m_identifyFeatures && m_manager && - m_manager->getToolMode() == ViewManager::EditMode && + m_manager->getToolModeFor(this) == ViewManager::EditMode && !m_manager->getSelections().empty() && !selectionIsBeingEdited()) { @@ -413,7 +413,7 @@ if (e) paint.setClipRect(r); - ViewManager::ToolMode toolMode = m_manager->getToolMode(); + ViewManager::ToolMode toolMode = m_manager->getToolModeFor(this); if (m_manager && // !m_manager->isPlaying() && @@ -1296,7 +1296,7 @@ m_dragMode = UnresolvedDrag; ViewManager::ToolMode mode = ViewManager::NavigateMode; - if (m_manager) mode = m_manager->getToolMode(); + if (m_manager) mode = m_manager->getToolModeFor(this); m_navigating = false; m_resizing = false; @@ -1415,7 +1415,7 @@ // cerr << "mouseReleaseEvent" << endl; ViewManager::ToolMode mode = ViewManager::NavigateMode; - if (m_manager) mode = m_manager->getToolMode(); + if (m_manager) mode = m_manager->getToolModeFor(this); m_releasing = true; @@ -1558,7 +1558,7 @@ } ViewManager::ToolMode mode = ViewManager::NavigateMode; - if (m_manager) mode = m_manager->getToolMode(); + if (m_manager) mode = m_manager->getToolModeFor(this); QPoint prevPoint = m_identifyPoint; m_identifyPoint = e->pos(); @@ -2100,7 +2100,7 @@ m_altPressed = (e->modifiers() & Qt::AltModifier); ViewManager::ToolMode mode = ViewManager::NavigateMode; - if (m_manager) mode = m_manager->getToolMode(); + if (m_manager) mode = m_manager->getToolModeFor(this); bool relocate = (mode == ViewManager::NavigateMode || (e->buttons() & Qt::MidButton)); @@ -2421,9 +2421,9 @@ Pane::editSelectionStart(QMouseEvent *e) { if (!m_identifyFeatures || - !m_manager || - m_manager->getToolMode() != ViewManager::EditMode) { - return false; + !m_manager || + m_manager->getToolModeFor(this) != ViewManager::EditMode) { + return false; } bool closeToLeft, closeToRight; @@ -2499,7 +2499,7 @@ void Pane::toolModeChanged() { - ViewManager::ToolMode mode = m_manager->getToolMode(); + ViewManager::ToolMode mode = m_manager->getToolModeFor(this); // SVDEBUG << "Pane::toolModeChanged(" << mode << ")" << endl; if (mode == ViewManager::MeasureMode && !m_measureCursor1) { @@ -2629,7 +2629,7 @@ } ViewManager::ToolMode mode = ViewManager::NavigateMode; - if (m_manager) mode = m_manager->getToolMode(); + if (m_manager) mode = m_manager->getToolModeFor(this); bool editable = false; Layer *layer = getSelectedLayer(); diff -r c65826b5e980 -r 084fd76deb89 view/ViewManager.cpp --- a/view/ViewManager.cpp Thu Jan 09 09:18:17 2014 +0000 +++ b/view/ViewManager.cpp Thu Jan 09 16:41:55 2014 +0000 @@ -364,6 +364,28 @@ }; } +ViewManager::ToolMode +ViewManager::getToolModeFor(const View *v) const +{ + if (m_toolModeOverrides.find(v) == m_toolModeOverrides.end()) { + return getToolMode(); + } else { + return m_toolModeOverrides.find(v)->second; + } +} + +void +ViewManager::setToolModeFor(const View *v, ToolMode mode) +{ + m_toolModeOverrides[v] = mode; +} + +void +ViewManager::clearToolModeOverrides() +{ + m_toolModeOverrides.clear(); +} + void ViewManager::setPlayLoopMode(bool mode) { diff -r c65826b5e980 -r 084fd76deb89 view/ViewManager.h --- a/view/ViewManager.h Thu Jan 09 09:18:17 2014 +0000 +++ b/view/ViewManager.h Thu Jan 09 16:41:55 2014 +0000 @@ -98,7 +98,7 @@ enum ToolMode { NavigateMode, SelectMode, - EditMode, + EditMode, DrawMode, EraseMode, MeasureMode, @@ -107,6 +107,13 @@ ToolMode getToolMode() const { return m_toolMode; } void setToolMode(ToolMode mode); + /// Override the tool mode for a specific view + void setToolModeFor(const View *v, ToolMode mode); + /// Return override mode if it exists for this view or global mode otherwise + ToolMode getToolModeFor(const View *v) const; + /// Clear all current view-specific overrides + void clearToolModeOverrides(); + bool getPlayLoopMode() const { return m_playLoopMode; } void setPlayLoopMode(bool on); @@ -274,6 +281,7 @@ Clipboard m_clipboard; ToolMode m_toolMode; + std::map m_toolModeOverrides; bool m_playLoopMode; bool m_playSelectionMode;