KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
core/Platform.h
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2020 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
12#pragma once
13
14#include "kddockwidgets/docks_export.h"
15#include "View.h"
16#include "kddockwidgets/KDDockWidgets.h"
17#include "kddockwidgets/QtCompat_p.h"
18
19#include <vector>
20#include <memory.h>
21
22namespace KDDockWidgets {
23
24namespace Core {
25class DelayedCall;
26class EventFilterInterface;
27struct CreateViewOptions;
28class ClassicDropIndicatorOverlay;
29class SegmentedDropIndicatorOverlay;
30class ViewFactory;
31class Window;
32
35class DOCKS_EXPORT Platform
36{
37public:
39 enum class DisplayType {
40 Other = 0,
41 X11 = 1,
42 Wayland = 2,
43 QtOffscreen = 3,
44 QtEGLFS = 4,
45 Windows = 5
46 };
47
48 virtual ~Platform();
50 virtual const char *name() const = 0;
51
53 static Platform *instance();
54
56 // Will be false at start up right before using KDDW and at shutdown after dtor runs
57 static bool hasInstance();
58
61 virtual bool hasActivePopup() const;
62
64 virtual std::shared_ptr<View> focusedView() const = 0;
65
68
71
73 virtual std::shared_ptr<Core::Window> windowAt(Point globalPos) const = 0;
74
76 virtual void sendEvent(View *, Event *) const = 0;
77
80 virtual int screenNumberForView(View *) const = 0;
81 virtual int screenNumberForWindow(std::shared_ptr<Core::Window>) const = 0;
82
84 virtual Size screenSizeFor(View *) const = 0;
85
89 virtual View *createView(Controller *, View *parent = nullptr) const = 0;
90
92 bool isQtWidgets() const;
93
95 bool isQtQuick() const;
96
98 bool isQt() const;
99
104 int startDragDistance() const;
105
107 virtual bool usesFallbackMouseGrabber() const = 0;
108
112 virtual bool inDisallowedDragView(Point globalPos) const = 0;
113
115 virtual void ungrabMouse() = 0;
116
119 virtual void runDelayed(int ms, Core::DelayedCall *c) = 0;
120
126 virtual bool isProcessingAppQuitEvent() const = 0;
127
130 void installGlobalEventFilter(EventFilterInterface *);
131
133 void removeGlobalEventFilter(EventFilterInterface *);
134
137 virtual QString applicationName() const = 0;
138
143 virtual void setMouseCursor(Qt::CursorShape, bool discardLast = false) = 0;
144
146 virtual void restoreMouseCursor() = 0;
147
149 virtual DisplayType displayType() const = 0;
150
152 virtual bool isLeftMouseButtonPressed() const = 0;
153
156
157 virtual std::shared_ptr<Screen> primaryScreen() const = 0;
158
162 virtual void dumpManagedBacktrace()
163 {
164 }
165
168 virtual void onFloatingWindowCreated(Core::FloatingWindow *);
169
172 virtual void onFloatingWindowDestroyed(Core::FloatingWindow *);
173
177 virtual void onMainWindowCreated(Core::MainWindow *);
178
181 virtual void onMainWindowDestroyed(Core::MainWindow *);
182
184 virtual Point cursorPos() const = 0;
185
187 virtual void setCursorPos(Point) = 0;
188
192 virtual QByteArray readFile(const QString &, bool &ok) const;
193
195 virtual bool supportsAeroSnap() const;
196
198 static std::vector<KDDockWidgets::FrontendType> frontendTypes();
199
201 static bool isInitialized();
202
203#if defined(DOCKS_DEVELOPER_MODE) && !defined(DARTAGNAN_BINDINGS_RUN)
205#define DEFAULT_TIMEOUT 20000
206
207 // Stuff required by the tests only and not used by dart bindings.
208
212 virtual KDDW_QCORO_TASK tests_wait(int ms) const = 0;
213
216 virtual KDDW_QCORO_TASK tests_waitForResize(View *, int timeout = DEFAULT_TIMEOUT) const = 0;
217 virtual KDDW_QCORO_TASK tests_waitForResize(Controller *, int timeout = DEFAULT_TIMEOUT) const = 0;
218 virtual KDDW_QCORO_TASK tests_waitForDeleted(View *, int timeout = DEFAULT_TIMEOUT) const = 0;
219 virtual KDDW_QCORO_TASK tests_waitForDeleted(Controller *, int timeout = DEFAULT_TIMEOUT) const = 0;
220
224 virtual KDDW_QCORO_TASK tests_waitForWindowActive(std::shared_ptr<Core::Window>, int timeout = DEFAULT_TIMEOUT) const = 0;
225
228 virtual KDDW_QCORO_TASK tests_waitForEvent(Core::Object *w, Event::Type type, int timeout = DEFAULT_TIMEOUT) const = 0;
229 virtual KDDW_QCORO_TASK tests_waitForEvent(View *, Event::Type type, int timeout = DEFAULT_TIMEOUT) const = 0;
230 virtual KDDW_QCORO_TASK tests_waitForEvent(std::shared_ptr<Core::Window>, Event::Type type,
231 int timeout = DEFAULT_TIMEOUT) const = 0;
232
233 virtual void tests_doubleClickOn(Point globalPos, View *receiver) = 0;
234 virtual void tests_doubleClickOn(Point globalPos, std::shared_ptr<Core::Window> receiver) = 0;
235 virtual void tests_pressOn(Point globalPos, View *receiver) = 0;
236 virtual void tests_pressOn(Point globalPos, std::shared_ptr<Core::Window> receiver) = 0;
237 virtual KDDW_QCORO_TASK tests_releaseOn(Point globalPos, View *receiver) = 0;
238 virtual KDDW_QCORO_TASK tests_mouseMove(Point globalPos, View *receiver) = 0;
239
242 virtual std::shared_ptr<Core::Window> tests_createWindow() = 0;
243
246 static void tests_initPlatform(int &argc, char *argv[], KDDockWidgets::FrontendType, bool defaultToOffscreenQPA = true);
247
250 static void tests_deinitPlatform();
251
252 std::string m_expectedWarning;
253#endif
254
255#ifdef DOCKS_TESTING_METHODS
256
257 class WarningObserver
258 {
259 KDDW_DELETE_COPY_CTOR(WarningObserver)
260 public:
261 WarningObserver() = default;
262 virtual ~WarningObserver();
263 virtual void onFatal() = 0;
264 };
265
269 virtual View *tests_createView(CreateViewOptions, View *parent = nullptr) = 0;
270
273 virtual View *tests_createFocusableView(CreateViewOptions, View *parent = nullptr) = 0;
274
276 virtual View *tests_createNonClosableView(View *parent = nullptr) = 0;
277
278 virtual void installMessageHandler() = 0;
279 virtual void uninstallMessageHandler() = 0;
280
283 virtual Core::MainWindow *
284 createMainWindow(const QString &uniqueName, CreateViewOptions,
285 MainWindowOptions options = MainWindowOption_HasCentralFrame,
286 View *parent = nullptr, Qt::WindowFlags = {}) const = 0;
287
288 virtual void pauseForDebugger();
289
290protected:
293 virtual void tests_initPlatform_impl()
294 {
295 }
296
299 virtual void tests_deinitPlatform_impl()
300 {
301 }
302
303#endif
304
305public:
306 class Private;
307 Private *const d;
308
309protected:
310 virtual int startDragDistance_impl() const;
311 Platform();
312
313 Platform(const Platform &) = delete;
314 Platform &operator=(const Platform &) = delete;
315};
316
317#if defined(DOCKS_DEVELOPER_MODE)
318
319#if !defined(DARTAGNAN_BINDINGS_RUN)
320
321struct SetExpectedWarning
322{
323 explicit SetExpectedWarning(const std::string &s)
324 {
325 if (!s.empty())
326 Platform::instance()->m_expectedWarning = s;
327 }
328
329 ~SetExpectedWarning()
330 {
331 Platform::instance()->m_expectedWarning.clear();
332 }
333
334 KDDW_DELETE_COPY_CTOR(SetExpectedWarning)
335};
336
337#endif // bindings
338
339#endif // dev-mode
340
341#if defined(DOCKS_TESTING_METHODS)
342
343struct CreateViewOptions
344{
345 bool isVisible = false;
346 Size sizeHint = {};
347 Size minSize = { 0, 0 };
348 Size maxSize = Size(16777215, 16777215);
349 Size size = { 1000, 1000 };
350 bool createWindow = false;
351
352 Size getMinSize() const
353 {
354 return minSize;
355 }
356
357 Size getMaxSize() const
358 {
359 return maxSize;
360 }
361
362 Size getSize() const
363 {
364 return size;
365 }
366};
367
368#endif
369
370} // Core
371
372} // KDDockWidgets
#define KDDW_DELETE_COPY_CTOR(NAME)
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
implements functions specific to a particular platform A platform can be for example qtwidgets,...
virtual QString applicationName() const =0
Returns the application name This name will be used as title of floating dock widgets which contain m...
virtual std::shared_ptr< Core::Window > windowAt(Point globalPos) const =0
Returns the window at the specified global coordinates.
DisplayType
Enum describing the graphics stack type.
Platform(const Platform &)=delete
virtual void setMouseCursor(Qt::CursorShape, bool discardLast=false)=0
Sets the mouse cursor to the specified shape, this has an application-wide effect Call restoreMouseCu...
virtual const char * name() const =0
Returns the name of the platform, only "qtwidgets" and "qtquick".
virtual bool isProcessingAppQuitEvent() const =0
Returns whether we're processing a Event::Quit.
virtual Vector< std::shared_ptr< Core::Window > > windows() const =0
Returns all windows.
virtual void restoreMouseCursor()=0
Undoes the call to setMouseCursor()
virtual bool inDisallowedDragView(Point globalPos) const =0
Returns whether the specified global position is on top of a view that isn't draggable....
virtual void dumpManagedBacktrace()
For non-C++, managed languages (having a VM) prints a non-native back-trace For example,...
virtual std::shared_ptr< Screen > primaryScreen() const =0
virtual int screenNumberForWindow(std::shared_ptr< Core::Window >) const =0
virtual bool usesFallbackMouseGrabber() const =0
Return whether we use the global event filter based mouse grabber.
virtual bool isLeftMouseButtonPressed() const =0
Returns whether the left mouse button is pressed.
virtual ViewFactory * createDefaultViewFactory()=0
Creates and returns the default ViewFactory.
virtual void setCursorPos(Point)=0
Sets the mouse cursor position in screen coordinates.
virtual View * createView(Controller *, View *parent=nullptr) const =0
Create an empty view For Qt this would just returns a empty QWidget or QQuickItem other frontends can...
virtual int screenNumberForView(View *) const =0
Returns the screen index for the specified view or window. It's up to the platform to decide how scre...
virtual DisplayType displayType() const =0
Returns the type of graphics stack being used.
virtual void ungrabMouse()=0
Releases the mouse grab, if any.
virtual void runDelayed(int ms, Core::DelayedCall *c)=0
virtual Size screenSizeFor(View *) const =0
Returns the size of the screen where this view is in.
virtual void sendEvent(View *, Event *) const =0
Sends the specified event to the specified view.
Platform & operator=(const Platform &)=delete
virtual Point cursorPos() const =0
Returns the mouse cursor position in screen coordinates.
virtual std::shared_ptr< View > focusedView() const =0
Returns the focused view, if any.
virtual Vector< std::shared_ptr< Screen > > screens() const =0
Returns all available screens.
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.
CursorShape

© 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