Skip to content

Commit

Permalink
Set sensible defaults for splitter sizes
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
droidmonkey committed Jun 2, 2024
1 parent db66d39 commit cbbef26
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
22 changes: 15 additions & 7 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ DatabaseWidget::DatabaseWidget(QSharedPointer<Database> 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);
Expand Down Expand Up @@ -363,20 +364,27 @@ QHash<Config::ConfigKey, QList<int>> DatabaseWidget::splitterSizes() const

void DatabaseWidget::setSplitterSizes(const QHash<Config::ConfigKey, QList<int>>& 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<int>(width() * 0.25), static_cast<int>(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<int>(height() * 0.8), static_cast<int>(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<int>(height() * 0.6), static_cast<int>(height() * 0.4)});
}
m_groupSplitter->setSizes(value);
break;
default:
break;
Expand Down
19 changes: 11 additions & 8 deletions src/gui/DatabaseWidgetStateSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down

0 comments on commit cbbef26

Please # to comment.