Mercurial > hg > svgui
comparison view/PaneStack.cpp @ 1459:42c87368287c
Merge from branch single-point
author | Chris Cannam |
---|---|
date | Fri, 17 May 2019 10:02:52 +0100 |
parents | 4a6ca97ce783 |
children | 69b7fdd6394f |
comparison
equal
deleted
inserted
replaced
1441:8d5bf4ab98ef | 1459:42c87368287c |
---|---|
41 QFrame(parent), | 41 QFrame(parent), |
42 m_currentPane(nullptr), | 42 m_currentPane(nullptr), |
43 m_showAccessories(true), | 43 m_showAccessories(true), |
44 m_showAlignmentViews(false), | 44 m_showAlignmentViews(false), |
45 m_splitter(new QSplitter), | 45 m_splitter(new QSplitter), |
46 m_autoResizeStack(new QWidget), | |
46 m_propertyStackStack(new QStackedWidget), | 47 m_propertyStackStack(new QStackedWidget), |
47 m_viewManager(viewManager), | 48 m_viewManager(viewManager), |
48 m_propertyStackMinWidth(100), | 49 m_propertyStackMinWidth(100), |
49 m_layoutStyle(PropertyStackPerPaneLayout) | 50 m_layoutStyle(PropertyStackPerPaneLayout), |
51 m_resizeMode(UserResizeable) | |
50 { | 52 { |
51 QHBoxLayout *layout = new QHBoxLayout; | 53 QHBoxLayout *layout = new QHBoxLayout; |
52 layout->setMargin(0); | 54 layout->setMargin(0); |
53 layout->setSpacing(0); | 55 layout->setSpacing(0); |
54 | 56 |
57 m_autoResizeLayout = new QVBoxLayout; | |
58 m_autoResizeLayout->setMargin(0); | |
59 m_autoResizeLayout->setSpacing(0); | |
60 m_autoResizeStack->setLayout(m_autoResizeLayout); | |
61 m_autoResizeStack->hide(); | |
62 layout->addWidget(m_autoResizeStack); | |
63 layout->setStretchFactor(m_autoResizeStack, 1); | |
64 | |
55 m_splitter->setOrientation(Qt::Vertical); | 65 m_splitter->setOrientation(Qt::Vertical); |
56 m_splitter->setOpaqueResize(false); | 66 m_splitter->setOpaqueResize(false); |
57 | 67 m_splitter->show(); |
58 layout->addWidget(m_splitter); | 68 layout->addWidget(m_splitter); |
59 layout->setStretchFactor(m_splitter, 1); | 69 layout->setStretchFactor(m_splitter, 1); |
70 | |
71 m_propertyStackStack->hide(); | |
60 layout->addWidget(m_propertyStackStack); | 72 layout->addWidget(m_propertyStackStack); |
61 m_propertyStackStack->hide(); | |
62 | 73 |
63 setLayout(layout); | 74 setLayout(layout); |
64 } | 75 } |
65 | 76 |
66 void | 77 void |
71 | 82 |
72 void | 83 void |
73 PaneStack::setShowAlignmentViews(bool show) | 84 PaneStack::setShowAlignmentViews(bool show) |
74 { | 85 { |
75 m_showAlignmentViews = show; | 86 m_showAlignmentViews = show; |
76 foreach (const PaneRec &r, m_panes) { | 87 // each alignment view shows alignment between the pane above and |
77 r.alignmentView->setVisible(m_showAlignmentViews); | 88 // the pane it is attached to: so pane 0 doesn't have a visible one |
89 for (int i = 1; in_range_for(m_panes, i); ++i) { | |
90 m_panes[i].alignmentView->setVisible(m_showAlignmentViews); | |
78 } | 91 } |
79 } | 92 } |
80 | 93 |
81 Pane * | 94 Pane * |
82 PaneStack::addPane(bool suppressPropertyBox) | 95 PaneStack::addPane(bool suppressPropertyBox) |
83 { | 96 { |
84 return insertPane(getPaneCount(), suppressPropertyBox); | |
85 } | |
86 | |
87 Pane * | |
88 PaneStack::insertPane(int index, bool suppressPropertyBox) | |
89 { | |
90 QFrame *frame = new QFrame; | 97 QFrame *frame = new QFrame; |
91 | 98 |
92 QGridLayout *layout = new QGridLayout; | 99 QGridLayout *layout = new QGridLayout; |
93 layout->setMargin(0); | 100 layout->setMargin(0); |
94 layout->setSpacing(2); | 101 layout->setHorizontalSpacing(m_viewManager->scalePixelSize(2)); |
102 if (m_showAlignmentViews) { | |
103 layout->setVerticalSpacing(0); | |
104 } else { | |
105 layout->setVerticalSpacing(m_viewManager->scalePixelSize(2)); | |
106 } | |
107 | |
108 AlignmentView *av = new AlignmentView(frame); | |
109 av->setFixedHeight(ViewManager::scalePixelSize(20)); | |
110 av->setViewManager(m_viewManager); | |
111 av->setVisible(false); // for now | |
112 layout->addWidget(av, 0, 1); | |
95 | 113 |
96 QPushButton *xButton = new QPushButton(frame); | 114 QPushButton *xButton = new QPushButton(frame); |
97 xButton->setIcon(IconLoader().load("cross")); | 115 xButton->setIcon(IconLoader().load("cross")); |
98 xButton->setFixedSize(QSize(16, 16)); | 116 xButton->setFixedSize(QSize(16, 16)); |
99 xButton->setFlat(true); | 117 xButton->setFlat(true); |
100 xButton->setVisible(m_showAccessories); | 118 xButton->setVisible(m_showAccessories); |
101 layout->addWidget(xButton, 0, 0); | 119 layout->addWidget(xButton, 1, 0); |
102 connect(xButton, SIGNAL(clicked()), this, SLOT(paneDeleteButtonClicked())); | 120 connect(xButton, SIGNAL(clicked()), this, SLOT(paneDeleteButtonClicked())); |
103 | 121 |
104 ClickableLabel *currentIndicator = new ClickableLabel(frame); | 122 ClickableLabel *currentIndicator = new ClickableLabel(frame); |
105 connect(currentIndicator, SIGNAL(clicked()), this, SLOT(indicatorClicked())); | 123 connect(currentIndicator, SIGNAL(clicked()), this, SLOT(indicatorClicked())); |
106 layout->addWidget(currentIndicator, 1, 0); | 124 layout->addWidget(currentIndicator, 2, 0); |
107 layout->setRowStretch(1, 20); | 125 layout->setRowStretch(1, 20); |
108 currentIndicator->setMinimumWidth(8); | 126 currentIndicator->setMinimumWidth(8); |
109 currentIndicator->setScaledContents(true); | 127 currentIndicator->setScaledContents(true); |
110 currentIndicator->setVisible(m_showAccessories); | 128 currentIndicator->setVisible(m_showAccessories); |
111 | 129 |
118 if (initialCentreFrame >= 0) { | 136 if (initialCentreFrame >= 0) { |
119 pane->setViewManager(m_viewManager, initialCentreFrame); | 137 pane->setViewManager(m_viewManager, initialCentreFrame); |
120 } else { | 138 } else { |
121 pane->setViewManager(m_viewManager); | 139 pane->setViewManager(m_viewManager); |
122 } | 140 } |
123 layout->addWidget(pane, 0, 1, 2, 1); | 141 layout->addWidget(pane, 1, 1, 2, 1); |
124 layout->setColumnStretch(1, 20); | 142 layout->setColumnStretch(1, 20); |
125 | |
126 AlignmentView *av = new AlignmentView(frame); | |
127 av->setFixedHeight(40);//!!! | |
128 av->setVisible(m_showAlignmentViews); | |
129 av->setViewManager(m_viewManager); | |
130 layout->addWidget(av, 2, 1); | |
131 | 143 |
132 QWidget *properties = nullptr; | 144 QWidget *properties = nullptr; |
133 if (suppressPropertyBox) { | 145 if (suppressPropertyBox) { |
134 properties = new QFrame(); | 146 properties = new QFrame(); |
135 } else { | 147 } else { |
140 this, SLOT(viewSelected(View *))); | 152 this, SLOT(viewSelected(View *))); |
141 connect(properties, SIGNAL(contextHelpChanged(const QString &)), | 153 connect(properties, SIGNAL(contextHelpChanged(const QString &)), |
142 this, SIGNAL(contextHelpChanged(const QString &))); | 154 this, SIGNAL(contextHelpChanged(const QString &))); |
143 } | 155 } |
144 if (m_layoutStyle == PropertyStackPerPaneLayout) { | 156 if (m_layoutStyle == PropertyStackPerPaneLayout) { |
145 layout->addWidget(properties, 0, 2, 2, 1); | 157 layout->addWidget(properties, 1, 2, 2, 1); |
146 } else { | 158 } else { |
147 properties->setParent(m_propertyStackStack); | 159 properties->setParent(m_propertyStackStack); |
148 m_propertyStackStack->addWidget(properties); | 160 m_propertyStackStack->addWidget(properties); |
149 } | 161 } |
150 layout->setColumnStretch(2, 0); | 162 layout->setColumnStretch(2, 0); |
158 rec.layout = layout; | 170 rec.layout = layout; |
159 rec.alignmentView = av; | 171 rec.alignmentView = av; |
160 m_panes.push_back(rec); | 172 m_panes.push_back(rec); |
161 | 173 |
162 frame->setLayout(layout); | 174 frame->setLayout(layout); |
163 m_splitter->insertWidget(index, frame); | 175 |
176 if (m_resizeMode == UserResizeable) { | |
177 m_splitter->addWidget(frame); | |
178 } else { | |
179 m_autoResizeLayout->addWidget(frame); | |
180 frame->adjustSize(); | |
181 } | |
164 | 182 |
165 connect(pane, SIGNAL(propertyContainerAdded(PropertyContainer *)), | 183 connect(pane, SIGNAL(propertyContainerAdded(PropertyContainer *)), |
166 this, SLOT(propertyContainerAdded(PropertyContainer *))); | 184 this, SLOT(propertyContainerAdded(PropertyContainer *))); |
167 connect(pane, SIGNAL(propertyContainerRemoved(PropertyContainer *)), | 185 connect(pane, SIGNAL(propertyContainerRemoved(PropertyContainer *)), |
168 this, SLOT(propertyContainerRemoved(PropertyContainer *))); | 186 this, SLOT(propertyContainerRemoved(PropertyContainer *))); |
191 } | 209 } |
192 | 210 |
193 void | 211 void |
194 PaneStack::relinkAlignmentViews() | 212 PaneStack::relinkAlignmentViews() |
195 { | 213 { |
196 for (int i = 0; i < (int)m_panes.size(); ++i) { | 214 if (m_panes.empty()) return; |
197 m_panes[i].alignmentView->setViewAbove(m_panes[i].pane); | 215 m_panes[0].alignmentView->hide(); |
198 if (i + 1 < (int)m_panes.size()) { | 216 for (int i = 1; in_range_for(m_panes, i); ++i) { |
199 m_panes[i].alignmentView->setViewBelow(m_panes[i+1].pane); | 217 m_panes[i].alignmentView->setViewAbove(m_panes[i-1].pane); |
200 } else { | 218 m_panes[i].alignmentView->setViewBelow(m_panes[i].pane); |
201 m_panes[i].alignmentView->setViewBelow(nullptr); | 219 m_panes[i].alignmentView->setVisible(true); |
202 } | |
203 } | 220 } |
204 } | 221 } |
205 | 222 |
206 void | 223 void |
207 PaneStack::unlinkAlignmentViews() | 224 PaneStack::unlinkAlignmentViews() |
208 { | 225 { |
209 for (int i = 0; i < (int)m_panes.size(); ++i) { | 226 for (int i = 0; in_range_for(m_panes, i); ++i) { |
210 m_panes[i].alignmentView->setViewAbove(nullptr); | 227 m_panes[i].alignmentView->setViewAbove(nullptr); |
211 m_panes[i].alignmentView->setViewBelow(nullptr); | 228 m_panes[i].alignmentView->setViewBelow(nullptr); |
212 } | 229 } |
213 } | 230 } |
214 | 231 |
404 } | 421 } |
405 | 422 |
406 showOrHidePaneAccessories(); | 423 showOrHidePaneAccessories(); |
407 emit paneHidden(pane); | 424 emit paneHidden(pane); |
408 emit paneHidden(); | 425 emit paneHidden(); |
426 relinkAlignmentViews(); | |
409 return; | 427 return; |
410 } | 428 } |
411 ++i; | 429 ++i; |
412 } | 430 } |
413 | |
414 relinkAlignmentViews(); | |
415 | 431 |
416 SVCERR << "WARNING: PaneStack::hidePane(" << pane << "): Pane not found in visible panes" << endl; | 432 SVCERR << "WARNING: PaneStack::hidePane(" << pane << "): Pane not found in visible panes" << endl; |
417 } | 433 } |
418 | 434 |
419 void | 435 void |
429 if (pw) pw->show(); | 445 if (pw) pw->show(); |
430 | 446 |
431 //!!! update current pane | 447 //!!! update current pane |
432 | 448 |
433 showOrHidePaneAccessories(); | 449 showOrHidePaneAccessories(); |
450 relinkAlignmentViews(); | |
434 | 451 |
435 return; | 452 return; |
436 } | 453 } |
437 ++i; | 454 ++i; |
438 } | 455 } |
439 | |
440 relinkAlignmentViews(); | |
441 | 456 |
442 SVCERR << "WARNING: PaneStack::showPane(" << pane << "): Pane not found in hidden panes" << endl; | 457 SVCERR << "WARNING: PaneStack::showPane(" << pane << "): Pane not found in hidden panes" << endl; |
443 } | 458 } |
444 | 459 |
445 void | 460 void |
653 } | 668 } |
654 | 669 |
655 void | 670 void |
656 PaneStack::sizePanesEqually() | 671 PaneStack::sizePanesEqually() |
657 { | 672 { |
673 if (m_resizeMode == AutoResizeOnly) { | |
674 return; | |
675 } | |
676 | |
658 QList<int> sizes = m_splitter->sizes(); | 677 QList<int> sizes = m_splitter->sizes(); |
659 if (sizes.empty()) return; | 678 if (sizes.empty()) return; |
660 | 679 |
661 int count = sizes.size(); | 680 int count = sizes.size(); |
662 | 681 |
710 */ | 729 */ |
711 | 730 |
712 m_splitter->setSizes(sizes); | 731 m_splitter->setSizes(sizes); |
713 } | 732 } |
714 | 733 |
734 void | |
735 PaneStack::setResizeMode(ResizeMode mode) | |
736 { | |
737 if (mode == UserResizeable) { | |
738 m_autoResizeStack->hide(); | |
739 m_splitter->show(); | |
740 } else { | |
741 m_autoResizeStack->show(); | |
742 m_splitter->hide(); | |
743 } | |
744 m_resizeMode = mode; | |
745 | |
746 // we don't actually move any existing panes yet! let's do that | |
747 // only if we turn out to need it, shall we? | |
748 } | |
749 |