45
45
#include < QSettings>
46
46
#include < QMenu>
47
47
#include < QApplication>
48
- #include < QGuiApplication>
49
- #include < QPointer>
50
48
51
49
#include " FloatingDockContainer.h"
52
50
#include " DockOverlay.h"
56
54
#include " IconProvider.h"
57
55
#include " DockingStateReader.h"
58
56
#include " DockAreaTitleBar.h"
57
+ #include " DockFocusController.h"
59
58
60
59
#ifdef Q_OS_LINUX
61
60
#include " linux/FloatingWidgetTitleBar.h"
@@ -108,9 +107,7 @@ struct DockManagerPrivate
108
107
CDockManager::eViewMenuInsertionOrder MenuInsertionOrder = CDockManager::MenuAlphabeticallySorted;
109
108
bool RestoringState = false ;
110
109
QVector<CFloatingDockContainer*> UninitializedFloatingWidgets;
111
- QPointer<CDockWidget> FocusedDockWidget = nullptr ;
112
- QPointer<CDockAreaWidget> FocusedArea = nullptr ;
113
- QPointer<CFloatingDockContainer> FloatingWidget = nullptr ;
110
+ CDockFocusController* FocusController = nullptr ;
114
111
115
112
/* *
116
113
* Private data constructor
@@ -168,12 +165,6 @@ struct DockManagerPrivate
168
165
* Adds action to menu - optionally in sorted order
169
166
*/
170
167
void addActionToMenu (QAction* Action, QMenu* Menu, bool InsertSorted);
171
-
172
- /* *
173
- * This function updates the focus style of the given dock widget and
174
- * the dock area that it belongs to
175
- */
176
- void updateDockWidgetFocus (CDockWidget* DockWidget);
177
168
};
178
169
// struct DockManagerPrivate
179
170
@@ -458,111 +449,6 @@ void DockManagerPrivate::addActionToMenu(QAction* Action, QMenu* Menu, bool Inse
458
449
}
459
450
460
451
461
- // ===========================================================================
462
- void updateDockWidgetFocusStyle (CDockWidget* DockWidget, bool Focused)
463
- {
464
- DockWidget->setProperty (" focused" , Focused);
465
- DockWidget->tabWidget ()->setProperty (" focused" , Focused);
466
- DockWidget->tabWidget ()->updateStyle ();
467
- internal::repolishStyle (DockWidget);
468
- }
469
-
470
-
471
- // ===========================================================================
472
- void updateDockAreaFocusStyle (CDockAreaWidget* DockArea, bool Focused)
473
- {
474
- DockArea->setProperty (" focused" , Focused);
475
- internal::repolishStyle (DockArea);
476
- internal::repolishStyle (DockArea->titleBar ());
477
- }
478
-
479
-
480
- // ===========================================================================
481
- void updateFloatingWidgetFocusStyle (CFloatingDockContainer* FloatingWidget, bool Focused)
482
- {
483
- #ifdef Q_OS_LINUX
484
- auto TitleBar = qobject_cast<CFloatingWidgetTitleBar*>(FloatingWidget->titleBarWidget ());
485
- if (!TitleBar)
486
- {
487
- return ;
488
- }
489
- TitleBar->setProperty (" focused" , Focused);
490
- TitleBar->updateStyle ();
491
- #else
492
- Q_UNUSED (FloatingWidget)
493
- Q_UNUSED (Focused)
494
- #endif
495
- }
496
-
497
-
498
- // ============================================================================
499
- void DockManagerPrivate::updateDockWidgetFocus (CDockWidget* DockWidget)
500
- {
501
- CDockAreaWidget* NewFocusedDockArea = nullptr ;
502
- if (FocusedDockWidget)
503
- {
504
- updateDockWidgetFocusStyle (FocusedDockWidget, false );
505
- }
506
-
507
- CDockWidget* old = FocusedDockWidget;
508
- if (DockWidget != FocusedDockWidget)
509
- {
510
- std::cout << " !!!!!!!!!!!! focusedDockWidgetChanged " << (FocusedDockWidget ? FocusedDockWidget->objectName ().toStdString () : " -" )
511
- << " -> " << (DockWidget ? DockWidget->objectName ().toStdString () : " -" ) << std::endl;
512
- }
513
- FocusedDockWidget = DockWidget;
514
- updateDockWidgetFocusStyle (FocusedDockWidget, true );
515
- NewFocusedDockArea = FocusedDockWidget->dockAreaWidget ();
516
- if (NewFocusedDockArea && (FocusedArea != NewFocusedDockArea))
517
- {
518
- if (FocusedArea)
519
- {
520
- std::cout << " FocusedArea" << std::endl;
521
- QObject::disconnect (FocusedArea, SIGNAL (viewToggled (bool )), _this, SLOT (onFocusedDockAreaViewToggled (bool )));
522
- updateDockAreaFocusStyle (FocusedArea, false );
523
- }
524
-
525
- FocusedArea = NewFocusedDockArea;
526
- updateDockAreaFocusStyle (FocusedArea, true );
527
- QObject::connect (FocusedArea, SIGNAL (viewToggled (bool )), _this, SLOT (onFocusedDockAreaViewToggled (bool )));
528
- }
529
-
530
-
531
- auto NewFloatingWidget = FocusedDockWidget->dockContainer ()->floatingWidget ();
532
- if (NewFloatingWidget)
533
- {
534
- std::cout << " NewFloatingWidget->setProperty(FocusedDockWidget)" << std::endl;
535
- NewFloatingWidget->setProperty (" FocusedDockWidget" , QVariant::fromValue (DockWidget));
536
- }
537
-
538
-
539
- #ifdef Q_OS_LINUX
540
- // This code is required for styling the floating widget titlebar for linux
541
- // depending on the current focus state
542
- if (FloatingWidget == NewFloatingWidget)
543
- {
544
- return ;
545
- }
546
-
547
- if (FloatingWidget)
548
- {
549
- updateFloatingWidgetFocusStyle (FloatingWidget, false );
550
- }
551
- FloatingWidget = NewFloatingWidget;
552
-
553
- if (FloatingWidget)
554
- {
555
- updateFloatingWidgetFocusStyle (FloatingWidget, true );
556
- }
557
- #endif
558
-
559
- if (old != DockWidget)
560
- {
561
- emit _this->focusedDockWidgetChanged (old, DockWidget);
562
- }
563
- }
564
-
565
-
566
452
// ============================================================================
567
453
CDockManager::CDockManager (QWidget *parent) :
568
454
CDockContainerWidget (this , parent),
@@ -583,8 +469,7 @@ CDockManager::CDockManager(QWidget *parent) :
583
469
584
470
if (CDockManager::configFlags ().testFlag (CDockManager::FocusStyling))
585
471
{
586
- connect (QApplication::instance (), SIGNAL (focusChanged (QWidget*, QWidget*)),
587
- this , SLOT (onApplicationFocusChanged (QWidget*, QWidget*)));
472
+ d->FocusController = new CDockFocusController (this );
588
473
}
589
474
}
590
475
@@ -720,16 +605,11 @@ bool CDockManager::restoreState(const QByteArray &state, int version)
720
605
emit restoringState ();
721
606
bool Result = d->restoreState (state, version);
722
607
d->RestoringState = false ;
723
- emit stateRestored ();
724
608
if (!IsHidden)
725
609
{
726
610
show ();
727
611
}
728
-
729
- if (d->FocusedDockWidget )
730
- {
731
- updateDockWidgetFocusStyle (d->FocusedDockWidget , false );
732
- }
612
+ emit stateRestored ();
733
613
return Result;
734
614
}
735
615
@@ -1026,127 +906,23 @@ CIconProvider& CDockManager::iconProvider()
1026
906
}
1027
907
1028
908
1029
- // ===========================================================================
1030
- void CDockManager::onApplicationFocusChanged (QWidget* focusedOld, QWidget* focusedNow)
1031
- {
1032
- if (isRestoringState ())
1033
- {
1034
- return ;
1035
- }
1036
- std::cout << " CDockManager::onFocusChanged" << std::endl;
1037
- std::cout << " focusedNow " << focusedNow << std::endl;
1038
- Q_UNUSED (focusedOld)
1039
- if (!focusedNow)
1040
- {
1041
- return ;
1042
- }
1043
-
1044
- CDockWidget* DockWidget = nullptr ;
1045
- auto DockWidgetTab = qobject_cast<CDockWidgetTab*>(focusedNow);
1046
- std::cout << " FocuseNow " << focusedNow->metaObject ()->className () << std::endl;
1047
- if (DockWidgetTab)
1048
- {
1049
- DockWidget = DockWidgetTab->dockWidget ();
1050
- }
1051
- else
1052
- {
1053
- DockWidget = internal::findParent<CDockWidget*>(focusedNow);
1054
- }
1055
-
1056
- #ifdef Q_OS_LINUX
1057
- if (!DockWidget)
1058
- {
1059
- return ;
1060
- }
1061
- #else
1062
- if (!DockWidget || DockWidget->tabWidget ()->isHidden ())
1063
- {
1064
- std::cout << " !DockWidget || !DockWidget->tabWidget()->isVisible() " << (DockWidget ? DockWidget->objectName ().toStdString () : " 0" ) << std::endl;
1065
- std::cout << " DockWidget->tabWidget()->isHidden() " << (DockWidget ? DockWidget->tabWidget ()->isHidden () : false ) << std::endl;
1066
- return ;
1067
- }
1068
- #endif
1069
-
1070
- std::cout << " CDockManager::onFocusChanged " << DockWidget->tabWidget ()->text ().toStdString () << std::endl;
1071
- d->updateDockWidgetFocus (DockWidget);
1072
- }
1073
-
1074
-
1075
- // ===========================================================================
1076
- void CDockManager::onFocusedDockAreaViewToggled (bool Open)
1077
- {
1078
- if (isRestoringState ())
1079
- {
1080
- return ;
1081
- }
1082
-
1083
- CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(sender ());
1084
- if (!DockArea || Open)
1085
- {
1086
- return ;
1087
- }
1088
- auto Container = DockArea->dockContainer ();
1089
- auto OpenedDockAreas = Container->openedDockAreas ();
1090
- if (OpenedDockAreas.isEmpty ())
1091
- {
1092
- return ;
1093
- }
1094
-
1095
- CDockManager::setWidgetFocus (OpenedDockAreas[0 ]->currentDockWidget ()->tabWidget ());
1096
- }
1097
-
1098
-
1099
909
// ===========================================================================
1100
910
void CDockManager::notifyWidgetOrAreaRelocation (QWidget* DroppedWidget)
1101
911
{
1102
- if (isRestoringState ())
1103
- {
1104
- return ;
1105
- }
1106
- std::cout << " \n\n CDockManager::notifyWidgetDrop" << std::endl;
1107
- CDockWidget* DockWidget = qobject_cast<CDockWidget*>(DroppedWidget);
1108
- if (DockWidget)
1109
- {
1110
- std::cout << " CDockManager::setWidgetFocus " << DockWidget->objectName ().toStdString () << std::endl;
1111
- CDockManager::setWidgetFocus (DockWidget->tabWidget ());
1112
- return ;
1113
- }
1114
-
1115
- CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(DroppedWidget);
1116
- if (!DockArea)
912
+ if (d->FocusController )
1117
913
{
1118
- return ;
914
+ d-> FocusController -> notifyWidgetOrAreaRelocation (DroppedWidget) ;
1119
915
}
1120
-
1121
- DockWidget = DockArea->currentDockWidget ();
1122
- CDockManager::setWidgetFocus (DockWidget->tabWidget ());
1123
- std::cout << " \n\n " << std::endl;
1124
916
}
1125
917
1126
918
1127
919
// ===========================================================================
1128
920
void CDockManager::notifyFloatingWidgetDrop (CFloatingDockContainer* FloatingWidget)
1129
921
{
1130
- std::cout << " \n\n CDockManager::notifyFloatingWidgetDrop" << std::endl;
1131
- if (!FloatingWidget || isRestoringState ())
1132
- {
1133
- return ;
1134
- }
1135
-
1136
- auto vDockWidget = FloatingWidget->property (" FocusedDockWidget" );
1137
- if (!vDockWidget.isValid ())
1138
- {
1139
- return ;
1140
- }
1141
- std::cout << " vDockWidget.isValid()" << std::endl;
1142
- auto DockWidget = vDockWidget.value <CDockWidget*>();
1143
- if (DockWidget)
922
+ if (d->FocusController )
1144
923
{
1145
- std::cout << " Dropped focus dock widget " << DockWidget->objectName ().toStdString () << std::endl;
1146
- DockWidget->dockAreaWidget ()->setCurrentDockWidget (DockWidget);
1147
- CDockManager::setWidgetFocus (DockWidget->tabWidget ());
924
+ d->FocusController ->notifyFloatingWidgetDrop (FloatingWidget);
1148
925
}
1149
- std::cout << " \n\n " << std::endl;
1150
926
}
1151
927
1152
928
0 commit comments