diff options
author | Oliver Eftevaag <[email protected]> | 2022-07-26 19:14:39 +0200 |
---|---|---|
committer | Oliver Eftevaag <[email protected]> | 2023-12-08 04:08:47 +0100 |
commit | 27c98f5a9a3047b7e33c1873d5fb23e7098e9661 (patch) | |
tree | 7cc20da9d9575b4cf1d0a39a42acc9ef044fc1b2 | |
parent | 2932810fe7c945b67810121ebf3032a122a27832 (diff) |
Use the PlatformServiceColorPicker for the ColorDialog's eye dropper
On wayland, it's not possible to use QScreen::grabWindow(), in order to
to pick a color from the screen.
However, it is possible to use the XDG desktop portal, to pick a color
for us.
In qtbase the commit 00a8957cef8f9406346d299da03f595427078f43 added a
new virtual function pickColor() to QPlatformService.
This patch takes advantage of this new API, to prioritize using this new
platform service if available, and fallback to the old behavior in case
it's not supported for the current platform.
Change-Id: Ia155531ff4e6ee1446f122dcb44d90753c11846b
Reviewed-by: Tor Arne Vestbø <[email protected]>
-rw-r--r-- | src/quickdialogs/quickdialogsquickimpl/qquickcolordialogimpl.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/quickdialogs/quickdialogsquickimpl/qquickcolordialogimpl.cpp b/src/quickdialogs/quickdialogsquickimpl/qquickcolordialogimpl.cpp index 3b45cb823e..6772f24faa 100644 --- a/src/quickdialogs/quickdialogsquickimpl/qquickcolordialogimpl.cpp +++ b/src/quickdialogs/quickdialogsquickimpl/qquickcolordialogimpl.cpp @@ -9,6 +9,7 @@ #include <QtQuickTemplates2/private/qquickslider_p.h> #include <qpa/qplatformintegration.h> +#include <qpa/qplatformservices.h> #include <private/qguiapplication_p.h> QT_BEGIN_NAMESPACE @@ -91,7 +92,7 @@ QQuickColorDialogImplAttached *QQuickColorDialogImplPrivate::attachedOrWarn() void QQuickColorDialogImplPrivate::eyeDropperEnter() { - Q_Q(const QQuickColorDialogImpl); + Q_Q(QQuickColorDialogImpl); if (m_eyeDropperMode) return; @@ -104,6 +105,19 @@ void QQuickColorDialogImplPrivate::eyeDropperEnter() m_eyeDropperWindow = window; } + if (auto *platformServices = QGuiApplicationPrivate::platformIntegration()->services(); + platformServices && platformServices->hasCapability(QPlatformServices::Capability::ColorPicking)) { + if (auto *colorPickerService = platformServices->colorPicker(m_eyeDropperWindow)) { + q->connect(colorPickerService, &QPlatformServiceColorPicker::colorPicked, q, + [q, colorPickerService](const QColor &color) { + colorPickerService->deleteLater(); + q->setColor(color); + }); + colorPickerService->pickColor(); + return; + } + } + m_eyeDropperPreviousColor = q->color(); if (!bool(eyeDropperEventFilter)) @@ -423,10 +437,13 @@ void QQuickColorDialogImpl::setOptions(const QSharedPointer<QColorDialogOptions> QQuickColorDialogImplAttached *attached = d->attachedOrWarn(); if (attached) { - const bool screenGrabbingAllowed = QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ScreenWindowGrabbing); + const auto *integration = QGuiApplicationPrivate::platformIntegration(); + const bool canSupportEyeDropper = + integration->hasCapability(QPlatformIntegration::ScreenWindowGrabbing) + || integration->services()->hasCapability(QPlatformServices::Capability::ColorPicking); const bool offscreen = qgetenv("QT_QPA_PLATFORM").compare(QLatin1String("offscreen"), Qt::CaseInsensitive) == 0; const bool noEyeDropperButton = (d->options && d->options->options() & QColorDialogOptions::NoEyeDropperButton); - attached->eyeDropperButton()->setVisible(!noEyeDropperButton && screenGrabbingAllowed && !offscreen); + attached->eyeDropperButton()->setVisible(!noEyeDropperButton && canSupportEyeDropper && !offscreen); if (d->options) { attached->buttonBox()->setVisible( |