diff --git a/src/Platform.h b/src/Platform.h index 693442f7..e42ea8fe 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -53,6 +53,13 @@ public: /// @brief Creates and returns the default FrameworkWidgetFactory virtual FrameworkWidgetFactory *createDefaultFrameworkWidgetFactory() = 0; +#ifdef DOCKS_DEVELOPER_MODE + /// @brief Waits for the specified window to be active (have the keyboard focus) + /// Window::isActive() should return true + /// @sa Window::isActive() + virtual bool tests_waitForWindowActive(std::shared_ptr, int timeout = 5000) const = 0; +#endif + public: /// @brief This signal is emitted when the currently focused view changes KDBindings::Signal> focusedViewChanged; diff --git a/src/Window.h b/src/Window.h index 842c546a..5b4d989f 100644 --- a/src/Window.h +++ b/src/Window.h @@ -59,7 +59,9 @@ public: virtual void resize(int width, int height) = 0; /// @brief Returns whether a window is active - /// An active window has keyboard focus + /// An active window has keyboard focus, and might have its window decos + /// highlighted. Windows are usually become active after you click on their + /// title bar, but can also be done programatically. virtual bool isActive() const = 0; /// @brief Returns the window state diff --git a/src/qtcommon/Platform_qt.cpp b/src/qtcommon/Platform_qt.cpp index 2826e047..dcf15e9d 100644 --- a/src/qtcommon/Platform_qt.cpp +++ b/src/qtcommon/Platform_qt.cpp @@ -15,6 +15,7 @@ #include #include #include +#include using namespace KDDockWidgets; @@ -52,3 +53,13 @@ std::shared_ptr Platform_qt::qobjectAsWindow(QObject *obj) const return windowFromQWindow(window); return nullptr; } + +#ifdef DOCKS_DEVELOPER_MODE + +bool Platform_qt::tests_waitForWindowActive(Window::Ptr window, int timeout) const +{ + auto windowqt = static_cast(window.get()); + return QTest::qWaitForWindowActive(windowqt->qtWindow(), timeout); +} + +#endif diff --git a/src/qtcommon/Platform_qt.h b/src/qtcommon/Platform_qt.h index 15b38f29..2a6e7fff 100644 --- a/src/qtcommon/Platform_qt.h +++ b/src/qtcommon/Platform_qt.h @@ -13,6 +13,7 @@ #include "docks_export.h" #include "Platform.h" +#include "Window_qt.h" namespace KDDockWidgets { @@ -28,6 +29,10 @@ public: QVector> windows() const override; std::shared_ptr qobjectAsWindow(QObject *) const override; virtual std::shared_ptr windowFromQWindow(QWindow *) const = 0; + +#ifdef DOCKS_DEVELOPER_MODE + bool tests_waitForWindowActive(std::shared_ptr, int timeout = 5000) const override; +#endif }; } diff --git a/tests/tst_docks.cpp b/tests/tst_docks.cpp index b3868e91..de16cc5f 100644 --- a/tests/tst_docks.cpp +++ b/tests/tst_docks.cpp @@ -21,6 +21,7 @@ #include "Position_p.h" #include "WindowBeingDragged_p.h" #include "MDIArea.h" +#include "Platform.h" #include "multisplitter/Item_p.h" #include "private/MultiSplitter_p.h" @@ -864,7 +865,7 @@ void TestDocks::tst_shutdown() auto m = createMainWindow(); m->show(); - QVERIFY(QTest::qWaitForWindowActive(m->view()->asQWidget()->windowHandle())); + QVERIFY(Platform::instance()->tests_waitForWindowActive(m->view()->windowHandle())); } #ifdef KDDOCKWIDGETS_QTWIDGETS diff --git a/tests/utils.cpp b/tests/utils.cpp index becc14b4..b6890551 100644 --- a/tests/utils.cpp +++ b/tests/utils.cpp @@ -13,6 +13,7 @@ #include "DropArea_p.h" #include "Config.h" #include "FrameworkWidgetFactory.h" +#include "Platform.h" #include #include @@ -83,7 +84,7 @@ DockWidgetBase *KDDockWidgets::Tests::createDockWidget(const QString &name, QWid dock->dptr()->morphIntoFloatingWindow(); dock->view()->activateWindow(); Q_ASSERT(dock->window()); - if (QTest::qWaitForWindowActive(dock->view()->asQWidget()->window()->windowHandle(), 1000)) { + if (Platform::instance()->tests_waitForWindowActive(dock->view()->windowHandle(), 1000)) { return dock; } qWarning() << Q_FUNC_INFO << "Couldn't activate window";