Commit 8879c7d1 authored by Jan Paul Batrina's avatar Jan Paul Batrina Committed by Christoph Cullmann
Browse files

Make collapsed sidebars resizable by mouse again

bccc7d35 hides plugin views when their
sidebar is collapsed which made the sidebar unresizable.

This commit adds a placeholder (an empty QLabel) which is shown
when the sidebar is collapsed so that it will still be resizable.
The plugin views are properly shown again after the sidebar is
manually expanded using the mouse.
parent 11ed6456
Pipeline #70133 passed with stage
in 5 minutes and 42 seconds
......@@ -24,6 +24,7 @@
#include <QContextMenuEvent>
#include <QDomDocument>
#include <QLabel>
#include <QMenu>
#include <QSizePolicy>
#include <QStyle>
......@@ -296,6 +297,13 @@ void Sidebar::setSplitter(QSplitter *sp)
m_ownSplit->setChildrenCollapsible(false);
m_ownSplit->hide();
// Add resize placeholder (an empty QLabel) so that sidebar will still be resizable after collapse
// see Sidebar::handleCollapse
m_resizePlaceholder = new QLabel();
m_ownSplit->addWidget(m_resizePlaceholder);
m_resizePlaceholder->hide();
m_resizePlaceholder->setMinimumSize(QSize(160, 160)); // Same minimum size set in ToolView::minimumSizeHint
connect(m_splitter, &QSplitter::splitterMoved, this, &Sidebar::handleCollapse);
}
......@@ -496,22 +504,52 @@ bool Sidebar::isCollapsed()
return false;
}
QList<int> wsizes = m_splitter->sizes();
return wsizes[ownSplitIndex] == 0;
return m_splitter->sizes()[ownSplitIndex] == 0;
}
void Sidebar::handleCollapse()
void Sidebar::handleCollapse(int pos, int index)
{
if (!isCollapsed()) {
Q_UNUSED(pos);
if (!m_splitter) {
return;
}
// If the sidebar is collapsed, we need to hide the activated plugin-views since they are,
// visually speaking, hidden from the user but technically isVisible() would still return true
for (const auto &[id, wid] : m_idToWidget) {
if (wid->isVisible()) {
wid->hide();
// Verify that the sidebar really belongs to m_splitter
// and that we are handling the correct/matching sidebar
// 0 | 1 | 2 <- ownSplitIndex
// 1 2 <- index (of splitters, represented by |)
// ownSplitIndex should only be equal to index or (index - 1)
const int ownSplitIndex = m_splitter->indexOf(m_ownSplit);
if (ownSplitIndex == -1 || qAbs(index - ownSplitIndex) > 1) {
return;
}
if (isCollapsed()) {
if (m_isPreviouslyCollapsed) {
return;
}
// If the sidebar is collapsed, we need to hide the activated plugin-views since they are,
// visually speaking, hidden from the user but technically isVisible() would still return true
for (const auto &[id, wid] : m_idToWidget) {
if (wid->isVisible()) {
wid->hide();
}
}
// show resize placeholder again, otherwise the sidebar splitter won't be manually resizable/expandable
m_resizePlaceholder->show();
m_isPreviouslyCollapsed = true;
} else if (m_isPreviouslyCollapsed && m_resizePlaceholder->isVisible()) {
// If the sidebar is manually expanded again, we need to show the activated plugin-views again
for (const auto &[id, wid] : m_idToWidget) {
if (isTabRaised(id)) {
wid->show();
}
}
m_resizePlaceholder->hide();
m_isPreviouslyCollapsed = false;
}
}
......@@ -541,6 +579,8 @@ void Sidebar::expandSidebar(ToolView *widget)
}
}
m_resizePlaceholder->hide();
m_isPreviouslyCollapsed = false;
m_splitter->setSizes(wsizes);
}
}
......
......@@ -29,6 +29,7 @@
class KActionMenu;
class QAction;
class QLabel;
class QPixmap;
class KConfigBase;
......@@ -183,7 +184,7 @@ public:
bool hideWidget(ToolView *widget);
bool isCollapsed();
void handleCollapse();
void handleCollapse(int pos, int index);
void expandSidebar(ToolView *widget);
void setLastSize(int s)
......@@ -250,6 +251,9 @@ private:
int m_popupButton = 0;
QLabel *m_resizePlaceholder;
bool m_isPreviouslyCollapsed = false;
Q_SIGNALS:
void sigShowPluginConfigPage(KTextEditor::Plugin *configpageinterface, int id);
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment