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
qappleiconengine_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 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
4#ifndef QAPPLEICONENGINE_P_H
5#define QAPPLEICONENGINE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtGui/qiconengine.h>
19
20#include <QtCore/qhash.h>
21
22#include <QtCore/private/qcore_mac_p.h>
23
26
28
29class Q_GUI_EXPORT QAppleIconEngine : public QIconEngine
30{
31public:
32 QAppleIconEngine(const QString &iconName);
33 ~QAppleIconEngine();
34 QIconEngine *clone() const override;
35 QString key() const override;
36 QString iconName() override;
37 bool isNull() override;
38
39 QList<QSize> availableSizes(QIcon::Mode, QIcon::State) override;
40 QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
41 QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override;
42 QPixmap scaledPixmap(const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale) override;
43 void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override;
44
45 static QList<QSize> availableIconSizes(double aspectRatio = 1.0);
46
47private:
48 const QString m_iconName;
49#if defined(Q_OS_MACOS)
50 const NSImage *m_image;
51#elif defined(QT_PLATFORM_UIKIT)
52 const UIImage *m_image;
53#endif
54 struct CacheKey {
55 constexpr CacheKey(QIcon::Mode mode, QIcon::State state, QSize size, qreal scale) noexcept
56 : modeAndState((quint64(mode) << 32) | state), size(size), scale(scale)
57 {}
58
59 quint64 modeAndState;
60 QSize size;
61 qreal scale;
62
63 friend constexpr bool operator==(const CacheKey &lhs, const CacheKey &rhs) noexcept
64 {
65 return lhs.modeAndState == rhs.modeAndState
66 && lhs.size == rhs.size
67 && lhs.scale == rhs.scale;
68 }
69 friend constexpr size_t qHash(const CacheKey &key, size_t seed) noexcept
70 { return qHashMulti(seed, key.modeAndState, key.size, key.scale); }
71 };
72 mutable QHash<CacheKey, QPixmap> m_cache;
73};
74
75QT_END_NAMESPACE
76
77#endif // QAPPLEICONENGINE_P_H
Q_FORWARD_DECLARE_OBJC_CLASS(NSImage)
Q_FORWARD_DECLARE_OBJC_CLASS(UIImage)
Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(RunLoopModeTracker))