comparison view/PaneStack.cpp @ 771:a964151832a7

Merge from branch tony_integration
author Chris Cannam
date Wed, 14 May 2014 09:54:34 +0100
parents b6dc57688c72
children 4c8ca536b54f
comparison
equal deleted inserted replaced
768:8b614632568c 771:a964151832a7
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) {
304 cerr << "PaneStack::showOrHidePaneAccessories: count == " << getPaneCount() << endl; 315 cerr << "PaneStack::showOrHidePaneAccessories: count == " << getPaneCount() << endl;
305 316
306 bool multi = (getPaneCount() > 1); 317 bool multi = (getPaneCount() > 1);
307 for (std::vector<PaneRec>::iterator i = m_panes.begin(); 318 for (std::vector<PaneRec>::iterator i = m_panes.begin();
308 i != m_panes.end(); ++i) { 319 i != m_panes.end(); ++i) {
309 i->xButton->setVisible(multi); 320 i->xButton->setVisible(multi && m_showAccessories);
310 i->currentIndicator->setVisible(multi); 321 i->currentIndicator->setVisible(multi && m_showAccessories);
311 } 322 }
312 } 323 }
313 324
314 int 325 int
315 PaneStack::getPaneCount() const 326 PaneStack::getPaneCount() const
596 QList<int> sizes = m_splitter->sizes(); 607 QList<int> sizes = m_splitter->sizes();
597 if (sizes.empty()) return; 608 if (sizes.empty()) return;
598 609
599 int count = sizes.size(); 610 int count = sizes.size();
600 611
601 int total = 0; 612 int fixed = 0, variable = 0, total = 0;
613 int varicount = 0;
614
602 for (int i = 0; i < count; ++i) { 615 for (int i = 0; i < count; ++i) {
603 total += sizes[i]; 616 total += sizes[i];
604 } 617 }
605 618
619 variable = total;
620
621 for (int i = 0; i < count; ++i) {
622 int minh = m_panes[i].pane->minimumSize().height();
623 if (minh == m_panes[i].pane->maximumSize().height()) {
624 fixed += minh;
625 variable -= minh;
626 } else {
627 varicount++;
628 }
629 }
630
606 if (total == 0) return; 631 if (total == 0) return;
607 632
608 sizes.clear(); 633 sizes.clear();
609 634
610 int each = total / count; 635 int each = (varicount > 0 ? (variable / varicount) : 0);
611 int remaining = total; 636 int remaining = total;
612 637
613 for (int i = 0; i < count; ++i) { 638 for (int i = 0; i < count; ++i) {
614 if (i == count - 1) { 639 if (i == count - 1) {
615 sizes.push_back(remaining); 640 sizes.push_back(remaining);
616 } else { 641 } else {
617 sizes.push_back(each); 642 int minh = m_panes[i].pane->minimumSize().height();
618 remaining -= each; 643 if (minh == m_panes[i].pane->maximumSize().height()) {
644 sizes.push_back(minh);
645 remaining -= minh;
646 } else {
647 sizes.push_back(each);
648 remaining -= each;
649 }
619 } 650 }
620 } 651 }
621 652
622 /* 653 /*
623 cerr << "sizes: "; 654 cerr << "sizes: ";
628 */ 659 */
629 660
630 m_splitter->setSizes(sizes); 661 m_splitter->setSizes(sizes);
631 } 662 }
632 663
633