mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 23:31:32 +08:00
Improved support for AutoHideTab drag and drop
This commit is contained in:
parent
4307f48d99
commit
bf22e54fc3
@ -117,7 +117,7 @@ struct AutoHideDockContainerPrivate
|
||||
CResizeHandle* ResizeHandle = nullptr;
|
||||
QSize Size; // creates invalid size
|
||||
QPointer<CAutoHideTab> SideTab;
|
||||
QSize OriginalDockWidgetSize;
|
||||
QSize InitialDockWidgetSize;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -197,6 +197,7 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarL
|
||||
Super(parent),
|
||||
d(new AutoHideDockContainerPrivate(this))
|
||||
{
|
||||
std::cout << "CAutoHideDockContainer::constructor" << std::endl;
|
||||
hide(); // auto hide dock container is initially always hidden
|
||||
d->SideTabBarArea = area;
|
||||
d->SideTab = componentsFactory()->createDockWidgetSideTab(nullptr);
|
||||
@ -217,7 +218,7 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarL
|
||||
d->ResizeHandle->setOpaqueResize(OpaqueResize);
|
||||
std::cout << "d->DockArea->size(); " << d->DockArea->size().width() << std::endl;
|
||||
d->Size = d->DockArea->size();
|
||||
d->OriginalDockWidgetSize = DockWidget->size();
|
||||
d->InitialDockWidgetSize = DockWidget->size();
|
||||
|
||||
addDockWidget(DockWidget);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CAutoHideDockContainer::resetToInitialDockWidgetSize()
|
||||
{
|
||||
auto OriginalSize = initialDockWidgetSize();
|
||||
if (orientation() == Qt::Horizontal)
|
||||
{
|
||||
setSize(OriginalSize.height());
|
||||
}
|
||||
else
|
||||
{
|
||||
setSize(OriginalSize.width());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,16 @@ public:
|
||||
* Returns the original size of the dock widget at the time it has been
|
||||
* 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.
|
||||
|
@ -61,6 +61,7 @@ struct AutoHideTabPrivate
|
||||
QPoint GlobalDragStartMousePosition;
|
||||
QPoint DragStartMousePosition;
|
||||
IFloatingWidget* FloatingWidget = nullptr;
|
||||
Qt::Orientation DragStartOrientation;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -182,6 +183,7 @@ bool AutoHideTabPrivate::startFloating(eDragState DraggingState)
|
||||
auto Size = DockArea->size();
|
||||
auto StartPos = DragStartMousePosition;
|
||||
auto AutoHideContainer = DockWidget->autoHideDockContainer();
|
||||
DragStartOrientation = AutoHideContainer->orientation();
|
||||
switch (SideBar->sideBarLocation())
|
||||
{
|
||||
case SideBarLeft:
|
||||
@ -373,13 +375,12 @@ bool CAutoHideTab::iconOnly() const
|
||||
void CAutoHideTab::contextMenuEvent(QContextMenuEvent* ev)
|
||||
{
|
||||
ev->accept();
|
||||
//d->saveDragStartMousePosition(ev->globalPos());
|
||||
d->saveDragStartMousePosition(ev->globalPos());
|
||||
|
||||
const bool isFloatable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable);
|
||||
QAction* Action;
|
||||
QMenu Menu(this);
|
||||
|
||||
|
||||
Action = Menu.addAction(tr("Detach"), this, SLOT(setDockWidgetFloating()));
|
||||
Action->setEnabled(isFloatable);
|
||||
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("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());
|
||||
}
|
||||
|
||||
@ -406,19 +400,6 @@ void CAutoHideTab::contextMenuEvent(QContextMenuEvent* ev)
|
||||
//============================================================================
|
||||
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();
|
||||
}
|
||||
|
||||
@ -427,7 +408,6 @@ void CAutoHideTab::setDockWidgetFloating()
|
||||
void CAutoHideTab::onAutoHideToActionClicked()
|
||||
{
|
||||
int Location = sender()->property(LocationProperty).toInt();
|
||||
std::cout << "CAutoHideTab::onAutoHideToActionClicked " << Location << std::endl;
|
||||
d->DockWidget->setAutoHide(true, (SideBarLocation)Location);
|
||||
}
|
||||
|
||||
@ -484,15 +464,16 @@ void CAutoHideTab::mouseReleaseEvent(QMouseEvent* ev)
|
||||
break;
|
||||
|
||||
case DraggingFloatingWidget:
|
||||
std::cout << "CAutoHideTab::mouseReleaseEvent" << std::endl;
|
||||
ev->accept();
|
||||
d->FloatingWidget->finishDragging();
|
||||
if (d->DockWidget->isAutoHide() && d->DragStartOrientation != orientation())
|
||||
{
|
||||
d->DockWidget->autoHideDockContainer()->resetToInitialDockWidgetSize();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
/*if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting))
|
||||
{
|
||||
d->focusController()->setDockWidgetTabPressed(false);
|
||||
}*/
|
||||
break; // do nothing
|
||||
}
|
||||
}
|
||||
@ -504,7 +485,6 @@ void CAutoHideTab::mouseReleaseEvent(QMouseEvent* ev)
|
||||
//============================================================================
|
||||
void CAutoHideTab::mouseMoveEvent(QMouseEvent* ev)
|
||||
{
|
||||
std::cout << "CAutoHideTab::mouseMoveEvent" << std::endl;
|
||||
if (!(ev->buttons() & Qt::LeftButton) || d->isDraggingState(DraggingInactive))
|
||||
{
|
||||
d->DragState = DraggingInactive;
|
||||
@ -532,7 +512,6 @@ void CAutoHideTab::mouseMoveEvent(QMouseEvent* ev)
|
||||
bool MouseOutsideBar = (MappedPos.x() < 0) || (MappedPos.x() > parentWidget()->rect().right());
|
||||
// Maybe a fixed drag distance is better here ?
|
||||
int DragDistanceY = qAbs(d->GlobalDragStartMousePosition.y() - internal::globalPositionOf(ev).y());
|
||||
std::cout << "DragDistanceY " << DragDistanceY << " MouseOutsideBar " << MouseOutsideBar << std::endl;
|
||||
if (DragDistanceY >= CDockManager::startDragDistance() || MouseOutsideBar)
|
||||
{
|
||||
// Floating is only allowed for widgets that are floatable
|
||||
@ -540,30 +519,12 @@ void CAutoHideTab::mouseMoveEvent(QMouseEvent* ev)
|
||||
auto Features = d->DockWidget->features();
|
||||
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();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -209,11 +209,6 @@ struct DockOverlayCrossPrivate
|
||||
CDockOverlay::eMode Mode)
|
||||
{
|
||||
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 overlayColor = iconColor(CDockOverlayCross::OverlayColor);
|
||||
if (overlayColor.alpha() == 255)
|
||||
@ -615,11 +610,6 @@ void CDockOverlay::paintEvent(QPaintEvent* event)
|
||||
}
|
||||
QPainter painter(this);
|
||||
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();
|
||||
Pen.setColor(Color.darker(120));
|
||||
Pen.setStyle(Qt::SolidLine);
|
||||
|
@ -1229,17 +1229,12 @@ void CDockWidget::setAutoHide(bool Enable, SideBarLocation Location)
|
||||
auto OldOrientation = AutoHideContainer->orientation();
|
||||
auto SideBar = dockContainer()->autoHideSideBar(Location);
|
||||
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)
|
||||
{
|
||||
auto OriginalSize = AutoHideContainer->originalDockWidgetSize();
|
||||
if (SideBar->orientation() == Qt::Horizontal)
|
||||
{
|
||||
AutoHideContainer->setSize(OriginalSize.height());
|
||||
}
|
||||
else
|
||||
{
|
||||
AutoHideContainer->setSize(OriginalSize.width());
|
||||
}
|
||||
AutoHideContainer->resetToInitialDockWidgetSize();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user