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
qapplefileiconengine.mm
Go to the documentation of this file.
1// Copyright (C) 2025 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
6
7#if defined(Q_OS_MACOS)
8# include <AppKit/AppKit.h>
9#elif defined(QT_PLATFORM_UIKIT)
10# include <UIKit/UIKit.h>
11#endif
12
13#include <QtCore/qurl.h>
14#include <QtGui/private/qcoregraphics_p.h>
15
17
18using namespace Qt::StringLiterals;
19
20QAppleFileIconEngine::QAppleFileIconEngine(const QFileInfo &info, QPlatformTheme::IconOptions opts)
21 : QAbstractFileIconEngine(info, opts)
22{
23#if defined(Q_OS_MACOS)
24 m_image = [[NSWorkspace sharedWorkspace] iconForFile:fileInfo().canonicalFilePath().toNSString()];
25#elif defined(QT_PLATFORM_UIKIT)
26 const QUrl url = QUrl::fromLocalFile(fileInfo().canonicalFilePath());
27 const auto controller = [UIDocumentInteractionController interactionControllerWithURL:url.toNSURL()];
28 const auto allIcons = controller.icons;
29 m_image = allIcons.count > 0 ? [allIcons firstObject] : nil;
30#endif
31 if (m_image)
32 [m_image retain];
33}
34
35QAppleFileIconEngine::~QAppleFileIconEngine()
36{
37 if (m_image)
38 [m_image release];
39}
40
41QList<QSize> QAppleFileIconEngine::availableSizes(QIcon::Mode, QIcon::State)
42{
43 return QAppleIconEngine::availableIconSizes();
44}
45
46bool QAppleFileIconEngine::isNull()
47{
48 return m_image == nil;
49}
50
51QPixmap QAppleFileIconEngine::filePixmap(const QSize &size, QIcon::Mode, QIcon::State)
52{
53 if (!m_image)
54 return QPixmap();
55
56 const QSize preferredSize = QSize(m_image.size.width,
57 m_image.size.height).scaled(size, Qt::KeepAspectRatio);
58
59 if (m_pixmap.size() == preferredSize)
60 return m_pixmap;
61
62#if defined(Q_OS_MACOS)
63 m_pixmap = qt_mac_toQPixmap(m_image, preferredSize);
64#elif defined(QT_PLATFORM_UIKIT)
65 m_pixmap = QPixmap::fromImage(qt_mac_toQImage(m_image, preferredSize));
66#endif
67 return m_pixmap;
68}
69
70QT_END_NAMESPACE