# HG changeset patch # User Chris Cannam # Date 1556636001 -3600 # Node ID 8afea53332f32882dac41b64d2836009a2f62609 # Parent 1ed6d666ec9e735e7e415347c40bbe413afc24e6 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 diff -r 1ed6d666ec9e -r 8afea53332f3 view/PaneStack.cpp --- 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 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? +} + diff -r 1ed6d666ec9e -r 8afea53332f3 view/PaneStack.h --- a/view/PaneStack.h Tue Apr 30 14:02:32 2019 +0100 +++ b/view/PaneStack.h Tue Apr 30 15:53:21 2019 +0100 @@ -25,6 +25,7 @@ class QWidget; class QLabel; class QStackedWidget; +class QVBoxLayout; class QSplitter; class QGridLayout; class QPushButton; @@ -41,10 +42,10 @@ Q_OBJECT public: - PaneStack(QWidget *parent, ViewManager *viewManager); + PaneStack(QWidget *parent, + ViewManager *viewManager); Pane *addPane(bool suppressPropertyBox = false); // I own the returned value - Pane *insertPane(int index, bool suppressPropertyBox = false); // I own the returned value void deletePane(Pane *pane); // Deletes the pane, but _not_ its layers int getPaneCount() const; // Returns only count of visible panes @@ -70,6 +71,14 @@ LayoutStyle getLayoutStyle() const { return m_layoutStyle; } void setLayoutStyle(LayoutStyle style); + enum ResizeMode { + UserResizeable = 0, + AutoResizeOnly = 1 + }; + + ResizeMode getResizeMode() const { return m_resizeMode; } + void setResizeMode(ResizeMode); + void setPropertyStackMinWidth(int mw); void setShowPaneAccessories(bool show); // current indicator, close button @@ -132,7 +141,10 @@ bool m_showAccessories; bool m_showAlignmentViews; - QSplitter *m_splitter; + QSplitter *m_splitter; // constitutes the stack in UserResizeable mode + QWidget *m_autoResizeStack; // constitutes the stack in AutoResizeOnly mode + QVBoxLayout *m_autoResizeLayout; + QStackedWidget *m_propertyStackStack; ViewManager *m_viewManager; // I don't own this @@ -145,6 +157,7 @@ void relinkAlignmentViews(); LayoutStyle m_layoutStyle; + ResizeMode m_resizeMode; }; #endif