1
0
mirror of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git synced 2025-04-01 02:42:39 +08:00

Improved support for AutoHideTab drag and drop

This commit is contained in:
Uwe Kindler 2023-07-07 15:20:43 +02:00 committed by Jon Jenssen
parent 6dc1ed59aa
commit c02a2c631f
5 changed files with 43 additions and 72 deletions

View File

@ -117,7 +117,7 @@ struct AutoHideDockContainerPrivate
CResizeHandle* ResizeHandle = nullptr; CResizeHandle* ResizeHandle = nullptr;
QSize Size; // creates invalid size QSize Size; // creates invalid size
QPointer<CAutoHideTab> SideTab; QPointer<CAutoHideTab> SideTab;
QSize OriginalDockWidgetSize; QSize InitialDockWidgetSize;
/** /**
* Private data constructor * Private data constructor
@ -197,6 +197,7 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarL
Super(parent), Super(parent),
d(new AutoHideDockContainerPrivate(this)) d(new AutoHideDockContainerPrivate(this))
{ {
std::cout << "CAutoHideDockContainer::constructor" << std::endl;
hide(); // auto hide dock container is initially always hidden hide(); // auto hide dock container is initially always hidden
d->SideTabBarArea = area; d->SideTabBarArea = area;
d->SideTab = componentsFactory()->createDockWidgetSideTab(nullptr); d->SideTab = componentsFactory()->createDockWidgetSideTab(nullptr);
@ -217,7 +218,7 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarL
d->ResizeHandle->setOpaqueResize(OpaqueResize); d->ResizeHandle->setOpaqueResize(OpaqueResize);
std::cout << "d->DockArea->size(); " << d->DockArea->size().width() << std::endl; std::cout << "d->DockArea->size(); " << d->DockArea->size().width() << std::endl;
d->Size = d->DockArea->size(); d->Size = d->DockArea->size();
d->OriginalDockWidgetSize = DockWidget->size(); d->InitialDockWidgetSize = DockWidget->size();
addDockWidget(DockWidget); addDockWidget(DockWidget);
parent->registerAutoHideWidget(this); parent->registerAutoHideWidget(this);
@ -662,9 +663,9 @@ bool CAutoHideDockContainer::event(QEvent* event)
//============================================================================ //============================================================================
QSize CAutoHideDockContainer::originalDockWidgetSize() const QSize CAutoHideDockContainer::initialDockWidgetSize() const
{ {
return d->OriginalDockWidgetSize; return d->InitialDockWidgetSize;
} }
@ -674,5 +675,20 @@ Qt::Orientation CAutoHideDockContainer::orientation() const
return autoHideSideBar()->orientation(); return autoHideSideBar()->orientation();
} }
//============================================================================
void CAutoHideDockContainer::resetToInitialDockWidgetSize()
{
auto OriginalSize = initialDockWidgetSize();
if (orientation() == Qt::Horizontal)
{
setSize(OriginalSize.height());
}
else
{
setSize(OriginalSize.width());
}
}
} }

View File

@ -171,7 +171,16 @@ public:
* Returns the original size of the dock widget at the time it has been * Returns the original size of the dock widget at the time it has been
* added to this auto hide widget * added to this auto hide widget
*/ */
QSize originalDockWidgetSize() const; QSize initialDockWidgetSize() const;
/**
* Resets the with or hight to the initial dock widget size dependinng on
* the orientation.
* If the orientation is Qt::Horizontal, then the height is reset to
* the initial size and if orientation is Qt::Vertical, then the width is
* reset to the initial size
*/
void resetToInitialDockWidgetSize();
/** /**
* Returns orientation of this container. * Returns orientation of this container.

View File

@ -61,6 +61,7 @@ struct AutoHideTabPrivate
QPoint GlobalDragStartMousePosition; QPoint GlobalDragStartMousePosition;
QPoint DragStartMousePosition; QPoint DragStartMousePosition;
IFloatingWidget* FloatingWidget = nullptr; IFloatingWidget* FloatingWidget = nullptr;
Qt::Orientation DragStartOrientation;
/** /**
* Private data constructor * Private data constructor
@ -182,6 +183,7 @@ bool AutoHideTabPrivate::startFloating(eDragState DraggingState)
auto Size = DockArea->size(); auto Size = DockArea->size();
auto StartPos = DragStartMousePosition; auto StartPos = DragStartMousePosition;
auto AutoHideContainer = DockWidget->autoHideDockContainer(); auto AutoHideContainer = DockWidget->autoHideDockContainer();
DragStartOrientation = AutoHideContainer->orientation();
switch (SideBar->sideBarLocation()) switch (SideBar->sideBarLocation())
{ {
case SideBarLeft: case SideBarLeft:
@ -373,13 +375,12 @@ bool CAutoHideTab::iconOnly() const
void CAutoHideTab::contextMenuEvent(QContextMenuEvent* ev) void CAutoHideTab::contextMenuEvent(QContextMenuEvent* ev)
{ {
ev->accept(); ev->accept();
//d->saveDragStartMousePosition(ev->globalPos()); d->saveDragStartMousePosition(ev->globalPos());
const bool isFloatable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable); const bool isFloatable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable);
QAction* Action; QAction* Action;
QMenu Menu(this); QMenu Menu(this);
Action = Menu.addAction(tr("Detach"), this, SLOT(setDockWidgetFloating())); Action = Menu.addAction(tr("Detach"), this, SLOT(setDockWidgetFloating()));
Action->setEnabled(isFloatable); Action->setEnabled(isFloatable);
auto IsPinnable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetPinnable); auto IsPinnable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetPinnable);
@ -392,13 +393,6 @@ void CAutoHideTab::contextMenuEvent(QContextMenuEvent* ev)
d->createAutoHideToAction(tr("Right"), SideBarRight, menu); d->createAutoHideToAction(tr("Right"), SideBarRight, menu);
d->createAutoHideToAction(tr("Bottom"), SideBarBottom, menu); d->createAutoHideToAction(tr("Bottom"), SideBarBottom, menu);
/*Menu.addSeparator();
Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested()));
Action->setEnabled(isClosable());
if (d->DockArea->openDockWidgetsCount() > 1)
{
Action = Menu.addAction(tr("Close Others"), this, SIGNAL(closeOtherTabsRequested()));
}*/
Menu.exec(ev->globalPos()); Menu.exec(ev->globalPos());
} }
@ -406,19 +400,6 @@ void CAutoHideTab::contextMenuEvent(QContextMenuEvent* ev)
//============================================================================ //============================================================================
void CAutoHideTab::setDockWidgetFloating() void CAutoHideTab::setDockWidgetFloating()
{ {
/*auto DockArea = dockWidget()->dockAreaWidget();
auto AutoHideContainer = dockWidget()->autoHideDockContainer();
auto OriginalSize = AutoHideContainer->originalDockWidgetSize();
auto DockAreaSize = DockArea->size();
if (ads::internal::isHorizontalSideBarLocation(sideBarLocation()))
{
DockAreaSize.setHeight(OriginalSize.height());
}
else
{
DockAreaSize.setWidth(OriginalSize.width());
}
DockArea->resize(DockAreaSize);*/
dockWidget()->setFloating(); dockWidget()->setFloating();
} }
@ -427,7 +408,6 @@ void CAutoHideTab::setDockWidgetFloating()
void CAutoHideTab::onAutoHideToActionClicked() void CAutoHideTab::onAutoHideToActionClicked()
{ {
int Location = sender()->property(LocationProperty).toInt(); int Location = sender()->property(LocationProperty).toInt();
std::cout << "CAutoHideTab::onAutoHideToActionClicked " << Location << std::endl;
d->DockWidget->setAutoHide(true, (SideBarLocation)Location); d->DockWidget->setAutoHide(true, (SideBarLocation)Location);
} }
@ -484,15 +464,16 @@ void CAutoHideTab::mouseReleaseEvent(QMouseEvent* ev)
break; break;
case DraggingFloatingWidget: case DraggingFloatingWidget:
std::cout << "CAutoHideTab::mouseReleaseEvent" << std::endl;
ev->accept(); ev->accept();
d->FloatingWidget->finishDragging(); d->FloatingWidget->finishDragging();
if (d->DockWidget->isAutoHide() && d->DragStartOrientation != orientation())
{
d->DockWidget->autoHideDockContainer()->resetToInitialDockWidgetSize();
}
break; break;
default: default:
/*if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting))
{
d->focusController()->setDockWidgetTabPressed(false);
}*/
break; // do nothing break; // do nothing
} }
} }
@ -504,7 +485,6 @@ void CAutoHideTab::mouseReleaseEvent(QMouseEvent* ev)
//============================================================================ //============================================================================
void CAutoHideTab::mouseMoveEvent(QMouseEvent* ev) void CAutoHideTab::mouseMoveEvent(QMouseEvent* ev)
{ {
std::cout << "CAutoHideTab::mouseMoveEvent" << std::endl;
if (!(ev->buttons() & Qt::LeftButton) || d->isDraggingState(DraggingInactive)) if (!(ev->buttons() & Qt::LeftButton) || d->isDraggingState(DraggingInactive))
{ {
d->DragState = DraggingInactive; d->DragState = DraggingInactive;
@ -532,7 +512,6 @@ void CAutoHideTab::mouseMoveEvent(QMouseEvent* ev)
bool MouseOutsideBar = (MappedPos.x() < 0) || (MappedPos.x() > parentWidget()->rect().right()); bool MouseOutsideBar = (MappedPos.x() < 0) || (MappedPos.x() > parentWidget()->rect().right());
// Maybe a fixed drag distance is better here ? // Maybe a fixed drag distance is better here ?
int DragDistanceY = qAbs(d->GlobalDragStartMousePosition.y() - internal::globalPositionOf(ev).y()); int DragDistanceY = qAbs(d->GlobalDragStartMousePosition.y() - internal::globalPositionOf(ev).y());
std::cout << "DragDistanceY " << DragDistanceY << " MouseOutsideBar " << MouseOutsideBar << std::endl;
if (DragDistanceY >= CDockManager::startDragDistance() || MouseOutsideBar) if (DragDistanceY >= CDockManager::startDragDistance() || MouseOutsideBar)
{ {
// Floating is only allowed for widgets that are floatable // Floating is only allowed for widgets that are floatable
@ -540,30 +519,12 @@ void CAutoHideTab::mouseMoveEvent(QMouseEvent* ev)
auto Features = d->DockWidget->features(); auto Features = d->DockWidget->features();
if (Features.testFlag(CDockWidget::DockWidgetFloatable) || (Features.testFlag(CDockWidget::DockWidgetMovable))) if (Features.testFlag(CDockWidget::DockWidgetFloatable) || (Features.testFlag(CDockWidget::DockWidgetMovable)))
{ {
// If we undock, we need to restore the initial position of this
// tab because it looks strange if it remains on its dragged position
/*if (d->isDraggingState(DraggingTab))
{
parentWidget()->layout()->update();
}*/
d->startFloating(); d->startFloating();
} }
return; return;
} }
/*else if (d->DockArea->openDockWidgetsCount() > 1
&& (internal::globalPositionOf(ev) - d->GlobalDragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving
{
// If we start dragging the tab, we save its inital position to
// restore it later
if (DraggingTab != d->DragState)
{
d->TabDragStartPosition = this->pos();
}
d->DragState = DraggingTab;
return;
}*/
Super::mouseMoveEvent(ev); Super::mouseMoveEvent(ev);
} }

View File

@ -209,11 +209,6 @@ struct DockOverlayCrossPrivate
CDockOverlay::eMode Mode) CDockOverlay::eMode Mode)
{ {
QColor borderColor = iconColor(CDockOverlayCross::FrameColor); QColor borderColor = iconColor(CDockOverlayCross::FrameColor);
// TODO: remove, this is just for debugging
if (Mode == CDockOverlay::ModeContainerOverlay)
{
borderColor = Qt::red;
}
QColor backgroundColor = iconColor(CDockOverlayCross::WindowBackgroundColor); QColor backgroundColor = iconColor(CDockOverlayCross::WindowBackgroundColor);
QColor overlayColor = iconColor(CDockOverlayCross::OverlayColor); QColor overlayColor = iconColor(CDockOverlayCross::OverlayColor);
if (overlayColor.alpha() == 255) if (overlayColor.alpha() == 255)
@ -615,11 +610,6 @@ void CDockOverlay::paintEvent(QPaintEvent* event)
} }
QPainter painter(this); QPainter painter(this);
QColor Color = palette().color(QPalette::Active, QPalette::Highlight); QColor Color = palette().color(QPalette::Active, QPalette::Highlight);
// TODO: This is just for debugging - remove later
if (d->Mode == CDockOverlay::ModeContainerOverlay)
{
Color = Qt::red;
}
QPen Pen = painter.pen(); QPen Pen = painter.pen();
Pen.setColor(Color.darker(120)); Pen.setColor(Color.darker(120));
Pen.setStyle(Qt::SolidLine); Pen.setStyle(Qt::SolidLine);

View File

@ -1229,17 +1229,12 @@ void CDockWidget::setAutoHide(bool Enable, SideBarLocation Location)
auto OldOrientation = AutoHideContainer->orientation(); auto OldOrientation = AutoHideContainer->orientation();
auto SideBar = dockContainer()->autoHideSideBar(Location); auto SideBar = dockContainer()->autoHideSideBar(Location);
SideBar->addAutoHideWidget(AutoHideContainer); SideBar->addAutoHideWidget(AutoHideContainer);
// If we move a horizontal auto hide container to a vertical position
// then we resize it to the orginal dock widget size, to avoid
// an extremely streched dock widget after insertion
if (SideBar->orientation() != OldOrientation) if (SideBar->orientation() != OldOrientation)
{ {
auto OriginalSize = AutoHideContainer->originalDockWidgetSize(); AutoHideContainer->resetToInitialDockWidgetSize();
if (SideBar->orientation() == Qt::Horizontal)
{
AutoHideContainer->setSize(OriginalSize.height());
}
else
{
AutoHideContainer->setSize(OriginalSize.width());
}
} }
} }
else else