QtCanpool 3.3.0
载入中...
搜索中...
未找到
dockwidget.cpp
浏览该文件的文档.
1
6#include "dockwidget.h"
7#include "dockwindow.h"
8#include "dockpanel.h"
9#include "docktab.h"
10#include "dockmanager.h"
11#include "dockutils.h"
12#include "docksplitter.h"
14#include "docksidetab.h"
16
17#include <QPointer>
18#include <QBoxLayout>
19#include <QAction>
20#include <QAbstractScrollArea>
21#include <QScrollArea>
22#include <QToolBar>
23#include <QXmlStreamWriter>
24
26
27class DockWidgetPrivate
28{
29public:
30 struct WidgetFactory {
31 DockWidget::FactoryFunc createWidget;
32 DockWidget::WidgetInsertMode insertMode;
33 };
34
35 QX_DECLARE_PUBLIC(DockWidget)
36public:
37 DockWidgetPrivate();
38 void init();
39 void showDockWidget();
40 void hideDockWidget();
41 void updateParentDockPanel();
42
43 void closeAutoHideDockWidgetsIfNeeded();
44
45 void setupToolBar();
46 void setupScrollArea();
47 bool createWidgetFromFactory();
48 void setToolBarStyleFromDockWindow();
49public:
50 DockWindow *m_window = nullptr;
51 QPointer<DockPanel> m_panel = nullptr;
52 QBoxLayout *m_layout = nullptr;
53 DockTab *m_tab = nullptr;
54 DockWidget::DockWidgetFeatures m_features = DockWidget::DefaultDockWidgetFeatures;
55 QList<QAction *> m_titleBarActions;
56 QAction *m_toggleViewAction = nullptr;
57 bool m_closed = false;
58 bool m_isFloatingTopLevel = false;
59 DockWidget::MinimumSizeHintMode m_minimumSizeHintMode = DockWidget::MinimumSizeHintFromDockWidget;
60 QWidget *m_widget = nullptr;
61 QScrollArea *m_scrollArea = nullptr;
62 QPointer<DockSideTab> m_sideTab;
63 DockWidget::ToolBarStyleSource m_toolBarStyleSource = DockWidget::ToolBarStyleFromDockWindow;
64 Qt::ToolButtonStyle m_toolBarStyleDocked = Qt::ToolButtonIconOnly;
65 Qt::ToolButtonStyle m_toolBarStyleFloating = Qt::ToolButtonTextUnderIcon;
66 QSize m_toolBarIconSizeDocked = QSize(16, 16);
67 QSize m_toolBarIconSizeFloating = QSize(24, 24);
68 QToolBar *m_toolBar = nullptr;
69 WidgetFactory *m_factory = nullptr;
70};
71
72DockWidgetPrivate::DockWidgetPrivate()
73{
74}
75
76void DockWidgetPrivate::init()
77{
78 Q_Q(DockWidget);
79
80 m_layout = new QBoxLayout(QBoxLayout::TopToBottom);
81 m_layout->setContentsMargins(0, 0, 0, 0);
82 m_layout->setSpacing(0);
83 q->setLayout(m_layout);
84
85 m_tab = new DockTab(q);
86}
87
88void DockWidgetPrivate::showDockWidget()
89{
90 Q_Q(DockWidget);
91
92 // Allow the widget not to be set when the DeleteContentOnClose flag is not set
93 if (!m_widget && m_features.testFlag(DockWidget::DeleteContentOnClose)) {
94 if (!createWidgetFromFactory()) {
95 Q_ASSERT(m_features.testFlag(DockWidget::DeleteContentOnClose) &&
96 "DeleteContentOnClose flag was set, but the widget "
97 "factory is missing or it doesn't return a valid QWidget.");
98 return;
99 }
100 }
101
102 if (!m_panel) {
103 DockFloatingContainer *floatingWidget = new DockFloatingContainer(q);
104 // We use the size hint of the content widget to provide a good initial size
105 floatingWidget->resize(m_widget ? m_widget->sizeHint() : q->sizeHint());
106 m_tab->show();
107 floatingWidget->show();
108 } else {
109 m_panel->setCurrentDockWidget(q);
110 m_panel->toggleView(true);
111 m_tab->show();
112 auto splitter = m_panel->parentSplitter();
113 while (splitter && !splitter->isVisible() && !m_panel->isAutoHide()) {
114 splitter->show();
115 splitter = internal::findParent<DockSplitter *>(splitter);
116 }
117
118 DockContainer *container = m_panel->dockContainer();
119 if (container->isFloating()) {
120 DockFloatingContainer *floatingWidget = internal::findParent<DockFloatingContainer *>(container);
121 floatingWidget->show();
122 }
123
124 // If this widget is pinned and there are no opened dock widgets, unpin the auto hide widget by moving it's
125 // contents to parent container While restoring state, opened dock widgets are not valid
126 if (container->openedDockWidgets().count() == 0 && m_panel->isAutoHide() && !m_window->isRestoringState()) {
127 m_panel->autoHideContainer()->moveContentsToParent();
128 }
129 }
130}
131
132void DockWidgetPrivate::hideDockWidget()
133{
134 m_tab->hide();
135 updateParentDockPanel();
136
137 closeAutoHideDockWidgetsIfNeeded();
138
139 if (m_features.testFlag(DockWidget::DeleteContentOnClose)) {
140 if (m_scrollArea) {
141 m_scrollArea->takeWidget();
142 delete m_scrollArea;
143 m_scrollArea = nullptr;
144 }
145 m_widget->deleteLater();
146 m_widget = nullptr;
147 }
148}
149
155void DockWidgetPrivate::updateParentDockPanel()
156{
157 if (!m_panel) {
158 return;
159 }
160 Q_Q(DockWidget);
161 if (m_panel->currentDockWidget() != q) {
162 return;
163 }
164 auto nextDockWidget = m_panel->nextOpenDockWidget(q);
165 if (nextDockWidget) {
166 m_panel->setCurrentDockWidget(nextDockWidget);
167 } else {
168 m_panel->hideAreaWithNoVisibleContent();
169 }
170}
171
176void DockWidgetPrivate::closeAutoHideDockWidgetsIfNeeded()
177{
178 Q_Q(DockWidget);
179 auto container = q->dockContainer();
180 if (!container) {
181 return;
182 }
183
184 if (q->dockWindow()->isRestoringState()) {
185 return;
186 }
187
188 // If the dock container is the dock manager, or if it is not empty, then we
189 // don't need to do anything
190 if ((container == q->dockWindow()) || !container->openedDockWidgets().isEmpty()) {
191 return;
192 }
193
194 for (auto autoHideWidget : container->autoHideWidgets()) {
195 auto dockWidget = autoHideWidget->dockWidget();
196 if (dockWidget == q) {
197 continue;
198 }
199
200 dockWidget->toggleView(false);
201 }
202}
203
204void DockWidgetPrivate::setupToolBar()
205{
206 Q_Q(DockWidget);
207 m_toolBar = new QToolBar(q);
208 m_toolBar->setObjectName("dockWidgetToolBar");
209 m_layout->insertWidget(0, m_toolBar);
210 m_toolBar->setIconSize(QSize(16, 16));
211 m_toolBar->toggleViewAction()->setEnabled(false);
212 m_toolBar->toggleViewAction()->setVisible(false);
213 q->connect(q, SIGNAL(topLevelChanged(bool)), SLOT(setToolbarFloatingStyle(bool)));
214}
215
219void DockWidgetPrivate::setupScrollArea()
220{
221 Q_Q(DockWidget);
222 m_scrollArea = new QScrollArea(q);
223 m_scrollArea->setObjectName("dockWidgetScrollArea");
224 m_scrollArea->setWidgetResizable(true);
225 m_layout->addWidget(m_scrollArea);
226}
227
232bool DockWidgetPrivate::createWidgetFromFactory()
233{
234 Q_Q(DockWidget);
235 if (!m_factory) {
236 return false;
237 }
238
239 QWidget *w = m_factory->createWidget(q);
240 if (!w) {
241 return false;
242 }
243
244 q->setWidget(w, m_factory->insertMode);
245 return true;
246}
247
251void DockWidgetPrivate::setToolBarStyleFromDockWindow()
252{
253 Q_Q(DockWidget);
254 if (!m_window) {
255 return;
256 }
257 auto state = DockWidget::StateDocked;
258 q->setToolBarIconSize(m_window->dockWidgetToolBarIconSize(state), state);
259 q->setToolBarStyle(m_window->dockWidgetToolBarStyle(state), state);
260 state = DockWidget::StateFloating;
261 q->setToolBarIconSize(m_window->dockWidgetToolBarIconSize(state), state);
262 q->setToolBarStyle(m_window->dockWidgetToolBarStyle(state), state);
263}
264
278DockWidget::DockWidget(const QString &title, QWidget *parent)
279 : Super{parent}
280{
282
283 // must before d->init(), create tab need title
284 setWindowTitle(title);
285 setObjectName(title);
286
287 Q_D(DockWidget);
288 d->init();
289
290 d->m_toggleViewAction = new QAction(title, this);
291 d->m_toggleViewAction->setCheckable(true);
292 connect(d->m_toggleViewAction, SIGNAL(triggered(bool)), this, SLOT(toggleView(bool)));
294
296 setFocusPolicy(Qt::ClickFocus);
297 }
298 QXDOCK_SET_BGCOLOR(this);
299}
300
305
310void DockWidget::setWidget(QWidget *w, WidgetInsertMode insertMode)
311{
312 Q_D(DockWidget);
313 if (d->m_widget) {
314 takeWidget();
315 }
316
317 auto scrollAreaWidget = qobject_cast<QAbstractScrollArea *>(w);
318 if (scrollAreaWidget || ForceNoScrollArea == insertMode) {
319 d->m_layout->addWidget(w);
320 if (scrollAreaWidget && scrollAreaWidget->viewport()) {
321 scrollAreaWidget->viewport()->setProperty("dockWidgetContent", true);
322 }
323 } else {
324 d->setupScrollArea();
325 d->m_scrollArea->setWidget(w);
326 }
327
328 d->m_widget = w;
329 d->m_widget->setProperty("dockWidgetContent", true);
330}
331
336QWidget *DockWidget::widget() const
337{
338 Q_D(const DockWidget);
339 return d->m_widget;
340}
341
346{
347 Q_D(DockWidget);
348 QWidget *w = nullptr;
349 if (d->m_scrollArea) {
350 d->m_layout->removeWidget(d->m_scrollArea);
351 w = d->m_scrollArea->takeWidget();
352 delete d->m_scrollArea;
353 d->m_scrollArea = nullptr;
354 d->m_widget = nullptr;
355 } else if (d->m_widget) {
356 d->m_layout->removeWidget(d->m_widget);
357 w = d->m_widget;
358 d->m_widget = nullptr;
359 }
360
361 if (w) {
362 w->setParent(nullptr);
363 }
364 return w;
365}
366
372{
373 Q_D(const DockWidget);
374 return d->m_tab;
375}
376
383DockWidget::DockWidgetFeatures DockWidget::features() const
384{
385 Q_D(const DockWidget);
386 if (d->m_window) {
387 return d->m_features & ~d->m_window->globallyLockedDockWidgetFeatures();
388 } else {
389 return d->m_features;
390 }
391}
392
396void DockWidget::setFeatures(DockWidgetFeatures features)
397{
398 Q_D(DockWidget);
399 if (d->m_features == features) {
400 return;
401 }
402 d->m_features = features;
404}
405
411{
412 auto fs = features();
413 internal::setFlag(fs, flag, on);
414 setFeatures(fs);
415}
416
421{
422 Q_D(DockWidget);
423 Q_EMIT featuresChanged(d->m_features);
424 d->m_tab->onDockWidgetFeaturesChanged();
425 if (DockPanel *panel = dockPanel()) {
426 panel->onDockWidgetFeaturesChanged();
427 }
428}
429
435{
436 Q_D(const DockWidget);
437 return d->m_window;
438}
439
445{
446 Q_D(const DockWidget);
447 if (d->m_panel) {
448 return d->m_panel->dockContainer();
449 } else {
450 return nullptr;
451 }
452}
453
459{
460 auto container = dockContainer();
461 return container ? container->floatingWidget() : nullptr;
462}
463
469{
470 Q_D(const DockWidget);
471 return d->m_panel;
472}
473
481{
482 if (!isInFloatingContainer()) {
483 return false;
484 }
485
486 return dockContainer()->topLevelDockWidget() == this;
487}
488
494{
495 auto container = dockContainer();
496 if (!container) {
497 return false;
498 }
499
500 if (!container->isFloating()) {
501 return false;
502 }
503
504 return true;
505}
506
511{
512 Q_D(const DockWidget);
513 return d->m_closed;
514}
515
521{
522 if (isFloating()) {
523 return dockContainer()->floatingWidget()->isFullScreen();
524 } else {
525 return Super::isFullScreen();
526 }
527}
528
534{
535 Q_D(const DockWidget);
536 return d->m_panel && (d->m_panel->openDockWidgetsCount() > 1);
537}
538
546{
547 Q_D(const DockWidget);
548 return d->m_panel && (d->m_panel->currentDockWidget() == this);
549}
550
555{
556 return dockWindow()->centralWidget() == this;
557}
558
564{
565 Q_D(const DockWidget);
566 return d->m_toggleViewAction;
567}
568
574{
575 if (!action) {
576 return;
577 }
578 Q_D(DockWidget);
579 d->m_toggleViewAction->setParent(nullptr);
580 delete d->m_toggleViewAction;
581 d->m_toggleViewAction = action;
582 d->m_toggleViewAction->setParent(this);
583 connect(d->m_toggleViewAction, SIGNAL(triggered(bool)), this, SLOT(toggleView(bool)));
584}
585
591{
592 Q_D(DockWidget);
593 if (mode == ActionModeToggle) {
594 d->m_toggleViewAction->setCheckable(true);
595 d->m_toggleViewAction->setIcon(QIcon());
596 } else {
597 d->m_toggleViewAction->setCheckable(false);
598 d->m_toggleViewAction->setIcon(d->m_tab->icon());
599 }
600}
601
606{
607 Q_D(DockWidget);
608 QAction *action = d->m_toggleViewAction;
609 action->blockSignals(true);
610 action->setChecked(checked);
611 action->blockSignals(false);
612}
613
614QList<QAction *> DockWidget::titleBarActions() const
615{
616 Q_D(const DockWidget);
617 return d->m_titleBarActions;
618}
619
628void DockWidget::setTitleBarActions(QList<QAction *> actions)
629{
630 Q_D(DockWidget);
631 d->m_titleBarActions = actions;
632}
633
638{
639 Q_D(const DockWidget);
640 return d->m_minimumSizeHintMode;
641}
642
649{
650 Q_D(DockWidget);
651 d->m_minimumSizeHintMode = mode;
652}
653
655{
656 Q_D(const DockWidget);
657 if (!d->m_widget) {
658 return QSize(60, 40);
659 }
660
661 switch (d->m_minimumSizeHintMode) {
663 return QSize(60, 40);
665 return d->m_widget->minimumSizeHint();
667 return minimumSize();
669 return d->m_widget->minimumSize();
670 }
671
672 return d->m_widget->minimumSizeHint();
673}
674
675QIcon DockWidget::icon() const
676{
677 Q_D(const DockWidget);
678 return d->m_tab->icon();
679}
680
681void DockWidget::setIcon(const QIcon &icon)
682{
683 Q_D(DockWidget);
684 d->m_tab->setIcon(icon);
685
686 if (d->m_sideTab) {
687 d->m_sideTab->setIcon(icon);
688 }
689
690 if (!d->m_toggleViewAction->isCheckable()) {
691 d->m_toggleViewAction->setIcon(icon);
692 }
693}
694
700QToolBar *DockWidget::toolBar() const
701{
702 if (!d_ptr->m_toolBar) {
703 d_ptr->setupToolBar();
704 }
705 return d_ptr->m_toolBar;
706}
707
713void DockWidget::setToolBar(QToolBar *toolBar)
714{
715 Q_D(DockWidget);
716 if (d->m_toolBar) {
717 delete d->m_toolBar;
718 }
719
720 d->m_toolBar = toolBar;
721 d->m_layout->insertWidget(0, d->m_toolBar);
722 this->connect(this, SIGNAL(topLevelChanged(bool)), SLOT(setToolBarFloatingStyle(bool)));
724}
725
727{
728 Q_D(const DockWidget);
729 return d->m_toolBarStyleSource;
730}
731
737{
738 Q_D(DockWidget);
739 d->m_toolBarStyleSource = source;
740 if (ToolBarStyleFromDockWindow == d->m_toolBarStyleSource) {
741 d->setToolBarStyleFromDockWindow();
742 }
743}
744
745Qt::ToolButtonStyle DockWidget::toolBarStyle(DockWidget::State state) const
746{
747 Q_D(const DockWidget);
748 if (StateFloating == state) {
749 return d->m_toolBarStyleFloating;
750 } else {
751 return d->m_toolBarStyleDocked;
752 }
753}
754
763void DockWidget::setToolBarStyle(Qt::ToolButtonStyle style, DockWidget::State state)
764{
765 Q_D(DockWidget);
766 if (StateFloating == state) {
767 d->m_toolBarStyleFloating = style;
768 } else {
769 d->m_toolBarStyleDocked = style;
770 }
771
773}
774
776{
777 Q_D(const DockWidget);
778 if (StateFloating == state) {
779 return d->m_toolBarIconSizeFloating;
780 } else {
781 return d->m_toolBarIconSizeDocked;
782 }
783}
784
791void DockWidget::setToolBarIconSize(const QSize &iconSize, DockWidget::State state)
792{
793 Q_D(DockWidget);
794 if (StateFloating == state) {
795 d->m_toolBarIconSizeFloating = iconSize;
796 } else {
797 d->m_toolBarIconSizeDocked = iconSize;
798 }
799
801}
802
809{
810 Q_D(const DockWidget);
811 return d->m_sideTab;
812}
813
818{
819 Q_D(DockWidget);
820 d->m_sideTab = sideTab;
821}
822
824{
825 Q_D(const DockWidget);
826 return !d->m_sideTab.isNull();
827}
828
834{
835 Q_D(const DockWidget);
836
837 if (!d->m_panel) {
838 return nullptr;
839 }
840
841 return d->m_panel->autoHideContainer();
842}
843
852
863{
864 Q_D(DockWidget);
865 if (d->m_factory) {
866 delete d->m_factory;
867 }
868
869 d->m_factory = new DockWidgetPrivate::WidgetFactory{createWidget, insertMode};
870}
871
872#ifndef QT_NO_TOOLTIP
873void DockWidget::setTabToolTip(const QString &text)
874{
875 Q_D(DockWidget);
876 if (d->m_tab) {
877 d->m_tab->setToolTip(text);
878 }
879 if (d->m_toggleViewAction) {
880 d->m_toggleViewAction->setToolTip(text);
881 }
882 if (d->m_panel) {
883 d->m_panel->markTitleBarMenuOutdated(); // update tabs menu
884 }
885}
886#endif
887
893{
894 Q_D(DockWidget);
895 QAction *a = qobject_cast<QAction *>(sender());
896 if (a == d->m_toggleViewAction && !d->m_toggleViewAction->isCheckable()) {
897 open = true;
898 }
899 // If the dock widget state is different, then we really need to toggle
900 // the state. If we are in the right state, then we simply make this
901 // dock widget the current dock widget
902 auto container = this->autoHideContainer();
903 if (d->m_closed != !open) {
904 toggleViewInternal(open);
905 } else if (open && d->m_panel && !container) {
906 raise();
907 }
908
909 if (open && container) {
910 container->collapseView(false);
911 }
912}
913
919{
920 Q_D(DockWidget);
921 if (d->m_window) {
922 d->m_window->removeDockWidget(this);
923 }
924 deleteLater();
925 d->m_closed = true;
926}
927
936
944{
948 } else {
949 toggleView(false);
950 }
951}
952
957void DockWidget::setAutoHide(bool enable, Qx::DockSideBarArea area, int tabIndex)
958{
960 return;
961 }
962
963 // Do nothing if nothing changes
964 if (enable == isAutoHide() && area == autoHideArea()) {
965 return;
966 }
967
968 auto panel = dockPanel();
969
970 if (!enable) {
971 panel->setAutoHide(false);
972 } else if (isAutoHide()) {
974 } else {
975 auto location = (Qx::DockSideBarNone == area) ? panel->calculateSideBarArea() : area;
976 dockContainer()->createAndSetupAutoHideContainer(location, this, tabIndex);
977 }
978}
979
992
1000{
1001 Q_D(DockWidget);
1002 if (d->m_panel && !isClosed()) {
1003 d->m_panel->setCurrentDockWidget(this);
1004 }
1005}
1006
1015{
1016 if (isClosed()) {
1017 return;
1018 }
1019
1021 if (isInFloatingContainer()) {
1022 auto floatingWindow = window();
1023 floatingWindow->raise();
1024 floatingWindow->activateWindow();
1025 }
1026}
1027
1040{
1041 if (isFloating()) {
1042 dockContainer()->floatingWidget()->showFullScreen();
1043 } else {
1044 Super::showFullScreen();
1045 }
1046}
1047
1053{
1054 if (isFloating()) {
1055 dockContainer()->floatingWidget()->showNormal();
1056 } else {
1057 Super::showNormal();
1058 }
1059}
1060
1065{
1066 Q_D(DockWidget);
1067 if (isClosed()) {
1068 return;
1069 }
1070
1071 if (this->isAutoHide()) {
1073 } else {
1074 d->m_tab->detachDockWidget();
1075 }
1076}
1077
1082{
1083 Q_D(DockWidget);
1084 if (!d->m_toolBar) {
1085 return;
1086 }
1087
1088 auto iconSize = floating ? d->m_toolBarIconSizeFloating : d->m_toolBarIconSizeDocked;
1089 if (iconSize != d->m_toolBar->iconSize()) {
1090 d->m_toolBar->setIconSize(iconSize);
1091 }
1092
1093 auto buttonStyle = floating ? d->m_toolBarStyleFloating : d->m_toolBarStyleDocked;
1094 if (buttonStyle != d->m_toolBar->toolButtonStyle()) {
1095 d->m_toolBar->setToolButtonStyle(buttonStyle);
1096 }
1097}
1098
1103{
1104 Q_D(DockWidget);
1105 d->m_window = window;
1106 if (!window) {
1107 return;
1108 }
1109
1110 if (d->m_toolBarStyleSource == DockWidget::ToolBarStyleFromDockWindow) {
1111 d->setToolBarStyleFromDockWindow();
1112 }
1113}
1114
1122{
1123 Q_D(DockWidget);
1124 d->m_panel = panel;
1125 d->m_toggleViewAction->setChecked(panel != nullptr && !this->isClosed());
1126 setParent(panel);
1127}
1128
1130{
1131 Q_D(DockWidget);
1132 d->m_closed = closed;
1133}
1134
1139void DockWidget::emitTopLevelEventForWidget(DockWidget *topLevelDockWidget, bool floating)
1140{
1141 if (topLevelDockWidget) {
1142 topLevelDockWidget->dockPanel()->updateTitleBarVisibility();
1143 topLevelDockWidget->emitTopLevelChanged(floating);
1144 }
1145}
1146
1153{
1154 Q_D(DockWidget);
1155 if (floating != d->m_isFloatingTopLevel) {
1156 d->m_isFloatingTopLevel = floating;
1157 Q_EMIT topLevelChanged(floating);
1158 }
1159}
1160
1166{
1167 Q_D(DockWidget);
1168 DockContainer *container = dockContainer();
1169 DockWidget *topLevelDockWidgetBefore = container ? container->topLevelDockWidget() : nullptr;
1170
1171 d->m_closed = !open;
1172 if (open) {
1173 d->showDockWidget();
1174 } else {
1175 d->hideDockWidget();
1176 }
1177 d->m_toggleViewAction->blockSignals(true);
1178 d->m_toggleViewAction->setChecked(open);
1179 d->m_toggleViewAction->blockSignals(false);
1180 if (d->m_panel) {
1181 d->m_panel->toggleDockWidgetView(this, open);
1182 if (d->m_panel->isAutoHide()) {
1183 // FIXME: toggleView(true) will show sidTab before mainwindow
1184 // d->m_panel->autoHideContainer()->toggleView(open);
1185 }
1186 }
1187
1188 if (open && topLevelDockWidgetBefore) {
1189 DockWidget::emitTopLevelEventForWidget(topLevelDockWidgetBefore, false);
1190 }
1191
1192 // Here we need to call the dockContainer() function again, because if
1193 // this dock widget was unassigned before the call to showDockWidget() then
1194 // it has a dock container now
1195 container = dockContainer();
1196 DockWidget *topLevelDockWidgetAfter = container ? container->topLevelDockWidget() : nullptr;
1197 DockWidget::emitTopLevelEventForWidget(topLevelDockWidgetAfter, true);
1198 DockFloatingContainer *floatingContainer = container ? container->floatingWidget() : nullptr;
1199 if (floatingContainer) {
1200 floatingContainer->updateWindowTitle();
1201 }
1202
1203 if (!open) {
1204 Q_EMIT closed();
1205 }
1206 Q_EMIT viewToggled(open);
1207}
1208
1214{
1215 Q_D(DockWidget);
1216
1217 if (!forceClose) {
1218 Q_EMIT closeRequested();
1219 }
1220 if (!forceClose && features().testFlag(DockWidget::CustomCloseHandling)) {
1221 return false;
1222 }
1224 // If the dock widget is floating, then we check if we also need to
1225 // delete the floating widget
1226 if (isFloating()) {
1227 DockFloatingContainer *floatingWidget = internal::findParent<DockFloatingContainer *>(this);
1228 if (floatingWidget->dockWidgets().count() == 1) {
1229 floatingWidget->deleteLater();
1230 } else {
1231 floatingWidget->hide();
1232 }
1233 }
1234
1235 if (d->m_panel && d->m_panel->isAutoHide()) {
1236 d->m_panel->autoHideContainer()->cleanupAndDelete();
1237 }
1239 Q_EMIT closed();
1240 } else {
1241 toggleView(false);
1242 }
1243 return true;
1244}
1245
1256{
1257 Q_D(DockWidget);
1258 d->m_closed = true;
1259 setParent(d->m_window);
1260 setVisible(false);
1261 setDockPanel(nullptr);
1262 tab()->setParent(this);
1263}
1264
1265void DockWidget::saveState(QXmlStreamWriter &s) const
1266{
1267 Q_D(const DockWidget);
1268 s.writeStartElement("Widget");
1269 s.writeAttribute("Name", objectName());
1270 s.writeAttribute("Closed", QString::number(d->m_closed ? 1 : 0));
1271 s.writeEndElement();
1272}
1273
1277bool DockWidget::event(QEvent *e)
1278{
1279 Q_D(DockWidget);
1280 switch (e->type()) {
1281 case QEvent::Hide:
1282 Q_EMIT visibilityChanged(false);
1283 break;
1284
1285 case QEvent::Show:
1286 Q_EMIT visibilityChanged(geometry().right() >= 0 && geometry().bottom() >= 0);
1287 break;
1288
1289 case QEvent::WindowTitleChange: {
1290 const auto title = windowTitle();
1291 if (d->m_tab) {
1292 d->m_tab->setText(title);
1293 }
1294 if (d->m_sideTab) {
1295 d->m_sideTab->setText(title);
1296 }
1297 if (d->m_toggleViewAction) {
1298 d->m_toggleViewAction->setText(title);
1299 }
1300 if (d->m_panel) {
1301 d->m_panel->markTitleBarMenuOutdated(); // update tabs menu
1302 }
1303
1304 auto floatingWidget = dockFloatingContainer();
1305 if (floatingWidget) {
1306 floatingWidget->updateWindowTitle();
1307 }
1308 Q_EMIT titleChanged(title);
1309 } break;
1310
1311 default:
1312 break;
1313 }
1314
1315 return Super::event(e);
1316}
1317
Auto hide container for hosting an auto hide dock widget
Qx::DockSideBarArea sideBarArea() const
void moveToNewSideBarArea(Qx::DockSideBarArea area, int tabIndex=-1)
Removes the AutoHide container from the current side bar and adds it to the new side bar given in are...
Container that manages a number of dock panels with single dock widgets or tabyfied dock widgets in e...
DockWidget * topLevelDockWidget() const
If hasTopLevelDockWidget() returns true, this function returns the one and only visible dock widget.
DockAutoHideContainer * createAndSetupAutoHideContainer(Qx::DockSideBarArea area, DockWidget *w, int tabIndex=-1)
Creates and initializes a dockwidget auto hide container into the given area.
DockFloatingContainer * floatingWidget() const
If this dock container is in a floating widget, this function returns the floating widget.
This implements a floating widget that is a dock container that accepts docking of dock widgets like ...
QList< DockWidget * > dockWidgets() const
This function returns a list of all dock widget in this floating widget.
static bool testConfigFlag(ConfigFlag flag)
static bool testAutoHideConfigFlag(AutoHideFlag flag)
DockPanel manages multiple instances of DockWidgets.
Definition dockpanel.h:31
void updateTitleBarVisibility()
Updates the dock panel layout and components visibility
A dock widget Side tab that shows a title or an icon.
Definition docksidetab.h:23
The DockWidget class provides a widget that can be docked inside a DockWindow or floated as a top-lev...
Definition dockwidget.h:31
bool isFullScreen() const
Returns true if the dock widget is floating and if the floating dock container is full screen
void setToolBarStyleSource(ToolBarStyleSource source)
Configures, if the dock widget uses the global tool bar styles from dock window or if it uses its own...
void titleChanged(const QString &title)
bool isClosed() const
Returns true, if this dock widget is closed.
void deleteDockWidget()
This function will delete the dock widget and its content from the docking system
Qx::DockSideBarArea autoHideArea() const
Returns the auto hide side bar area or Qx::DockSideBarNone if, this is not an autohide dock widget
void setClosedState(bool closed)
void setIcon(const QIcon &icon)
virtual QSize minimumSizeHint() const override
void emitTopLevelChanged(bool floating)
Use this function to emit a top level changed event.
void toggleAutoHide(Qx::DockSideBarArea area=Qx::DockSideBarNone)
Switches the dock widget to auto hide mode or vice versa depending on its current state.
QIcon icon() const
bool isInFloatingContainer() const
The function returns true, if the dock widget is floating and it also returns true if it is docked in...
std::function< QWidget *(QWidget *)> FactoryFunc
Definition dockwidget.h:190
virtual QList< QAction * > titleBarActions() const
void setMinimumSizeHintMode(MinimumSizeHintMode mode)
Configures the minimum size hint that is returned by the minimumSizeHint() function.
void viewToggled(bool open)
void notifyFeaturesChanged()
Triggers notification of feature change signals and functions
void setDockWindow(DockWindow *window)
Assigns the dock window that manages this dock widget
static void emitTopLevelEventForWidget(DockWidget *topLevelDockWidget, bool floating)
Call this function to emit a topLevelChanged() signal and to update the dock panel tool bar visibilit...
void setAsCurrentTab()
Makes this dock widget the current tab in its dock panel.
WidgetInsertMode
Sets the widget for the dock widget to widget.
Definition dockwidget.h:115
MinimumSizeHintMode minimumSizeHintMode() const
Get the minimum size hint mode configured by setMinimumSizeHintMode
ToggleViewActionMode
This mode configures the behavior of the toggle view action.
Definition dockwidget.h:75
QSize toolBarIconSize(State state) const
DockSideTab * sideTab() const
Returns the side tab widget for this dock, if this dock widget is in a auto hide container.
void setTitleBarActions(QList< QAction * > actions)
Set the actions that will be shown in the dock title bar if this dock widget is the active tab.
void setFeatures(DockWidgetFeatures features)
Sets, whether the dock widget is movable, closable, and floatable.
DockTab * tab() const
Returns the tab widget of this dock widget that is shown in the dock title bar
void setToggleViewActionChecked(bool checked)
This function changes the toggle view action without emitting any signal
virtual bool event(QEvent *e) override
Emits titleChanged signal if title change event occurs
QAction * toggleViewAction() const
Returns a checkable action that can be used to show or close this dock widget.
void showNormal()
This function complements showFullScreen() to restore the widget after it has been in full screen mod...
void setToggleViewActionMode(ToggleViewActionMode mode)
Configures the behavior of the toggle view action.
void closeDockWidget()
Closes the dock widget.
void setFloating()
This function will make a docked widget floating
MinimumSizeHintMode
The mode of the minimumSizeHint() that is returned by the DockWidget minimumSizeHint() function.
Definition dockwidget.h:91
@ MinimumSizeHintFromContentMinimumSize
Definition dockwidget.h:95
@ MinimumSizeHintFromDockWidgetMinimumSize
Definition dockwidget.h:94
void featuresChanged(DockWidget::DockWidgetFeatures features)
DockContainer * dockContainer() const
Returns the dock container widget this dock panel belongs to or 0 if this dock widget has not been do...
void setWidgetFactory(FactoryFunc createWidget, WidgetInsertMode insertMode=AutoScrollArea)
Only used when the feature flag DeleteContentOnClose is set.
ToolBarStyleSource toolBarStyleSource() const
void showFullScreen()
Shows the widget in full-screen mode.
DockPanel * dockPanel() const
Returns the dock panel this dock widget belongs to or 0 if this dock widget has not been docked yet
bool isCentralWidget() const
Returns true if the dock widget is set as central widget of it's dock window
void visibilityChanged(bool visible)
This signal is emitted when the dock widget becomes visible (or invisible).
void setAutoHide(bool enable, Qx::DockSideBarArea area=Qx::DockSideBarNone, int tabIndex=-1)
Sets the dock widget into auto hide mode if this feature is enabled via DockManager::setAutoHideFlags...
Qt::ToolButtonStyle toolBarStyle(State state) const
void flagAsUnassigned()
This is a helper function for the dock manager to flag this widget as unassigned.
void setDockPanel(DockPanel *panel)
If this dock widget is inserted into a dock panel, the dock panel will be registered on this widget v...
DockAutoHideContainer * autoHideContainer() const
Returns the auto hide dock container of this dock widget or 0 if there is none
bool isCurrentTab() const
Returns true if this dock widget is the current one in the dock panel that contains it.
DockWindow * dockWindow() const
Returns the dock window that manages the dock widget or 0 if the widget has not been assigned to any ...
void topLevelChanged(bool topLevel)
This signal is emitted when the floating property changes.
void requestCloseDockWidget()
Request closing of the dock widget.
DockWidgetFeatures features() const
This property holds whether the dock widget is movable, closable, and floatable.
void setWidget(QWidget *w, WidgetInsertMode insertMode=AutoScrollArea)
Sets the widget for the dock widget to widget.
void setFeature(DockWidgetFeature flag, bool on)
Sets the feature flag for this dock widget if on is true; otherwise clears the flag.
void setToolBarIconSize(const QSize &iconSize, State state)
This function sets the tool button icon size for the given state.
bool isTabbed() const
Returns true if this dock widget is in a dock panel, that contains at least 2 opened dock widgets
QToolBar * toolBar() const
This function returns the dock widget top tool bar.
DockFloatingContainer * dockFloatingContainer() const
This function return the floating DockContainer if is isFloating() is true and a nullptr if this dock...
QWidget * widget() const
Returns the widget for the dock widget.
bool isAutoHide() const
void setToolBarFloatingStyle(bool floating)
Adjusts the toolbar icon sizes according to the floating state
void toggleViewInternal(bool open)
Internal toggle view function that does not check if the widget already is in the given state
void setSideTab(DockSideTab *sideTab)
Assign a side tab widget if this dock widget is an auto hide container
void toggleView(bool open=true)
This property controls whether the dock widget is open or closed.
void setToolBarStyle(Qt::ToolButtonStyle style, State state)
This function sets the tool button style for the given dock widget state.
void raise()
Brings the dock widget to the front This means:
void setToggleViewAction(QAction *action)
Use provided action to be the default toggle view action for this dock widget.
void setToolBar(QToolBar *toolBar)
Assign a new tool bar that is shown above the content widget.
bool closeDockWidgetInternal(bool forceClose=false)
Internal close dock widget implementation.
void setTabToolTip(const QString &text)
QWidget * takeWidget()
Remove the widget from the dock and give ownership back to the caller
bool isFloating() const
This property holds whether the dock widget is floating.
void saveState(QXmlStreamWriter &s) const
The central dock window that maintains the complete docking system.
Definition dockwindow.h:36
DockWidget * centralWidget() const
#define QXDOCK_SET_BGCOLOR(w)
Definition dockutils.h:172
void setFlag(T &flags, typename T::enum_type flag, bool on=true)
Definition dockutils.h:43
DockSideBarArea
@ DockSideBarNone
#define QX_INIT_PRIVATE(Class)
#define QX_DECLARE_PUBLIC(Class)
#define QX_FINI_PRIVATE()
#define QX_DOCK_END_NAMESPACE
#define QX_DOCK_BEGIN_NAMESPACE
QColor text
QColor window