Skip to content

Commit 8f696ea

Browse files
Fixed a regression in DockWidgetTab that caused wron positioning of FloatingDockContainer when moving the mouse
1 parent ce1e8c8 commit 8f696ea

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/DockWidgetTab.cpp

+12-13
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct DockWidgetTabPrivate
6767
CDockWidget* DockWidget;
6868
QLabel* IconLabel = nullptr;
6969
tTabLabel* TitleLabel;
70-
QPoint DragStartMousePosition;
70+
QPoint GlobalDragStartMousePosition;
7171
bool IsActiveTab = false;
7272
CDockAreaWidget* DockArea = nullptr;
7373
eDragState DragState = DraggingInactive;
@@ -219,7 +219,7 @@ void DockWidgetTabPrivate::createLayout()
219219
void DockWidgetTabPrivate::moveTab(QMouseEvent* ev)
220220
{
221221
ev->accept();
222-
QPoint Distance = ev->globalPos() - DragStartMousePosition;
222+
QPoint Distance = ev->globalPos() - GlobalDragStartMousePosition;
223223
Distance.setY(0);
224224
auto TargetPos = Distance + TabDragStartPosition;
225225
_this->move(TargetPos);
@@ -246,6 +246,7 @@ bool DockWidgetTabPrivate::startFloating(eDragState DraggingState)
246246

247247
ADS_PRINT("startFloating");
248248
DragState = DraggingState;
249+
auto DragStartMousePosition = _this->mapFromGlobal(GlobalDragStartMousePosition);
249250
QSize Size = DockArea->size();
250251
IFloatingWidget* FloatingWidget = nullptr;
251252
bool OpaqueUndocking = CDockManager::configFlags().testFlag(CDockManager::OpaqueUndocking) ||
@@ -265,16 +266,14 @@ bool DockWidgetTabPrivate::startFloating(eDragState DraggingState)
265266

266267
if (DraggingFloatingWidget == DraggingState)
267268
{
268-
FloatingWidget->startFloating(_this->mapFromGlobal(DragStartMousePosition),
269-
Size, DraggingFloatingWidget, _this);
269+
FloatingWidget->startFloating(DragStartMousePosition, Size, DraggingFloatingWidget, _this);
270270
auto Overlay = DockWidget->dockManager()->containerOverlay();
271271
Overlay->setAllowedAreas(OuterDockAreas);
272272
this->FloatingWidget = FloatingWidget;
273273
}
274274
else
275275
{
276-
FloatingWidget->startFloating(_this->mapFromGlobal(DragStartMousePosition),
277-
Size, DraggingInactive, nullptr);
276+
FloatingWidget->startFloating(DragStartMousePosition, Size, DraggingInactive, nullptr);
278277
}
279278

280279
return true;
@@ -305,7 +304,7 @@ void CDockWidgetTab::mousePressEvent(QMouseEvent* ev)
305304
if (ev->button() == Qt::LeftButton)
306305
{
307306
ev->accept();
308-
d->DragStartMousePosition = ev->globalPos();
307+
d->GlobalDragStartMousePosition = ev->globalPos();
309308
d->DragState = DraggingMousePressed;
310309
emit clicked();
311310
return;
@@ -321,7 +320,7 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev)
321320
if (ev->button() == Qt::LeftButton)
322321
{
323322
auto CurrentDragState = d->DragState;
324-
d->DragStartMousePosition = QPoint();
323+
d->GlobalDragStartMousePosition = QPoint();
325324
d->DragState = DraggingInactive;
326325

327326
switch (CurrentDragState)
@@ -373,7 +372,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
373372
}
374373

375374
// Maybe a fixed drag distance is better here ?
376-
int DragDistanceY = qAbs(d->DragStartMousePosition.y() - ev->globalPos().y());
375+
int DragDistanceY = qAbs(d->GlobalDragStartMousePosition.y() - ev->globalPos().y());
377376
if (DragDistanceY >= CDockManager::startDragDistance())
378377
{
379378
// If this is the last dock area in a dock container with only
@@ -400,7 +399,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
400399
return;
401400
}
402401
else if (d->DockArea->openDockWidgetsCount() > 1
403-
&& (ev->globalPos() - d->DragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving
402+
&& (ev->globalPos() - d->GlobalDragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving
404403
{
405404
// If we start dragging the tab, we save its inital position to
406405
// restore it later
@@ -425,7 +424,7 @@ void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev)
425424
return;
426425
}
427426

428-
d->DragStartMousePosition = ev->globalPos();
427+
d->GlobalDragStartMousePosition = ev->globalPos();
429428
QMenu Menu(this);
430429
auto Action = Menu.addAction(tr("Detach"), this, SLOT(detachDockWidget()));
431430
Action->setEnabled(d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable));
@@ -550,7 +549,7 @@ void CDockWidgetTab::mouseDoubleClickEvent(QMouseEvent *event)
550549
if ((!d->DockArea->dockContainer()->isFloating() || d->DockArea->dockWidgetsCount() > 1)
551550
&& d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable))
552551
{
553-
d->DragStartMousePosition = event->globalPos();
552+
d->GlobalDragStartMousePosition = event->globalPos();
554553
d->startFloating(DraggingInactive);
555554
}
556555

@@ -588,7 +587,7 @@ void CDockWidgetTab::detachDockWidget()
588587
{
589588
return;
590589
}
591-
d->DragStartMousePosition = QCursor::pos();
590+
d->GlobalDragStartMousePosition = QCursor::pos();
592591
d->startFloating(DraggingInactive);
593592
}
594593

0 commit comments

Comments
 (0)