Improved tab dragging, added support for undocking if mouse leaves tabbar during tb dragging

This commit is contained in:
Uwe Kindler 2020-02-19 22:29:29 +01:00
parent fd28f0f751
commit 8c12d912b4
2 changed files with 6 additions and 5 deletions

View File

@ -488,7 +488,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
// uncomment the following line if you want to use opaque undocking and
// opaque splitter resizing
// CDockManager::setConfigFlags(CDockManager::DefaultOpaqueConfig);
//CDockManager::setConfigFlags(CDockManager::DefaultOpaqueConfig);
// uncomment the following line if you want a fixed tab width that does
// not change if the visibility of the close button changes

View File

@ -215,6 +215,8 @@ void DockWidgetTabPrivate::moveTab(QMouseEvent* ev)
QPoint Distance = ev->globalPos() - GlobalDragStartMousePosition;
Distance.setY(0);
auto TargetPos = Distance + TabDragStartPosition;
TargetPos.rx() = qMax(TargetPos.x(), 0);
TargetPos.rx() = qMin(_this->parentWidget()->rect().right() - _this->width() + 1, TargetPos.rx());
_this->move(TargetPos);
_this->raise();
}
@ -357,19 +359,18 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
}
// move tab
bool TabOutsideBar = false;
if (d->isDraggingState(DraggingTab))
{
// Moving the tab is always allowed because it does not mean moving the
// dock widget around
d->moveTab(ev);
TabOutsideBar = (geometry().right() < 0) || (geometry().left() > parentWidget()->rect().right());
}
auto MappedPos = mapToParent(ev->pos());
bool MouseOutsideBar = (MappedPos.x() < 0) || (MappedPos.x() > parentWidget()->rect().right());
// Maybe a fixed drag distance is better here ?
int DragDistanceY = qAbs(d->GlobalDragStartMousePosition.y() - ev->globalPos().y());
if (DragDistanceY >= CDockManager::startDragDistance() || TabOutsideBar)
if (DragDistanceY >= CDockManager::startDragDistance() || MouseOutsideBar)
{
// If this is the last dock area in a dock container with only
// one single dock widget it does not make sense to move it to a new