Commit b712c9fc authored by Eugene Popov's avatar Eugene Popov Committed by Nate Graham
Browse files

[Split view] Reset splitter position on double click

This commit makes Dolphin to reset the position of the Split View splitter
on double-click.

BUG: 206525
FIXED-IN: 21.12
parent 99cc976a
Pipeline #77388 canceled with stage
......@@ -12,7 +12,6 @@
#include "global.h"
#include <QVariantAnimation>
#include <QSplitter>
#include <QGridLayout>
#include <QWidgetAction>
#include <QStyle>
......@@ -28,7 +27,7 @@ DolphinTabPage::DolphinTabPage(const QUrl &primaryUrl, const QUrl &secondaryUrl,
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
m_splitter = new QSplitter(Qt::Horizontal, this);
m_splitter = new DolphinTabPageSplitter(Qt::Horizontal, this);
m_splitter->setChildrenCollapsible(false);
connect(m_splitter, &QSplitter::splitterMoved,
this, &DolphinTabPage::splitterMoved);
......@@ -505,3 +504,47 @@ void DolphinTabPage::startExpandViewAnimation(DolphinViewContainer *expandingCon
}
m_expandViewAnimation->start(QAbstractAnimation::DeleteWhenStopped);
}
DolphinTabPageSplitterHandle::DolphinTabPageSplitterHandle(Qt::Orientation orientation, QSplitter *parent)
: QSplitterHandle(orientation, parent)
, m_mouseReleaseWasReceived(false)
{}
bool DolphinTabPageSplitterHandle::event(QEvent *event)
{
switch (event->type()) {
case QEvent::MouseButtonPress:
m_mouseReleaseWasReceived = false;
break;
case QEvent::MouseButtonRelease:
if (m_mouseReleaseWasReceived) {
resetSplitterSizes();
}
m_mouseReleaseWasReceived = !m_mouseReleaseWasReceived;
break;
case QEvent::MouseButtonDblClick:
m_mouseReleaseWasReceived = false;
resetSplitterSizes();
break;
default:
break;
}
return QSplitterHandle::event(event);
}
void DolphinTabPageSplitterHandle::resetSplitterSizes()
{
QList<int> splitterSizes = splitter()->sizes();
std::fill(splitterSizes.begin(), splitterSizes.end(), 0);
splitter()->setSizes(splitterSizes);
}
DolphinTabPageSplitter::DolphinTabPageSplitter(Qt::Orientation orientation, QWidget *parent)
: QSplitter(orientation, parent)
{}
QSplitterHandle* DolphinTabPageSplitter::createHandle()
{
return new DolphinTabPageSplitterHandle(orientation(), this);
}
......@@ -11,12 +11,13 @@
#include <QPointer>
#include <QUrl>
#include <QWidget>
#include <QSplitter>
class DolphinNavigatorsWidgetAction;
class DolphinViewContainer;
class QSplitter;
class QVariantAnimation;
class KFileItemList;
class DolphinTabPageSplitter;
enum Animated {
WithAnimation,
......@@ -185,7 +186,7 @@ private:
void startExpandViewAnimation(DolphinViewContainer *expandingContainer);
private:
QSplitter* m_splitter;
DolphinTabPageSplitter *m_splitter;
QPointer<DolphinNavigatorsWidgetAction> m_navigatorsWidget;
QPointer<DolphinViewContainer> m_primaryViewContainer;
......@@ -199,4 +200,34 @@ private:
bool m_active;
};
class DolphinTabPageSplitterHandle : public QSplitterHandle
{
Q_OBJECT
public:
explicit DolphinTabPageSplitterHandle(Qt::Orientation orientation, QSplitter *parent);
protected:
bool event(QEvent *event) override;
private:
void resetSplitterSizes();
// Sometimes QSplitterHandle doesn't receive MouseButtonDblClick event.
// We can detect that MouseButtonDblClick event should have been
// received if we receive two MouseButtonRelease events in a row.
bool m_mouseReleaseWasReceived;
};
class DolphinTabPageSplitter : public QSplitter
{
Q_OBJECT
public:
explicit DolphinTabPageSplitter(Qt::Orientation orientation, QWidget *parent);
protected:
QSplitterHandle* createHandle() override;
};
#endif // DOLPHIN_TAB_PAGE_H
Markdown is supported
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