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
5
6#include <AppKit/NSWorkspace.h>
7#include <AppKit/NSColorSampler.h>
8#include <Foundation/NSURL.h>
9
10#include <QtCore/QUrl>
11#include <QtCore/qscopedvaluerollback.h>
12
13#include <QtGui/qdesktopservices.h>
14#include <QtGui/private/qcoregraphics_p.h>
15
17
18bool QCocoaServices::openUrl(const QUrl &url)
19{
20 // avoid recursing back into self
21 if (url == m_handlingUrl)
22 return false;
23
24 return [[NSWorkspace sharedWorkspace] openURL:url.toNSURL()];
25}
26
27bool QCocoaServices::openDocument(const QUrl &url)
28{
29 return openUrl(url);
30}
31
32/* Callback from macOS that the application should handle a URL */
33bool QCocoaServices::handleUrl(const QUrl &url)
34{
35 QScopedValueRollback<QUrl> rollback(m_handlingUrl, url);
36 // FIXME: Add platform services callback from QDesktopServices::setUrlHandler
37 // so that we can warn the user if calling setUrlHandler without also setting
38 // up the matching keys in the Info.plist file (CFBundleURLTypes and friends).
39 return QDesktopServices::openUrl(url);
40}
41
43{
44public:
46 ~QCocoaColorPicker() { [m_colorSampler release]; }
47
49 {
50 [m_colorSampler showSamplerWithSelectionHandler:^(NSColor *selectedColor) {
51 emit colorPicked(qt_mac_toQColor(selectedColor));
52 }];
53 }
54private:
55 NSColorSampler *m_colorSampler = nullptr;
56};
57
58
60{
61 Q_UNUSED(parent);
62 return new QCocoaColorPicker;
63}
64
65bool QCocoaServices::hasCapability(Capability capability) const
66{
67 switch (capability) {
68 case ColorPicking: return true;
69 default: return false;
70 }
71}
72
73QT_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
Combined button and popup list for selecting options.