mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-25 23:51:33 +08:00
Added finishDragging() function to IFloatingWidget to prevent installing event filters
This commit is contained in:
parent
5e230d8874
commit
02143eac71
@ -174,8 +174,13 @@ void CDockAreaTabBar::mouseReleaseEvent(QMouseEvent* ev)
|
||||
{
|
||||
ADS_PRINT("CDockAreaTabBar::mouseReleaseEvent");
|
||||
ev->accept();
|
||||
d->FloatingWidget = nullptr;
|
||||
d->DragStartMousePos = QPoint();
|
||||
if (d->FloatingWidget)
|
||||
{
|
||||
auto FloatingWidget = d->FloatingWidget;
|
||||
d->FloatingWidget = nullptr;
|
||||
FloatingWidget->finishDragging();
|
||||
}
|
||||
return;
|
||||
}
|
||||
QScrollArea::mouseReleaseEvent(ev);
|
||||
|
@ -205,6 +205,8 @@ bool DockManagerPrivate::checkFormat(const QByteArray &state, int version)
|
||||
bool DockManagerPrivate::restoreStateFromXml(const QByteArray &state, int version,
|
||||
bool Testing)
|
||||
{
|
||||
Q_UNUSED(version);
|
||||
|
||||
if (state.isEmpty())
|
||||
{
|
||||
return false;
|
||||
|
@ -311,14 +311,27 @@ void CDockWidgetTab::mousePressEvent(QMouseEvent* ev)
|
||||
//============================================================================
|
||||
void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev)
|
||||
{
|
||||
auto CurrentDragState = d->DragState;
|
||||
d->DragStartMousePosition = QPoint();
|
||||
d->DragState = DraggingInactive;
|
||||
|
||||
switch (CurrentDragState)
|
||||
{
|
||||
case DraggingTab:
|
||||
// End of tab moving, emit signal
|
||||
if (d->isDraggingState(DraggingTab) && d->DockArea)
|
||||
if (d->DockArea)
|
||||
{
|
||||
emit moved(ev->globalPos());
|
||||
}
|
||||
break;
|
||||
|
||||
case DraggingFloatingWidget:
|
||||
d->FloatingWidget->finishDragging();
|
||||
break;
|
||||
|
||||
default:; // do nothing
|
||||
}
|
||||
|
||||
d->DragStartMousePosition = QPoint();
|
||||
d->DragState = DraggingInactive;
|
||||
Super::mouseReleaseEvent(ev);
|
||||
}
|
||||
|
||||
|
@ -260,11 +260,6 @@ CFloatingDockContainer::CFloatingDockContainer(CDockManager *DockManager) :
|
||||
#endif
|
||||
|
||||
DockManager->registerFloatingWidget(this);
|
||||
|
||||
// We install an event filter to detect mouse release events because we
|
||||
// do not receive mouse release event if the floating widget is behind
|
||||
// the drop overlay cross
|
||||
qApp->installEventFilter(this);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
@ -493,20 +488,6 @@ bool CFloatingDockContainer::event(QEvent *e)
|
||||
return QWidget::event(e);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
bool CFloatingDockContainer::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
Q_UNUSED(watched);
|
||||
if (event->type() == QEvent::MouseButtonRelease
|
||||
&& d->isState(DraggingFloatingWidget))
|
||||
{
|
||||
ADS_PRINT("FloatingWidget::eventFilter QEvent::MouseButtonRelease");
|
||||
finishDragging();
|
||||
d->titleMouseReleaseEvent();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void CFloatingDockContainer::startFloating(const QPoint &DragStartMousePos,
|
||||
@ -640,6 +621,7 @@ void CFloatingDockContainer::finishDragging()
|
||||
d->MouseEventHandler = nullptr;
|
||||
}
|
||||
#endif
|
||||
d->titleMouseReleaseEvent();
|
||||
}
|
||||
|
||||
} // namespace ads
|
||||
|
@ -74,6 +74,11 @@ public:
|
||||
* startFloating() was called
|
||||
*/
|
||||
virtual void moveFloating() = 0;
|
||||
|
||||
/**
|
||||
* Tells the widget that to finish dragging if the mouse is released
|
||||
*/
|
||||
virtual void finishDragging() = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -110,8 +115,8 @@ protected:
|
||||
* Use moveToGlobalPos() to move the widget to a new position
|
||||
* depending on the start position given in Pos parameter
|
||||
*/
|
||||
void startFloating(const QPoint& DragStartMousePos, const QSize& Size,
|
||||
eDragState DragState, QWidget* MouseEventHandler);
|
||||
virtual void startFloating(const QPoint& DragStartMousePos, const QSize& Size,
|
||||
eDragState DragState, QWidget* MouseEventHandler) override;
|
||||
|
||||
/**
|
||||
* Call this function to start dragging the floating widget
|
||||
@ -126,7 +131,7 @@ protected:
|
||||
* Call this function if you explicitly want to signal that dragging has
|
||||
* finished
|
||||
*/
|
||||
void finishDragging();
|
||||
virtual void finishDragging() override;
|
||||
|
||||
/**
|
||||
* Call this function if you just want to initialize the position
|
||||
@ -164,7 +169,6 @@ protected: // reimplements QWidget
|
||||
virtual void closeEvent(QCloseEvent *event) override;
|
||||
virtual void hideEvent(QHideEvent *event) override;
|
||||
virtual void showEvent(QShowEvent *event) override;
|
||||
virtual bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
public:
|
||||
using Super = QWidget;
|
||||
|
@ -39,7 +39,6 @@ struct FloatingOverlayPrivate
|
||||
CDockContainerWidget *DropContainer = nullptr;
|
||||
qreal WindowOpacity;
|
||||
bool Hidden = false;
|
||||
bool IgnoreMouseEvents = false;
|
||||
QPixmap ContentPreviewPixmap;
|
||||
|
||||
|
||||
@ -184,10 +183,6 @@ CFloatingOverlay::CFloatingOverlay(QWidget* Content, QWidget* parent) :
|
||||
#endif
|
||||
|
||||
setWindowOpacity(0.6);
|
||||
// We install an event filter to detect mouse release events because we
|
||||
// do not receive mouse release event if the floating widget is behind
|
||||
// the drop overlay cross
|
||||
qApp->installEventFilter(this);
|
||||
|
||||
// Create a static image of the widget that should get undocked
|
||||
// This is like some kind preview image like it is uses in drag and drop
|
||||
@ -265,13 +260,9 @@ void CFloatingOverlay::moveEvent(QMoveEvent *event)
|
||||
|
||||
|
||||
//============================================================================
|
||||
bool CFloatingOverlay::eventFilter(QObject *watched, QEvent *event)
|
||||
void CFloatingOverlay::finishDragging()
|
||||
{
|
||||
Q_UNUSED(watched);
|
||||
if (event->type() == QEvent::MouseButtonRelease && !d->IgnoreMouseEvents)
|
||||
{
|
||||
ADS_PRINT("FloatingWidget::eventFilter QEvent::MouseButtonRelease");
|
||||
|
||||
ADS_PRINT("CFloatingOverlay::finishDragging");
|
||||
auto DockDropArea = d->DockManager->dockAreaOverlay()->dropAreaUnderCursor();
|
||||
auto ContainerDropArea = d->DockManager->containerOverlay()->dropAreaUnderCursor();
|
||||
bool DropPossible = (DockDropArea != InvalidDockWidgetArea) || (ContainerDropArea != InvalidDockWidgetArea);
|
||||
@ -307,13 +298,6 @@ bool CFloatingOverlay::eventFilter(QObject *watched, QEvent *event)
|
||||
this->close();
|
||||
d->DockManager->containerOverlay()->hideOverlay();
|
||||
d->DockManager->dockAreaOverlay()->hideOverlay();
|
||||
// Because we use the event filter, we receive multiple mouse release
|
||||
// events. To prevent multiple code execution, we ignore all mouse
|
||||
// events after the first mouse event
|
||||
d->IgnoreMouseEvents = true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,7 +31,6 @@ private:
|
||||
|
||||
protected:
|
||||
virtual void moveEvent(QMoveEvent *event) override;
|
||||
virtual bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
virtual void paintEvent(QPaintEvent *e) override;
|
||||
|
||||
/**
|
||||
@ -57,6 +56,11 @@ public:
|
||||
* startFloating() was called
|
||||
*/
|
||||
virtual void moveFloating() override;
|
||||
|
||||
/**
|
||||
* Finishes dragging
|
||||
*/
|
||||
virtual void finishDragging() override;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user