Mercurial > hg > svgui
changeset 323:267586900360
* Add [x] button to pane to quickly delete it
author | Chris Cannam |
---|---|
date | Wed, 07 Nov 2007 16:37:17 +0000 |
parents | 07aa52466142 |
children | 1f67b110c1a3 |
files | view/PaneStack.cpp view/PaneStack.h |
diffstat | 2 files changed, 48 insertions(+), 3 deletions(-) [+] |
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();
--- 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 <QFrame> +#include <map> + 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<PaneRec> m_panes; std::vector<PaneRec> m_hiddenPanes; + std::map<QWidget *, Pane *> m_xButtonMap; + QSplitter *m_splitter; QStackedWidget *m_propertyStackStack;