diff view/PaneStack.cpp @ 605:a7a89ebe4b02

Show current-pane indicator and close-pane button only if there is more than one pane
author Chris Cannam
date Mon, 23 Jan 2012 14:28:40 +0000
parents 4806715f7a19
children fbab21439115
line wrap: on
line diff
--- a/view/PaneStack.cpp	Fri Jan 13 17:43:06 2012 +0000
+++ b/view/PaneStack.cpp	Mon Jan 23 14:28:40 2012 +0000
@@ -104,8 +104,6 @@
     layout->addWidget(pane, 0, 1, 2, 1);
     layout->setColumnStretch(1, 20);
 
-    m_xButtonMap[xButton] = pane;
-
     QWidget *properties = 0;
     if (suppressPropertyBox) {
 	properties = new QFrame();
@@ -129,6 +127,7 @@
     PaneRec rec;
     rec.pane = pane;
     rec.propertyStack = properties;
+    rec.xButton = xButton;
     rec.currentIndicator = currentIndicator;
     rec.frame = frame;
     rec.layout = layout;
@@ -157,6 +156,8 @@
 	setCurrentPane(pane);
     }
 
+    showOrHidePaneAccessories();
+
     return pane;
 }
 
@@ -263,15 +264,6 @@
 
     emit paneAboutToBeDeleted(pane);
 
-    for (std::map<QWidget *, Pane *>::iterator i = m_xButtonMap.begin();
-         i != m_xButtonMap.end(); ++i) {
-
-        if (i->second == pane) {
-            m_xButtonMap.erase(i);
-            break;
-        }
-    }
-
     delete pane->parent();
 
     if (m_currentPane == pane) {
@@ -282,9 +274,24 @@
 	}
     }
 
+    showOrHidePaneAccessories();
+
     emit paneDeleted();
 }
 
+void
+PaneStack::showOrHidePaneAccessories()
+{
+    std::cerr << "PaneStack::showOrHidePaneAccessories: count == " << getPaneCount() << std::endl;
+
+    bool multi = (getPaneCount() > 1);
+    for (std::vector<PaneRec>::iterator i = m_panes.begin();
+         i != m_panes.end(); ++i) {
+        i->xButton->setVisible(multi);
+        i->currentIndicator->setVisible(multi);
+    }
+}
+
 int
 PaneStack::getPaneCount() const
 {
@@ -319,14 +326,15 @@
 		}
 	    }
 	    
+            showOrHidePaneAccessories();
+            emit paneHidden(pane);
+            emit paneHidden();
 	    return;
 	}
 	++i;
     }
 
     std::cerr << "WARNING: PaneStack::hidePane(" << pane << "): Pane not found in visible panes" << std::endl;
-    emit paneHidden(pane);
-    emit paneHidden();
 }
 
 void
@@ -343,6 +351,8 @@
 
 	    //!!! update current pane
 
+            showOrHidePaneAccessories();
+
 	    return;
 	}
 	++i;
@@ -541,11 +551,9 @@
 PaneStack::paneDeleteButtonClicked()
 {
     QObject *s = sender();
-    QWidget *w = dynamic_cast<QWidget *>(s);
-    if (w) {
-        if (m_xButtonMap.find(w) != m_xButtonMap.end()) {
-            Pane *p = m_xButtonMap[w];
-            emit paneDeleteButtonClicked(p);
+    for (size_t i = 0; i < m_panes.size(); ++i) {
+	if (m_panes[i].xButton == s) {
+            emit paneDeleteButtonClicked(m_panes[i].pane);
         }
     }
 }