blob: 87212c265c9d4fa1d9fbf0a6e7db76fed82d6717 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qcocoaservices.h"
#include <AppKit/NSWorkspace.h>
#include <AppKit/NSColorSampler.h>
#include <Foundation/NSURL.h>
#include <QtCore/QUrl>
#include <QtCore/qscopedvaluerollback.h>
#include <QtGui/qdesktopservices.h>
#include <QtGui/private/qcoregraphics_p.h>
QT_BEGIN_NAMESPACE
bool QCocoaServices::openUrl(const QUrl &url)
{
// avoid recursing back into self
if (url == m_handlingUrl)
return false;
return [[NSWorkspace sharedWorkspace] openURL:url.toNSURL()];
}
bool QCocoaServices::openDocument(const QUrl &url)
{
return openUrl(url);
}
/* Callback from macOS that the application should handle a URL */
bool QCocoaServices::handleUrl(const QUrl &url)
{
QScopedValueRollback<QUrl> rollback(m_handlingUrl, url);
// FIXME: Add platform services callback from QDesktopServices::setUrlHandler
// so that we can warn the user if calling setUrlHandler without also setting
// up the matching keys in the Info.plist file (CFBundleURLTypes and friends).
return QDesktopServices::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
|