comparison view/PaneStack.cpp @ 718:e5f4385615ac tony_integration

Merge from tonioni branch
author Chris Cannam
date Tue, 28 Jan 2014 15:02:09 +0000
parents 67b167bb60ab
children 596414d20ef0
comparison
equal deleted inserted replaced
704:b81f21f2c4c3 718:e5f4385615ac
37 //#define DEBUG_PANE_STACK 1 37 //#define DEBUG_PANE_STACK 1
38 38
39 PaneStack::PaneStack(QWidget *parent, ViewManager *viewManager) : 39 PaneStack::PaneStack(QWidget *parent, ViewManager *viewManager) :
40 QFrame(parent), 40 QFrame(parent),
41 m_currentPane(0), 41 m_currentPane(0),
42 m_showAccessories(true),
42 m_splitter(new QSplitter), 43 m_splitter(new QSplitter),
43 m_propertyStackStack(new QStackedWidget), 44 m_propertyStackStack(new QStackedWidget),
44 m_viewManager(viewManager), 45 m_viewManager(viewManager),
45 m_propertyStackMinWidth(100), 46 m_propertyStackMinWidth(100),
46 m_layoutStyle(PropertyStackPerPaneLayout) 47 m_layoutStyle(PropertyStackPerPaneLayout)
58 m_propertyStackStack->hide(); 59 m_propertyStackStack->hide();
59 60
60 setLayout(layout); 61 setLayout(layout);
61 } 62 }
62 63
64 void
65 PaneStack::setShowPaneAccessories(bool show)
66 {
67 m_showAccessories = show;
68 }
69
63 Pane * 70 Pane *
64 PaneStack::addPane(bool suppressPropertyBox) 71 PaneStack::addPane(bool suppressPropertyBox)
65 { 72 {
66 return insertPane(getPaneCount(), suppressPropertyBox); 73 return insertPane(getPaneCount(), suppressPropertyBox);
67 } 74 }
77 84
78 QPushButton *xButton = new QPushButton(frame); 85 QPushButton *xButton = new QPushButton(frame);
79 xButton->setIcon(IconLoader().load("cross")); 86 xButton->setIcon(IconLoader().load("cross"));
80 xButton->setFixedSize(QSize(16, 16)); 87 xButton->setFixedSize(QSize(16, 16));
81 xButton->setFlat(true); 88 xButton->setFlat(true);
89 xButton->setVisible(m_showAccessories);
82 layout->addWidget(xButton, 0, 0); 90 layout->addWidget(xButton, 0, 0);
83 connect(xButton, SIGNAL(clicked()), this, SLOT(paneDeleteButtonClicked())); 91 connect(xButton, SIGNAL(clicked()), this, SLOT(paneDeleteButtonClicked()));
84 92
85 ClickableLabel *currentIndicator = new ClickableLabel(frame); 93 ClickableLabel *currentIndicator = new ClickableLabel(frame);
86 connect(currentIndicator, SIGNAL(clicked()), this, SLOT(indicatorClicked())); 94 connect(currentIndicator, SIGNAL(clicked()), this, SLOT(indicatorClicked()));
87 layout->addWidget(currentIndicator, 1, 0); 95 layout->addWidget(currentIndicator, 1, 0);
88 layout->setRowStretch(1, 20); 96 layout->setRowStretch(1, 20);
89 currentIndicator->setMinimumWidth(8); 97 currentIndicator->setMinimumWidth(8);
90 currentIndicator->setScaledContents(true); 98 currentIndicator->setScaledContents(true);
99 currentIndicator->setVisible(m_showAccessories);
91 100
92 long initialCentreFrame = -1; 101 long initialCentreFrame = -1;
93 for (int i = 0; i < m_panes.size(); ++i) { 102 for (int i = 0; i < m_panes.size(); ++i) {
94 long f = m_panes[i].pane->getCentreFrame(); 103 long f = m_panes[i].pane->getCentreFrame();
95 initialCentreFrame = f; 104 initialCentreFrame = f;
147 this, SLOT(rightButtonMenuRequested(QPoint))); 156 this, SLOT(rightButtonMenuRequested(QPoint)));
148 connect(pane, SIGNAL(dropAccepted(QStringList)), 157 connect(pane, SIGNAL(dropAccepted(QStringList)),
149 this, SLOT(paneDropAccepted(QStringList))); 158 this, SLOT(paneDropAccepted(QStringList)));
150 connect(pane, SIGNAL(dropAccepted(QString)), 159 connect(pane, SIGNAL(dropAccepted(QString)),
151 this, SLOT(paneDropAccepted(QString))); 160 this, SLOT(paneDropAccepted(QString)));
161 connect(pane, SIGNAL(doubleClickSelectInvoked(size_t)),
162 this, SIGNAL(doubleClickSelectInvoked(size_t)));
152 163
153 emit paneAdded(pane); 164 emit paneAdded(pane);
154 emit paneAdded(); 165 emit paneAdded();
155 166
156 if (!m_currentPane) { 167 if (!m_currentPane) {
286 cerr << "PaneStack::showOrHidePaneAccessories: count == " << getPaneCount() << endl; 297 cerr << "PaneStack::showOrHidePaneAccessories: count == " << getPaneCount() << endl;
287 298
288 bool multi = (getPaneCount() > 1); 299 bool multi = (getPaneCount() > 1);
289 for (std::vector<PaneRec>::iterator i = m_panes.begin(); 300 for (std::vector<PaneRec>::iterator i = m_panes.begin();
290 i != m_panes.end(); ++i) { 301 i != m_panes.end(); ++i) {
291 i->xButton->setVisible(multi); 302 i->xButton->setVisible(multi && m_showAccessories);
292 i->currentIndicator->setVisible(multi); 303 i->currentIndicator->setVisible(multi && m_showAccessories);
293 } 304 }
294 } 305 }
295 306
296 int 307 int
297 PaneStack::getPaneCount() const 308 PaneStack::getPaneCount() const
578 QList<int> sizes = m_splitter->sizes(); 589 QList<int> sizes = m_splitter->sizes();
579 if (sizes.empty()) return; 590 if (sizes.empty()) return;
580 591
581 int count = sizes.size(); 592 int count = sizes.size();
582 593
583 int total = 0; 594 int fixed = 0, variable = 0, total = 0;
595 int varicount = 0;
596
584 for (int i = 0; i < count; ++i) { 597 for (int i = 0; i < count; ++i) {
585 total += sizes[i]; 598 total += sizes[i];
586 } 599 }
587 600
601 variable = total;
602
603 for (int i = 0; i < count; ++i) {
604 int minh = m_panes[i].pane->minimumSize().height();
605 if (minh == m_panes[i].pane->maximumSize().height()) {
606 fixed += minh;
607 variable -= minh;
608 } else {
609 varicount++;
610 }
611 }
612
588 if (total == 0) return; 613 if (total == 0) return;
589 614
590 sizes.clear(); 615 sizes.clear();
591 616
592 int each = total / count; 617 int each = (varicount > 0 ? (variable / varicount) : 0);
593 int remaining = total; 618 int remaining = total;
594 619
595 for (int i = 0; i < count; ++i) { 620 for (int i = 0; i < count; ++i) {
596 if (i == count - 1) { 621 if (i == count - 1) {
597 sizes.push_back(remaining); 622 sizes.push_back(remaining);
598 } else { 623 } else {
599 sizes.push_back(each); 624 int minh = m_panes[i].pane->minimumSize().height();
600 remaining -= each; 625 if (minh == m_panes[i].pane->maximumSize().height()) {
626 sizes.push_back(minh);
627 remaining -= minh;
628 } else {
629 sizes.push_back(each);
630 remaining -= each;
631 }
601 } 632 }
602 } 633 }
603 634
604 /* 635 /*
605 cerr << "sizes: "; 636 cerr << "sizes: ";
610 */ 641 */
611 642
612 m_splitter->setSizes(sizes); 643 m_splitter->setSizes(sizes);
613 } 644 }
614 645
615