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++
Let Krita build with PyQt6
Freya Lupen6601a23c4104
diff --git a/CMakeLists.txt b/CMakeLists.txtindex 1469a78d0b..78dc9b05e8 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -104,7 +104,7 @@ function(macos_test_fixrpath)if (APPLE AND BUILD_TESTING)foreach(TEST IN LISTS ARGN)set_property(TARGET ${TEST}- PROPERTY BUILD_RPATH "@loader_path/../../../../lib;@loader_path/../lib;@loader_path/../Frameworks;${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}")+ PROPERTY BUILD_RPATH "@loader_path/../../../../lib;@loader_path/../lib;@loader_path/../Frameworks;${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_LIBDIR}")endforeach()endif()endfunction()diff --git a/cmake/modules/FindPyQt6.cmake b/cmake/modules/FindPyQt6.cmakenew file mode 100644index 0000000000..4b39ff73ff--- /dev/null+++ b/cmake/modules/FindPyQt6.cmake@@ -0,0 +1,72 @@+# Find PyQt6+# ~~~~~~~~~~+# SPDX-FileCopyrightText: 2014 Simon Edwards <[email protected]>+# SPDX-FileCopyrightText: 2021 L. E. Segovia <[email protected]>+#+# SPDX-License-Identifier: BSD-3-Clause+#+# PyQt6 website: http://www.riverbankcomputing.co.uk/pyqt/index.php+#+# Find the installed version of PyQt6. FindPyQt6 should only be called after+# Python has been found.+#+# This file defines the following variables:+#+# PYQT6_VERSION - The version of PyQt6 found expressed as a 6 digit hex number+# suitable for comparison as a string+#+# PYQT6_VERSION_STR - The version of PyQt6 as a human readable string.+#+# PYQT6_SIP_DIR - The directory holding the PyQt6 .sip files.++IF(EXISTS PYQT6_VERSION)+ # Already in cache, be silent+ SET(PYQT6_FOUND TRUE)+ELSE(EXISTS PYQT6_VERSION)++ FIND_FILE(_find_pyqt6_py FindPyQt6.py PATHS ${CMAKE_MODULE_PATH})+++ if (WIN32)+ # python modules need Qt and C++ libraries be added via explicit+ # calls to os.add_dll_directory(), so we should provide it with+ # correct paths+ get_target_property(LIBQT6CORE_PATH Qt6::Core IMPORTED_LOCATION_RELEASE)+ get_filename_component(LIBQT6CORE_PATH ${LIBQT6CORE_PATH} PATH)+ get_filename_component(MINGW_PATH ${CMAKE_CXX_COMPILER} PATH)++ set(_pyqt6_python_path "${KRITA_PYTHONPATH_V4};${KRITA_PYTHONPATH_V5};$ENV{PYTHONPATH}")++ EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E env+ "PYTHONPATH=${_pyqt6_python_path}"+ "PYTHONDLLPATH=${LIBQT6CORE_PATH};${MINGW_PATH};"+ ${Python_EXECUTABLE} ${_find_pyqt6_py}+ OUTPUT_VARIABLE pyqt6_config)+ else (WIN32)+ set(_pyqt6_python_path "${KRITA_PYTHONPATH_V4}:${KRITA_PYTHONPATH_V5}:$ENV{PYTHONPATH}")++ EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E env+ "PYTHONPATH=${_pyqt6_python_path}"+ ${Python_EXECUTABLE} ${_find_pyqt6_py}+ OUTPUT_VARIABLE pyqt6_config)+ endif (WIN32)++ IF(pyqt6_config)+ STRING(REGEX REPLACE "^pyqt_version:([^\n]+).*$" "\\1" PYQT6_VERSION ${pyqt6_config})+ STRING(REGEX REPLACE ".*\npyqt_version_str:([^\n]+).*$" "\\1" PYQT6_VERSION_STR ${pyqt6_config})+ STRING(REGEX REPLACE ".*\npyqt_sip_dir:([^\n]+).*$" "\\1" PYQT6_SIP_DIR ${pyqt6_config})++ SET(PYQT6_FOUND TRUE)+ ENDIF(pyqt6_config)++ IF(PYQT6_FOUND)+ IF(NOT PYQT6_FIND_QUIETLY)+ MESSAGE(STATUS "Found PyQt6 version: ${PYQT6_VERSION_STR}")+ ENDIF(NOT PYQT6_FIND_QUIETLY)+ ELSE(PYQT6_FOUND)+ IF(PYQT6_FIND_REQUIRED)+ MESSAGE(FATAL_ERROR "Could not find PyQt6.")+ ENDIF(PYQT6_FIND_REQUIRED)+ ENDIF(PYQT6_FOUND)++ENDIF(EXISTS PYQT6_VERSION)diff --git a/cmake/modules/FindPyQt6.py b/cmake/modules/FindPyQt6.pynew file mode 100644index 0000000000..bc53e469f0--- /dev/null+++ b/cmake/modules/FindPyQt6.py@@ -0,0 +1,41 @@+# SPDX-FileCopyrightText: 2014 Simon Edwards <[email protected]>+# SPDX-FileCopyrightText: 2021 L. E. Segovia <[email protected]>+#+# SPDX-License-Identifier: BSD-3-Clause+#++import re+import sys+import os+import sysconfig++try:+ # On Windows and Python 3.8+ python doesn't load module DLL's+ # from the current PATH environment, therefore we should add+ # path to Qt's DLL's manually. This variable is passed from+ # FindPyQt6.cmake+ for path in os.environ['PYTHONDLLPATH'].split(';'):+ os.add_dll_directory(path)+except:+ pass++import PyQt6.QtCore++print("pyqt_version:%06.0x" % PyQt6.QtCore.PYQT_VERSION)+print("pyqt_version_str:%s" % PyQt6.QtCore.PYQT_VERSION_STR)++pyqt_version_tag = ""+in_t = False++# If we use a system install with a custom PYTHONPATH, PyQt6+# may not be within the system tree.+pyqt6_dir = os.path.dirname(PyQt6.__file__)+lib_site_packages = sysconfig.get_path('platlib')+# Check this first.+if pyqt6_dir.startswith(lib_site_packages):+ pyqt_sip_dir = os.path.join(sysconfig.get_path('platlib'), "PyQt6", "bindings")+else:+ # If so, change it.+ pyqt_sip_dir = os.path.join(pyqt6_dir, "bindings")++print("pyqt_sip_dir:%s" % pyqt_sip_dir)diff --git a/cmake/modules/SIPMacros.cmake b/cmake/modules/SIPMacros.cmakeindex cba0d86208..113a3b3234 100644--- a/cmake/modules/SIPMacros.cmake+++ b/cmake/modules/SIPMacros.cmake@@ -148,13 +148,23 @@ else()if (SIP_MODULE)set(sip_name ${SIP_MODULE})else()- set(sip_name "sip")+ set(sip_name "PyQt${QT_MAJOR_VERSION}.sip")+ endif()++ if (QT_MAJOR_VERSION STREQUAL "6")+ set(abi_version "13.0")+ set(sip_disabled_features "[\"Krita_Qt5\"]")+ else()+ set(abi_version "12.8")+ set(sip_disabled_features "[]")endif()set(module_tags)- foreach(_tag ${SIP_TAGS})- string(APPEND module_tags "\"${_tag}\",")- endforeach()+ if (QT_MAJOR_VERSION STREQUAL "5")+ foreach(_tag ${SIP_TAGS})+ string(APPEND module_tags "\"${_tag}\",")+ endforeach()+ endif()set(module_tags "[${module_tags}]")set(sip_include_dirs)diff --git a/cmake/modules/pyproject.toml.in b/cmake/modules/pyproject.toml.inindex 462063bac1..fd0fa7a091 100644--- a/cmake/modules/pyproject.toml.in+++ b/cmake/modules/pyproject.toml.in@@ -9,8 +9,9 @@ name = "@module_name_toml@"sip-module = "@sip_name@"sip-include-dirs = @sip_include_dirs@sip-files-dir = "@module_srcs@"-abi-version = "12.8"+abi-version = "@abi_version@"[tool.sip.bindings.@module_name_toml@]pep484-pyi = truetags = @module_tags@+disabled-features = @sip_disabled_features@diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txtindex 09ac696d8e..6483999114 100644--- a/plugins/CMakeLists.txt+++ b/plugins/CMakeLists.txt@@ -11,6 +11,6 @@ add_subdirectory( paintops )add_subdirectory( tools )add_subdirectory( qt )-if (HAVE_PYQT5 AND HAVE_SIP AND HAVE_PYTHONLIBS)+if ((HAVE_PYQT5 OR HAVE_PYQT6) AND HAVE_SIP AND HAVE_PYTHONLIBS)add_subdirectory( python )endif()diff --git a/plugins/extensions/pykrita/plugin/CMakeLists.txt b/plugins/extensions/pykrita/plugin/CMakeLists.txtindex 512d9c6b2d..e908ed2f07 100644--- a/plugins/extensions/pykrita/plugin/CMakeLists.txt+++ b/plugins/extensions/pykrita/plugin/CMakeLists.txt@@ -50,7 +50,7 @@ install(TARGETS kritapykrita DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})# Install "built-in" apiinstall(DIRECTORY krita- DESTINATION ${LIB_INSTALL_DIR}/krita-python-libs+ DESTINATION ${KDE_INSTALL_LIBDIR}/krita-python-libsFILES_MATCHING PATTERN "*.py")diff --git a/plugins/extensions/pykrita/plugin/PythonPluginManager.cpp b/plugins/extensions/pykrita/plugin/PythonPluginManager.cppindex ce1cee23f7..58a9c73faf 100644--- a/plugins/extensions/pykrita/plugin/PythonPluginManager.cpp+++ b/plugins/extensions/pykrita/plugin/PythonPluginManager.cpp@@ -13,11 +13,11 @@#include <QFile>#include <QFileInfo>#include <KoResourcePaths.h>-#include <KConfigCore/KConfig>-#include <KConfigCore/KDesktopFile>-#include <KI18n/KLocalizedString>-#include <KConfigCore/KSharedConfig>-#include <KConfigCore/KConfigGroup>+#include <KConfig>+#include <KDesktopFile>+#include <KLocalizedString>+#include <KSharedConfig>+#include <KConfigGroup>#include <KisUsageLogger.h>diff --git a/plugins/extensions/pykrita/plugin/PythonPluginsModel.cpp b/plugins/extensions/pykrita/plugin/PythonPluginsModel.cppindex 6e5a7cc8f7..04137cf273 100644--- a/plugins/extensions/pykrita/plugin/PythonPluginsModel.cpp+++ b/plugins/extensions/pykrita/plugin/PythonPluginsModel.cpp@@ -11,7 +11,7 @@#include "PythonPluginsModel.h"#include <kcolorscheme.h>-#include <KI18n/KLocalizedString>+#include <KLocalizedString>#include "PythonPluginManager.h"@@ -89,12 +89,14 @@ QVariant PythonPluginsModel::data(const QModelIndex& index, const int role) cons}}break;+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) // todo: why does this fail to build on Qt6?case Qt::ForegroundRole:if (plugin->isUnstable()) {KColorScheme scheme(QPalette::Inactive, KColorScheme::View);return scheme.foreground(KColorScheme::NegativeText).color();}break;+#endifdefault:break;}diff --git a/plugins/extensions/pykrita/plugin/utilities.cpp b/plugins/extensions/pykrita/plugin/utilities.cppindex fe2608297a..170d120b33 100644--- a/plugins/extensions/pykrita/plugin/utilities.cpp+++ b/plugins/extensions/pykrita/plugin/utilities.cpp@@ -391,12 +391,14 @@ bool Python::setPath(const QStringList& scriptPaths)paths.append(d + "/" + p2 + "/site-packages");paths.append(d + "/" + p2 + "/site-packages/PyQt5");+ paths.append(d + "/" + p2 + "/site-packages/PyQt6");}else {#endifpaths.append(originalPath + "/lib-dynload");paths.append(originalPath + "/site-packages");paths.append(originalPath + "/site-packages/PyQt5");+ paths.append(originalPath + "/site-packages/PyQt6");#ifdef Q_OS_MAC}#endifdiff --git a/plugins/extensions/pykrita/sip/CMakeLists.txt b/plugins/extensions/pykrita/sip/CMakeLists.txtindex d3e6f4262a..4f308ac53b 100644--- a/plugins/extensions/pykrita/sip/CMakeLists.txt+++ b/plugins/extensions/pykrita/sip/CMakeLists.txt@@ -20,7 +20,7 @@ if(${SIP_VERSION_STR} VERSION_LESS 5)set(SIP_EXTRA_OPTIONS ${SIP_EXTRA_OPTIONS} -n ${PYQT5_SIP_NAME})ENDIF (PYQT5_SIP_NAME)- set(PYTHON_SITE_PACKAGES_INSTALL_DIR ${LIB_INSTALL_DIR}/krita-python-libs)+ set(PYTHON_SITE_PACKAGES_INSTALL_DIR ${KDE_INSTALL_LIBDIR}/krita-python-libs)file(GLOB PYKRITA_KRITA_sip_files ./krita/*.sip)set(SIP_EXTRA_FILES_DEPEND ${PYKRITA_KRITA_sip_files})add_sip_python_module(PyKrita.krita ./krita/kritamod.sip kritalibkis kritaui kritaimage kritalibbrush)@@ -29,7 +29,7 @@ else()set(SIP_MODULE ${PYQT_SIP_NAME})set(SIP_TAGS ${PYQT_SIP_TAGS})set(SIP_INCLUDES ${PYQT_SIP_DIR})- set(PYTHON_SITE_PACKAGES_INSTALL_DIR ${LIB_INSTALL_DIR}/krita-python-libs)+ set(PYTHON_SITE_PACKAGES_INSTALL_DIR ${KDE_INSTALL_LIBDIR}/krita-python-libs)set(SIP_EXTRA_FILES_DEPEND "${CMAKE_CURRENT_SOURCE_DIR}/krita")set(SIP_EXTRA_STUBS "${CMAKE_CURRENT_SOURCE_DIR}/extra.pyi")add_sip_python_module_v5(PyKrita.krita ./krita/kritamod.sip kritalibkis kritaui kritaimage kritalibbrush)diff --git a/plugins/extensions/pykrita/sip/krita/KisCubicCurve.sip b/plugins/extensions/pykrita/sip/krita/KisCubicCurve.sipindex d1320f154c..176c9e513c 100644--- a/plugins/extensions/pykrita/sip/krita/KisCubicCurve.sip+++ b/plugins/extensions/pykrita/sip/krita/KisCubicCurve.sip@@ -47,9 +47,16 @@ public:bool isConstant(qreal x) const;void setName(const QString& name);const QString& name() const;+ %If (Krita_Qt5)static qreal interpolateLinear(qreal normalizedValue, const QVector<qreal> &transfer);const QVector<quint16> uint16Transfer(int size = 256) const;const QVector<qreal> floatTransfer(int size = 256) const;+ %End+ %If (!Krita_Qt5)+ static qreal interpolateLinear(qreal normalizedValue, const QList<qreal> &transfer);+ const QList<quint16> uint16Transfer(int size = 256) const;+ const QList<qreal> floatTransfer(int size = 256) const;+ %EndQString toString() const;void fromString(const QString&);};diff --git a/plugins/extensions/pykrita/sip/krita/ManagedColor.sip b/plugins/extensions/pykrita/sip/krita/ManagedColor.sipindex 321ceedb66..8e68225b7d 100644--- a/plugins/extensions/pykrita/sip/krita/ManagedColor.sip+++ b/plugins/extensions/pykrita/sip/krita/ManagedColor.sip@@ -26,9 +26,16 @@ public:QString colorProfile() const;bool setColorProfile(const QString &colorProfile);bool setColorSpace(const QString &colorModel, const QString &colorDepth, const QString &colorProfile);+ %If (Krita_Qt5)QVector<float> components() const;QVector<float> componentsOrdered() const;void setComponents(const QVector<float> &values);+ %End+ %If (!Krita_Qt5)+ QList<float> components() const;+ QList<float> componentsOrdered() const;+ void setComponents(const QList<float> &values);+ %EndQString toXML() const;void fromXML(const QString &xml);QString toQString();diff --git a/plugins/extensions/pykrita/sip/krita/kritamod.sip b/plugins/extensions/pykrita/sip/krita/kritamod.sipindex 4a74356b23..0f688721d2 100644--- a/plugins/extensions/pykrita/sip/krita/kritamod.sip+++ b/plugins/extensions/pykrita/sip/krita/kritamod.sip@@ -4,6 +4,8 @@#pragma GCC visibility push(default)%End+%Feature Krita_Qt5+%Import QtCore/QtCoremod.sip%Import QtGui/QtGuimod.sip%Import QtXml/QtXmlmod.sip