diff base/ViewManager.cpp @ 8:214054a0d8b8

* Hook up tool selection buttons to switch the cursor mode * Implement simple and multi-selection, snapping to the resolution of the current layer. You can't actually do anything with a selection yet
author Chris Cannam
date Mon, 23 Jan 2006 17:02:57 +0000
parents d86891498eef
children 73d85d19919f
line wrap: on
line diff
--- a/base/ViewManager.cpp	Thu Jan 19 17:59:11 2006 +0000
+++ b/base/ViewManager.cpp	Mon Jan 23 17:02:57 2006 +0000
@@ -21,7 +21,9 @@
     m_globalCentreFrame(0),
     m_globalZoom(1024),
     m_lastLeft(0), 
-    m_lastRight(0)
+    m_lastRight(0),
+    m_inProgressExclusive(true),
+    m_toolMode(NavigateMode)
 {
     connect(this, 
 	    SIGNAL(centreFrameChanged(void *, unsigned long, bool)),
@@ -50,6 +52,107 @@
     return m_globalZoom;
 }
 
+bool
+ViewManager::haveInProgressSelection() const
+{
+    return !m_inProgressSelection.isEmpty();
+}
+
+const Selection &
+ViewManager::getInProgressSelection(bool &exclusive) const
+{
+    exclusive = m_inProgressExclusive;
+    return m_inProgressSelection;
+}
+
+void
+ViewManager::setInProgressSelection(const Selection &selection, bool exclusive)
+{
+    m_inProgressExclusive = exclusive;
+    m_inProgressSelection = selection;
+    if (exclusive) clearSelections();
+    emit selectionChanged();
+}
+
+void
+ViewManager::clearInProgressSelection()
+{
+    m_inProgressSelection = Selection();
+    emit selectionChanged();
+}
+
+const ViewManager::SelectionList &
+ViewManager::getSelections() const
+{
+    return m_selections;
+}
+
+void
+ViewManager::setSelection(const Selection &selection)
+{
+    clearSelections();
+    addSelection(selection);
+}
+
+void
+ViewManager::addSelection(const Selection &selection)
+{
+    m_selections.insert(selection);
+
+    // Cope with a sitation where the new selection overlaps one or
+    // more existing ones.  This is a terribly inefficient way to do
+    // this, but that probably isn't significant in real life.
+
+     for (SelectionList::iterator i = m_selections.begin();
+	 i != m_selections.end(); ) {
+	
+	SelectionList::iterator j = i;
+	if (++j == m_selections.end()) break;
+
+	if (i->getEndFrame() >= j->getStartFrame()) {
+	    Selection merged(i->getStartFrame(),
+			     std::max(i->getEndFrame(), j->getEndFrame()));
+	    m_selections.erase(i);
+	    m_selections.erase(j);
+	    m_selections.insert(merged);
+	    i = m_selections.begin();
+	} else {
+	    ++i;
+	}
+    }
+
+    emit selectionChanged();
+}
+
+void
+ViewManager::removeSelection(const Selection &selection)
+{
+    //!!! Likewise this needs to cope correctly with the situation
+    //where selection is not one of the original selection set but
+    //simply overlaps one of them (cutting down the original selection
+    //appropriately)
+
+    m_selections.erase(selection);
+
+    emit selectionChanged();
+}
+
+void
+ViewManager::clearSelections()
+{
+    m_selections.clear();
+
+    emit selectionChanged();
+}
+
+void
+ViewManager::setToolMode(ToolMode mode)
+{
+    m_toolMode = mode;
+
+    emit toolModeChanged();
+}
+
 void
 ViewManager::setAudioPlaySource(AudioPlaySource *source)
 {
@@ -119,6 +222,12 @@
     }
 }
 
+bool
+ViewManager::isPlaying() const
+{
+    return m_playSource && m_playSource->isPlaying();
+}
+
 void
 ViewManager::considerSeek(void *p, unsigned long f, bool locked)
 {