Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcocoaservices.mm
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
7#include <AppKit/NSWorkspace.h>
8#include <AppKit/NSColorSampler.h>
9#include <Foundation/NSURL.h>
10
11#include <QtCore/QUrl>
12#include <QtCore/qscopedvaluerollback.h>
13
14#include <QtGui/qdesktopservices.h>
15#include <QtGui/private/qcoregraphics_p.h>
16
18
19bool QCocoaServices::openUrl(const QUrl &url)
20{
21 // avoid recursing back into self
22 if (url == m_handlingUrl)
23 return false;
24
25 return [[NSWorkspace sharedWorkspace] openURL:url.toNSURL()];
26}
27
28bool QCocoaServices::openDocument(const QUrl &url)
29{
30 return openUrl(url);
31}
32
33/* Callback from macOS that the application should handle a URL */
34bool QCocoaServices::handleUrl(const QUrl &url)
35{
36 QScopedValueRollback<QUrl> rollback(m_handlingUrl, url);
37 // FIXME: Add platform services callback from QDesktopServices::setUrlHandler
38 // so that we can warn the user if calling setUrlHandler without also setting
39 // up the matching keys in the Info.plist file (CFBundleURLTypes and friends).
40 return QDesktopServices::openUrl(url);
41}
42
44{
45public:
47 ~QCocoaColorPicker() { [m_colorSampler release]; }
48
50 {
51 [m_colorSampler showSamplerWithSelectionHandler:^(NSColor *selectedColor) {
52 emit colorPicked(qt_mac_toQColor(selectedColor));
53 }];
54 }
55private:
56 NSColorSampler *m_colorSampler = nullptr;
57};
58
59
61{
62 Q_UNUSED(parent);
63 return new QCocoaColorPicker;
64}
65
66bool QCocoaServices::hasCapability(Capability capability) const
67{
68 switch (capability) {
69 case ColorPicking: return true;
70 default: return false;
71 }
72}
73
74QT_END_NAMESPACE
void pickColor() override
bool handleUrl(const QUrl &url)
bool hasCapability(Capability capability) const override
QPlatformServiceColorPicker * colorPicker(QWindow *parent) override
bool openUrl(const QUrl &url) override
bool openDocument(const QUrl &url) override