KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
flutter/Platform.cpp
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#include "Platform.h"
13#include "kddockwidgets/KDDockWidgets.h"
14
15#include "Window_p.h"
16#include "Screen_p.h"
17#include "views/View.h"
18#include "core/Platform_p.h"
19#include "core/Logging_p.h"
20#include "core/ObjectGuard_p.h"
21#include "core/ViewGuard.h"
22#include "ViewFactory.h"
23#include "kddockwidgets/core/MainWindow.h"
24
25#include <mutex>
26#include <memory.h>
27
28using namespace KDDockWidgets;
29using namespace KDDockWidgets::flutter;
30
31Point Platform::s_lastCursorPosition = { -1, -1 };
32
33class flutter::Platform::Private
34{
35public:
36 std::shared_ptr<Core::View> m_focusedView;
37 std::optional<int> m_testsResult;
38};
39
41 : d(new Private())
42{
43 init();
44}
45
47{
48 delete d;
49}
50
52{
53}
54
55std::shared_ptr<Core::View> Platform::focusedView() const
56{
57 return d->m_focusedView;
58}
59
61{
62 KDDW_WARN("Platform::windows: Not implemented");
63 return {};
64}
65
66void Platform::sendEvent(Core::View *, Event *) const
67{
68 KDDW_WARN("Platform::sendEvent: Not implemented");
69}
70
71const char *Platform::name() const
72{
73 KDDW_WARN("Platform::name: Not implemented");
74 return nullptr;
75}
76
78{
79 return false;
80}
81
86
87Core::Window::Ptr Platform::windowAt(Point) const
88{
89 KDDW_WARN("Platform::windowAt: Not implemented");
90 return {};
91}
92
94{
95 KDDW_WARN("Platform::screenNumberFor: Not implemented");
96 return -1;
97}
98
99int Platform::screenNumberFor(std::shared_ptr<Core::Window>) const
100{
101 KDDW_WARN("Platform::screenNumberFor: Not implemented");
102 return {};
103}
104
106{
107 KDDW_WARN("Platform::isProcessingAppQuitEven: Not implemented");
108 return {};
109}
110
112{
113 // FLUTTER_TODO
114 // KDDW_WARN("Platform::applicationName: Not implemented");
115 return {};
116}
117
119{
120 KDDW_WARN("Platform::setMouseCursor: Not implemented");
121}
122
124{
125 KDDW_WARN("Platform::restoreMouseCursor: Not implemented");
126}
127
133
135{
136 KDDW_WARN("Platform::isLeftMouseButtonPressed: Not implemented");
137 return {};
138}
139
141{
142 KDDW_WARN("Platform::screenSizeFor: Not implemented");
143 return {};
144}
145
147{
148 KDDW_WARN("Platform::createView: Not implemented");
149 return nullptr;
150}
151
153{
154 return false;
155}
156
158{
159 return false;
160}
161
163{
164 KDDW_WARN("Platform::ungrabMouse: Not implemented");
165}
166
167Core::Screen::List Platform::screens() const
168{
170 return { primaryScreen() };
171}
172
173Core::Screen::Ptr Platform::primaryScreen() const
174{
175 return std::make_shared<flutter::Screen>();
176}
177
179{
180 KDDW_WARN("Platform::onFloatingWindowCreated: Implemented in dart");
181}
182
184{
185 KDDW_WARN("Platform::onFloatingWindowDestroyed: Implemented in dart");
186}
187
189{
190 KDDW_WARN("Platform::onMainWindowCreated: Implemented in dart");
191}
192
194{
195 KDDW_WARN("Platform::onMainWindowDestroyed: Implemented in dart");
196}
197
199{
200 KDDW_WARN("Platform::onDropIndicatorOverlayCreated: Implemented in dart");
201}
202
204{
205 KDDW_WARN("Platform::onDropIndicatorOverlayDestroyed: Implemented in dart");
206}
207
209{
210 KDDW_WARN("Platform::rebuildWindowOverlay: Implemented in dart");
211}
212
213void Platform::runDelayed(int, Core::DelayedCall *)
214{
215 Q_UNREACHABLE(); // Platform.dart gets called instead
216}
217
222
224{
225 KDDW_WARN("Platform::setCursorPos: Not implemented");
226}
227
228
229#ifdef DOCKS_TESTING_METHODS
230
231void Platform::installMessageHandler()
232{
233}
234
235void Platform::uninstallMessageHandler()
236{
237}
238
239void Platform::pauseForDebugger()
240{
241 pauseForDartDebugger();
242}
243
244
245namespace KDDockWidgets::flutter {
246
247class TestView_flutter : public flutter::View
248{
249public:
250 explicit TestView_flutter(Core::CreateViewOptions opts, Core::View *)
251 : flutter::View(nullptr, Core::ViewType::None, nullptr /* FLUTTER_TODO parent*/)
252 , m_opts(opts)
253 {
254 }
255
256 ~TestView_flutter();
257
258 Size maxSizeHint() const override
259 {
260 return {};
261 }
262
263private:
264 Core::CreateViewOptions m_opts;
265};
266
267class FocusableTestView_flutter : public flutter::View
268{
269public:
270 explicit FocusableTestView_flutter(Core::CreateViewOptions opts, Core::View *)
271 : flutter::View(nullptr, Core::ViewType::None, nullptr /* FLUTTER_TODO parent*/)
272 , m_opts(opts)
273 {
274 }
275
276 ~FocusableTestView_flutter();
277
278 Size maxSizeHint() const override
279 {
280 return {};
281 }
282
283private:
284 Core::CreateViewOptions m_opts;
285};
286
287class NonClosableTestView_flutter : public flutter::View
288{
289public:
290 explicit NonClosableTestView_flutter(Core::View *)
291 : flutter::View(nullptr, Core::ViewType::None, nullptr /* FLUTTER_TODO parent*/)
292 {
293 }
294
295 ~NonClosableTestView_flutter();
296};
297
298TestView_flutter::~TestView_flutter() = default;
299NonClosableTestView_flutter::~NonClosableTestView_flutter() = default;
300FocusableTestView_flutter::~FocusableTestView_flutter() = default;
301
302}
303
304static std::mutex m_mutex;
305void Platform::runTests()
306{
307#ifdef KDDW_FLUTTER_HAS_COROUTINES
308 // Called from Flutter, so C++ tests run in the ui thread
309 assert(s_runTestsFunc);
310
311 // The tests run in a co-routine, meaning they can be interrupted (due to a C++ wait or deleteLater)
312 // and the Flutter event loop keeps running. When they are actually finished, the "then()" block is run.
313 s_runTestsFunc().then([this](auto result) {
314 std::lock_guard<std::mutex> locker(m_mutex);
315 assert(!d->m_testsResult.has_value());
316 d->m_testsResult = result ? 0 : 1;
317 });
318#endif
319}
320
321void Platform::resumeCoRoutines()
322{
323#ifdef KDDW_FLUTTER_HAS_COROUTINES
324 m_coRoutines.resume();
325#endif
326}
327
328void Platform::scheduleResumeCoRoutines(int) const
329{
330 KDDW_WARN("Platform::scheduleResumeCoRoutines: Implemented in dart instead");
331}
332
333std::optional<int> Platform::testsResult() const
334{
335 std::lock_guard<std::mutex> locker(m_mutex);
336 return d->m_testsResult;
337}
338
339void Platform::tests_initPlatform_impl()
340{
341}
342
343void Platform::tests_deinitPlatform_impl()
344{
345}
346
347Core::View *Platform::tests_createView(Core::CreateViewOptions, Core::View *)
348{
349 Q_UNREACHABLE(); // Platform.dart gets called instead
350 return {};
351}
352
353Core::View *Platform::tests_createFocusableView(Core::CreateViewOptions opts, Core::View *parent)
354{
355 // FLUTTER_TODO: It's not focusable. To fix when we get to those tests
356 return tests_createView(opts, parent);
357}
358
359Core::View *Platform::tests_createNonClosableView(Core::View *parent)
360{
361 // FLUTTER_TODO: It's not non-closable. To fix when we get to those tests
362 return tests_createView({ .isVisible = true }, parent);
363}
364
365Core::MainWindow *Platform::createMainWindow(const QString &, Core::CreateViewOptions,
366 MainWindowOptions, Core::View *,
367 Qt::WindowFlags) const
368{
369 Q_UNREACHABLE(); // Platform.dart gets called instead
370 return {};
371}
372
373#endif
374
375
376void Platform::setFocusedView(std::shared_ptr<Core::View> view)
377{
378 d->m_focusedView = view;
379}
380
381#ifdef KDDW_FLUTTER_HAS_COROUTINES
382
383Platform::RunTestsFunc Platform::s_runTestsFunc = nullptr;
384
385KDDW_QCORO_TASK Platform::tests_waitForWindowActive(std::shared_ptr<Core::Window>, int) const
386{
387 co_return co_await tests_wait(1000);
388}
389
390KDDW_QCORO_TASK Platform::tests_waitForEvent(Core::Object *, Event::Type, int) const
391{
392 co_return co_await tests_wait(1000);
393}
394
395KDDW_QCORO_TASK Platform::tests_waitForEvent(Core::View *, Event::Type, int) const
396{
397 co_return co_await tests_wait(1000);
398}
399
400KDDW_QCORO_TASK Platform::tests_waitForEvent(std::shared_ptr<Core::Window>, Event::Type,
401 int) const
402{
403 co_return co_await tests_wait(1000);
404}
405
406KDDW_QCORO_TASK Platform::tests_wait(int ms) const
407{
409 scheduleResumeCoRoutines(ms);
410
412 co_await m_coRoutines.suspend();
413
414 co_return true;
415}
416
417KDDW_QCORO_TASK Platform::tests_waitForResize(Core::View *, int) const
418{
419 co_return co_await tests_wait(1000);
420}
421
422KDDW_QCORO_TASK Platform::tests_waitForResize(Core::Controller *, int) const
423{
424 co_return co_await tests_wait(1000);
425}
426
427KDDW_QCORO_TASK Platform::tests_waitForDeleted(Core::Controller *obj, int timeout) const
428{
429 if (!obj)
430 co_return true;
431
432 Core::ObjectGuard<Core::Controller> guard = obj;
433 int elapsed = 0;
434 const int step = 100;
435
436 while (guard && elapsed < timeout) {
437 co_await tests_wait(step);
438 elapsed += step;
439 }
440
441 co_return guard.isNull();
442}
443
444KDDW_QCORO_TASK Platform::tests_waitForDeleted(Core::View *view, int timeout) const
445{
446 if (!view)
447 co_return true;
448
449 Core::ViewGuard guard(view);
450
451 int elapsed = 0;
452 const int step = 100;
453
454 while (guard && elapsed < timeout) {
455 co_await tests_wait(step);
456 elapsed += step;
457 }
458
459 co_return guard.isNull();
460}
461
462std::shared_ptr<Core::Window> Platform::tests_createWindow()
463{
464 auto window = new flutter::Window(tests_createView({}, nullptr)->asWrapper());
465 return std::shared_ptr<Core::Window>(window);
466}
467
468void Platform::tests_doubleClickOn(Point, Core::View *)
469{
470 KDDW_WARN("Platform::tests_doubleClickOn: Not implemented yet");
471}
472
473void Platform::tests_doubleClickOn(Point, std::shared_ptr<Core::Window>)
474{
475 KDDW_WARN("Platform::tests_doubleClickOn: Not implemented yet");
476}
477
478QCoro::Task<bool> kddw_fakeMouseMove(Point globalPos);
479QCoro::Task<bool> kddw_fakeMouseButton(Point globalPos, bool isPress);
480
481void Platform::tests_pressOn(Point globalPos, Core::View *)
482{
483 kddw_fakeMouseButton(globalPos, /*isPress=*/true);
484}
485
486void Platform::tests_pressOn(Point globalPos, std::shared_ptr<Core::Window>)
487{
488 kddw_fakeMouseButton(globalPos, /*isPress=*/true);
489}
490
491KDDW_QCORO_TASK Platform::tests_releaseOn(Point globalPos, Core::View *)
492{
493 co_await kddw_fakeMouseButton(globalPos, /*isPress=*/false);
494 co_return true;
495}
496
497KDDW_QCORO_TASK Platform::tests_mouseMove(Point globalPos, Core::View *)
498{
499 co_await kddw_fakeMouseMove(globalPos);
500 co_return true;
501}
502
503#endif
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
DisplayType
Enum describing the graphics stack type.
A factory class for allowing the user to customize some internal views. This is optional,...
This class provides a weak reference to a view i.e., it becomes null automatically once a View is des...
Definition ViewGuard.h:27
int screenNumberFor(Core::View *) const override
Returns the screen index for the specified view or window. It's up to the platform to decide how scre...
bool isLeftMouseButtonPressed() const override
Returns whether the left mouse button is pressed.
Core::View * createView(Core::Controller *controller, Core::View *parent=nullptr) const override
Create an empty view For Qt this would just returns a empty QWidget or QQuickItem other frontends can...
Size screenSizeFor(Core::View *) const override
Returns the size of the screen where this view is in.
std::shared_ptr< Core::Window > windowAt(Point globalPos) const override
Returns the window at the specified global coordinates.
bool isProcessingAppQuitEvent() const override
Returns whether we're processing a Event::Quit.
Core::ViewFactory * createDefaultViewFactory() override
Creates and returns the default ViewFactory.
const char * name() const override
Returns the name of the platform, only "qtwidgets" and "qtquick".
void ungrabMouse() override
Releases the mouse grab, if any.
void onMainWindowDestroyed(Core::MainWindow *) override
Called when a main window is created. Overridden by flutter, so it can destroy the window.
std::shared_ptr< Core::Screen > primaryScreen() const override
bool usesFallbackMouseGrabber() const override
Return whether we use the global event filter based mouse grabber.
bool hasActivePopup() const override
Returns whether a popup is open Usually not needed to override. Investigate further in case side bars...
Vector< std::shared_ptr< Core::Window > > windows() const override
Returns all windows.
virtual void onDropIndicatorOverlayDestroyed(flutter::IndicatorWindow *)
void onMainWindowCreated(Core::MainWindow *) override
Called when a main window is created. Overridden by flutter, so it can create a window Used by tests ...
void onFloatingWindowCreated(Core::FloatingWindow *) override
Called when a floating window is created. Overridden by flutter, so it can create a window.
void setMouseCursor(Qt::CursorShape, bool discardLast=false) override
Sets the mouse cursor to the specified shape, this has an application-wide effect Call restoreMouseCu...
void sendEvent(Core::View *, Event *) const override
Sends the specified event to the specified view.
Point cursorPos() const override
Returns the mouse cursor position in screen coordinates.
virtual void onDropIndicatorOverlayCreated(flutter::IndicatorWindow *)
std::shared_ptr< Core::View > focusedView() const override
Returns the focused view, if any.
void runDelayed(int ms, Core::DelayedCall *c) override
void restoreMouseCursor() override
Undoes the call to setMouseCursor()
void setCursorPos(Point) override
Sets the mouse cursor position in screen coordinates.
void onFloatingWindowDestroyed(Core::FloatingWindow *) override
Called when a floating window is created. Overridden by flutter, so it can destroy the window.
void setFocusedView(std::shared_ptr< Core::View >)
DisplayType displayType() const override
Returns the type of graphics stack being used.
QString applicationName() const override
Returns the application name This name will be used as title of floating dock widgets which contain m...
Vector< std::shared_ptr< Core::Screen > > screens() const override
Returns all available screens.
bool inDisallowedDragView(Point globalPos) const override
Returns whether the specified global position is on top of a view that isn't draggable....
The default ViewFactory for Flutter frontend.
An asynchronously executed task.
Definition qcorotask.h:458
static std::mutex m_mutex
ViewType
Each View type also has a specific Controller associated with, except for ViewType::None.
Definition Controller.h:26
Class to abstract QAction, so code still works with QtQuick and Flutter.
@ None
Just use the defaults.
CursorShape
typedef WindowFlags
A factory class for allowing the user to customize some internal widgets.

© 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