Mercurial > hg > svgui
comparison 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 |
comparison
equal
deleted
inserted
replaced
322:07aa52466142 | 323:267586900360 |
---|---|
16 | 16 |
17 #include "PaneStack.h" | 17 #include "PaneStack.h" |
18 | 18 |
19 #include "Pane.h" | 19 #include "Pane.h" |
20 #include "widgets/PropertyStack.h" | 20 #include "widgets/PropertyStack.h" |
21 #include "widgets/IconLoader.h" | |
21 #include "layer/Layer.h" | 22 #include "layer/Layer.h" |
22 #include "ViewManager.h" | 23 #include "ViewManager.h" |
23 | 24 |
24 #include <QApplication> | 25 #include <QApplication> |
25 #include <QHBoxLayout> | 26 #include <QHBoxLayout> |
27 #include <QVBoxLayout> | |
26 #include <QPainter> | 28 #include <QPainter> |
27 #include <QPalette> | 29 #include <QPalette> |
28 #include <QLabel> | 30 #include <QLabel> |
31 #include <QPushButton> | |
29 #include <QSplitter> | 32 #include <QSplitter> |
30 #include <QStackedWidget> | 33 #include <QStackedWidget> |
31 | 34 |
32 #include <iostream> | 35 #include <iostream> |
33 | 36 |
62 QFrame *frame = new QFrame; | 65 QFrame *frame = new QFrame; |
63 QHBoxLayout *layout = new QHBoxLayout; | 66 QHBoxLayout *layout = new QHBoxLayout; |
64 layout->setMargin(0); | 67 layout->setMargin(0); |
65 layout->setSpacing(2); | 68 layout->setSpacing(2); |
66 | 69 |
70 QVBoxLayout *vlayout = new QVBoxLayout; | |
71 layout->addLayout(vlayout); | |
72 layout->setStretchFactor(vlayout, 1); | |
73 | |
74 QPushButton *xButton = new QPushButton(frame); | |
75 xButton->setIcon(IconLoader().load("cross")); | |
76 xButton->setFixedSize(QSize(16, 16)); | |
77 vlayout->addWidget(xButton); | |
78 vlayout->setStretchFactor(xButton, 1); | |
79 connect(xButton, SIGNAL(clicked()), this, SLOT(paneDeleteButtonClicked())); | |
80 | |
67 QLabel *currentIndicator = new QLabel(frame); | 81 QLabel *currentIndicator = new QLabel(frame); |
68 currentIndicator->setFixedWidth(QPainter(this).fontMetrics().width("x")); | 82 // currentIndicator->setFixedWidth(QPainter(this).fontMetrics().width("x")); |
69 layout->addWidget(currentIndicator); | 83 vlayout->addWidget(currentIndicator); |
70 layout->setStretchFactor(currentIndicator, 1); | 84 vlayout->setStretchFactor(currentIndicator, 10); |
71 currentIndicator->setScaledContents(true); | 85 currentIndicator->setScaledContents(true); |
72 | 86 |
73 Pane *pane = new Pane(frame); | 87 Pane *pane = new Pane(frame); |
74 pane->setViewManager(m_viewManager); | 88 pane->setViewManager(m_viewManager); |
75 layout->addWidget(pane); | 89 layout->addWidget(pane); |
76 layout->setStretchFactor(pane, 10); | 90 layout->setStretchFactor(pane, 10); |
91 | |
92 m_xButtonMap[xButton] = pane; | |
77 | 93 |
78 QWidget *properties = 0; | 94 QWidget *properties = 0; |
79 if (suppressPropertyBox) { | 95 if (suppressPropertyBox) { |
80 properties = new QFrame(); | 96 properties = new QFrame(); |
81 } else { | 97 } else { |
229 return; | 245 return; |
230 } | 246 } |
231 } | 247 } |
232 | 248 |
233 emit paneAboutToBeDeleted(pane); | 249 emit paneAboutToBeDeleted(pane); |
250 | |
251 for (std::map<QWidget *, Pane *>::iterator i = m_xButtonMap.begin(); | |
252 i != m_xButtonMap.end(); ++i) { | |
253 | |
254 if (i->second == pane) { | |
255 m_xButtonMap.erase(i); | |
256 break; | |
257 } | |
258 } | |
234 | 259 |
235 delete pane->parent(); | 260 delete pane->parent(); |
236 | 261 |
237 if (m_currentPane == pane) { | 262 if (m_currentPane == pane) { |
238 if (m_panes.size() > 0) { | 263 if (m_panes.size() > 0) { |
502 Pane *pane = dynamic_cast<Pane *>(sender()); | 527 Pane *pane = dynamic_cast<Pane *>(sender()); |
503 emit dropAccepted(pane, text); | 528 emit dropAccepted(pane, text); |
504 } | 529 } |
505 | 530 |
506 void | 531 void |
532 PaneStack::paneDeleteButtonClicked() | |
533 { | |
534 QObject *s = sender(); | |
535 QWidget *w = dynamic_cast<QWidget *>(s); | |
536 if (w) { | |
537 if (m_xButtonMap.find(w) != m_xButtonMap.end()) { | |
538 Pane *p = m_xButtonMap[w]; | |
539 emit paneDeleteButtonClicked(p); | |
540 } | |
541 } | |
542 } | |
543 | |
544 void | |
507 PaneStack::sizePanesEqually() | 545 PaneStack::sizePanesEqually() |
508 { | 546 { |
509 QList<int> sizes = m_splitter->sizes(); | 547 QList<int> sizes = m_splitter->sizes(); |
510 if (sizes.empty()) return; | 548 if (sizes.empty()) return; |
511 | 549 |