Skip to content

Commit 8c12d91

Browse files
Improved tab dragging, added support for undocking if mouse leaves tabbar during tb dragging
1 parent fd28f0f commit 8c12d91

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

demo/MainWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
488488

489489
// uncomment the following line if you want to use opaque undocking and
490490
// opaque splitter resizing
491-
// CDockManager::setConfigFlags(CDockManager::DefaultOpaqueConfig);
491+
//CDockManager::setConfigFlags(CDockManager::DefaultOpaqueConfig);
492492

493493
// uncomment the following line if you want a fixed tab width that does
494494
// not change if the visibility of the close button changes

src/DockWidgetTab.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ void DockWidgetTabPrivate::moveTab(QMouseEvent* ev)
215215
QPoint Distance = ev->globalPos() - GlobalDragStartMousePosition;
216216
Distance.setY(0);
217217
auto TargetPos = Distance + TabDragStartPosition;
218+
TargetPos.rx() = qMax(TargetPos.x(), 0);
219+
TargetPos.rx() = qMin(_this->parentWidget()->rect().right() - _this->width() + 1, TargetPos.rx());
218220
_this->move(TargetPos);
219221
_this->raise();
220222
}
@@ -357,19 +359,18 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
357359
}
358360

359361
// move tab
360-
bool TabOutsideBar = false;
361362
if (d->isDraggingState(DraggingTab))
362363
{
363364
// Moving the tab is always allowed because it does not mean moving the
364365
// dock widget around
365366
d->moveTab(ev);
366-
TabOutsideBar = (geometry().right() < 0) || (geometry().left() > parentWidget()->rect().right());
367367
}
368368

369-
369+
auto MappedPos = mapToParent(ev->pos());
370+
bool MouseOutsideBar = (MappedPos.x() < 0) || (MappedPos.x() > parentWidget()->rect().right());
370371
// Maybe a fixed drag distance is better here ?
371372
int DragDistanceY = qAbs(d->GlobalDragStartMousePosition.y() - ev->globalPos().y());
372-
if (DragDistanceY >= CDockManager::startDragDistance() || TabOutsideBar)
373+
if (DragDistanceY >= CDockManager::startDragDistance() || MouseOutsideBar)
373374
{
374375
// If this is the last dock area in a dock container with only
375376
// one single dock widget it does not make sense to move it to a new

0 commit comments

Comments
 (0)