# HG changeset patch # User Chris Cannam # Date 1194453437 0 # Node ID 2675869003603da0f30b5f10e4cf3e0677a8de9f # Parent 07aa524661428f68d7a21915b547c40cf15a7c60 * Add [x] button to pane to quickly delete it diff -r 07aa52466142 -r 267586900360 view/PaneStack.cpp --- a/view/PaneStack.cpp Thu Nov 01 10:45:28 2007 +0000 +++ b/view/PaneStack.cpp Wed Nov 07 16:37:17 2007 +0000 @@ -18,14 +18,17 @@ #include "Pane.h" #include "widgets/PropertyStack.h" +#include "widgets/IconLoader.h" #include "layer/Layer.h" #include "ViewManager.h" #include #include +#include #include #include #include +#include #include #include @@ -64,10 +67,21 @@ layout->setMargin(0); layout->setSpacing(2); + QVBoxLayout *vlayout = new QVBoxLayout; + layout->addLayout(vlayout); + layout->setStretchFactor(vlayout, 1); + + QPushButton *xButton = new QPushButton(frame); + xButton->setIcon(IconLoader().load("cross")); + xButton->setFixedSize(QSize(16, 16)); + vlayout->addWidget(xButton); + vlayout->setStretchFactor(xButton, 1); + connect(xButton, SIGNAL(clicked()), this, SLOT(paneDeleteButtonClicked())); + QLabel *currentIndicator = new QLabel(frame); - currentIndicator->setFixedWidth(QPainter(this).fontMetrics().width("x")); - layout->addWidget(currentIndicator); - layout->setStretchFactor(currentIndicator, 1); +// currentIndicator->setFixedWidth(QPainter(this).fontMetrics().width("x")); + vlayout->addWidget(currentIndicator); + vlayout->setStretchFactor(currentIndicator, 10); currentIndicator->setScaledContents(true); Pane *pane = new Pane(frame); @@ -75,6 +89,8 @@ layout->addWidget(pane); layout->setStretchFactor(pane, 10); + m_xButtonMap[xButton] = pane; + QWidget *properties = 0; if (suppressPropertyBox) { properties = new QFrame(); @@ -232,6 +248,15 @@ emit paneAboutToBeDeleted(pane); + for (std::map::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) { @@ -504,6 +529,19 @@ } void +PaneStack::paneDeleteButtonClicked() +{ + QObject *s = sender(); + QWidget *w = dynamic_cast(s); + if (w) { + if (m_xButtonMap.find(w) != m_xButtonMap.end()) { + Pane *p = m_xButtonMap[w]; + emit paneDeleteButtonClicked(p); + } + } +} + +void PaneStack::sizePanesEqually() { QList sizes = m_splitter->sizes(); diff -r 07aa52466142 -r 267586900360 view/PaneStack.h --- a/view/PaneStack.h Thu Nov 01 10:45:28 2007 +0000 +++ b/view/PaneStack.h Wed Nov 07 16:37:17 2007 +0000 @@ -19,6 +19,8 @@ #include +#include + class QWidget; class QLabel; class QStackedWidget; @@ -85,6 +87,8 @@ void dropAccepted(Pane *pane, QStringList uriList); void dropAccepted(Pane *pane, QString text); + void paneDeleteButtonClicked(Pane *pane); + public slots: void propertyContainerAdded(PropertyContainer *); void propertyContainerRemoved(PropertyContainer *); @@ -94,6 +98,7 @@ void rightButtonMenuRequested(QPoint); void paneDropAccepted(QStringList); void paneDropAccepted(QString); + void paneDeleteButtonClicked(); protected: Pane *m_currentPane; @@ -110,6 +115,8 @@ std::vector m_panes; std::vector m_hiddenPanes; + std::map m_xButtonMap; + QSplitter *m_splitter; QStackedWidget *m_propertyStackStack;