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++

Use native color picking api for screen color sampling

Luna Lovecraft256654ff31e9
diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txt
index 068cb2bf57..d57453b562 100644
--- a/libs/ui/CMakeLists.txt
+++ b/libs/ui/CMakeLists.txt
@@ -778,6 +778,13 @@ if (HAVE_X11)
endif()
if (QT_MAJOR_VERSION STREQUAL "6")
+ #Need provate headers to access platform stuff for proper screen color sampling
+ set_source_files_properties(
+ widgets/KisScreenColorSampler.cpp
+ PROPERTIES
+ INCLUDE_DIRECTORIES "${Qt${QT_MAJOR_VERSION}Gui_PRIVATE_INCLUDE_DIRS}"
+ )
+
target_link_libraries(kritaui
PRIVATE
Qt6::OpenGLWidgets
diff --git a/libs/ui/widgets/KisScreenColorSampler.cpp b/libs/ui/widgets/KisScreenColorSampler.cpp
index 8e9aa58d2e..5429dfdf15 100644
--- a/libs/ui/widgets/KisScreenColorSampler.cpp
+++ b/libs/ui/widgets/KisScreenColorSampler.cpp
@@ -109,6 +109,14 @@ void KisScreenColorSampler::setPerformRealColorSamplingOfCanvas(bool enable)
void KisScreenColorSampler::sampleScreenColor()
{
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ if (!performRealColorSamplingOfCanvas()) {
+ if (tryToUsePlatformIntegration()) {
+ return;
+ }
+ }
+#endif
+
m_d->updateInputGrabberWidget();
if (m_d->inputGrabberWidget == nullptr) {
Q_EMIT sigNewColorSampled(currentColor());
@@ -325,3 +333,35 @@ KIS_DECLARE_STATIC_INITIALIZER {
KisDlgInternalColorSelector::setScreenColorSamplerFactory(KisScreenColorSampler::createScreenColorSampler);
}
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+#include <QtGui/private/qguiapplication_p.h>
+#include <QtGui/qpa/qplatformintegration.h>
+#include <qpa/qplatformservices.h>
+
+bool KisScreenColorSampler::tryToUsePlatformIntegration()
+{
+ //Uses the screenshot portal on linux, since we can't just look at raw pixels anymore
+ auto *services = QGuiApplicationPrivate::platformIntegration()->services();
+
+ if (services && services->hasCapability(QPlatformServices::Capability::ColorPicking)) {
+ QPlatformServiceColorPicker *colorPicker = services->colorPicker(QGuiApplication::allWindows().first());
+
+ if (colorPicker) {
+ connect(colorPicker, SIGNAL(colorPicked(const QColor&)), this, SLOT(colorPicked(const QColor&)));
+
+ colorPicker->pickColor();
+ return true;
+ }
+ }
+ return false;
+}
+
+void KisScreenColorSampler::colorPicked(const QColor& color)
+{
+ KoColor col;
+ col.fromQColor(color);
+ setCurrentColor(col);
+
+ Q_EMIT sigNewColorSampled(currentColor());
+}
+#endif
diff --git a/libs/ui/widgets/KisScreenColorSampler.h b/libs/ui/widgets/KisScreenColorSampler.h
index ef157be513..a323909e93 100644
--- a/libs/ui/widgets/KisScreenColorSampler.h
+++ b/libs/ui/widgets/KisScreenColorSampler.h
@@ -62,6 +62,12 @@ private:
void updateColorLabelText(const QPoint &globalPos);
void releaseColorSampling();
void continueUpdateColorSampling(const QPoint &globalPos);
+
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ bool tryToUsePlatformIntegration();
+private Q_SLOTS:
+ void colorPicked(const QColor &color);
+#endif
};
class KisScreenColorSamplingEventFilter : public QObject {