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

© 2019-2022 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 Mon Mar 7 2022 02:01:20 for KDDockWidgets API Documentation by doxygen 1.8.20