Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix splits leaving empty gap #78

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void Container::connectWidget(QWidget *widget)
connect(widget, &QWidget::destroyed, this, [=]() {
if (m_splitter->count() == 0)
{
setParent(nullptr);
deleteLater();
}
else
Expand Down
48 changes: 28 additions & 20 deletions src/splitcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,39 @@ SplitContainer::SplitContainer(Qt::Orientation orientation, QWidget *parent) : C

void SplitContainer::split(QWidget *source_widget, QWidget *new_widget, Qt::Orientation orientation)
{
disconnectWidget(source_widget);
if (m_splitter->count() <= 1)
{
addWidget(new_widget);
m_splitter->setOrientation(orientation);
}
else
{
disconnectWidget(source_widget);

int index = m_splitter->indexOf(source_widget);
int index = m_splitter->indexOf(source_widget);

SplitContainer *container = new SplitContainer(orientation, this);
SplitContainer *container = new SplitContainer(orientation, this);

// NOTE: replaceWidget() will move focus to another widget, which will screw up the focus order in
// LastFocusedFilter. We therefore clear the focus before calling the function, and reapply the focus after.
QWidget *regain_focus_widget = nullptr;
if (source_widget->isAncestorOf(focusWidget()))
{
regain_focus_widget = focusWidget();
regain_focus_widget->clearFocus();
}
// NOTE: replaceWidget() will move focus to another widget, which will screw up the focus order in
// LastFocusedFilter. We therefore clear the focus before calling the function, and reapply the focus after.
QWidget *regain_focus_widget = nullptr;
if (source_widget->isAncestorOf(focusWidget()))
{
regain_focus_widget = focusWidget();
regain_focus_widget->clearFocus();
}

m_splitter->replaceWidget(index, container);
m_splitter->replaceWidget(index, container);

if (regain_focus_widget)
regain_focus_widget->setFocus();
if (regain_focus_widget)
regain_focus_widget->setFocus();

// NOTE: Adding the source_widget to the container after calling replaceWidget() will ensure that the splitter ratio
// will be preserved.
container->addWidget(source_widget);
container->addWidget(new_widget);
container->m_splitter->setSizes(QList<int>({INT_MAX, INT_MAX}));
// NOTE: Adding the source_widget to the container after calling replaceWidget() will ensure that the splitter
// ratio will be preserved.
container->addWidget(source_widget);
container->addWidget(new_widget);
container->m_splitter->setSizes(QList<int>({INT_MAX, INT_MAX}));

connectWidget(container);
connectWidget(container);
}
}
Loading