Mercurial > hg > svgui
diff view/PaneStack.cpp @ 323:267586900360
* Add [x] button to pane to quickly delete it
author | Chris Cannam |
---|---|
date | Wed, 07 Nov 2007 16:37:17 +0000 |
parents | 984c1975f1ff |
children | 1f67b110c1a3 |
line wrap: on
line diff
--- 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 <QApplication> #include <QHBoxLayout> +#include <QVBoxLayout> #include <QPainter> #include <QPalette> #include <QLabel> +#include <QPushButton> #include <QSplitter> #include <QStackedWidget> @@ -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<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) { @@ -504,6 +529,19 @@ } void +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); + } + } +} + +void PaneStack::sizePanesEqually() { QList<int> sizes = m_splitter->sizes();