Debian Codegraph @

include/util/ddciicon.h

raw
1 // SPDX-FileCopyrightText: 2022-2023 UnionTech Software Technology Co., Ltd.
2 //
3 // SPDX-License-Identifier: LGPL-3.0-or-later
4
5 #pragma once
6 #include "ddciiconpalette.h"
7
8 #include <dtkgui_global.h>
9
10 #include <QPixmap>
11 #include <QSharedPointer>
12
13 DCORE_BEGIN_NAMESPACE
14 class DDciFile;
15 DCORE_END_NAMESPACE
16
17 DGUI_BEGIN_NAMESPACE
18
19 typedef void* DDciIconMatchResult;
20
21 class DDciIconImagePrivate;
22 class DDciIconImage {
23 friend class DDciIcon;
24 public:
25 DDciIconImage() = default;
26 DDciIconImage(const DDciIconImage &other);
27 DDciIconImage &operator=(const DDciIconImage &other) noexcept;
28 DDciIconImage(DDciIconImage && other) noexcept;
29 DDciIconImage &operator=(DDciIconImage &&other) noexcept;
30 void swap(DDciIconImage &other) noexcept { d.swap(other.d); }
31 ~DDciIconImage();
32
33 bool operator==(const DDciIconImage &other) const {
34 return d == other.d;
35 }
36 bool operator!=(const DDciIconImage &other) const {
37 return d != other.d;
38 }
39
40 inline bool isNull() const {
41 return !d;
42 }
43 void reset();
44
45 QImage toImage(const DDciIconPalette &palette = DDciIconPalette()) const;
46 void paint(QPainter *painter, const QRectF &rect, Qt::Alignment alignment = Qt::AlignCenter,
47 const DDciIconPalette &palette = DDciIconPalette()) const;
48
49 bool hasPalette() const;
50 bool supportsAnimation() const;
51 bool atBegin() const;
52 bool atEnd() const;
53 bool jumpToNextImage();
54 int loopCount() const;
55 int maxImageCount() const;
56 int currentImageDuration() const;
57 int currentImageNumber() const;
58
59 protected:
60 DDciIconImage(const QSharedPointer<DDciIconImagePrivate> &dd)
61 : d(dd) {}
62
63 QSharedPointer<DDciIconImagePrivate> d;
64 };
65
66 class DDciIconPrivate;
67 class DDciIcon
68 {
69 public:
70 enum Mode {
71 Normal = 0,
72 Disabled = 1,
73 Hover = 2,
74 Pressed = 3
75 };
76 enum Theme {
77 Light = 0,
78 Dark = 1
79 };
80 D_DECL_DEPRECATED enum IconAttibute {
81 HasPalette = 0x001
82 };
83 using IconAttribute = DDciIcon::IconAttibute;
84 enum IconMatchedFlag {
85 None = 0,
86 DontFallbackMode = 0x01,
87 RegardPaddingsAsSize = 0x02
88 };
89 Q_DECLARE_FLAGS(IconMatchedFlags, IconMatchedFlag)
90 Q_FLAGS(IconMatchedFlags);
91
92 DDciIcon();
93 explicit DDciIcon(const DCORE_NAMESPACE::DDciFile *dciFile);
94 explicit DDciIcon(const QString &fileName);
95 explicit DDciIcon(const QByteArray &data);
96 DDciIcon(const DDciIcon &other);
97 DDciIcon &operator=(const DDciIcon &other) noexcept;
98 ~DDciIcon();
99 DDciIcon(DDciIcon && other) noexcept;
100 DDciIcon &operator=(DDciIcon &&other) noexcept;
101 void swap(DDciIcon &other) noexcept { d.swap(other.d); }
102
103 bool isNull() const;
104 DDciIconMatchResult matchIcon(int size, Theme theme, Mode mode, IconMatchedFlags flags = None) const;
105
106 int actualSize(DDciIconMatchResult result) const;
107 int actualSize(int size, Theme theme, Mode mode = Normal) const;
108
109 QList<int> availableSizes(Theme theme, Mode mode = Normal) const;
110 bool isSupportedAttribute(DDciIconMatchResult result, IconAttribute attr) const;
111 static bool isSupportedAttribute(const DDciIconImage &image, IconAttribute attr);
112
113 QPixmap pixmap(qreal devicePixelRatio, int iconSize, Theme theme, Mode mode = Normal,
114 const DDciIconPalette &palette = DDciIconPalette()) const;
115 QPixmap pixmap(qreal devicePixelRatio, int iconSize, DDciIconMatchResult result,
116 const DDciIconPalette &palette = DDciIconPalette()) const;
117
118 void paint(QPainter *painter, const QRect &rect, qreal devicePixelRatio, Theme theme, Mode mode = Normal,
119 Qt::Alignment alignment = Qt::AlignCenter, const DDciIconPalette &palette = DDciIconPalette()) const;
120 void paint(QPainter *painter, const QRect &rect, qreal devicePixelRatio, DDciIconMatchResult result,
121 Qt::Alignment alignment = Qt::AlignCenter, const DDciIconPalette &palette = DDciIconPalette()) const;
122
123 DDciIconImage image(DDciIconMatchResult result, int size, qreal devicePixelRatio) const;
124
125 static DDciIcon fromTheme(const QString &name);
126 static DDciIcon fromTheme(const QString &name, const DDciIcon &fallback);
127
128 // TODO: Should be compatible with QIcon
129 private:
130 QSharedDataPointer<DDciIconPrivate> d;
131 #ifndef QT_NO_DATASTREAM
132 friend QDataStream &operator<<(QDataStream &, const DDciIcon &);
133 friend QDataStream &operator>>(QDataStream &, DDciIcon &);
134 #endif
135 };
136
137 #ifndef QT_NO_DATASTREAM
138 QDataStream &operator<<(QDataStream &, const DDciIcon &);
139 QDataStream &operator>>(QDataStream &, DDciIcon &);
140 #endif
141
142 DGUI_END_NAMESPACE
143 Q_DECLARE_METATYPE(DTK_GUI_NAMESPACE::DDciIcon);