From f446af2aa592997f6bc4aa3b5559cf477f9259f8 Mon Sep 17 00:00:00 2001 From: Volker Krause Date: Mon, 14 Feb 2022 18:12:24 +0100 Subject: Add KWindowStateSaver This is basically the C++ counter-part to https://invent.kde.org/frameworks/kconfig/-/merge_requests/94 and allows to easily retrofit window size persistence on existing windows/ dialogs, replacing e.g. code like https://invent.kde.org/pim/pimcommon/-/blob/master/src/pimcommon/widgets/kpimprintpreviewdialog.cpp. This is a bit more complicated than one might expect, as KWindowConfig works with QWindows, but that's something freshly created QWidget windows/ dialogs don't have yet. Additionally, we are in a library here that doesn't depend on Qt::Widgets. To overcome this we move the widget-dependent code (basically just a call to QWidget::windowHandle()) to inline template code (and thus into the consumer), use std::function's type erasure to pass it into the library code, and an event filter on the widget to wait for the QWindow to become available. --- autotests/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'autotests/CMakeLists.txt') diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 7b5a73b1..458f8f97 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -82,3 +82,8 @@ if (NOT CMAKE_CROSSCOMPILING) add_subdirectory(kconfig_compiler) endif() endif() + +find_package(Qt${QT_MAJOR_VERSION} OPTIONAL_COMPONENTS Widgets) +if (TARGET Qt${QT_MAJOR_VERSION}::Widgets) + ecm_add_test(kwindowstatesavertest.cpp LINK_LIBRARIES KF5::ConfigGui Qt${QT_MAJOR_VERSION}::Test Qt${QT_MAJOR_VERSION}::Widgets) +endif() -- cgit v1.2.1