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
57 virtual bool hasActivePopup() const;
58
60 virtual std::shared_ptr<View> focusedView() const = 0;
61
64
67
69 virtual std::shared_ptr<Core::Window> windowAt(Point globalPos) const = 0;
70
72 virtual void sendEvent(View *, Event *) const = 0;
73
76 virtual int screenNumberFor(View *) const = 0;
77 virtual int screenNumberFor(std::shared_ptr<Core::Window>) const = 0;
78
80 virtual Size screenSizeFor(View *) const = 0;
81
85 virtual View *createView(Controller *, View *parent = nullptr) const = 0;
86
88 bool isQtWidgets() const;
89
91 bool isQtQuick() const;
92
94 bool isQt() const;
95
100 int startDragDistance() const;
101
103 virtual bool usesFallbackMouseGrabber() const = 0;
104
108 virtual bool inDisallowedDragView(Point globalPos) const = 0;
109
111 virtual void ungrabMouse() = 0;
112
115 virtual void runDelayed(int ms, Core::DelayedCall *c) = 0;
116
122 virtual bool isProcessingAppQuitEvent() const = 0;
123
126 void installGlobalEventFilter(EventFilterInterface *);
127
129 void removeGlobalEventFilter(EventFilterInterface *);
130
133 virtual QString applicationName() const = 0;
134
139 virtual void setMouseCursor(Qt::CursorShape, bool discardLast = false) = 0;
140
142 virtual void restoreMouseCursor() = 0;
143
145 virtual DisplayType displayType() const = 0;
146
148 virtual bool isLeftMouseButtonPressed() const = 0;
149
152
153 virtual std::shared_ptr<Screen> primaryScreen() const = 0;
154
158 virtual void dumpManagedBacktrace()
159 {
160 }
161
164 virtual void onFloatingWindowCreated(Core::FloatingWindow *);
165
168 virtual void onFloatingWindowDestroyed(Core::FloatingWindow *);
169
173 virtual void onMainWindowCreated(Core::MainWindow *);
174
177 virtual void onMainWindowDestroyed(Core::MainWindow *);
178
180 virtual Point cursorPos() const = 0;
181
183 virtual void setCursorPos(Point) = 0;
184
188 virtual QByteArray readFile(const QString &, bool &ok) const;
189
191 virtual bool supportsAeroSnap() const;
192
194 static std::vector<KDDockWidgets::FrontendType> frontendTypes();
195
196
197#if defined(DOCKS_DEVELOPER_MODE) && !defined(DARTAGNAN_BINDINGS_RUN)
198 // Stuff required by the tests only and not used by dart bindings.
199
203 virtual KDDW_QCORO_TASK tests_wait(int ms) const = 0;
204
207 virtual KDDW_QCORO_TASK tests_waitForResize(View *, int timeout = 2000) const = 0;
208 virtual KDDW_QCORO_TASK tests_waitForResize(Controller *, int timeout = 2000) const = 0;
209 virtual KDDW_QCORO_TASK tests_waitForDeleted(View *, int timeout = 2000) const = 0;
210 virtual KDDW_QCORO_TASK tests_waitForDeleted(Controller *, int timeout = 2000) const = 0;
211
215 virtual KDDW_QCORO_TASK tests_waitForWindowActive(std::shared_ptr<Core::Window>, int timeout = 5000) const = 0;
216
219 virtual KDDW_QCORO_TASK tests_waitForEvent(Core::Object *w, Event::Type type, int timeout = 5000) const = 0;
220 virtual KDDW_QCORO_TASK tests_waitForEvent(View *, Event::Type type, int timeout = 5000) const = 0;
221 virtual KDDW_QCORO_TASK tests_waitForEvent(std::shared_ptr<Core::Window>, Event::Type type,
222 int timeout = 5000) const = 0;
223
224 virtual void tests_doubleClickOn(Point globalPos, View *receiver) = 0;
225 virtual void tests_doubleClickOn(Point globalPos, std::shared_ptr<Core::Window> receiver) = 0;
226 virtual void tests_pressOn(Point globalPos, View *receiver) = 0;
227 virtual void tests_pressOn(Point globalPos, std::shared_ptr<Core::Window> receiver) = 0;
228 virtual KDDW_QCORO_TASK tests_releaseOn(Point globalPos, View *receiver) = 0;
229 virtual KDDW_QCORO_TASK tests_mouseMove(Point globalPos, View *receiver) = 0;
230
233 virtual std::shared_ptr<Core::Window> tests_createWindow() = 0;
234
237 static void tests_initPlatform(int &argc, char *argv[], KDDockWidgets::FrontendType);
238
241 static void tests_deinitPlatform();
242
243 std::string m_expectedWarning;
244#endif
245
246#ifdef DOCKS_TESTING_METHODS
247
248 class WarningObserver
249 {
250 KDDW_DELETE_COPY_CTOR(WarningObserver)
251 public:
252 WarningObserver() = default;
253 virtual ~WarningObserver();
254 virtual void onFatal() = 0;
255 };
256
258 static bool isInitialized();
259
263 virtual View *tests_createView(CreateViewOptions, View *parent = nullptr) = 0;
264
267 virtual View *tests_createFocusableView(CreateViewOptions, View *parent = nullptr) = 0;
268
270 virtual View *tests_createNonClosableView(View *parent = nullptr) = 0;
271
272 virtual void installMessageHandler() = 0;
273 virtual void uninstallMessageHandler() = 0;
274
277 virtual Core::MainWindow *
278 createMainWindow(const QString &uniqueName, CreateViewOptions,
279 MainWindowOptions options = MainWindowOption_HasCentralFrame,
280 View *parent = nullptr, Qt::WindowFlags = {}) const = 0;
281
282 virtual void pauseForDebugger();
283
284protected:
287 virtual void tests_initPlatform_impl()
288 {
289 }
290
293 virtual void tests_deinitPlatform_impl()
294 {
295 }
296
297#endif
298
299public:
300 class Private;
301 Private *const d;
302
303protected:
304 virtual int startDragDistance_impl() const;
305 Platform();
306
307 Platform(const Platform &) = delete;
308 Platform &operator=(const Platform &) = delete;
309};
310
311#if defined(DOCKS_DEVELOPER_MODE)
312
313#if !defined(DARTAGNAN_BINDINGS_RUN)
314
315struct SetExpectedWarning
316{
317 explicit SetExpectedWarning(const std::string &s)
318 {
319 if (!s.empty())
320 Platform::instance()->m_expectedWarning = s;
321 }
322
323 ~SetExpectedWarning()
324 {
325 Platform::instance()->m_expectedWarning.clear();
326 }
327
328 KDDW_DELETE_COPY_CTOR(SetExpectedWarning)
329};
330
331#endif // bindings
332
333#endif // dev-mode
334
335#if defined(DOCKS_TESTING_METHODS)
336
337struct CreateViewOptions
338{
339 bool isVisible = false;
340 Size sizeHint = {};
341 Size minSize = { 0, 0 };
342 Size maxSize = Size(16777215, 16777215);
343 Size size = { 1000, 1000 };
344 bool createWindow = false;
345
346 Size getMinSize() const
347 {
348 return minSize;
349 }
350
351 Size getMaxSize() const
352 {
353 return maxSize;
354 }
355
356 Size getSize() const
357 {
358 return size;
359 }
360};
361
362#endif
363
364} // Core
365
366} // 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.
virtual int screenNumberFor(std::shared_ptr< Core::Window >) const =0
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 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 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.
virtual int screenNumberFor(View *) const =0
Returns the screen index for the specified view or window. It's up to the platform to decide how scre...
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