From cbbef264b6a7a0b4ed6c36e2e1851840eb94bb5e Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Sun, 2 Jun 2024 11:21:00 -0400 Subject: [PATCH] Set sensible defaults for splitter sizes * 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) --- src/gui/DatabaseWidget.cpp | 22 +++++++++++++++------- src/gui/DatabaseWidgetStateSync.cpp | 19 +++++++++++-------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index b8f4c78fba..df39d70ede 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -141,6 +141,7 @@ DatabaseWidget::DatabaseWidget(QSharedPointer db, QWidget* parent) m_mainSplitter->addWidget(rightHandSideWidget); 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); @@ -363,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 7264c23df8..62934a1276 100644 --- a/src/gui/DatabaseWidgetStateSync.cpp +++ b/src/gui/DatabaseWidgetStateSync.cpp @@ -62,17 +62,20 @@ 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] { + m_blockUpdates = true; - m_activeDbWidget->setSplitterSizes(m_splitterSizes); + m_activeDbWidget->setSplitterSizes(m_splitterSizes); - if (m_activeDbWidget->isSearchActive()) { - restoreSearchView(); - } else { - restoreListView(); - } + 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()));