From 8cbbe7cdfc75e0f7b7286e205c6b981ce886f59f Mon Sep 17 00:00:00 2001 From: Kevin J Date: Thu, 13 Jun 2024 03:26:34 +0200 Subject: [PATCH] Fix sidebar resize behaviour (#10641) * Fix database view splitters resize behaviour * Set default ratio sizes for first-run based on the size of the database widget itself * Fix setting splitter sizes before database widget has had a chance to render for the first time * Disallow collapsing the entry view (source of several bug reports) Fixes: #10613 --------- Co-authored-by: Jonathan White --- src/gui/DatabaseWidget.cpp | 32 +++++++++++++++++++---------- src/gui/DatabaseWidgetStateSync.cpp | 23 +++++++++++++-------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 2146f1aea6..d7600bc1fc 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -121,8 +121,9 @@ DatabaseWidget::DatabaseWidget(QSharedPointer db, QWidget* parent) m_groupSplitter->setChildrenCollapsible(true); m_groupSplitter->addWidget(m_groupView); m_groupSplitter->addWidget(tagsWidget); - m_groupSplitter->setStretchFactor(0, 70); - m_groupSplitter->setStretchFactor(1, 30); + m_groupSplitter->setStretchFactor(0, 100); + m_groupSplitter->setStretchFactor(1, 0); + m_groupSplitter->setSizes({1, 1}); auto rightHandSideWidget = new QWidget(m_mainSplitter); auto rightHandSideVBox = new QVBoxLayout(); @@ -138,8 +139,10 @@ DatabaseWidget::DatabaseWidget(QSharedPointer db, QWidget* parent) m_mainSplitter->setChildrenCollapsible(true); m_mainSplitter->addWidget(m_groupSplitter); m_mainSplitter->addWidget(rightHandSideWidget); - m_mainSplitter->setStretchFactor(0, 30); - m_mainSplitter->setStretchFactor(1, 70); + m_mainSplitter->setStretchFactor(0, 0); + m_mainSplitter->setStretchFactor(1, 100); + m_mainSplitter->setCollapsible(1, false); + m_mainSplitter->setSizes({1, 1}); m_previewSplitter->setOrientation(Qt::Vertical); m_previewSplitter->setChildrenCollapsible(true); @@ -361,20 +364,27 @@ QHash> DatabaseWidget::splitterSizes() const void DatabaseWidget::setSplitterSizes(const QHash>& sizes) { + // Set the splitter sizes, if the size is invalid set a default ratio based on this widget size for (auto itr = sizes.constBegin(); itr != sizes.constEnd(); ++itr) { - // Less than two sizes indicates an invalid value - if (itr.value().size() < 2) { - continue; - } + auto value = itr.value(); switch (itr.key()) { case Config::GUI_SplitterState: - m_mainSplitter->setSizes(itr.value()); + if (value.size() < 2) { + value = QList({static_cast(width() * 0.25), static_cast(width() * 0.75)}); + } + m_mainSplitter->setSizes(value); break; case Config::GUI_PreviewSplitterState: - m_previewSplitter->setSizes(itr.value()); + if (value.size() < 2) { + value = QList({static_cast(height() * 0.8), static_cast(height() * 0.2)}); + } + m_previewSplitter->setSizes(value); break; case Config::GUI_GroupSplitterState: - m_groupSplitter->setSizes(itr.value()); + if (value.size() < 2) { + value = QList({static_cast(height() * 0.6), static_cast(height() * 0.4)}); + } + m_groupSplitter->setSizes(value); break; default: break; diff --git a/src/gui/DatabaseWidgetStateSync.cpp b/src/gui/DatabaseWidgetStateSync.cpp index 9cc22254ff..8f1d55d156 100644 --- a/src/gui/DatabaseWidgetStateSync.cpp +++ b/src/gui/DatabaseWidgetStateSync.cpp @@ -64,17 +64,24 @@ void DatabaseWidgetStateSync::setActive(DatabaseWidget* dbWidget) m_activeDbWidget = dbWidget; if (m_activeDbWidget) { - m_blockUpdates = true; + // Give the database widget a chance to render itself before restoring the state + QTimer::singleShot(0, this, [this] { + if (!m_activeDbWidget) { + return; + } - m_activeDbWidget->setSplitterSizes(m_splitterSizes); + m_blockUpdates = true; - if (m_activeDbWidget->isSearchActive()) { - restoreSearchView(); - } else { - restoreListView(); - } + m_activeDbWidget->setSplitterSizes(m_splitterSizes); + + if (m_activeDbWidget->isSearchActive()) { + restoreSearchView(); + } else { + restoreListView(); + } - m_blockUpdates = false; + m_blockUpdates = false; + }); connect(m_activeDbWidget, SIGNAL(splitterSizesChanged()), SLOT(updateSplitterSizes())); connect(m_activeDbWidget, SIGNAL(entryViewStateChanged()), SLOT(updateViewState()));