Mercurial > hg > svgui
diff 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 |
line wrap: on
line diff
--- a/view/PaneStack.cpp Tue Apr 30 14:02:32 2019 +0100 +++ b/view/PaneStack.cpp Tue Apr 30 15:53:21 2019 +0100 @@ -43,22 +43,32 @@ m_showAccessories(true), m_showAlignmentViews(false), m_splitter(new QSplitter), + m_autoResizeStack(new QWidget), m_propertyStackStack(new QStackedWidget), m_viewManager(viewManager), m_propertyStackMinWidth(100), - m_layoutStyle(PropertyStackPerPaneLayout) + m_layoutStyle(PropertyStackPerPaneLayout), + m_resizeMode(UserResizeable) { QHBoxLayout *layout = new QHBoxLayout; layout->setMargin(0); layout->setSpacing(0); + m_autoResizeLayout = new QVBoxLayout; + m_autoResizeLayout->setSpacing(0); + m_autoResizeStack->setLayout(m_autoResizeLayout); + m_autoResizeStack->hide(); + layout->addWidget(m_autoResizeStack); + layout->setStretchFactor(m_autoResizeStack, 1); + m_splitter->setOrientation(Qt::Vertical); m_splitter->setOpaqueResize(false); - + m_splitter->show(); layout->addWidget(m_splitter); layout->setStretchFactor(m_splitter, 1); + + m_propertyStackStack->hide(); layout->addWidget(m_propertyStackStack); - m_propertyStackStack->hide(); setLayout(layout); } @@ -73,38 +83,44 @@ PaneStack::setShowAlignmentViews(bool show) { m_showAlignmentViews = show; - for (int i = 0; in_range_for(m_panes, i); ++i) { - m_panes[i].alignmentView->setVisible(m_showAlignmentViews && - in_range_for(m_panes, i+1)); + // each alignment view shows alignment between the pane above and + // the pane it is attached to: so pane 0 doesn't have a visible one + for (int i = 1; in_range_for(m_panes, i); ++i) { + m_panes[i].alignmentView->setVisible(m_showAlignmentViews); } } Pane * PaneStack::addPane(bool suppressPropertyBox) { - return insertPane(getPaneCount(), suppressPropertyBox); -} - -Pane * -PaneStack::insertPane(int index, bool suppressPropertyBox) -{ QFrame *frame = new QFrame; QGridLayout *layout = new QGridLayout; layout->setMargin(0); - layout->setSpacing(2); + layout->setHorizontalSpacing(m_viewManager->scalePixelSize(2)); + if (m_showAlignmentViews) { + layout->setVerticalSpacing(0); + } else { + layout->setVerticalSpacing(m_viewManager->scalePixelSize(2)); + } + + AlignmentView *av = new AlignmentView(frame); + av->setFixedHeight(ViewManager::scalePixelSize(20)); + av->setViewManager(m_viewManager); + av->setVisible(false); // for now + layout->addWidget(av, 0, 1); QPushButton *xButton = new QPushButton(frame); xButton->setIcon(IconLoader().load("cross")); xButton->setFixedSize(QSize(16, 16)); xButton->setFlat(true); xButton->setVisible(m_showAccessories); - layout->addWidget(xButton, 0, 0); + layout->addWidget(xButton, 1, 0); connect(xButton, SIGNAL(clicked()), this, SLOT(paneDeleteButtonClicked())); ClickableLabel *currentIndicator = new ClickableLabel(frame); connect(currentIndicator, SIGNAL(clicked()), this, SLOT(indicatorClicked())); - layout->addWidget(currentIndicator, 1, 0); + layout->addWidget(currentIndicator, 2, 0); layout->setRowStretch(1, 20); currentIndicator->setMinimumWidth(8); currentIndicator->setScaledContents(true); @@ -121,15 +137,9 @@ } else { pane->setViewManager(m_viewManager); } - layout->addWidget(pane, 0, 1, 2, 1); + layout->addWidget(pane, 1, 1, 2, 1); layout->setColumnStretch(1, 20); - AlignmentView *av = new AlignmentView(frame); - av->setFixedHeight(ViewManager::scalePixelSize(20)); - av->setViewManager(m_viewManager); - av->setVisible(false); // for now - layout->addWidget(av, 2, 1); - QWidget *properties = nullptr; if (suppressPropertyBox) { properties = new QFrame(); @@ -143,7 +153,7 @@ this, SIGNAL(contextHelpChanged(const QString &))); } if (m_layoutStyle == PropertyStackPerPaneLayout) { - layout->addWidget(properties, 0, 2, 2, 1); + layout->addWidget(properties, 1, 2, 2, 1); } else { properties->setParent(m_propertyStackStack); m_propertyStackStack->addWidget(properties); @@ -161,7 +171,13 @@ m_panes.push_back(rec); frame->setLayout(layout); - m_splitter->insertWidget(index, frame); + + if (m_resizeMode == UserResizeable) { + m_splitter->addWidget(frame); + } else { + m_autoResizeLayout->addWidget(frame); + frame->adjustSize(); + } connect(pane, SIGNAL(propertyContainerAdded(PropertyContainer *)), this, SLOT(propertyContainerAdded(PropertyContainer *))); @@ -194,22 +210,19 @@ void PaneStack::relinkAlignmentViews() { - for (int i = 0; i < (int)m_panes.size(); ++i) { - m_panes[i].alignmentView->setViewAbove(m_panes[i].pane); - if (i + 1 < (int)m_panes.size()) { - m_panes[i].alignmentView->setViewBelow(m_panes[i+1].pane); - m_panes[i].alignmentView->setVisible(true); - } else { - m_panes[i].alignmentView->setViewBelow(nullptr); - m_panes[i].alignmentView->setVisible(false); - } + if (m_panes.empty()) return; + m_panes[0].alignmentView->hide(); + for (int i = 1; in_range_for(m_panes, i); ++i) { + m_panes[i].alignmentView->setViewAbove(m_panes[i-1].pane); + m_panes[i].alignmentView->setViewBelow(m_panes[i].pane); + m_panes[i].alignmentView->setVisible(true); } } void PaneStack::unlinkAlignmentViews() { - for (int i = 0; i < (int)m_panes.size(); ++i) { + for (int i = 0; in_range_for(m_panes, i); ++i) { m_panes[i].alignmentView->setViewAbove(nullptr); m_panes[i].alignmentView->setViewBelow(nullptr); } @@ -656,6 +669,10 @@ void PaneStack::sizePanesEqually() { + if (m_resizeMode == AutoResizeOnly) { + return; + } + QList<int> sizes = m_splitter->sizes(); if (sizes.empty()) return; @@ -713,3 +730,19 @@ m_splitter->setSizes(sizes); } +void +PaneStack::setResizeMode(ResizeMode mode) +{ + if (mode == UserResizeable) { + m_autoResizeStack->hide(); + m_splitter->show(); + } else { + m_autoResizeStack->show(); + m_splitter->hide(); + } + m_resizeMode = mode; + + // we don't actually move any existing panes yet! let's do that + // only if we turn out to need it, shall we? +} +