Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Move window focus checking into its own component, for separate qt6 version.

Wolthera van Hövell tot Westerflier62c297f522f3
diff --git a/plugins/dockers/textproperties/qml/TextProperties.qml b/plugins/dockers/textproperties/qml/TextProperties.qml
index 2540ccb12a..3c3ab37922 100644
--- a/plugins/dockers/textproperties/qml/TextProperties.qml
+++ b/plugins/dockers/textproperties/qml/TextProperties.qml
@@ -3,12 +3,11 @@
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
-import QtQuick 2.0
+import QtQuick 2.15
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.12
import org.krita.flake.text 1.0
import org.krita.components 1.0 as Kis
-import QtQuick.Window 2.15
Control {
id: root;
@@ -21,26 +20,13 @@ Control {
target: canvasObserver;
function onTextPropertyConfigChanged() {updatePropertyVisibilityState()}
function onTextPropertiesChanged() {setProperties()}
- }
- Window.onActiveFocusItemChanged: {
- /// Quick test to check this docker is in focus.
- let currentFocusItem = Window.activeFocusItem;
- let anyFocus = (typeof currentFocusItem !== "undefined" || currentFocusItem);
- if (anyFocus) {
- anyFocus = false;
- let testFocus = currentFocusItem;
- while (typeof testFocus !== "undefined" && testFocus) {
- if (testFocus == root) {
- anyFocus = true;
- break;
- }
- testFocus = testFocus.parent;
- }
- }
- canvasObserver.hasFocus = anyFocus;
}
+ Kis.WindowFocusChecker {
+ id: focusChecker;
+ onInFocusChanged: canvasObserver.hasFocus = inFocus;
+ }
property TextPropertyConfigModel configModel : canvasObserver.textPropertyConfig;
property double canvasDPI: canvasObserver.dpi;
diff --git a/qmlmodules/components/CMakeLists.txt b/qmlmodules/components/CMakeLists.txt
index c43689f5eb..b5055f057e 100644
--- a/qmlmodules/components/CMakeLists.txt
+++ b/qmlmodules/components/CMakeLists.txt
@@ -74,6 +74,10 @@ ecm_target_qml_sources(kritaqmlcomponents PRIVATE PATH +Fusion SOURCES
qml/themedComponents/+Fusion/ToolSeparatorBase.qml
)
+ecm_target_qml_sources(kritaqmlcomponents PRIVATE PATH +qt5 SOURCES
+ qml/+qt5/WindowFocusChecker.qml
+)
+
ecm_target_qml_sources(kritaqmlcomponents SOURCES
qml/button/GroupButton.qml
qml/button/OptionButtonStrip.qml
@@ -95,6 +99,8 @@ ecm_target_qml_sources(kritaqmlcomponents SOURCES
qml/AngleSelector.qml
qml/InformingTextInput.qml
+ qml/WindowFocusChecker.qml
+
)
if (QT_MAJOR_VERSION STREQUAL "6")
target_link_libraries(kritaqmlcomponents
diff --git a/qmlmodules/components/qml/+qt5/WindowFocusChecker.qml b/qmlmodules/components/qml/+qt5/WindowFocusChecker.qml
new file mode 100644
index 0000000000..ae4984abe6
--- /dev/null
+++ b/qmlmodules/components/qml/+qt5/WindowFocusChecker.qml
@@ -0,0 +1,37 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+import QtQuick 2.15
+import QtQuick.Window 2.15
+
+/**
+ This object tests whether the current active item is a child of the
+ parent of this item. This can be used to figure out if a collection
+ of controls is being interacted with by the user.
+
+ This is the qt5 version.
+ */
+Item {
+ property bool inFocus: false;
+
+ Window.onActiveFocusItemChanged: {
+ let root = (parent && typeof parent !== 'undefined')? parent: this;
+ /// Quick test to check this docker is in focus.
+ let currentFocusItem = Window.activeFocusItem;
+ let anyFocus = (typeof currentFocusItem !== "undefined" || currentFocusItem);
+ if (anyFocus) {
+ anyFocus = false;
+ let testFocus = currentFocusItem;
+ while (typeof testFocus !== "undefined" && testFocus) {
+ if (testFocus === root) {
+ anyFocus = true;
+ break;
+ }
+ testFocus = testFocus.parent;
+ }
+ }
+ inFocus = anyFocus;
+ }
+}
diff --git a/qmlmodules/components/qml/WindowFocusChecker.qml b/qmlmodules/components/qml/WindowFocusChecker.qml
new file mode 100644
index 0000000000..0a6005d83d
--- /dev/null
+++ b/qmlmodules/components/qml/WindowFocusChecker.qml
@@ -0,0 +1,36 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+import QtQuick
+
+/**
+ This object tests whether the current active item is a child of the
+ parent of this item. This can be used to figure out if a collection
+ of controls is being interacted with by the user.
+
+ This is the qt6 version.
+ */
+Item {
+ property bool inFocus: false;
+
+ Window.onActiveFocusItemChanged: {
+ let root = (parent && typeof parent !== 'undefined')? parent: this;
+ /// Quick test to check this docker is in focus.
+ let currentFocusItem = Window.activeFocusItem;
+ let anyFocus = (typeof currentFocusItem !== "undefined" || currentFocusItem);
+ if (anyFocus) {
+ anyFocus = false;
+ let testFocus = currentFocusItem;
+ while (typeof testFocus !== "undefined" && testFocus) {
+ if (testFocus === root) {
+ anyFocus = true;
+ break;
+ }
+ testFocus = testFocus.parent;
+ }
+ }
+ inFocus = anyFocus;
+ }
+}
diff --git a/qmlmodules/widgets/KisQQuickWidget.cpp b/qmlmodules/widgets/KisQQuickWidget.cpp
index acceeb3159..25ec2cbc6d 100644
--- a/qmlmodules/widgets/KisQQuickWidget.cpp
+++ b/qmlmodules/widgets/KisQQuickWidget.cpp
@@ -63,6 +63,11 @@ KisQQuickWidget::KisQQuickWidget(QWidget *parent): QQuickWidget(parent)
* a "+StyleName" folder.
*/
extraSelectors << QQuickStyle::name();
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ extraSelectors << "qt6";
+#elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+ extraSelectors << "qt5";
+#endif
selector->setExtraSelectors(extraSelectors);