macOS: Implement QPlatformServiceColorPicker via NSColorSampler
The default behavior for QColorDialog is to use the native dialog, but for clients that implement their own color dialog we should provide the plumbing to do the actual color picking. The fallback path for this on macOS involves grabbing the screen, which brings up the permission dialog. The NSColorSampler API does not have this issue. [ChangeLog][macOS] Non native color dialogs now use native color picking when picking colors from the screen. Pick-to: 6.6 Change-Id: Idd08a90a3747546fd9825431ab7a4f5b5fa40784 Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io> Reviewed-by: Doris Verria <doris.verria@qt.io>bb10
parent
1202594db6
commit
9590ed6ba6
|
|
@ -11,8 +11,12 @@ QT_BEGIN_NAMESPACE
|
|||
class QCocoaServices : public QPlatformServices
|
||||
{
|
||||
public:
|
||||
bool hasCapability(Capability capability) const override;
|
||||
|
||||
bool openUrl(const QUrl &url) override;
|
||||
bool openDocument(const QUrl &url) override;
|
||||
|
||||
QPlatformServiceColorPicker *colorPicker(QWindow *parent) override;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@
|
|||
#include "qcocoaservices.h"
|
||||
|
||||
#include <AppKit/NSWorkspace.h>
|
||||
#include <AppKit/NSColorSampler.h>
|
||||
#include <Foundation/NSURL.h>
|
||||
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtGui/private/qcoregraphics_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
|
@ -20,4 +22,35 @@ bool QCocoaServices::openDocument(const QUrl &url)
|
|||
return openUrl(url);
|
||||
}
|
||||
|
||||
class QCocoaColorPicker : public QPlatformServiceColorPicker
|
||||
{
|
||||
public:
|
||||
QCocoaColorPicker() : m_colorSampler([NSColorSampler new]) {}
|
||||
~QCocoaColorPicker() { [m_colorSampler release]; }
|
||||
|
||||
void pickColor() override
|
||||
{
|
||||
[m_colorSampler showSamplerWithSelectionHandler:^(NSColor *selectedColor) {
|
||||
emit colorPicked(qt_mac_toQColor(selectedColor));
|
||||
}];
|
||||
}
|
||||
private:
|
||||
NSColorSampler *m_colorSampler = nullptr;
|
||||
};
|
||||
|
||||
|
||||
QPlatformServiceColorPicker *QCocoaServices::colorPicker(QWindow *parent)
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return new QCocoaColorPicker;
|
||||
}
|
||||
|
||||
bool QCocoaServices::hasCapability(Capability capability) const
|
||||
{
|
||||
switch (capability) {
|
||||
case ColorPicking: return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
Loading…
Reference in New Issue