Skip to content

Commit bf22e54

Browse files
Improved support for AutoHideTab drag and drop
1 parent 4307f48 commit bf22e54

File tree

5 files changed

+43
-72
lines changed

5 files changed

+43
-72
lines changed

src/AutoHideDockContainer.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ struct AutoHideDockContainerPrivate
117117
CResizeHandle* ResizeHandle = nullptr;
118118
QSize Size; // creates invalid size
119119
QPointer<CAutoHideTab> SideTab;
120-
QSize OriginalDockWidgetSize;
120+
QSize InitialDockWidgetSize;
121121

122122
/**
123123
* Private data constructor
@@ -197,6 +197,7 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarL
197197
Super(parent),
198198
d(new AutoHideDockContainerPrivate(this))
199199
{
200+
std::cout << "CAutoHideDockContainer::constructor" << std::endl;
200201
hide(); // auto hide dock container is initially always hidden
201202
d->SideTabBarArea = area;
202203
d->SideTab = componentsFactory()->createDockWidgetSideTab(nullptr);
@@ -217,7 +218,7 @@ CAutoHideDockContainer::CAutoHideDockContainer(CDockWidget* DockWidget, SideBarL
217218
d->ResizeHandle->setOpaqueResize(OpaqueResize);
218219
std::cout << "d->DockArea->size(); " << d->DockArea->size().width() << std::endl;
219220
d->Size = d->DockArea->size();
220-
d->OriginalDockWidgetSize = DockWidget->size();
221+
d->InitialDockWidgetSize = DockWidget->size();
221222

222223
addDockWidget(DockWidget);
223224
parent->registerAutoHideWidget(this);
@@ -662,9 +663,9 @@ bool CAutoHideDockContainer::event(QEvent* event)
662663

663664

664665
//============================================================================
665-
QSize CAutoHideDockContainer::originalDockWidgetSize() const
666+
QSize CAutoHideDockContainer::initialDockWidgetSize() const
666667
{
667-
return d->OriginalDockWidgetSize;
668+
return d->InitialDockWidgetSize;
668669
}
669670

670671

@@ -674,5 +675,20 @@ Qt::Orientation CAutoHideDockContainer::orientation() const
674675
return autoHideSideBar()->orientation();
675676
}
676677

678+
679+
//============================================================================
680+
void CAutoHideDockContainer::resetToInitialDockWidgetSize()
681+
{
682+
auto OriginalSize = initialDockWidgetSize();
683+
if (orientation() == Qt::Horizontal)
684+
{
685+
setSize(OriginalSize.height());
686+
}
687+
else
688+
{
689+
setSize(OriginalSize.width());
690+
}
691+
}
692+
677693
}
678694

src/AutoHideDockContainer.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,16 @@ class ADS_EXPORT CAutoHideDockContainer : public QFrame
171171
* Returns the original size of the dock widget at the time it has been
172172
* added to this auto hide widget
173173
*/
174-
QSize originalDockWidgetSize() const;
174+
QSize initialDockWidgetSize() const;
175+
176+
/**
177+
* Resets the with or hight to the initial dock widget size dependinng on
178+
* the orientation.
179+
* If the orientation is Qt::Horizontal, then the height is reset to
180+
* the initial size and if orientation is Qt::Vertical, then the width is
181+
* reset to the initial size
182+
*/
183+
void resetToInitialDockWidgetSize();
175184

176185
/**
177186
* Returns orientation of this container.

src/AutoHideTab.cpp

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct AutoHideTabPrivate
6161
QPoint GlobalDragStartMousePosition;
6262
QPoint DragStartMousePosition;
6363
IFloatingWidget* FloatingWidget = nullptr;
64+
Qt::Orientation DragStartOrientation;
6465

6566
/**
6667
* Private data constructor
@@ -182,6 +183,7 @@ bool AutoHideTabPrivate::startFloating(eDragState DraggingState)
182183
auto Size = DockArea->size();
183184
auto StartPos = DragStartMousePosition;
184185
auto AutoHideContainer = DockWidget->autoHideDockContainer();
186+
DragStartOrientation = AutoHideContainer->orientation();
185187
switch (SideBar->sideBarLocation())
186188
{
187189
case SideBarLeft:
@@ -373,13 +375,12 @@ bool CAutoHideTab::iconOnly() const
373375
void CAutoHideTab::contextMenuEvent(QContextMenuEvent* ev)
374376
{
375377
ev->accept();
376-
//d->saveDragStartMousePosition(ev->globalPos());
378+
d->saveDragStartMousePosition(ev->globalPos());
377379

378380
const bool isFloatable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetFloatable);
379381
QAction* Action;
380382
QMenu Menu(this);
381383

382-
383384
Action = Menu.addAction(tr("Detach"), this, SLOT(setDockWidgetFloating()));
384385
Action->setEnabled(isFloatable);
385386
auto IsPinnable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetPinnable);
@@ -392,33 +393,13 @@ void CAutoHideTab::contextMenuEvent(QContextMenuEvent* ev)
392393
d->createAutoHideToAction(tr("Right"), SideBarRight, menu);
393394
d->createAutoHideToAction(tr("Bottom"), SideBarBottom, menu);
394395

395-
/*Menu.addSeparator();
396-
Action = Menu.addAction(tr("Close"), this, SIGNAL(closeRequested()));
397-
Action->setEnabled(isClosable());
398-
if (d->DockArea->openDockWidgetsCount() > 1)
399-
{
400-
Action = Menu.addAction(tr("Close Others"), this, SIGNAL(closeOtherTabsRequested()));
401-
}*/
402396
Menu.exec(ev->globalPos());
403397
}
404398

405399

406400
//============================================================================
407401
void CAutoHideTab::setDockWidgetFloating()
408402
{
409-
/*auto DockArea = dockWidget()->dockAreaWidget();
410-
auto AutoHideContainer = dockWidget()->autoHideDockContainer();
411-
auto OriginalSize = AutoHideContainer->originalDockWidgetSize();
412-
auto DockAreaSize = DockArea->size();
413-
if (ads::internal::isHorizontalSideBarLocation(sideBarLocation()))
414-
{
415-
DockAreaSize.setHeight(OriginalSize.height());
416-
}
417-
else
418-
{
419-
DockAreaSize.setWidth(OriginalSize.width());
420-
}
421-
DockArea->resize(DockAreaSize);*/
422403
dockWidget()->setFloating();
423404
}
424405

@@ -427,7 +408,6 @@ void CAutoHideTab::setDockWidgetFloating()
427408
void CAutoHideTab::onAutoHideToActionClicked()
428409
{
429410
int Location = sender()->property(LocationProperty).toInt();
430-
std::cout << "CAutoHideTab::onAutoHideToActionClicked " << Location << std::endl;
431411
d->DockWidget->setAutoHide(true, (SideBarLocation)Location);
432412
}
433413

@@ -484,15 +464,16 @@ void CAutoHideTab::mouseReleaseEvent(QMouseEvent* ev)
484464
break;
485465

486466
case DraggingFloatingWidget:
467+
std::cout << "CAutoHideTab::mouseReleaseEvent" << std::endl;
487468
ev->accept();
488469
d->FloatingWidget->finishDragging();
470+
if (d->DockWidget->isAutoHide() && d->DragStartOrientation != orientation())
471+
{
472+
d->DockWidget->autoHideDockContainer()->resetToInitialDockWidgetSize();
473+
}
489474
break;
490475

491476
default:
492-
/*if (CDockManager::testConfigFlag(CDockManager::FocusHighlighting))
493-
{
494-
d->focusController()->setDockWidgetTabPressed(false);
495-
}*/
496477
break; // do nothing
497478
}
498479
}
@@ -504,7 +485,6 @@ void CAutoHideTab::mouseReleaseEvent(QMouseEvent* ev)
504485
//============================================================================
505486
void CAutoHideTab::mouseMoveEvent(QMouseEvent* ev)
506487
{
507-
std::cout << "CAutoHideTab::mouseMoveEvent" << std::endl;
508488
if (!(ev->buttons() & Qt::LeftButton) || d->isDraggingState(DraggingInactive))
509489
{
510490
d->DragState = DraggingInactive;
@@ -532,38 +512,19 @@ void CAutoHideTab::mouseMoveEvent(QMouseEvent* ev)
532512
bool MouseOutsideBar = (MappedPos.x() < 0) || (MappedPos.x() > parentWidget()->rect().right());
533513
// Maybe a fixed drag distance is better here ?
534514
int DragDistanceY = qAbs(d->GlobalDragStartMousePosition.y() - internal::globalPositionOf(ev).y());
535-
std::cout << "DragDistanceY " << DragDistanceY << " MouseOutsideBar " << MouseOutsideBar << std::endl;
536515
if (DragDistanceY >= CDockManager::startDragDistance() || MouseOutsideBar)
537516
{
538517
// Floating is only allowed for widgets that are floatable
539518
// We can create the drag preview if the widget is movable.
540519
auto Features = d->DockWidget->features();
541520
if (Features.testFlag(CDockWidget::DockWidgetFloatable) || (Features.testFlag(CDockWidget::DockWidgetMovable)))
542521
{
543-
// If we undock, we need to restore the initial position of this
544-
// tab because it looks strange if it remains on its dragged position
545-
/*if (d->isDraggingState(DraggingTab))
546-
{
547-
parentWidget()->layout()->update();
548-
}*/
549522
d->startFloating();
550523
}
551524
return;
552525
}
553-
/*else if (d->DockArea->openDockWidgetsCount() > 1
554-
&& (internal::globalPositionOf(ev) - d->GlobalDragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving
555-
{
556-
// If we start dragging the tab, we save its inital position to
557-
// restore it later
558-
if (DraggingTab != d->DragState)
559-
{
560-
d->TabDragStartPosition = this->pos();
561-
}
562-
d->DragState = DraggingTab;
563-
return;
564-
}*/
565526

566-
Super::mouseMoveEvent(ev);
527+
Super::mouseMoveEvent(ev);
567528
}
568529

569530

src/DockOverlay.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,6 @@ struct DockOverlayCrossPrivate
209209
CDockOverlay::eMode Mode)
210210
{
211211
QColor borderColor = iconColor(CDockOverlayCross::FrameColor);
212-
// TODO: remove, this is just for debugging
213-
if (Mode == CDockOverlay::ModeContainerOverlay)
214-
{
215-
borderColor = Qt::red;
216-
}
217212
QColor backgroundColor = iconColor(CDockOverlayCross::WindowBackgroundColor);
218213
QColor overlayColor = iconColor(CDockOverlayCross::OverlayColor);
219214
if (overlayColor.alpha() == 255)
@@ -615,11 +610,6 @@ void CDockOverlay::paintEvent(QPaintEvent* event)
615610
}
616611
QPainter painter(this);
617612
QColor Color = palette().color(QPalette::Active, QPalette::Highlight);
618-
// TODO: This is just for debugging - remove later
619-
if (d->Mode == CDockOverlay::ModeContainerOverlay)
620-
{
621-
Color = Qt::red;
622-
}
623613
QPen Pen = painter.pen();
624614
Pen.setColor(Color.darker(120));
625615
Pen.setStyle(Qt::SolidLine);

src/DockWidget.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,17 +1229,12 @@ void CDockWidget::setAutoHide(bool Enable, SideBarLocation Location)
12291229
auto OldOrientation = AutoHideContainer->orientation();
12301230
auto SideBar = dockContainer()->autoHideSideBar(Location);
12311231
SideBar->addAutoHideWidget(AutoHideContainer);
1232+
// If we move a horizontal auto hide container to a vertical position
1233+
// then we resize it to the orginal dock widget size, to avoid
1234+
// an extremely streched dock widget after insertion
12321235
if (SideBar->orientation() != OldOrientation)
12331236
{
1234-
auto OriginalSize = AutoHideContainer->originalDockWidgetSize();
1235-
if (SideBar->orientation() == Qt::Horizontal)
1236-
{
1237-
AutoHideContainer->setSize(OriginalSize.height());
1238-
}
1239-
else
1240-
{
1241-
AutoHideContainer->setSize(OriginalSize.width());
1242-
}
1237+
AutoHideContainer->resetToInitialDockWidgetSize();
12431238
}
12441239
}
12451240
else

0 commit comments

Comments
 (0)