34
34
#include < QElapsedTimer>
35
35
#include < QMenu>
36
36
#include < QEvent>
37
+ #include < QTimer>
37
38
38
39
#include " AutoHideDockContainer.h"
39
40
#include " AutoHideSideBar.h"
@@ -57,7 +58,7 @@ struct AutoHideTabPrivate
57
58
CAutoHideSideBar* SideBar = nullptr ;
58
59
Qt::Orientation Orientation{Qt::Vertical};
59
60
QElapsedTimer TimeSinceHoverMousePress;
60
- QElapsedTimer TimeSinceDragOver ;
61
+ QTimer DragOverTimer ;
61
62
bool MousePressed = false ;
62
63
eDragState DragState = DraggingInactive;
63
64
QPoint GlobalDragStartMousePosition;
@@ -258,6 +259,11 @@ CAutoHideTab::CAutoHideTab(QWidget* parent) :
258
259
if (CDockManager::testAutoHideConfigFlag (CDockManager::AutoHideOpenOnDragHover)) {
259
260
setAcceptDrops (true );
260
261
}
262
+
263
+ d->DragOverTimer .setInterval (CDockManager::configParam (
264
+ CDockManager::AutoHideOpenOnDragHoverDelay_ms, 500 ).toInt ());
265
+ d->DragOverTimer .setSingleShot (true );
266
+ connect (&d->DragOverTimer , &QTimer::timeout, this , &CAutoHideTab::onDragHoverDelayExpired);
261
267
}
262
268
263
269
@@ -498,89 +504,83 @@ void CAutoHideTab::mouseReleaseEvent(QMouseEvent* ev)
498
504
499
505
500
506
// ============================================================================
501
- void CAutoHideTab::mouseMoveEvent (QMouseEvent* ev)
507
+ void CAutoHideTab::mouseMoveEvent (QMouseEvent * ev)
502
508
{
503
- if (!(ev->buttons () & Qt::LeftButton) || d->isDraggingState (DraggingInactive))
504
- {
505
- d->DragState = DraggingInactive;
506
- Super::mouseMoveEvent (ev);
507
- return ;
508
- }
509
+ if (!(ev->buttons () & Qt::LeftButton)
510
+ || d->isDraggingState (DraggingInactive))
511
+ {
512
+ d->DragState = DraggingInactive;
513
+ Super::mouseMoveEvent (ev);
514
+ return ;
515
+ }
509
516
510
- // move floating window
511
- if (d->isDraggingState (DraggingFloatingWidget))
512
- {
513
- d->FloatingWidget ->moveFloating ();
514
- Super::mouseMoveEvent (ev);
515
- return ;
516
- }
517
+ // move floating window
518
+ if (d->isDraggingState (DraggingFloatingWidget))
519
+ {
520
+ d->FloatingWidget ->moveFloating ();
521
+ Super::mouseMoveEvent (ev);
522
+ return ;
523
+ }
517
524
518
- // move tab
519
- if (d->isDraggingState (DraggingTab))
520
- {
521
- // Moving the tab is always allowed because it does not mean moving the
522
- // dock widget around
523
- // d->moveTab(ev);
524
- }
525
+ // move tab
526
+ if (d->isDraggingState (DraggingTab))
527
+ {
528
+ // Moving the tab is always allowed because it does not mean moving the
529
+ // dock widget around
530
+ // d->moveTab(ev);
531
+ }
525
532
526
- auto MappedPos = mapToParent (ev->pos ());
527
- bool MouseOutsideBar = (MappedPos.x () < 0 ) || (MappedPos.x () > parentWidget ()->rect ().right ());
528
- // Maybe a fixed drag distance is better here ?
529
- int DragDistanceY = qAbs (d->GlobalDragStartMousePosition .y () - internal::globalPositionOf (ev).y ());
530
- if (DragDistanceY >= CDockManager::startDragDistance () || MouseOutsideBar)
533
+ auto MappedPos = mapToParent (ev->pos ());
534
+ bool MouseOutsideBar = (MappedPos.x () < 0 )
535
+ || (MappedPos.x () > parentWidget ()->rect ().right ());
536
+ // Maybe a fixed drag distance is better here ?
537
+ int DragDistanceY = qAbs (
538
+ d->GlobalDragStartMousePosition .y ()
539
+ - internal::globalPositionOf (ev).y ());
540
+ if (DragDistanceY >= CDockManager::startDragDistance () || MouseOutsideBar)
531
541
{
532
- // Floating is only allowed for widgets that are floatable
542
+ // Floating is only allowed for widgets that are floatable
533
543
// We can create the drag preview if the widget is movable.
534
544
auto Features = d->DockWidget ->features ();
535
- if (Features.testFlag (CDockWidget::DockWidgetFloatable) || (Features.testFlag (CDockWidget::DockWidgetMovable)))
536
- {
537
- d->startFloating ();
538
- }
539
- return ;
545
+ if (Features.testFlag (CDockWidget::DockWidgetFloatable)
546
+ || (Features.testFlag (CDockWidget::DockWidgetMovable)))
547
+ {
548
+ d->startFloating ();
549
+ }
550
+ return ;
540
551
}
541
552
542
- Super::mouseMoveEvent (ev);
553
+ Super::mouseMoveEvent (ev);
543
554
}
544
555
545
556
// ============================================================================
546
- void CAutoHideTab::dragEnterEvent (QDragEnterEvent* ev) {
547
- if (CDockManager::testAutoHideConfigFlag (CDockManager::AutoHideOpenOnDragHover)) {
548
- if (!d->TimeSinceDragOver .isValid ()) {
549
- d->TimeSinceDragOver .restart ();
550
- ev->accept ();
551
- }
552
- else if (d->TimeSinceDragOver .hasExpired (500 )) {
553
- ev->accept ();
554
- }
555
- }
557
+ void CAutoHideTab::dragEnterEvent (QDragEnterEvent *ev)
558
+ {
559
+ Q_UNUSED (ev);
560
+ if (CDockManager::testAutoHideConfigFlag (CDockManager::AutoHideOpenOnDragHover))
561
+ {
562
+ d->DragOverTimer .start ();
563
+ ev->accept ();
564
+ }
556
565
}
557
566
558
567
// ============================================================================
559
- void CAutoHideTab::dragLeaveEvent (QDragLeaveEvent* ev) {
560
- if (CDockManager::testAutoHideConfigFlag (CDockManager::AutoHideOpenOnDragHover)) {
561
- d->TimeSinceDragOver .invalidate ();
562
- d->forwardEventToDockContainer (ev);
563
- }
568
+ void CAutoHideTab::dragLeaveEvent (QDragLeaveEvent *ev)
569
+ {
570
+ Q_UNUSED (ev);
571
+ if (CDockManager::testAutoHideConfigFlag (CDockManager::AutoHideOpenOnDragHover))
572
+ {
573
+ d->DragOverTimer .stop ();
574
+ }
564
575
}
565
576
566
- // ============================================================================
567
- void CAutoHideTab::dragMoveEvent (QDragMoveEvent* ev) {
568
- if (CDockManager::testAutoHideConfigFlag (CDockManager::AutoHideOpenOnDragHover)
569
- && d->TimeSinceDragOver .isValid ()
570
- && d->TimeSinceDragOver .hasExpired (500 )) {
571
- d->TimeSinceDragOver .invalidate ();
572
- d->DockWidget ->autoHideDockContainer ()->collapseView (false );
573
- ev->accept ();
574
- }
575
- }
576
577
577
578
// ============================================================================
578
579
void CAutoHideTab::requestCloseDockWidget ()
579
580
{
580
581
d->DockWidget ->requestCloseDockWidget ();
581
582
}
582
583
583
-
584
584
// ============================================================================
585
585
int CAutoHideTab::tabIndex () const
586
586
{
@@ -593,4 +593,28 @@ int CAutoHideTab::tabIndex() const
593
593
}
594
594
595
595
596
+ // ============================================================================
597
+ void CAutoHideTab::onDragHoverDelayExpired ()
598
+ {
599
+ static const char * const PropertyId = " ActiveDragOverAutoHideContainer" ;
600
+
601
+ // First we check if there is an active auto hide container that is visible
602
+ // In this case, we collapse it before we open the new one
603
+ auto v = d->DockWidget ->dockManager ()->property (PropertyId);
604
+ if (v.isValid ())
605
+ {
606
+ auto ActiveAutoHideContainer = v.value <QPointer<CAutoHideDockContainer>>();
607
+ if (ActiveAutoHideContainer)
608
+ {
609
+ ActiveAutoHideContainer->collapseView (true );
610
+ }
611
+ }
612
+
613
+ auto AutoHideContainer = d->DockWidget ->autoHideDockContainer ();
614
+ AutoHideContainer->collapseView (false );
615
+ d->DockWidget ->dockManager ()->setProperty (PropertyId,
616
+ QVariant::fromValue (QPointer (AutoHideContainer)));
617
+ }
618
+
619
+
596
620
}
0 commit comments