comparison view/PaneStack.cpp @ 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 4806715f7a19
children fbab21439115
comparison
equal deleted inserted replaced
604:afed40a40d1d 605:a7a89ebe4b02
102 pane->setViewManager(m_viewManager); 102 pane->setViewManager(m_viewManager);
103 } 103 }
104 layout->addWidget(pane, 0, 1, 2, 1); 104 layout->addWidget(pane, 0, 1, 2, 1);
105 layout->setColumnStretch(1, 20); 105 layout->setColumnStretch(1, 20);
106 106
107 m_xButtonMap[xButton] = pane;
108
109 QWidget *properties = 0; 107 QWidget *properties = 0;
110 if (suppressPropertyBox) { 108 if (suppressPropertyBox) {
111 properties = new QFrame(); 109 properties = new QFrame();
112 } else { 110 } else {
113 properties = new PropertyStack(frame, pane); 111 properties = new PropertyStack(frame, pane);
127 layout->setColumnStretch(2, 1); 125 layout->setColumnStretch(2, 1);
128 126
129 PaneRec rec; 127 PaneRec rec;
130 rec.pane = pane; 128 rec.pane = pane;
131 rec.propertyStack = properties; 129 rec.propertyStack = properties;
130 rec.xButton = xButton;
132 rec.currentIndicator = currentIndicator; 131 rec.currentIndicator = currentIndicator;
133 rec.frame = frame; 132 rec.frame = frame;
134 rec.layout = layout; 133 rec.layout = layout;
135 m_panes.push_back(rec); 134 m_panes.push_back(rec);
136 135
155 154
156 if (!m_currentPane) { 155 if (!m_currentPane) {
157 setCurrentPane(pane); 156 setCurrentPane(pane);
158 } 157 }
159 158
159 showOrHidePaneAccessories();
160
160 return pane; 161 return pane;
161 } 162 }
162 163
163 void 164 void
164 PaneStack::setPropertyStackMinWidth(int mw) 165 PaneStack::setPropertyStackMinWidth(int mw)
261 } 262 }
262 } 263 }
263 264
264 emit paneAboutToBeDeleted(pane); 265 emit paneAboutToBeDeleted(pane);
265 266
266 for (std::map<QWidget *, Pane *>::iterator i = m_xButtonMap.begin();
267 i != m_xButtonMap.end(); ++i) {
268
269 if (i->second == pane) {
270 m_xButtonMap.erase(i);
271 break;
272 }
273 }
274
275 delete pane->parent(); 267 delete pane->parent();
276 268
277 if (m_currentPane == pane) { 269 if (m_currentPane == pane) {
278 if (m_panes.size() > 0) { 270 if (m_panes.size() > 0) {
279 setCurrentPane(m_panes[0].pane); 271 setCurrentPane(m_panes[0].pane);
280 } else { 272 } else {
281 setCurrentPane(0); 273 setCurrentPane(0);
282 } 274 }
283 } 275 }
284 276
277 showOrHidePaneAccessories();
278
285 emit paneDeleted(); 279 emit paneDeleted();
280 }
281
282 void
283 PaneStack::showOrHidePaneAccessories()
284 {
285 std::cerr << "PaneStack::showOrHidePaneAccessories: count == " << getPaneCount() << std::endl;
286
287 bool multi = (getPaneCount() > 1);
288 for (std::vector<PaneRec>::iterator i = m_panes.begin();
289 i != m_panes.end(); ++i) {
290 i->xButton->setVisible(multi);
291 i->currentIndicator->setVisible(multi);
292 }
286 } 293 }
287 294
288 int 295 int
289 PaneStack::getPaneCount() const 296 PaneStack::getPaneCount() const
290 { 297 {
317 } else { 324 } else {
318 setCurrentPane(0); 325 setCurrentPane(0);
319 } 326 }
320 } 327 }
321 328
329 showOrHidePaneAccessories();
330 emit paneHidden(pane);
331 emit paneHidden();
322 return; 332 return;
323 } 333 }
324 ++i; 334 ++i;
325 } 335 }
326 336
327 std::cerr << "WARNING: PaneStack::hidePane(" << pane << "): Pane not found in visible panes" << std::endl; 337 std::cerr << "WARNING: PaneStack::hidePane(" << pane << "): Pane not found in visible panes" << std::endl;
328 emit paneHidden(pane);
329 emit paneHidden();
330 } 338 }
331 339
332 void 340 void
333 PaneStack::showPane(Pane *pane) 341 PaneStack::showPane(Pane *pane)
334 { 342 {
340 m_hiddenPanes.erase(i); 348 m_hiddenPanes.erase(i);
341 QWidget *pw = dynamic_cast<QWidget *>(pane->parent()); 349 QWidget *pw = dynamic_cast<QWidget *>(pane->parent());
342 if (pw) pw->show(); 350 if (pw) pw->show();
343 351
344 //!!! update current pane 352 //!!! update current pane
353
354 showOrHidePaneAccessories();
345 355
346 return; 356 return;
347 } 357 }
348 ++i; 358 ++i;
349 } 359 }
539 549
540 void 550 void
541 PaneStack::paneDeleteButtonClicked() 551 PaneStack::paneDeleteButtonClicked()
542 { 552 {
543 QObject *s = sender(); 553 QObject *s = sender();
544 QWidget *w = dynamic_cast<QWidget *>(s); 554 for (size_t i = 0; i < m_panes.size(); ++i) {
545 if (w) { 555 if (m_panes[i].xButton == s) {
546 if (m_xButtonMap.find(w) != m_xButtonMap.end()) { 556 emit paneDeleteButtonClicked(m_panes[i].pane);
547 Pane *p = m_xButtonMap[w];
548 emit paneDeleteButtonClicked(p);
549 } 557 }
550 } 558 }
551 } 559 }
552 560
553 void 561 void