mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 13:15:43 +08:00
Fixed a regression in DockWidgetTab that caused wron positioning of FloatingDockContainer when moving the mouse
This commit is contained in:
parent
ce1e8c8beb
commit
8f696ea36a
@ -67,7 +67,7 @@ struct DockWidgetTabPrivate
|
|||||||
CDockWidget* DockWidget;
|
CDockWidget* DockWidget;
|
||||||
QLabel* IconLabel = nullptr;
|
QLabel* IconLabel = nullptr;
|
||||||
tTabLabel* TitleLabel;
|
tTabLabel* TitleLabel;
|
||||||
QPoint DragStartMousePosition;
|
QPoint GlobalDragStartMousePosition;
|
||||||
bool IsActiveTab = false;
|
bool IsActiveTab = false;
|
||||||
CDockAreaWidget* DockArea = nullptr;
|
CDockAreaWidget* DockArea = nullptr;
|
||||||
eDragState DragState = DraggingInactive;
|
eDragState DragState = DraggingInactive;
|
||||||
@ -219,7 +219,7 @@ void DockWidgetTabPrivate::createLayout()
|
|||||||
void DockWidgetTabPrivate::moveTab(QMouseEvent* ev)
|
void DockWidgetTabPrivate::moveTab(QMouseEvent* ev)
|
||||||
{
|
{
|
||||||
ev->accept();
|
ev->accept();
|
||||||
QPoint Distance = ev->globalPos() - DragStartMousePosition;
|
QPoint Distance = ev->globalPos() - GlobalDragStartMousePosition;
|
||||||
Distance.setY(0);
|
Distance.setY(0);
|
||||||
auto TargetPos = Distance + TabDragStartPosition;
|
auto TargetPos = Distance + TabDragStartPosition;
|
||||||
_this->move(TargetPos);
|
_this->move(TargetPos);
|
||||||
@ -246,6 +246,7 @@ bool DockWidgetTabPrivate::startFloating(eDragState DraggingState)
|
|||||||
|
|
||||||
ADS_PRINT("startFloating");
|
ADS_PRINT("startFloating");
|
||||||
DragState = DraggingState;
|
DragState = DraggingState;
|
||||||
|
auto DragStartMousePosition = _this->mapFromGlobal(GlobalDragStartMousePosition);
|
||||||
QSize Size = DockArea->size();
|
QSize Size = DockArea->size();
|
||||||
IFloatingWidget* FloatingWidget = nullptr;
|
IFloatingWidget* FloatingWidget = nullptr;
|
||||||
bool OpaqueUndocking = CDockManager::configFlags().testFlag(CDockManager::OpaqueUndocking) ||
|
bool OpaqueUndocking = CDockManager::configFlags().testFlag(CDockManager::OpaqueUndocking) ||
|
||||||
@ -265,16 +266,14 @@ bool DockWidgetTabPrivate::startFloating(eDragState DraggingState)
|
|||||||
|
|
||||||
if (DraggingFloatingWidget == DraggingState)
|
if (DraggingFloatingWidget == DraggingState)
|
||||||
{
|
{
|
||||||
FloatingWidget->startFloating(_this->mapFromGlobal(DragStartMousePosition),
|
FloatingWidget->startFloating(DragStartMousePosition, Size, DraggingFloatingWidget, _this);
|
||||||
Size, DraggingFloatingWidget, _this);
|
|
||||||
auto Overlay = DockWidget->dockManager()->containerOverlay();
|
auto Overlay = DockWidget->dockManager()->containerOverlay();
|
||||||
Overlay->setAllowedAreas(OuterDockAreas);
|
Overlay->setAllowedAreas(OuterDockAreas);
|
||||||
this->FloatingWidget = FloatingWidget;
|
this->FloatingWidget = FloatingWidget;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FloatingWidget->startFloating(_this->mapFromGlobal(DragStartMousePosition),
|
FloatingWidget->startFloating(DragStartMousePosition, Size, DraggingInactive, nullptr);
|
||||||
Size, DraggingInactive, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -305,7 +304,7 @@ void CDockWidgetTab::mousePressEvent(QMouseEvent* ev)
|
|||||||
if (ev->button() == Qt::LeftButton)
|
if (ev->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
ev->accept();
|
ev->accept();
|
||||||
d->DragStartMousePosition = ev->globalPos();
|
d->GlobalDragStartMousePosition = ev->globalPos();
|
||||||
d->DragState = DraggingMousePressed;
|
d->DragState = DraggingMousePressed;
|
||||||
emit clicked();
|
emit clicked();
|
||||||
return;
|
return;
|
||||||
@ -321,7 +320,7 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev)
|
|||||||
if (ev->button() == Qt::LeftButton)
|
if (ev->button() == Qt::LeftButton)
|
||||||
{
|
{
|
||||||
auto CurrentDragState = d->DragState;
|
auto CurrentDragState = d->DragState;
|
||||||
d->DragStartMousePosition = QPoint();
|
d->GlobalDragStartMousePosition = QPoint();
|
||||||
d->DragState = DraggingInactive;
|
d->DragState = DraggingInactive;
|
||||||
|
|
||||||
switch (CurrentDragState)
|
switch (CurrentDragState)
|
||||||
@ -373,7 +372,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Maybe a fixed drag distance is better here ?
|
// Maybe a fixed drag distance is better here ?
|
||||||
int DragDistanceY = qAbs(d->DragStartMousePosition.y() - ev->globalPos().y());
|
int DragDistanceY = qAbs(d->GlobalDragStartMousePosition.y() - ev->globalPos().y());
|
||||||
if (DragDistanceY >= CDockManager::startDragDistance())
|
if (DragDistanceY >= CDockManager::startDragDistance())
|
||||||
{
|
{
|
||||||
// If this is the last dock area in a dock container with only
|
// If this is the last dock area in a dock container with only
|
||||||
@ -400,7 +399,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (d->DockArea->openDockWidgetsCount() > 1
|
else if (d->DockArea->openDockWidgetsCount() > 1
|
||||||
&& (ev->globalPos() - d->DragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving
|
&& (ev->globalPos() - d->GlobalDragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving
|
||||||
{
|
{
|
||||||
// If we start dragging the tab, we save its inital position to
|
// If we start dragging the tab, we save its inital position to
|
||||||
// restore it later
|
// restore it later
|
||||||
@ -425,7 +424,7 @@ void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->DragStartMousePosition = ev->globalPos();
|
d->GlobalDragStartMousePosition = ev->globalPos();
|
||||||
QMenu Menu(this);
|
QMenu Menu(this);
|
||||||
auto Action = Menu.addAction(tr("Detach"), this, SLOT(detachDockWidget()));
|
auto Action = Menu.addAction(tr("Detach"), this, SLOT(detachDockWidget()));
|
||||||
Action->setEnabled(d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable));
|
Action->setEnabled(d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable));
|
||||||
@ -550,7 +549,7 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
|
|||||||
if ((!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
|
if ((!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
|
||||||
&& d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
|
&& d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
|
||||||
{
|
{
|
||||||
d->DragStartMousePosition = event->globalPos();
|
d->GlobalDragStartMousePosition = event->globalPos();
|
||||||
d->startFloating(DraggingInactive);
|
d->startFloating(DraggingInactive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -588,7 +587,7 @@ void CDockWidgetTab::detachDockWidget()
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
d->DragStartMousePosition = QCursor::pos();
|
d->GlobalDragStartMousePosition = QCursor::pos();
|
||||||
d->startFloating(DraggingInactive);
|
d->startFloating(DraggingInactive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user