Commit 7d83863a authored by Eugene Popov's avatar Eugene Popov
Browse files

[Splitter] Improve double click detection

This MR improves double click detection on the splitter handle. 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.
parent c50877f8
Pipeline #70552 passed with stage
in 6 minutes and 26 seconds
......@@ -14,23 +14,46 @@ class SplitterHandle : public QSplitterHandle
public:
SplitterHandle(Qt::Orientation orientation, QSplitter *parent)
: QSplitterHandle(orientation, parent)
, m_mouseReleaseWasReceived(false)
{
}
protected:
virtual void mouseDoubleClickEvent(QMouseEvent *event) override
bool event(QEvent *event) override
{
QList<int> _sizes = splitter()->sizes();
if (_sizes.size() == 2) {
const int halfSize = (_sizes[0] + _sizes[1]) / 2;
_sizes[0] = halfSize;
_sizes[1] = halfSize;
splitter()->setSizes(_sizes);
} else {
QSplitterHandle::mouseDoubleClickEvent(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);
}
private:
void resetSplitterSizes()
{
QList<int> splitterSizes = splitter()->sizes();
std::fill(splitterSizes.begin(), splitterSizes.end(), 0);
splitter()->setSizes(splitterSizes);
}
// 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;
};
KateSplitter::KateSplitter(Qt::Orientation orientation, QWidget *parent)
......
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