changeset 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 afed40a40d1d
children fbab21439115
files view/PaneStack.cpp view/PaneStack.h
diffstat 2 files changed, 30 insertions(+), 20 deletions(-) [+]
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);
         }
     }
 }
--- a/view/PaneStack.h	Fri Jan 13 17:43:06 2012 +0000
+++ b/view/PaneStack.h	Mon Jan 23 14:28:40 2012 +0000
@@ -25,6 +25,7 @@
 class QStackedWidget;
 class QSplitter;
 class QGridLayout;
+class QPushButton;
 class View;
 class Pane;
 class Layer;
@@ -109,6 +110,7 @@
     {
 	Pane        *pane;
 	QWidget     *propertyStack;
+        QPushButton *xButton;
 	QLabel      *currentIndicator;
         QFrame      *frame;
         QGridLayout *layout;
@@ -117,8 +119,6 @@
     std::vector<PaneRec> m_panes;
     std::vector<PaneRec> m_hiddenPanes;
 
-    std::map<QWidget *, Pane *> m_xButtonMap;
-
     QSplitter *m_splitter;
     QStackedWidget *m_propertyStackStack;
 
@@ -126,6 +126,8 @@
     int m_propertyStackMinWidth;
     void sizePropertyStacks();
 
+    void showOrHidePaneAccessories();
+
     LayoutStyle m_layoutStyle;
 };