KDDockWidgets API Documentation 1.7
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-2023 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"
22#include "private/multisplitter/Item_p.h"
23#include "private/DockRegistry_p.h"
24#include "private/Utils_p.h"
25#include "private/DragController_p.h"
27
28#include <QDebug>
29#include <QOperatingSystemVersion>
30
31#ifdef KDDOCKWIDGETS_QTQUICK
32#include "private/quick/Helpers_p.h"
33#include <QQmlEngine>
34#include <QQmlContext>
35#endif
36
37namespace KDDockWidgets {
38
39class Config::Private
40{
41public:
42 Private()
43 : m_frameworkWidgetFactory(new DefaultWidgetFactory())
44 {
45 }
46
47 ~Private()
48 {
49 delete m_frameworkWidgetFactory;
50 }
51
52 void fixFlags();
53
54 QQmlEngine *m_qmlEngine = nullptr;
55 DockWidgetFactoryFunc m_dockWidgetFactoryFunc = nullptr;
56 MainWindowFactoryFunc m_mainWindowFactoryFunc = nullptr;
57 TabbingAllowedFunc m_tabbingAllowedFunc = nullptr;
58 DropIndicatorAllowedFunc m_dropIndicatorAllowedFunc = nullptr;
59 FrameworkWidgetFactory *m_frameworkWidgetFactory = nullptr;
60 Flags m_flags = Flag_Default;
61 InternalFlags m_internalFlags = InternalFlag_None;
62 CustomizableWidgets m_disabledPaintEvents = CustomizableWidget_None;
63 qreal m_draggedWindowOpacity = Q_QNAN;
64 int m_mdiPopupThreshold = 250;
65 bool m_dropIndicatorsInhibited = false;
66#ifdef KDDOCKWIDGETS_QTQUICK
67 QtQuickHelpers m_qquickHelpers;
68#endif
69};
70
71Config::Config()
72 : d(new Private())
73{
74 d->fixFlags();
75
76 // stuff in multisplitter/ can't include the framework widget factory, so set it here
77 auto separatorCreator = [](Layouting::Widget *parent) {
79 };
80
81 Layouting::Config::self().setSeparatorFactoryFunc(separatorCreator);
82}
83
85{
86 static Config config;
87 return config;
88}
89
91{
92 delete d;
93}
94
95Config::Flags Config::flags() const
96{
97 return d->m_flags;
98}
99
100void Config::setFlags(Flags f)
101{
102 auto dr = DockRegistry::self();
103 if (!dr->isEmpty(/*excludeBeingDeleted=*/true)) {
104 qWarning() << Q_FUNC_INFO << "Only use this function at startup before creating any DockWidget or MainWindow"
105 << "; These are already created: " << dr->mainWindowsNames()
106 << dr->dockWidgetNames() << dr->floatingWindows();
107 return;
108 }
109
110 d->m_flags = f;
111 d->fixFlags();
112
113 auto multisplitterFlags = Layouting::Config::self().flags();
114 multisplitterFlags.setFlag(Layouting::Config::Flag::LazyResize, d->m_flags & Flag_LazyResize);
115 Layouting::Config::self().setFlags(multisplitterFlags);
116}
117
119{
120 d->m_dockWidgetFactoryFunc = func;
121}
122
124{
125 return d->m_dockWidgetFactoryFunc;
126}
127
129{
130 d->m_mainWindowFactoryFunc = func;
131}
132
134{
135 return d->m_mainWindowFactoryFunc;
136}
137
139{
140 Q_ASSERT(wf);
141 delete d->m_frameworkWidgetFactory;
142 d->m_frameworkWidgetFactory = wf;
143}
144
146{
147 return d->m_frameworkWidgetFactory;
148}
149
154
156{
157 if (!DockRegistry::self()->isEmpty(/*excludeBeingDeleted=*/true)) {
158 qWarning() << Q_FUNC_INFO << "Only use this function at startup before creating any DockWidget or MainWindow";
159 return;
160 }
161
163}
164
166{
167 d->m_draggedWindowOpacity = opacity;
168}
169
171{
172 return d->m_draggedWindowOpacity;
173}
174
176{
177 d->m_tabbingAllowedFunc = func;
178}
179
181{
182 return d->m_tabbingAllowedFunc;
183}
184
186{
187 d->m_dropIndicatorAllowedFunc = func;
188}
189
191{
192 return d->m_dropIndicatorAllowedFunc;
193}
194
196{
197 if (!DockRegistry::self()->isEmpty(/*excludeBeingDeleted=*/false)) {
198 qWarning() << Q_FUNC_INFO << "Only use this function at startup before creating any DockWidget or MainWindow";
199 return;
200 }
201
202 Layouting::Item::hardcodedMinimumSize = size;
203}
204
206{
207 return Layouting::Item::hardcodedMinimumSize;
208}
209
211{
212 if (!DockRegistry::self()->isEmpty(/*excludeBeingDeleted=*/false)) {
213 qWarning() << Q_FUNC_INFO << "Only use this function at startup before creating any DockWidget or MainWindow";
214 return;
215 }
216
217 Layouting::Item::hardcodedMaximumSize = size;
218}
219
221{
222 return Layouting::Item::hardcodedMaximumSize;
223}
224
225Config::InternalFlags Config::internalFlags() const
226{
227 return d->m_internalFlags;
228}
229
230void Config::setInternalFlags(InternalFlags flags)
231{
232 d->m_internalFlags = flags;
233}
234
235#ifdef KDDOCKWIDGETS_QTQUICK
236void Config::setQmlEngine(QQmlEngine *qmlEngine)
237{
238 if (d->m_qmlEngine) {
239 qWarning() << Q_FUNC_INFO << "Already has QML engine";
240 return;
241 }
242
243 if (!qmlEngine) {
244 qWarning() << Q_FUNC_INFO << "Null QML engine";
245 return;
246 }
247
248 auto dr = DockRegistry::self(); // make sure our QML types are registered
249 QQmlContext *context = qmlEngine->rootContext();
250 context->setContextProperty(QStringLiteral("_kddwHelpers"), &d->m_qquickHelpers);
251 context->setContextProperty(QStringLiteral("_kddwDockRegistry"), dr);
252 context->setContextProperty(QStringLiteral("_kddwDragController"), DragController::instance());
253 context->setContextProperty(QStringLiteral("_kddw_widgetFactory"), d->m_frameworkWidgetFactory);
254
255 d->m_qmlEngine = qmlEngine;
256}
257
258QQmlEngine *Config::qmlEngine() const
259{
260 if (!d->m_qmlEngine)
261 qWarning() << "Please call KDDockWidgets::Config::self()->setQmlEngine(engine)";
262
263 return d->m_qmlEngine;
264}
265#endif
266
267void Config::Private::fixFlags()
268{
269#if defined(Q_OS_WIN)
270 if (QOperatingSystemVersion::current().majorVersion() < 10) {
271 // Aero-snap requires Windows 10
272 m_flags = m_flags & ~Flag_AeroSnapWithClientDecos;
273 } else {
274 // Unconditional now
275 m_flags |= Flag_AeroSnapWithClientDecos;
276 }
277
278 // These are mutually exclusive:
279 if ((m_flags & Flag_AeroSnapWithClientDecos) && (m_flags & Flag_NativeTitleBar)) {
280 // We're either using native or client decorations, let's use native.
281 m_flags = m_flags & ~Flag_AeroSnapWithClientDecos;
282 }
283#elif defined(Q_OS_MACOS)
284 // Not supported on macOS:
285 m_flags = m_flags & ~Flag_AeroSnapWithClientDecos;
286#else
287 if (KDDockWidgets::isWayland()) {
288 // Native title bar is forced on Wayland. Needed for moving the window.
289 // The inner KDDW title bar is used for DnD.
290 m_flags |= Flag_NativeTitleBar;
291 } else {
292 // Not supported on linux/X11
293 // On Linux, dragging the title bar of a window doesn't generate NonClientMouseEvents
294 // at least with KWin anyway. We can make this more granular and allow it for other
295 // X11 window managers
296 m_flags = m_flags & ~Flag_NativeTitleBar;
297 m_flags = m_flags & ~Flag_AeroSnapWithClientDecos;
298 }
299#endif
300
301#if (!defined(Q_OS_WIN) && !defined(Q_OS_MACOS))
302 // QtQuick doesn't support AeroSnap yet. Some problem with the native events not being received...
303 m_flags = m_flags & ~Flag_AeroSnapWithClientDecos;
304#endif
305
306
307#if defined(DOCKS_DEVELOPER_MODE)
308 // We allow to disable aero-snap during development
309 if (m_internalFlags & InternalFlag_NoAeroSnap) {
310 // The only way to disable AeroSnap
311 m_flags = m_flags & ~Flag_AeroSnapWithClientDecos;
312 }
313#endif
314
315 if (m_flags & Flag_DontUseUtilityFloatingWindows) {
316 m_internalFlags |= InternalFlag_DontUseParentForFloatingWindows;
317 m_internalFlags |= InternalFlag_DontUseQtToolWindowsForFloatingWindows;
318 }
319
320 if (m_flags & Flag_ShowButtonsOnTabBarIfTitleBarHidden) {
321 // Flag_ShowButtonsOnTabBarIfTitleBarHidden doesn't make sense if used alone
322 m_flags |= Flag_HideTitleBarWhenTabsVisible;
323 }
324}
325
326void Config::setDisabledPaintEvents(CustomizableWidgets widgets)
327{
328 d->m_disabledPaintEvents = widgets;
329}
330
331Config::CustomizableWidgets Config::disabledPaintEvents() const
332{
333 return d->m_disabledPaintEvents;
334}
335
337{
338 d->m_mdiPopupThreshold = threshold;
339}
340
342{
343 return d->m_mdiPopupThreshold;
344}
345
347{
348 if (d->m_dropIndicatorsInhibited != inhibit) {
349 d->m_dropIndicatorsInhibited = inhibit;
350 Q_EMIT DockRegistry::self()->dropIndicatorsInhibitedChanged(inhibit);
351 }
352}
353
355{
356 return d->m_dropIndicatorsInhibited;
357}
358
360{
361 qDebug() << "Flags: " << d->m_flags << d->m_internalFlags;
362}
363
364}
Application-wide config to tune certain behaviours of the framework.
A factory class for allowing the user to customize some internal widgets.
An abstraction/wrapper around QWidget, QtQuickItem or anything else.
Singleton to allow to choose certain behaviours of the framework.
Definition Config.h:75
void setDockWidgetFactoryFunc(DockWidgetFactoryFunc)
Registers a DockWidgetFactoryFunc.
Definition Config.cpp:118
int mdiPopupThreshold() const
Definition Config.cpp:341
void setAbsoluteWidgetMaxSize(QSize size)
Sets the maximum size a dock widget can have. Widgets can still provide their own max-size and it wil...
Definition Config.cpp:210
void printDebug()
Prints some debug information.
Definition Config.cpp:359
void setInternalFlags(InternalFlags flags)
Definition Config.cpp:230
InternalFlags internalFlags() const
Definition Config.cpp:225
MainWindowFactoryFunc mainWindowFactoryFunc() const
Returns the MainWindowFactoryFunc. nullptr by default.
Definition Config.cpp:133
Config::CustomizableWidgets disabledPaintEvents() const
Definition Config.cpp:331
void setDropIndicatorsInhibited(bool inhibit) const
Allows to disable support for drop indicators while dragging By default drop indicators will be shown...
Definition Config.cpp:346
void setFlags(Flags flags)
setter for the flags
Definition Config.cpp:100
void setTabbingAllowedFunc(TabbingAllowedFunc func)
Allows the user to intercept a docking attempt to center (tabbed) and disallow it.
Definition Config.cpp:175
void setDraggedWindowOpacity(qreal opacity)
sets the dragged window opacity 1.0 is fully opaque while 0.0 is fully transparent
Definition Config.cpp:165
@ InternalFlag_None
The default.
Definition Config.h:131
void setDropIndicatorAllowedFunc(DropIndicatorAllowedFunc func)
Allows the client app to disallow certain docking indicators.
Definition Config.cpp:185
DockWidgetFactoryFunc dockWidgetFactoryFunc() const
Returns the DockWidgetFactoryFunc. nullptr by default.
Definition Config.cpp:123
FrameworkWidgetFactory * frameworkWidgetFactory() const
getter for the framework widget factory
Definition Config.cpp:145
void setFrameworkWidgetFactory(FrameworkWidgetFactory *)
Sets the WidgetFactory.
Definition Config.cpp:138
void setSeparatorThickness(int value)
setter for separatorThickness Note: Only use this function at startup before creating any DockWidget ...
Definition Config.cpp:155
QSize absoluteWidgetMaxSize() const
Definition Config.cpp:220
@ CustomizableWidget_None
None.
Definition Config.h:116
TabbingAllowedFunc tabbingAllowedFunc() const
Used internally by the framework. Returns the function which was passed to setTabbingAllowedFunc() By...
Definition Config.cpp:180
void setAbsoluteWidgetMinSize(QSize size)
Sets the minimum size a dock widget can have. Widgets can still provide their own min-size and it wil...
Definition Config.cpp:195
QSize absoluteWidgetMinSize() const
Definition Config.cpp:205
static Config & self()
returns the singleton Config instance
Definition Config.cpp:84
qreal draggedWindowOpacity() const
returns the opacity to use when dragging dock widgets By default it's 1.0, fully opaque
Definition Config.cpp:170
void setMainWindowFactoryFunc(MainWindowFactoryFunc)
counter-part of DockWidgetFactoryFunc but for the main window. Should be rarely used....
Definition Config.cpp:128
bool dropIndicatorsInhibited() const
Returns whether drop indicators are inhibited. by default this is false unless you call setDropIndica...
Definition Config.cpp:354
void setMDIPopupThreshold(int)
Sets the MDI popup threshold. When the layout is MDI and you drag a dock widget X pixels behond the w...
Definition Config.cpp:336
void setDisabledPaintEvents(CustomizableWidgets)
Disables our internal widget's paint events By default, KDDockWidget's internal widgets reimplement p...
Definition Config.cpp:326
Flags flags() const
returns the chosen flags
Definition Config.cpp:95
DropIndicatorAllowedFunc dropIndicatorAllowedFunc() const
Used internally by the framework. Returns the function which was passed to setDropIndicatorAllowedFun...
Definition Config.cpp:190
@ Flag_Default
The defaults.
Definition Config.h:110
@ Flag_LazyResize
The dock widgets are resized in a lazy manner. The actual resize only happens when you release the mo...
Definition Config.h:99
int separatorThickness() const
Returns the thickness of the separator.
Definition Config.cpp:150
~Config()
destructor, called at shutdown
Definition Config.cpp:90
The FrameworkWidgetFactory that's used if none is specified.
A factory class for allowing the user to customize some internal widgets. This is optional,...
virtual Layouting::Separator * createSeparator(Layouting::Widget *parent=nullptr) const =0
Called internally by the framework to create a Separator Override to provide your own Separator sub-c...
Config::Flags flags() const
returns the flags;
int separatorThickness() const
Returns the thickness of the separator.
void setSeparatorThickness(int value)
setter for separatorThickness Note: Only use this function at startup before creating any Item
void setFlags(Flags)
sets the flags. Set only before creating any Item
static Config & self()
returns the singleton Config instance
An abstraction/wrapper around QWidget, QtQuickItem or anything else.
Definition Widget.h:77
KDDockWidgets::MainWindowBase *(* MainWindowFactoryFunc)(const QString &name)
Definition Config.h:40
bool(* DropIndicatorAllowedFunc)(DropLocation location, const QVector< DockWidgetBase * > &source, const QVector< DockWidgetBase * > &target, DropArea *dropArea)
Function to allow more granularity to disallow where widgets are dropped.
Definition Config.h:54
bool(* TabbingAllowedFunc)(const QVector< DockWidgetBase * > &source, const QVector< DockWidgetBase * > &target)
Function to allow the user more granularity to disallow dock widgets to tab together.
Definition Config.h:65
KDDockWidgets::DockWidgetBase *(* DockWidgetFactoryFunc)(const QString &name)
Definition Config.h:39
QOperatingSystemVersion current()

© 2019-2023 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 on Wed Nov 1 2023 00:02:31 for KDDockWidgets API Documentation by doxygen 1.9.8