Move the mouse handling from Separator to SeparatorWidget

As it's QWidget specific
This commit is contained in:
Sergio Martins
2020-05-24 17:58:04 +01:00
parent 7f49f6e6a4
commit 7c9ee4f497
4 changed files with 40 additions and 22 deletions

View File

@@ -24,8 +24,7 @@
#include "Item_p.h" #include "Item_p.h"
#include "Config.h" #include "Config.h"
#include <QMouseEvent> #include <QGuiApplication>
#include <QApplication>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
# include <windows.h> # include <windows.h>
@@ -85,7 +84,7 @@ Qt::Orientation Separator::orientation() const
return d->orientation; return d->orientation;
} }
void Separator::mousePressEvent(QMouseEvent *) void Separator::onMousePress()
{ {
s_separatorBeingDragged = this; s_separatorBeingDragged = this;
@@ -97,7 +96,14 @@ void Separator::mousePressEvent(QMouseEvent *)
} }
} }
void Separator::mouseMoveEvent(QMouseEvent *ev) void Separator::onMouseDoubleClick()
{
// a double click means we'll resize the left and right neighbour so that they occupy
// the same size (or top/bottom, depending on orientation).
d->parentContainer->requestEqualSize(this);
}
void Separator::onMouseMove(QPoint pos)
{ {
if (!isBeingDragged()) if (!isBeingDragged())
return; return;
@@ -118,7 +124,7 @@ void Separator::mouseMoveEvent(QMouseEvent *ev)
} }
#endif #endif
const int positionToGoTo = Layouting::pos(mapToParent(ev->pos()), d->orientation); const int positionToGoTo = Layouting::pos(mapToParent(pos), d->orientation);
const int minPos = d->parentContainer->minPosForSeparator_global(this); const int minPos = d->parentContainer->minPosForSeparator_global(this);
const int maxPos = d->parentContainer->maxPosForSeparator_global(this); const int maxPos = d->parentContainer->maxPosForSeparator_global(this);
@@ -135,18 +141,6 @@ void Separator::mouseMoveEvent(QMouseEvent *ev)
d->parentContainer->requestSeparatorMove(this, positionToGoTo - position()); d->parentContainer->requestSeparatorMove(this, positionToGoTo - position());
} }
void Separator::mouseReleaseEvent(QMouseEvent *)
{
onMouseReleased();
}
void Separator::mouseDoubleClickEvent(QMouseEvent *)
{
// a double click means we'll resize the left and right neighbour so that they occupy
// the same size (or top/bottom, depending on orientation).
d->parentContainer->requestEqualSize(this);
}
void Separator::onMouseReleased() void Separator::onMouseReleased()
{ {
if (d->lazyResizeRubberBand) { if (d->lazyResizeRubberBand) {

View File

@@ -58,15 +58,14 @@ public:
protected: protected:
explicit Separator(Widget *hostWidget); explicit Separator(Widget *hostWidget);
void mousePressEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;
void mouseReleaseEvent(QMouseEvent *) override;
void mouseDoubleClickEvent(QMouseEvent *) override;
virtual Widget* createRubberBand(Widget *parent) { Q_UNUSED(parent); return nullptr; } virtual Widget* createRubberBand(Widget *parent) { Q_UNUSED(parent); return nullptr; }
void onMousePress();
void onMouseReleased();
void onMouseDoubleClick();
void onMouseMove(QPoint pos);
private: private:
friend class Config; friend class Config;
void onMouseReleased();
void setLazyPosition(int); void setLazyPosition(int);
bool isBeingDragged() const; bool isBeingDragged() const;
bool usesLazyResize() const; bool usesLazyResize() const;

View File

@@ -25,6 +25,7 @@
#include <QPainter> #include <QPainter>
#include <QStyleOption> #include <QStyleOption>
#include <QRubberBand> #include <QRubberBand>
#include <QMouseEvent>
using namespace KDDockWidgets; using namespace KDDockWidgets;
@@ -65,6 +66,26 @@ void SeparatorWidget::leaveEvent(QEvent *)
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
} }
void SeparatorWidget::mousePressEvent(QMouseEvent *)
{
onMousePress();
}
void SeparatorWidget::mouseMoveEvent(QMouseEvent *ev)
{
onMouseMove(ev->pos());
}
void SeparatorWidget::mouseReleaseEvent(QMouseEvent *)
{
onMouseReleased();
}
void SeparatorWidget::mouseDoubleClickEvent(QMouseEvent *)
{
onMouseDoubleClick();
}
Layouting::Widget *SeparatorWidget::createRubberBand(Layouting::Widget *parent) Layouting::Widget *SeparatorWidget::createRubberBand(Layouting::Widget *parent)
{ {
if (!parent) { if (!parent) {

View File

@@ -40,6 +40,10 @@ protected:
void paintEvent(QPaintEvent *) override; void paintEvent(QPaintEvent *) override;
void enterEvent(QEvent *) override; void enterEvent(QEvent *) override;
void leaveEvent(QEvent *) override; void leaveEvent(QEvent *) override;
void mousePressEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;
void mouseReleaseEvent(QMouseEvent *) override;
void mouseDoubleClickEvent(QMouseEvent *) override;
Layouting::Widget* createRubberBand(Layouting::Widget *parent) override; Layouting::Widget* createRubberBand(Layouting::Widget *parent) override;
}; };