Commit 45ddedbd authored by Jan Paul Batrina's avatar Jan Paul Batrina Committed by Christoph Cullmann
Browse files

Update Sidebar::m_lastSize when resized using the mouse

parent a6aa61d1
Pipeline #72406 passed with stage
in 5 minutes and 45 seconds
......@@ -290,6 +290,12 @@ void Sidebar::setSplitter(QSplitter *sp)
// if splitter was set before, disconnect handler for collapse
if (m_splitter) {
disconnect(m_splitter, &QSplitter::splitterMoved, this, &Sidebar::handleCollapse);
const int ownSplitIndex = m_splitter->indexOf(m_ownSplit);
for (int i : {ownSplitIndex, ownSplitIndex + 1}) {
if (i > 0 && i < m_splitter->count()) {
m_splitter->handle(i)->removeEventFilter(this);
}
}
}
m_splitter = sp;
......@@ -307,6 +313,14 @@ void Sidebar::setSplitter(QSplitter *sp)
connect(m_splitter, &QSplitter::splitterMoved, this, &Sidebar::handleCollapse);
}
void Sidebar::updateLastSizeOnResize()
{
const int splitHandleIndex = qMin(m_splitter->indexOf(m_ownSplit) + 1, m_splitter->count() - 1);
// this method requires that a splitter handle for resizing the sidebar exists
Q_ASSERT(splitHandleIndex > 0);
m_splitter->handle(splitHandleIndex)->installEventFilter(this);
}
ToolView *Sidebar::addWidget(const QIcon &icon, const QString &text, ToolView *widget)
{
static int id = 0;
......@@ -658,6 +672,12 @@ bool Sidebar::eventFilter(QObject *obj, QEvent *ev)
return true;
}
}
} else if (ev->type() == QEvent::MouseButtonRelease) {
// The sidebar's splitter handle handle is release, so we update the sidebar's size. See Sidebar::updateLastSizeOnResize
QMouseEvent *e = static_cast<QMouseEvent *>(ev);
if (e->button() == Qt::LeftButton) {
updateLastSize();
}
}
return false;
......@@ -893,6 +913,8 @@ MainWindow::MainWindow(QWidget *parentWidget)
for (const auto &sidebar : qAsConst(m_sidebars)) {
connect(sidebar.get(), &Sidebar::sigShowPluginConfigPage, this, &MainWindow::sigShowPluginConfigPage);
// all sidebar splitter handles are instantiated, so we can now safely call this
sidebar->updateLastSizeOnResize();
}
}
......
......@@ -176,6 +176,12 @@ public:
void setSplitter(QSplitter *sp);
/**
* Monitor resizes using the mouse and update the last size accordingly.
* Only call this when the sidebar has siblings in the splitter (i.e. m_splitter->count() >= 2) to guarantee that resize handles exist
*/
void updateLastSizeOnResize();
public:
ToolView *addWidget(const QIcon &icon, const QString &text, ToolView *widget);
bool removeWidget(ToolView *widget);
......
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