comparison view/PaneStack.cpp @ 1447:8afea53332f3 single-point

Add option to make pane sizes auto-resize-only (i.e. remove user control via a splitter); also place alignment views above panes instead of below, meaning the extra bit of space that we currently have for the pane without one at least goes to the primary pane
author Chris Cannam
date Tue, 30 Apr 2019 15:53:21 +0100
parents 1ed6d666ec9e
children 4a6ca97ce783
comparison
equal deleted inserted replaced
1446:1ed6d666ec9e 1447:8afea53332f3
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->setSpacing(0);
59 m_autoResizeStack->setLayout(m_autoResizeLayout);
60 m_autoResizeStack->hide();
61 layout->addWidget(m_autoResizeStack);
62 layout->setStretchFactor(m_autoResizeStack, 1);
63
55 m_splitter->setOrientation(Qt::Vertical); 64 m_splitter->setOrientation(Qt::Vertical);
56 m_splitter->setOpaqueResize(false); 65 m_splitter->setOpaqueResize(false);
57 66 m_splitter->show();
58 layout->addWidget(m_splitter); 67 layout->addWidget(m_splitter);
59 layout->setStretchFactor(m_splitter, 1); 68 layout->setStretchFactor(m_splitter, 1);
69
70 m_propertyStackStack->hide();
60 layout->addWidget(m_propertyStackStack); 71 layout->addWidget(m_propertyStackStack);
61 m_propertyStackStack->hide();
62 72
63 setLayout(layout); 73 setLayout(layout);
64 } 74 }
65 75
66 void 76 void
71 81
72 void 82 void
73 PaneStack::setShowAlignmentViews(bool show) 83 PaneStack::setShowAlignmentViews(bool show)
74 { 84 {
75 m_showAlignmentViews = show; 85 m_showAlignmentViews = show;
76 for (int i = 0; in_range_for(m_panes, i); ++i) { 86 // each alignment view shows alignment between the pane above and
77 m_panes[i].alignmentView->setVisible(m_showAlignmentViews && 87 // the pane it is attached to: so pane 0 doesn't have a visible one
78 in_range_for(m_panes, i+1)); 88 for (int i = 1; in_range_for(m_panes, i); ++i) {
89 m_panes[i].alignmentView->setVisible(m_showAlignmentViews);
79 } 90 }
80 } 91 }
81 92
82 Pane * 93 Pane *
83 PaneStack::addPane(bool suppressPropertyBox) 94 PaneStack::addPane(bool suppressPropertyBox)
84 { 95 {
85 return insertPane(getPaneCount(), suppressPropertyBox);
86 }
87
88 Pane *
89 PaneStack::insertPane(int index, bool suppressPropertyBox)
90 {
91 QFrame *frame = new QFrame; 96 QFrame *frame = new QFrame;
92 97
93 QGridLayout *layout = new QGridLayout; 98 QGridLayout *layout = new QGridLayout;
94 layout->setMargin(0); 99 layout->setMargin(0);
95 layout->setSpacing(2); 100 layout->setHorizontalSpacing(m_viewManager->scalePixelSize(2));
101 if (m_showAlignmentViews) {
102 layout->setVerticalSpacing(0);
103 } else {
104 layout->setVerticalSpacing(m_viewManager->scalePixelSize(2));
105 }
106
107 AlignmentView *av = new AlignmentView(frame);
108 av->setFixedHeight(ViewManager::scalePixelSize(20));
109 av->setViewManager(m_viewManager);
110 av->setVisible(false); // for now
111 layout->addWidget(av, 0, 1);
96 112
97 QPushButton *xButton = new QPushButton(frame); 113 QPushButton *xButton = new QPushButton(frame);
98 xButton->setIcon(IconLoader().load("cross")); 114 xButton->setIcon(IconLoader().load("cross"));
99 xButton->setFixedSize(QSize(16, 16)); 115 xButton->setFixedSize(QSize(16, 16));
100 xButton->setFlat(true); 116 xButton->setFlat(true);
101 xButton->setVisible(m_showAccessories); 117 xButton->setVisible(m_showAccessories);
102 layout->addWidget(xButton, 0, 0); 118 layout->addWidget(xButton, 1, 0);
103 connect(xButton, SIGNAL(clicked()), this, SLOT(paneDeleteButtonClicked())); 119 connect(xButton, SIGNAL(clicked()), this, SLOT(paneDeleteButtonClicked()));
104 120
105 ClickableLabel *currentIndicator = new ClickableLabel(frame); 121 ClickableLabel *currentIndicator = new ClickableLabel(frame);
106 connect(currentIndicator, SIGNAL(clicked()), this, SLOT(indicatorClicked())); 122 connect(currentIndicator, SIGNAL(clicked()), this, SLOT(indicatorClicked()));
107 layout->addWidget(currentIndicator, 1, 0); 123 layout->addWidget(currentIndicator, 2, 0);
108 layout->setRowStretch(1, 20); 124 layout->setRowStretch(1, 20);
109 currentIndicator->setMinimumWidth(8); 125 currentIndicator->setMinimumWidth(8);
110 currentIndicator->setScaledContents(true); 126 currentIndicator->setScaledContents(true);
111 currentIndicator->setVisible(m_showAccessories); 127 currentIndicator->setVisible(m_showAccessories);
112 128
119 if (initialCentreFrame >= 0) { 135 if (initialCentreFrame >= 0) {
120 pane->setViewManager(m_viewManager, initialCentreFrame); 136 pane->setViewManager(m_viewManager, initialCentreFrame);
121 } else { 137 } else {
122 pane->setViewManager(m_viewManager); 138 pane->setViewManager(m_viewManager);
123 } 139 }
124 layout->addWidget(pane, 0, 1, 2, 1); 140 layout->addWidget(pane, 1, 1, 2, 1);
125 layout->setColumnStretch(1, 20); 141 layout->setColumnStretch(1, 20);
126
127 AlignmentView *av = new AlignmentView(frame);
128 av->setFixedHeight(ViewManager::scalePixelSize(20));
129 av->setViewManager(m_viewManager);
130 av->setVisible(false); // for now
131 layout->addWidget(av, 2, 1);
132 142
133 QWidget *properties = nullptr; 143 QWidget *properties = nullptr;
134 if (suppressPropertyBox) { 144 if (suppressPropertyBox) {
135 properties = new QFrame(); 145 properties = new QFrame();
136 } else { 146 } else {
141 this, SLOT(viewSelected(View *))); 151 this, SLOT(viewSelected(View *)));
142 connect(properties, SIGNAL(contextHelpChanged(const QString &)), 152 connect(properties, SIGNAL(contextHelpChanged(const QString &)),
143 this, SIGNAL(contextHelpChanged(const QString &))); 153 this, SIGNAL(contextHelpChanged(const QString &)));
144 } 154 }
145 if (m_layoutStyle == PropertyStackPerPaneLayout) { 155 if (m_layoutStyle == PropertyStackPerPaneLayout) {
146 layout->addWidget(properties, 0, 2, 2, 1); 156 layout->addWidget(properties, 1, 2, 2, 1);
147 } else { 157 } else {
148 properties->setParent(m_propertyStackStack); 158 properties->setParent(m_propertyStackStack);
149 m_propertyStackStack->addWidget(properties); 159 m_propertyStackStack->addWidget(properties);
150 } 160 }
151 layout->setColumnStretch(2, 0); 161 layout->setColumnStretch(2, 0);
159 rec.layout = layout; 169 rec.layout = layout;
160 rec.alignmentView = av; 170 rec.alignmentView = av;
161 m_panes.push_back(rec); 171 m_panes.push_back(rec);
162 172
163 frame->setLayout(layout); 173 frame->setLayout(layout);
164 m_splitter->insertWidget(index, frame); 174
175 if (m_resizeMode == UserResizeable) {
176 m_splitter->addWidget(frame);
177 } else {
178 m_autoResizeLayout->addWidget(frame);
179 frame->adjustSize();
180 }
165 181
166 connect(pane, SIGNAL(propertyContainerAdded(PropertyContainer *)), 182 connect(pane, SIGNAL(propertyContainerAdded(PropertyContainer *)),
167 this, SLOT(propertyContainerAdded(PropertyContainer *))); 183 this, SLOT(propertyContainerAdded(PropertyContainer *)));
168 connect(pane, SIGNAL(propertyContainerRemoved(PropertyContainer *)), 184 connect(pane, SIGNAL(propertyContainerRemoved(PropertyContainer *)),
169 this, SLOT(propertyContainerRemoved(PropertyContainer *))); 185 this, SLOT(propertyContainerRemoved(PropertyContainer *)));
192 } 208 }
193 209
194 void 210 void
195 PaneStack::relinkAlignmentViews() 211 PaneStack::relinkAlignmentViews()
196 { 212 {
197 for (int i = 0; i < (int)m_panes.size(); ++i) { 213 if (m_panes.empty()) return;
198 m_panes[i].alignmentView->setViewAbove(m_panes[i].pane); 214 m_panes[0].alignmentView->hide();
199 if (i + 1 < (int)m_panes.size()) { 215 for (int i = 1; in_range_for(m_panes, i); ++i) {
200 m_panes[i].alignmentView->setViewBelow(m_panes[i+1].pane); 216 m_panes[i].alignmentView->setViewAbove(m_panes[i-1].pane);
201 m_panes[i].alignmentView->setVisible(true); 217 m_panes[i].alignmentView->setViewBelow(m_panes[i].pane);
202 } else { 218 m_panes[i].alignmentView->setVisible(true);
203 m_panes[i].alignmentView->setViewBelow(nullptr);
204 m_panes[i].alignmentView->setVisible(false);
205 }
206 } 219 }
207 } 220 }
208 221
209 void 222 void
210 PaneStack::unlinkAlignmentViews() 223 PaneStack::unlinkAlignmentViews()
211 { 224 {
212 for (int i = 0; i < (int)m_panes.size(); ++i) { 225 for (int i = 0; in_range_for(m_panes, i); ++i) {
213 m_panes[i].alignmentView->setViewAbove(nullptr); 226 m_panes[i].alignmentView->setViewAbove(nullptr);
214 m_panes[i].alignmentView->setViewBelow(nullptr); 227 m_panes[i].alignmentView->setViewBelow(nullptr);
215 } 228 }
216 } 229 }
217 230
654 } 667 }
655 668
656 void 669 void
657 PaneStack::sizePanesEqually() 670 PaneStack::sizePanesEqually()
658 { 671 {
672 if (m_resizeMode == AutoResizeOnly) {
673 return;
674 }
675
659 QList<int> sizes = m_splitter->sizes(); 676 QList<int> sizes = m_splitter->sizes();
660 if (sizes.empty()) return; 677 if (sizes.empty()) return;
661 678
662 int count = sizes.size(); 679 int count = sizes.size();
663 680
711 */ 728 */
712 729
713 m_splitter->setSizes(sizes); 730 m_splitter->setSizes(sizes);
714 } 731 }
715 732
733 void
734 PaneStack::setResizeMode(ResizeMode mode)
735 {
736 if (mode == UserResizeable) {
737 m_autoResizeStack->hide();
738 m_splitter->show();
739 } else {
740 m_autoResizeStack->show();
741 m_splitter->hide();
742 }
743 m_resizeMode = mode;
744
745 // we don't actually move any existing panes yet! let's do that
746 // only if we turn out to need it, shall we?
747 }
748