Skip to content

Commit b9479db

Browse files
Started implementing autohide drag functionality
1 parent 34cc91a commit b9479db

File tree

5 files changed

+229
-14
lines changed

5 files changed

+229
-14
lines changed

src/DockContainerWidget.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,14 +1626,16 @@ int CDockContainerWidget::visibleDockAreaCount() const
16261626
void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWidget,
16271627
const QPoint& TargetPos)
16281628
{
1629+
//dockContainer()->createAndSetupAutoHideContainer(area, this);
16291630
ADS_PRINT("CDockContainerWidget::dropFloatingWidget");
16301631
CDockWidget* SingleDroppedDockWidget = FloatingWidget->topLevelDockWidget();
16311632
CDockWidget* SingleDockWidget = topLevelDockWidget();
1632-
CDockAreaWidget* DockArea = dockAreaAt(TargetPos);
16331633
auto dropArea = InvalidDockWidgetArea;
16341634
auto ContainerDropArea = d->DockManager->containerOverlay()->dropAreaUnderCursor();
16351635
bool Dropped = false;
16361636

1637+
CDockAreaWidget* DockArea = dockAreaAt(TargetPos);
1638+
std::cout << "DockArea: " << DockArea << " dropArea: " << dropArea << std::endl;
16371639
if (DockArea)
16381640
{
16391641
auto dropOverlay = d->DockManager->dockAreaOverlay();
@@ -1654,15 +1656,30 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
16541656
}
16551657

16561658
// mouse is over container
1657-
if (InvalidDockWidgetArea == dropArea)
1659+
std::cout << "Mouse is over container" << std::endl;
1660+
if (InvalidDockWidgetArea == dropArea && InvalidDockWidgetArea != ContainerDropArea)
16581661
{
1659-
dropArea = ContainerDropArea;
1660-
ADS_PRINT("Container Drop Content: " << dropArea);
1661-
if (dropArea != InvalidDockWidgetArea)
1662-
{
1663-
d->dropIntoContainer(FloatingWidget, dropArea);
1664-
Dropped = true;
1665-
}
1662+
if (internal::isSideBarArea(ContainerDropArea))
1663+
{
1664+
auto SideBarLocation = internal::toSideBarLocation(ContainerDropArea);
1665+
std::cout << "Drop into sidebar " << std::endl;
1666+
auto NewDockAreas = FloatingWidget->findChildren<CDockAreaWidget*>(
1667+
QString(), Qt::FindChildrenRecursively);
1668+
for (auto DockArea : NewDockAreas)
1669+
{
1670+
auto DockWidgets = DockArea->dockWidgets();
1671+
for (auto DockWidget : DockWidgets)
1672+
{
1673+
createAndSetupAutoHideContainer(SideBarLocation, DockWidget);
1674+
}
1675+
}
1676+
}
1677+
else
1678+
{
1679+
ADS_PRINT("Container Drop Content: " << ContainerDropArea);
1680+
d->dropIntoContainer(FloatingWidget, ContainerDropArea);
1681+
}
1682+
Dropped = true;
16661683
}
16671684

16681685
// Remove the auto hide widgets from the FloatingWidget and insert

src/DockOverlay.cpp

Lines changed: 121 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@
3838

3939
#include "DockAreaWidget.h"
4040
#include "DockAreaTitleBar.h"
41+
#include "DockContainerWidget.h"
42+
#include "AutoHideSideBar.h"
43+
#include "DockManager.h"
4144

4245
#include <iostream>
4346

4447
namespace ads
4548
{
49+
static const int AutoHideAreaWidth = 32;
4650

4751
/**
4852
* Private data class of CDockOverlay
@@ -62,6 +66,12 @@ struct DockOverlayPrivate
6266
* Private data constructor
6367
*/
6468
DockOverlayPrivate(CDockOverlay* _public) : _this(_public) {}
69+
70+
/**
71+
* Returns the overlay width / height depending on the visibility
72+
* of the sidebar
73+
*/
74+
int sideBarOverlaySize(SideBarLocation sideBarLocation);
6575
};
6676

6777
/**
@@ -155,8 +165,20 @@ struct DockOverlayCrossPrivate
155165
QLabel* l = new QLabel();
156166
l->setObjectName("DockWidgetAreaLabel");
157167

158-
const qreal metric = dropIndicatiorWidth(l);
159-
const QSizeF size(metric, metric);
168+
qreal metric = dropIndicatiorWidth(l);
169+
QSizeF size(metric, metric);
170+
if (internal::isSideBarArea(DockWidgetArea))
171+
{
172+
auto SideBarLocation = internal::toSideBarLocation(DockWidgetArea);
173+
if (internal::isHorizontalSideBarLocation(SideBarLocation))
174+
{
175+
size.setHeight(size.height() / 2);
176+
}
177+
else
178+
{
179+
size.setWidth(size.width() / 2);
180+
}
181+
}
160182

161183
l->setPixmap(createHighDpiDropIndicatorPixmap(size, DockWidgetArea, Mode));
162184
l->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
@@ -283,7 +305,7 @@ struct DockOverlayCrossPrivate
283305
p.restore();
284306

285307
// Draw arrow for outer container drop indicators
286-
if (CDockOverlay::ModeContainerOverlay == Mode && DockWidgetArea != CenterDockWidgetArea)
308+
/*if (CDockOverlay::ModeContainerOverlay == Mode && DockWidgetArea != CenterDockWidgetArea)
287309
{
288310
QRectF ArrowRect;
289311
ArrowRect.setSize(baseSize);
@@ -317,7 +339,7 @@ struct DockOverlayCrossPrivate
317339
}
318340
319341
p.drawPolygon(Arrow);
320-
}
342+
}*/
321343

322344
pm.setDevicePixelRatio(DevicePixelRatio);
323345
return pm;
@@ -326,6 +348,22 @@ struct DockOverlayCrossPrivate
326348
};
327349

328350

351+
//============================================================================
352+
int DockOverlayPrivate::sideBarOverlaySize(SideBarLocation sideBarLocation)
353+
{
354+
auto Container = qobject_cast<CDockContainerWidget*>(TargetWidget.data());
355+
auto SideBar = Container->sideTabBar(sideBarLocation);
356+
if (!SideBar || !SideBar->isVisibleTo(Container))
357+
{
358+
return AutoHideAreaWidth;
359+
}
360+
else
361+
{
362+
return (SideBar->orientation() == Qt::Horizontal) ? SideBar->height() : SideBar->width();
363+
}
364+
}
365+
366+
329367
//============================================================================
330368
CDockOverlay::CDockOverlay(QWidget* parent, eMode Mode) :
331369
QFrame(parent),
@@ -375,15 +413,42 @@ DockWidgetAreas CDockOverlay::allowedAreas() const
375413
//============================================================================
376414
DockWidgetArea CDockOverlay::dropAreaUnderCursor() const
377415
{
416+
if (!d->TargetWidget)
417+
{
418+
return InvalidDockWidgetArea;
419+
}
420+
378421
DockWidgetArea Result = d->Cross->cursorLocation();
379422
if (Result != InvalidDockWidgetArea)
380423
{
381424
return Result;
382425
}
383426

384-
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(d->TargetWidget.data());
427+
auto DockArea = qobject_cast<CDockAreaWidget*>(d->TargetWidget.data());
385428
if (!DockArea)
386429
{
430+
/*auto Rect = rect();
431+
const QPoint pos = mapFromGlobal(QCursor::pos());
432+
if (pos.x() < d->sideBarOverlaySize(SideBarLeft))
433+
{
434+
return LeftAutoHideArea;
435+
}
436+
else if (pos.x() > (Rect.width() - d->sideBarOverlaySize(SideBarRight)))
437+
{
438+
return RightAutoHideArea;
439+
}
440+
else if (pos.y() < d->sideBarOverlaySize(SideBarTop))
441+
{
442+
return TopAutoHideArea;
443+
}
444+
else if (pos.y() > (Rect.height() - d->sideBarOverlaySize(SideBarBottom)))
445+
{
446+
return BottomAutoHideArea;
447+
}
448+
else
449+
{
450+
return Result;
451+
}*/
387452
return Result;
388453
}
389454

@@ -490,6 +555,10 @@ void CDockOverlay::paintEvent(QPaintEvent* event)
490555
case BottomDockWidgetArea: r.setY(r.height() * (1 - 1 / Factor)); break;
491556
case LeftDockWidgetArea: r.setWidth(r.width() / Factor); break;
492557
case CenterDockWidgetArea: r = rect();break;
558+
case LeftAutoHideArea: r.setWidth(d->sideBarOverlaySize(SideBarLeft)); break;
559+
case RightAutoHideArea: r.setX(r.width() - d->sideBarOverlaySize(SideBarRight)); break;
560+
case TopAutoHideArea: r.setHeight(d->sideBarOverlaySize(SideBarTop)); break;
561+
case BottomAutoHideArea: r.setY(r.height() - d->sideBarOverlaySize(SideBarBottom)); break;
493562
default: return;
494563
}
495564
QPainter painter(this);
@@ -574,6 +643,23 @@ QPoint DockOverlayCrossPrivate::areaGridPosition(const DockWidgetArea area)
574643
default: return QPoint();
575644
}
576645
}
646+
else if (CDockManager::autoHideConfigFlags().testFlag(CDockManager::AutoHideFeatureEnabled))
647+
{
648+
switch (area)
649+
{
650+
case TopDockWidgetArea: return QPoint(1, 3);
651+
case RightDockWidgetArea: return QPoint(3, 5);
652+
case BottomDockWidgetArea: return QPoint(5, 3);
653+
case LeftDockWidgetArea: return QPoint(3, 1);
654+
case CenterDockWidgetArea: return QPoint(3, 3);
655+
656+
case TopAutoHideArea: return QPoint(0, 3);
657+
case RightAutoHideArea: return QPoint(3, 6);
658+
case BottomAutoHideArea: return QPoint(6, 3);
659+
case LeftAutoHideArea: return QPoint(3, 0);
660+
default: return QPoint();
661+
}
662+
}
577663
else
578664
{
579665
switch (area)
@@ -627,6 +713,16 @@ void CDockOverlayCross::setupOverlayCross(CDockOverlay::eMode Mode)
627713
areaWidgets.insert(BottomDockWidgetArea, d->createDropIndicatorWidget(BottomDockWidgetArea, Mode));
628714
areaWidgets.insert(LeftDockWidgetArea, d->createDropIndicatorWidget(LeftDockWidgetArea, Mode));
629715
areaWidgets.insert(CenterDockWidgetArea, d->createDropIndicatorWidget(CenterDockWidgetArea, Mode));
716+
717+
if (CDockManager::autoHideConfigFlags().testFlag(CDockManager::AutoHideFeatureEnabled)
718+
&& CDockOverlay::ModeContainerOverlay == Mode)
719+
{
720+
areaWidgets.insert(TopAutoHideArea, d->createDropIndicatorWidget(TopAutoHideArea, Mode));
721+
areaWidgets.insert(RightAutoHideArea, d->createDropIndicatorWidget(RightAutoHideArea, Mode));
722+
areaWidgets.insert(BottomAutoHideArea, d->createDropIndicatorWidget(BottomAutoHideArea, Mode));
723+
areaWidgets.insert(LeftAutoHideArea, d->createDropIndicatorWidget(LeftAutoHideArea, Mode));
724+
}
725+
630726
#if QT_VERSION >= 0x050600
631727
d->LastDevicePixelRatio = devicePixelRatioF();
632728
#else
@@ -713,6 +809,26 @@ void CDockOverlayCross::setAreaWidgets(const QHash<DockWidgetArea, QWidget*>& wi
713809
d->GridLayout->setColumnStretch(3, 0);
714810
d->GridLayout->setColumnStretch(4, 1);
715811
}
812+
else if (CDockManager::autoHideConfigFlags().testFlag(CDockManager::AutoHideFeatureEnabled))
813+
{
814+
d->GridLayout->setContentsMargins(4, 4, 4, 4);
815+
d->GridLayout->setSpacing(4);
816+
d->GridLayout->setRowStretch(0, 0);
817+
d->GridLayout->setRowStretch(1, 0);
818+
d->GridLayout->setRowStretch(2, 1);
819+
d->GridLayout->setRowStretch(3, 1);
820+
d->GridLayout->setRowStretch(4, 1);
821+
d->GridLayout->setRowStretch(5, 0);
822+
d->GridLayout->setRowStretch(6, 0);
823+
824+
d->GridLayout->setColumnStretch(0, 0);
825+
d->GridLayout->setColumnStretch(1, 0);
826+
d->GridLayout->setColumnStretch(2, 1);
827+
d->GridLayout->setColumnStretch(3, 1);
828+
d->GridLayout->setColumnStretch(4, 1);
829+
d->GridLayout->setColumnStretch(5, 0);
830+
d->GridLayout->setColumnStretch(6, 0);
831+
}
716832
else
717833
{
718834
d->GridLayout->setContentsMargins(4, 4, 4, 4);

src/FloatingDragPreview.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ void CFloatingDragPreview::startFloating(const QPoint &DragStartMousePos,
347347
void CFloatingDragPreview::finishDragging()
348348
{
349349
ADS_PRINT("CFloatingDragPreview::finishDragging");
350+
std::cout << "CFloatingDragPreview::finishDragging" << std::endl;
350351

351352
auto DockDropArea = d->DockManager->dockAreaOverlay()->visibleDropAreaUnderCursor();
352353
auto ContainerDropArea = d->DockManager->containerOverlay()->visibleDropAreaUnderCursor();
@@ -369,12 +370,28 @@ void CFloatingDragPreview::finishDragging()
369370
}
370371
else if (ContainerDropArea != InvalidDockWidgetArea)
371372
{
373+
std::cout << "ContainerDropArea != InvalidDockWidgetArea " << ContainerDropArea << std::endl;
372374
// If there is only one single dock area, and we drop into the center
373375
// then we tabify the dropped widget into the only visible dock area
374376
if (d->DropContainer->visibleDockAreaCount() <= 1 && CenterDockWidgetArea == ContainerDropArea)
375377
{
376378
d->DropContainer->dropWidget(d->Content, ContainerDropArea, d->DropContainer->dockAreaAt(QCursor::pos()));
377379
}
380+
else if (internal::isSideBarArea(ContainerDropArea))
381+
{
382+
// Drop into AutoHideArea
383+
auto DockWidget = qobject_cast<CDockWidget*>(d->Content);
384+
auto DockArea = qobject_cast<CDockAreaWidget*>(d->Content);
385+
auto SideBarLocation = internal::toSideBarLocation(ContainerDropArea);
386+
if (DockWidget)
387+
{
388+
DockWidget->toggleAutoHide(SideBarLocation);
389+
}
390+
else if (DockArea)
391+
{
392+
DockArea->toggleAutoHide(SideBarLocation);
393+
}
394+
}
378395
else
379396
{
380397
d->DropContainer->dropWidget(d->Content, ContainerDropArea, nullptr);

src/ads_globals.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,47 @@ CDockInsertParam dockAreaInsertParameters(DockWidgetArea Area)
333333
}
334334

335335

336+
//============================================================================
337+
SideBarLocation toSideBarLocation(DockWidgetArea Area)
338+
{
339+
switch (Area)
340+
{
341+
case LeftAutoHideArea: return SideBarLeft;
342+
case RightAutoHideArea: return SideBarRight;
343+
case TopAutoHideArea: return SideBarTop;
344+
case BottomAutoHideArea: return SideBarBottom;
345+
default:
346+
return SideBarNone;
347+
}
348+
349+
return SideBarNone;
350+
}
351+
352+
353+
//============================================================================
354+
bool isHorizontalSideBarLocation(SideBarLocation Location)
355+
{
356+
switch (Location)
357+
{
358+
case SideBarTop:
359+
case SideBarBottom: return true;
360+
case SideBarLeft:
361+
case SideBarRight: return false;
362+
default:
363+
return false;
364+
}
365+
366+
return false;
367+
}
368+
369+
370+
//============================================================================
371+
bool isSideBarArea(DockWidgetArea Area)
372+
{
373+
return toSideBarLocation(Area) != SideBarNone;
374+
}
375+
376+
336377
//============================================================================
337378
QPixmap createTransparentPixmap(const QPixmap& Source, qreal Opacity)
338379
{

0 commit comments

Comments
 (0)