KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
Config.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2019 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: SĂ©rgio Martins <sergio.martins@kdab.com>
6
7 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
8
9 Contact KDAB at <info@kdab.com> for commercial licensing options.
10*/
11
19#include "Config.h"
20#include "core/layouting/Item_p.h"
21#include "core/DockRegistry.h"
22#include "core/DockRegistry_p.h"
23#include "core/Utils_p.h"
24#include "core/DragController_p.h"
25#include "core/ViewFactory.h"
26#include "core/Separator.h"
27#include "core/Platform.h"
28#include "core/View.h"
29#include "core/Logging_p.h"
30
31#include <iostream>
32#include <limits>
33
34using namespace KDDockWidgets::Core;
35
36namespace KDDockWidgets {
37
39{
40 if (auto platform = Platform::instance())
41 return platform->createDefaultViewFactory();
42
43 KDDW_ERROR("No Platform found. Forgot to call KDDockWidgets::initFrontend(<platform>) ?");
44 std::terminate();
45 return nullptr;
46}
47
48class Config::Private
49{
50public:
51 Private()
52 : m_viewFactory(createDefaultViewFactory())
53 {
54 }
55
56 ~Private()
57 {
58 delete m_viewFactory;
59 }
60
61 void fixFlags();
62
63 DockWidgetFactoryFunc m_dockWidgetFactoryFunc = nullptr;
64 MainWindowFactoryFunc m_mainWindowFactoryFunc = nullptr;
65 DropIndicatorAllowedFunc m_dropIndicatorAllowedFunc = nullptr;
66 DragAboutToStartFunc m_dragAboutToStartFunc = nullptr;
67 DragEndedFunc m_dragEndedFunc = nullptr;
68 ViewFactory *m_viewFactory = nullptr;
69 Flags m_flags = Flag_Default;
70 MDIFlags m_mdiFlags = MDIFlag_None;
71 InternalFlags m_internalFlags = InternalFlag_None;
72 CustomizableWidgets m_disabledPaintEvents = CustomizableWidget_None;
73 double m_draggedWindowOpacity = std::numeric_limits<double>::quiet_NaN();
74 bool m_transparencyOnlyOverDropIndicator = false;
75 int m_mdiPopupThreshold = 250;
76 int m_startDragDistance = -1;
77 bool m_dropIndicatorsInhibited = false;
78 bool m_layoutSaverStrictMode = false;
79 bool m_onlyProgrammaticDrag = false;
80};
81
82Config::Config()
83 : d(new Private())
84{
85 d->fixFlags();
86}
87
88Config &Config::self()
89{
90 static Config config;
91 return config;
92}
93
94Config::~Config()
95{
96 delete d;
98 delete Platform::instance();
99 }
100}
101
102Config::Flags Config::flags() const
103{
104 return d->m_flags;
105}
106
107Config::MDIFlags Config::mdiFlags() const
108{
109 return d->m_mdiFlags;
110}
111
112void Config::setMDIFlags(MDIFlags flags)
113{
114 d->m_mdiFlags = flags;
115}
116
117void Config::setFlags(Flags f)
118{
119 // Most flags aren't allowed to be changed at runtime.
120 // Some are. More can be supported but they need to be examined in a case-by-case
121 // basis.
122
123 static const Flags mutableFlags = Flag::Flag_AutoHideAsTabGroups;
124 const Flags changedFlags = f ^ d->m_flags;
125 const bool nonMutableFlagsChanged = (changedFlags & ~mutableFlags);
126
127 if (nonMutableFlagsChanged) {
128 auto dr = DockRegistry::self();
129 if (!dr->isEmpty(/*excludeBeingDeleted=*/true)) {
130 std::cerr
131 << "Config::setFlags: "
132 << "Only use this function at startup before creating any DockWidget or MainWindow"
133 << "; These are already created: " << dr->mainWindowsNames().size() << dr->dockWidgetNames().size()
134 << dr->floatingWindows().size() << "\n";
135 return;
136 }
137 }
138
139 d->m_flags = f;
140 d->fixFlags();
141}
142
144bool Config::hasFlag(Flag flag)
145{
146 return (Config::self().flags() & flag) == flag;
147}
148
150bool Config::hasMDIFlag(MDIFlag flag)
151{
152 return (Config::self().mdiFlags() & flag) == flag;
153}
154
155void Config::setDockWidgetFactoryFunc(DockWidgetFactoryFunc func)
156{
157 d->m_dockWidgetFactoryFunc = func;
158}
159
160DockWidgetFactoryFunc Config::dockWidgetFactoryFunc() const
161{
162 return d->m_dockWidgetFactoryFunc;
163}
164
165void Config::setMainWindowFactoryFunc(MainWindowFactoryFunc func)
166{
167 d->m_mainWindowFactoryFunc = func;
168}
169
170MainWindowFactoryFunc Config::mainWindowFactoryFunc() const
171{
172 return d->m_mainWindowFactoryFunc;
173}
174
175void Config::setViewFactory(ViewFactory *wf)
176{
177 assert(wf);
178 delete d->m_viewFactory;
179 d->m_viewFactory = wf;
180}
181
182ViewFactory *Config::viewFactory() const
183{
184 return d->m_viewFactory;
185}
186
187int Config::separatorThickness() const
188{
189 return Item::separatorThickness;
190}
191
192int Config::layoutSpacing() const
193{
194 return Item::layoutSpacing;
195}
196
197void Config::setSeparatorThickness(int value)
198{
199 if (!DockRegistry::self()->isEmpty(/*excludeBeingDeleted=*/true)) {
200 std::cerr
201 << "Config::setSeparatorThickness: Only use this function at startup before creating any DockWidget or MainWindow\n";
202 return;
203 }
204
205 if (value < 0 || value >= 100) {
206 std::cerr << "Config::setSeparatorThickness: Invalid value" << value << "\n";
207 return;
208 }
209
210 Item::separatorThickness = value;
211 Item::layoutSpacing = value;
212}
213
214void Config::setLayoutSpacing(int value)
215{
216 if (!DockRegistry::self()->isEmpty(/*excludeBeingDeleted=*/true)) {
217 std::cerr
218 << "Config::setLayoutSpacing: Only use this function at startup before creating any DockWidget or MainWindow\n";
219 return;
220 }
221
222 if (value < 0 || value >= 100) {
223 std::cerr << "Config::setLayoutSpacing: Invalid value" << value << "\n";
224 return;
225 }
226
227 Item::layoutSpacing = value;
228}
229
230void Config::setDraggedWindowOpacity(double opacity)
231{
232 d->m_draggedWindowOpacity = opacity;
233}
234
235void Config::setTransparencyOnlyOverDropIndicator(bool only)
236{
237 d->m_transparencyOnlyOverDropIndicator = only;
238}
239
240double Config::draggedWindowOpacity() const
241{
242 return d->m_draggedWindowOpacity;
243}
244
245bool Config::transparencyOnlyOverDropIndicator() const
246{
247 return d->m_transparencyOnlyOverDropIndicator;
248}
249
250void Config::setDropIndicatorAllowedFunc(DropIndicatorAllowedFunc func)
251{
252 d->m_dropIndicatorAllowedFunc = func;
253}
254
255DropIndicatorAllowedFunc Config::dropIndicatorAllowedFunc() const
256{
257 return d->m_dropIndicatorAllowedFunc;
258}
259
260void Config::setDragAboutToStartFunc(DragAboutToStartFunc func)
261{
262 d->m_dragAboutToStartFunc = func;
263}
264
265DragAboutToStartFunc Config::dragAboutToStartFunc() const
266{
267 return d->m_dragAboutToStartFunc;
268}
269
270void Config::setDragEndedFunc(DragEndedFunc func)
271{
272 d->m_dragEndedFunc = func;
273}
274
275DragEndedFunc Config::dragEndedFunc() const
276{
277 return d->m_dragEndedFunc;
278}
279
280void Config::setAbsoluteWidgetMinSize(Size size)
281{
282 if (!DockRegistry::self()->isEmpty(/*excludeBeingDeleted=*/false)) {
283 std::cerr
284 << "Config::setAbsoluteWidgetMinSize: Only use this function at startup before creating any DockWidget or MainWindow\n";
285 return;
286 }
287
288 Item::hardcodedMinimumSize = size;
289}
290
291Size Config::absoluteWidgetMinSize() const
292{
293 return Item::hardcodedMinimumSize;
294}
295
296void Config::setAbsoluteWidgetMaxSize(Size size)
297{
298 if (!DockRegistry::self()->isEmpty(/*excludeBeingDeleted=*/false)) {
299 std::cerr
300 << "Config::setAbsoluteWidgetMinSize: Only use this function at startup before creating any DockWidget or MainWindow\n";
301 return;
302 }
303
304 Item::hardcodedMaximumSize = size;
305}
306
307Size Config::absoluteWidgetMaxSize() const
308{
309 return Item::hardcodedMaximumSize;
310}
311
312Config::InternalFlags Config::internalFlags() const
313{
314 return d->m_internalFlags;
315}
316
317void Config::setInternalFlags(InternalFlags flags)
318{
319 d->m_internalFlags = flags;
320}
321
322void Config::Private::fixFlags()
323{
324 if (Platform::instance()->supportsAeroSnap()) {
325 // Unconditional now
326 m_flags |= Flag_AeroSnapWithClientDecos;
327 } else {
328 m_flags = m_flags & ~Flag_AeroSnapWithClientDecos;
329 }
330
331 // These are mutually exclusive:
332 if ((m_flags & Flag_AeroSnapWithClientDecos) && (m_flags & Flag_NativeTitleBar)) {
333 // We're either using native or client decorations, let's use native.
334 m_flags = m_flags & ~Flag_AeroSnapWithClientDecos;
335 }
336
337#if defined(Q_OS_LINUX)
338 if (KDDockWidgets::isWayland()) {
339 // Native title bar is forced on Wayland. Needed for moving the window.
340 // The inner KDDW title bar is used for DnD.
341 m_flags |= Flag_NativeTitleBar;
342 } else {
343 // On Linux, dragging the title bar of a window doesn't generate NonClientMouseEvents
344 // at least with KWin anyway. We can make this more granular and allow it for other
345 // X11 window managers
346 m_flags = m_flags & ~Flag_NativeTitleBar;
347 }
348#endif
349
350#if (!defined(KDDW_FRONTEND_QT_WINDOWS) && !defined(Q_OS_MACOS))
351 // QtQuick doesn't support AeroSnap yet. Some problem with the native events not being
352 // received...
353 m_flags = m_flags & ~Flag_AeroSnapWithClientDecos;
354#endif
355
356
357#if defined(DOCKS_DEVELOPER_MODE)
358 // We allow to disable aero-snap during development
359 if (m_internalFlags & InternalFlag_NoAeroSnap) {
360 // The only way to disable AeroSnap
361 m_flags = m_flags & ~Flag_AeroSnapWithClientDecos;
362 }
363#endif
364
365 if (m_flags & Flag_DontUseUtilityFloatingWindows) {
366 m_internalFlags |= InternalFlag_DontUseParentForFloatingWindows;
367 m_internalFlags |= InternalFlag_DontUseQtToolWindowsForFloatingWindows;
368 }
369
370 if (m_flags & Flag_ShowButtonsOnTabBarIfTitleBarHidden) {
371 // Flag_ShowButtonsOnTabBarIfTitleBarHidden doesn't make sense if used alone
372 m_flags |= Flag_HideTitleBarWhenTabsVisible;
373 }
374}
375
376void Config::setDisabledPaintEvents(CustomizableWidgets widgets)
377{
378 d->m_disabledPaintEvents = widgets;
379}
380
381Config::CustomizableWidgets Config::disabledPaintEvents() const
382{
383 return d->m_disabledPaintEvents;
384}
385
386void Config::setMDIPopupThreshold(int threshold)
387{
388 d->m_mdiPopupThreshold = threshold;
389}
390
391int Config::mdiPopupThreshold() const
392{
393 return d->m_mdiPopupThreshold;
394}
395
396void Config::setDropIndicatorsInhibited(bool inhibit) const
397{
398 if (d->m_dropIndicatorsInhibited != inhibit) {
399 d->m_dropIndicatorsInhibited = inhibit;
400 DockRegistry::self()->dptr()->dropIndicatorsInhibitedChanged.emit(inhibit);
401 }
402}
403
404bool Config::dropIndicatorsInhibited() const
405{
406 return d->m_dropIndicatorsInhibited;
407}
408
409void Config::setStartDragDistance(int pixels)
410{
411 d->m_startDragDistance = pixels;
412}
413
414int Config::startDragDistance() const
415{
416 return d->m_startDragDistance;
417}
418
419void Config::printDebug()
420{
421 std::cerr << "Flags: " << d->m_flags << d->m_internalFlags << "\n";
422}
423
424void Config::setLayoutSaverStrictMode(bool is)
425{
426 d->m_layoutSaverStrictMode = is;
427}
428
429bool Config::layoutSaverUsesStrictMode() const
430{
431 return d->m_layoutSaverStrictMode;
432}
433
434void Config::setOnlyProgrammaticDrag(bool only)
435{
436 d->m_onlyProgrammaticDrag = only;
437}
438
439bool Config::onlyProgrammaticDrag() const
440{
441 return d->m_onlyProgrammaticDrag;
442}
443
444}
Application-wide config to tune certain behaviours of the framework.
Singleton to allow to choose certain behaviours of the framework.
Definition Config.h:64
@ InternalFlag_None
The default.
Definition Config.h:156
@ CustomizableWidget_None
None.
Definition Config.h:138
MDIFlag
Flags to be used in MDI mode.
Definition Config.h:182
Flag
Flag enum to tune certain behaviours, the defaults are Flag_Default.
Definition Config.h:77
@ Flag_Default
The defaults.
Definition Config.h:132
static Platform * instance()
Returns the platform singleton.
static bool isInitialized()
Returns whether the Platform was already initialized.
A factory class for allowing the user to customize some internal views. This is optional,...
Class to abstract QAction, so code still works with QtQuick and Flutter.
void(* DragEndedFunc)()
Definition Config.h:38
static ViewFactory * createDefaultViewFactory()
Definition Config.cpp:38
bool(* DropIndicatorAllowedFunc)(DropLocation location, const Vector< Core::DockWidget * > &source, const Vector< Core::DockWidget * > &target, Core::DropArea *dropArea)
Function to allow more granularity to disallow where widgets are dropped.
Definition Config.h:52
KDDockWidgets::Core::DockWidget *(* DockWidgetFactoryFunc)(const QString &name)
Definition Config.h:35
bool(* DragAboutToStartFunc)(Core::Draggable *draggable)
Definition Config.h:37
KDDockWidgets::Core::MainWindow *(* MainWindowFactoryFunc)(const QString &name, KDDockWidgets::MainWindowOptions)
Definition Config.h:36

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDDockWidgets
Advanced Dock Widget Framework for Qt
https://www.kdab.com/development-resources/qt-tools/kddockwidgets/
Generated by doxygen 1.9.8