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 SvgTextLabel and DoubleSpinBox to a shared QML module

Halla Rempt66270712d148
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 78dc9b05e8..c18f4b4e4e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -406,7 +406,7 @@ if (BUILD_WITH_QT6)
find_package(ECM 6.0 REQUIRED CONFIG)
else()
set(QT_MAJOR_VERSION 5)
- find_package(ECM 5.90 REQUIRED CONFIG)
+ find_package(ECM 5.91 REQUIRED CONFIG)
endif()
# KDE Frameworks
@@ -426,6 +426,7 @@ include(ECMGenerateHeaders)
include(GenerateExportHeader)
include(ECMMarkAsTest)
include(ECMInstallIcons)
+include(ECMQmlModule)
include(CMakePackageConfigHelpers)
include(WriteBasicConfigVersionFile)
@@ -1473,6 +1474,7 @@ include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}
add_subdirectory(sdk/tests)
add_subdirectory(libs)
+add_subdirectory(qmlmodules)
add_subdirectory(plugins)
if (BUILD_TESTING)
add_subdirectory(benchmarks)
diff --git a/plugins/dockers/textproperties/qml/BaselineShift.qml b/plugins/dockers/textproperties/qml/BaselineShift.qml
index 748f8a783f..393e0a8c24 100644
--- a/plugins/dockers/textproperties/qml/BaselineShift.qml
+++ b/plugins/dockers/textproperties/qml/BaselineShift.qml
@@ -7,6 +7,7 @@ import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.12
import org.krita.flake.text 1.0
+import org.krita.qml 1.0
TextPropertyBase {
propertyName: i18nc("@label", "Baseline-Shift")
diff --git a/plugins/dockers/textproperties/qml/FontSize.qml b/plugins/dockers/textproperties/qml/FontSize.qml
index b996373789..99fe5a798d 100644
--- a/plugins/dockers/textproperties/qml/FontSize.qml
+++ b/plugins/dockers/textproperties/qml/FontSize.qml
@@ -7,6 +7,7 @@ import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.12
import org.krita.flake.text 1.0
+import org.krita.qml 1.0
TextPropertyBase {
propertyName: i18nc("@label:spinbox", "Font Size");
diff --git a/plugins/dockers/textproperties/qml/FontStyle.qml b/plugins/dockers/textproperties/qml/FontStyle.qml
index abb7c3db82..7a8fb52b15 100644
--- a/plugins/dockers/textproperties/qml/FontStyle.qml
+++ b/plugins/dockers/textproperties/qml/FontStyle.qml
@@ -7,6 +7,7 @@ import QtQuick 2.15
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.12
import org.krita.flake.text 1.0
+import org.krita.qml 1.0
CollapsibleGroupProperty {
propertyName: i18nc("@label", "Font Style");
diff --git a/plugins/dockers/textproperties/qml/LetterSpacing.qml b/plugins/dockers/textproperties/qml/LetterSpacing.qml
index 9f095a5ffc..5fe334ae13 100644
--- a/plugins/dockers/textproperties/qml/LetterSpacing.qml
+++ b/plugins/dockers/textproperties/qml/LetterSpacing.qml
@@ -7,6 +7,7 @@ import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.12
import org.krita.flake.text 1.0
+import org.krita.qml 1.0
TextPropertyBase {
propertyName: i18nc("@label:spinbox", "Letter Spacing");
diff --git a/plugins/dockers/textproperties/qml/LineHeight.qml b/plugins/dockers/textproperties/qml/LineHeight.qml
index 89894ec755..9342354b58 100644
--- a/plugins/dockers/textproperties/qml/LineHeight.qml
+++ b/plugins/dockers/textproperties/qml/LineHeight.qml
@@ -7,6 +7,7 @@ import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.12
import org.krita.flake.text 1.0
+import org.krita.qml 1.0
TextPropertyBase {
propertyName: i18nc("@label", "Line Height");
diff --git a/plugins/dockers/textproperties/qml/TabSize.qml b/plugins/dockers/textproperties/qml/TabSize.qml
index 56d2fd2162..1abbaa2247 100644
--- a/plugins/dockers/textproperties/qml/TabSize.qml
+++ b/plugins/dockers/textproperties/qml/TabSize.qml
@@ -7,6 +7,7 @@ import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.12
import org.krita.flake.text 1.0
+import org.krita.qml 1.0
TextPropertyBase {
propertyName: i18nc("@title:group", "Tab Size");
diff --git a/plugins/dockers/textproperties/qml/TextIndent.qml b/plugins/dockers/textproperties/qml/TextIndent.qml
index c8362aab2a..2f84f72bc8 100644
--- a/plugins/dockers/textproperties/qml/TextIndent.qml
+++ b/plugins/dockers/textproperties/qml/TextIndent.qml
@@ -7,6 +7,7 @@ import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.12
import org.krita.flake.text 1.0
+import org.krita.qml 1.0
CollapsibleGroupProperty {
propertyName: i18nc("@title:group", "Text Indent");
diff --git a/plugins/dockers/textproperties/qml/WordSpacing.qml b/plugins/dockers/textproperties/qml/WordSpacing.qml
index 3406c825ce..c2c81c01e3 100644
--- a/plugins/dockers/textproperties/qml/WordSpacing.qml
+++ b/plugins/dockers/textproperties/qml/WordSpacing.qml
@@ -7,6 +7,7 @@ import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.12
import org.krita.flake.text 1.0
+import org.krita.qml 1.0
TextPropertyBase {
propertyName: i18nc("@title:group", "Word Spacing");
diff --git a/plugins/dockers/textproperties/textproperties.qrc b/plugins/dockers/textproperties/textproperties.qrc
index 652269dc1d..d48cbeea0c 100644
--- a/plugins/dockers/textproperties/textproperties.qrc
+++ b/plugins/dockers/textproperties/textproperties.qrc
@@ -32,7 +32,6 @@
<file alias="RevertPropertyButton.qml">qml/RevertPropertyButton.qml</file>
<file alias="TextPropertyBaseList.qml">qml/TextPropertyBaseList.qml</file>
<file alias="UnitComboBox.qml">qml/UnitComboBox.qml</file>
- <file alias="DoubleSpinBox.qml">qml/DoubleSpinBox.qml</file>
<file alias="FontResourceDropdown.qml">qml/FontResourceDropdown.qml</file>
<file alias="light_edit-undo-tristate.svg">icons/light_edit-undo-tristate.svg</file>
<file alias="font-color-type-clr-bitmap.svg">icons/font-color-type-clr-bitmap.svg</file>
diff --git a/plugins/tools/svgtexttool/CMakeLists.txt b/plugins/tools/svgtexttool/CMakeLists.txt
index f1399a8a18..c6618883a6 100644
--- a/plugins/tools/svgtexttool/CMakeLists.txt
+++ b/plugins/tools/svgtexttool/CMakeLists.txt
@@ -26,7 +26,6 @@ set (SvgTextTool_SRCS
glyphpalette/GlyphPaletteDialog.cpp
glyphpalette/GlyphPaletteProxyModel.cpp
- glyphpalette/SvgTextLabel.cpp
glyphpalette/GlyphPaletteAltPopup.cpp
)
@@ -58,6 +57,7 @@ target_link_libraries(krita_tool_svgtext_static
Qt${QT_MAJOR_VERSION}::QuickControls2
Qt${QT_MAJOR_VERSION}::Qml
KF${KF_MAJOR}::I18n)
+
target_link_libraries(krita_tool_svgtext PRIVATE krita_tool_svgtext_static)
install(TARGETS krita_tool_svgtext DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
diff --git a/plugins/tools/svgtexttool/Plugin.cpp b/plugins/tools/svgtexttool/Plugin.cpp
index 627bed20ed..d67a7d7704 100644
--- a/plugins/tools/svgtexttool/Plugin.cpp
+++ b/plugins/tools/svgtexttool/Plugin.cpp
@@ -8,19 +8,20 @@
#include <kpluginfactory.h>
+#include <QQmlEngine>
+
#include <KoShapeRegistry.h>
#include <KoToolRegistry.h>
#include <KisStaticInitializer.h>
#include "SvgTextToolFactory.h"
-#include "glyphpalette/SvgTextLabel.h"
#include "glyphpalette/GlyphPaletteProxyModel.h"
K_PLUGIN_FACTORY_WITH_JSON(PluginFactory, "krita_tool_svgtext.json", registerPlugin<Plugin>();)
KIS_DECLARE_STATIC_INITIALIZER {
- qmlRegisterType<SvgTextLabel>("org.krita.tools.text", 1, 0, "SvgTextLabel");
+ //qmlRegisterType<SvgTextLabel>("org.krita.tools.text", 1, 0, "SvgTextLabel");
qmlRegisterType<GlyphPaletteProxyModel>("org.krita.tools.text", 1, 0, "GlyphPaletteProxyModel");
}
Plugin::Plugin(QObject *parent, const QVariantList &)
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphDelegate.qml b/plugins/tools/svgtexttool/glyphpalette/GlyphDelegate.qml
index 7059186d78..75acd93503 100644
--- a/plugins/tools/svgtexttool/glyphpalette/GlyphDelegate.qml
+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphDelegate.qml
@@ -6,6 +6,7 @@
import QtQuick 2.15
import QtQuick.Controls 2.5
import org.krita.tools.text 1.0
+import org.krita.qml 1.0
SvgTextLabel {
id: glyphLabel;
diff --git a/qmlmodules/CMakeLists.txt b/qmlmodules/CMakeLists.txt
new file mode 100644
index 0000000000..6bb1046cdd
--- /dev/null
+++ b/qmlmodules/CMakeLists.txt
@@ -0,0 +1,5 @@
+#add_subdirectory(types)
+#add_subdirectory(utilities)
+#add_subdirectory(resources)
+#add_subdirectory(widgets)
+add_subdirectory(libqml)
diff --git a/qmlmodules/libqml/CMakeLists.txt b/qmlmodules/libqml/CMakeLists.txt
new file mode 100644
index 0000000000..2043955c7a
--- /dev/null
+++ b/qmlmodules/libqml/CMakeLists.txt
@@ -0,0 +1,27 @@
+ecm_add_qml_module(kritaqml
+ URI org.krita.qml
+ VERSION 1.0
+ SHARED
+ GENERATE_PLUGIN_SOURCE
+)
+
+target_sources(kritaqml
+ PUBLIC
+ SvgTextLabel.cpp
+)
+
+target_link_libraries(kritaqml
+ PUBLIC
+ kritaui
+ PRIVATE
+ Qt::Quick
+)
+
+ecm_target_qml_sources(kritaqml SOURCES
+ qml/DoubleSpinBox.qml
+)
+
+ecm_finalize_qml_module(kritaqml DESTINATION ${KDE_INSTALL_QMLDIR})
+
+install(TARGETS kritaqml ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
+
diff --git a/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.cpp b/qmlmodules/libqml/SvgTextLabel.cpp
similarity index 100%
rename from plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.cpp
rename to qmlmodules/libqml/SvgTextLabel.cpp
diff --git a/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.h b/qmlmodules/libqml/SvgTextLabel.h
similarity index 100%
rename from plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.h
rename to qmlmodules/libqml/SvgTextLabel.h
diff --git a/qmlmodules/libqml/qml/DoubleSpinBox.qml b/qmlmodules/libqml/qml/DoubleSpinBox.qml
new file mode 100644
index 0000000000..c1708a9660
--- /dev/null
+++ b/qmlmodules/libqml/qml/DoubleSpinBox.qml
@@ -0,0 +1,30 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+
+
+// Simple double spinbox based on Qt example implementation, should proly be switched to spinbox slider at some point.
+SpinBox {
+ editable: true;
+ wheelEnabled: true;
+
+ property int decimals: 2;
+ property int multiplier: Math.pow(10, decimals);
+
+ validator: DoubleValidator {
+ bottom: Math.min(from, to)
+ top: Math.max(from, to)
+ }
+
+ textFromValue: function(value, locale) {
+ return Number(value / multiplier).toLocaleString(locale, 'f', decimals)
+ }
+
+ valueFromText: function(text, locale) {
+ return Number.fromLocaleString(locale, text) * multiplier;
+ }
+}