Improved and fixed handling of CDockWidget::DockWidgetMovable - moving the tab in the tabbar is always allowed, only moving the complete dock widget can be blocked by clearing this flag

This commit is contained in:
Uwe Kindler 2018-08-24 14:04:21 +02:00
parent 6b93ae9c39
commit 3f40c997e5
3 changed files with 23 additions and 27 deletions

View File

@ -18,9 +18,9 @@ class CDockAreaWidget;
struct DockAreaTabBarPrivate; struct DockAreaTabBarPrivate;
/** /**
* Custom scroll bar implementation for dock area tab bar * Custom tabbar implementation for tab area that is shown on top of a
* This scroll area enables floating of a whole dock area including all * dock area widget.
* dock widgets * The tabbar displays the tab widgets of the contained dock widgets.
*/ */
class CDockAreaTabBar : public QScrollArea class CDockAreaTabBar : public QScrollArea
{ {

View File

@ -45,7 +45,7 @@ class CDockWidget;
/** /**
* DockAreaWidget manages multiple instances of DckWidgets. * DockAreaWidget manages multiple instances of DockWidgets.
* It displays a title tab, which is clickable and will switch to * It displays a title tab, which is clickable and will switch to
* the contents associated to the title when clicked. * the contents associated to the title when clicked.
*/ */

View File

@ -240,19 +240,16 @@ void CDockWidgetTab::mouseReleaseEvent(QMouseEvent* ev)
// End of tab moving, change order now // End of tab moving, change order now
if (d->isDraggingState(DraggingTab) && d->DockArea) if (d->isDraggingState(DraggingTab) && d->DockArea)
{ {
if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { // Find tab under mouse
// Find tab under mouse QPoint pos = d->DockArea->mapFromGlobal(ev->globalPos());
QPoint pos = d->DockArea->mapFromGlobal(ev->globalPos()); int fromIndex = d->DockArea->tabIndex(d->DockWidget);
int fromIndex = d->DockArea->tabIndex(d->DockWidget); int toIndex = d->DockArea->indexOfContentByTitlePos(pos, this);
int toIndex = d->DockArea->indexOfContentByTitlePos(pos, this); if (-1 == toIndex)
if (-1 == toIndex) {
{ toIndex = d->DockArea->count() - 1;
toIndex = d->DockArea->count() - 1; }
} qDebug() << "Move tab from " << fromIndex << " to " << toIndex;
qDebug() << "Move tab from " << fromIndex << " to " << toIndex; d->DockArea->reorderDockWidget(fromIndex, toIndex);
d->DockArea->reorderDockWidget(fromIndex, toIndex);
}
} }
if (!d->DragStartMousePosition.isNull()) if (!d->DragStartMousePosition.isNull())
@ -276,11 +273,10 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
return; return;
} }
// move floating winwdow
if (d->isDraggingState(DraggingFloatingWidget)) if (d->isDraggingState(DraggingFloatingWidget))
{ {
if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { d->FloatingWidget->moveFloating();
d->FloatingWidget->moveFloating();
}
QFrame::mouseMoveEvent(ev); QFrame::mouseMoveEvent(ev);
return; return;
} }
@ -288,15 +284,17 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
// move tab // move tab
if (d->isDraggingState(DraggingTab)) if (d->isDraggingState(DraggingTab))
{ {
if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { // Moving the tab is always allowed because it does not mean moving the
d->moveTab(ev); // dock widget around
} d->moveTab(ev);
} }
bool MouseInsideTitleArea = d->titleAreaGeometryContains(ev->globalPos()); bool MouseInsideTitleArea = d->titleAreaGeometryContains(ev->globalPos());
if (!MouseInsideTitleArea) if (!MouseInsideTitleArea)
{ {
if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { // Floating is only allowed for widgets that are movable
if (d->DockWidget->features().testFlag(CDockWidget::DockWidgetMovable))
{
d->startFloating(); d->startFloating();
} }
return; return;
@ -304,9 +302,7 @@ void CDockWidgetTab::mouseMoveEvent(QMouseEvent* ev)
else if (d->DockArea->count() > 1 else if (d->DockArea->count() > 1
&& (ev->pos() - d->DragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving && (ev->pos() - d->DragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving
{ {
if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { d->DragState = DraggingTab;
d->DragState = DraggingTab;
}
return; return;
} }