DtkGui
DTK Gui module
载入中...
搜索中...
未找到
ddciicon.h
浏览该文件的文档.
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
13DCORE_BEGIN_NAMESPACE
14class DDciFile;
15DCORE_END_NAMESPACE
16
17DGUI_BEGIN_NAMESPACE
18
19typedef void* DDciIconMatchResult;
20
21class DDciIconImagePrivate;
23 friend class DDciIcon;
24public:
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); }
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
59protected:
60 DDciIconImage(const QSharedPointer<DDciIconImagePrivate> &dd)
61 : d(dd) {}
62
63 QSharedPointer<DDciIconImagePrivate> d;
64};
65
66class DDciIconPrivate;
68{
69public:
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 };
81 HasPalette = 0x001
82 };
84 None = 0,
85 DontFallbackMode = 0x01,
86 RegardPaddingsAsSize = 0x02
87 };
88 Q_DECLARE_FLAGS(IconMatchedFlags, IconMatchedFlag)
89 Q_FLAGS(IconMatchedFlags);
90
91 DDciIcon();
92 explicit DDciIcon(const DCORE_NAMESPACE::DDciFile *dciFile);
93 explicit DDciIcon(const QString &fileName);
94 explicit DDciIcon(const QByteArray &data);
95 DDciIcon(const DDciIcon &other);
96 DDciIcon &operator=(const DDciIcon &other) noexcept;
97 ~DDciIcon();
98 DDciIcon(DDciIcon && other) noexcept;
99 DDciIcon &operator=(DDciIcon &&other) noexcept;
100 void swap(DDciIcon &other) noexcept { d.swap(other.d); }
101
102 bool isNull() const;
103 DDciIconMatchResult matchIcon(int size, Theme theme, Mode mode, IconMatchedFlags flags = None) const;
104
105 int actualSize(DDciIconMatchResult result) const;
106 int actualSize(int size, Theme theme, Mode mode = Normal) const;
107
108 QList<int> availableSizes(Theme theme, Mode mode = Normal) const;
109 bool isSupportedAttribute(DDciIconMatchResult result, IconAttibute attr) const;
110 static bool isSupportedAttribute(const DDciIconImage &image, IconAttibute attr);
111
112 QPixmap pixmap(qreal devicePixelRatio, int iconSize, Theme theme, Mode mode = Normal,
113 const DDciIconPalette &palette = DDciIconPalette()) const;
114 QPixmap pixmap(qreal devicePixelRatio, int iconSize, DDciIconMatchResult result,
115 const DDciIconPalette &palette = DDciIconPalette()) const;
116
117 void paint(QPainter *painter, const QRect &rect, qreal devicePixelRatio, Theme theme, Mode mode = Normal,
118 Qt::Alignment alignment = Qt::AlignCenter, const DDciIconPalette &palette = DDciIconPalette()) const;
119 void paint(QPainter *painter, const QRect &rect, qreal devicePixelRatio, DDciIconMatchResult result,
120 Qt::Alignment alignment = Qt::AlignCenter, const DDciIconPalette &palette = DDciIconPalette()) const;
121
122 DDciIconImage image(DDciIconMatchResult result, int size, qreal devicePixelRatio) const;
123
124 static DDciIcon fromTheme(const QString &name);
125 static DDciIcon fromTheme(const QString &name, const DDciIcon &fallback);
126
127 // TODO: Should be compatible with QIcon
128private:
129 QSharedDataPointer<DDciIconPrivate> d;
130#ifndef QT_NO_DATASTREAM
131 friend QDataStream &operator<<(QDataStream &, const DDciIcon &);
132 friend QDataStream &operator>>(QDataStream &, DDciIcon &);
133#endif
134};
135
136#ifndef QT_NO_DATASTREAM
137QDataStream &operator<<(QDataStream &, const DDciIcon &);
138QDataStream &operator>>(QDataStream &, DDciIcon &);
139#endif
140
141DGUI_END_NAMESPACE
142Q_DECLARE_METATYPE(DTK_GUI_NAMESPACE::DDciIcon);
Definition ddciicon.h:22
void swap(DDciIconImage &other) noexcept
Definition ddciicon.h:30
bool operator==(const DDciIconImage &other) const
Definition ddciicon.h:33
bool operator!=(const DDciIconImage &other) const
Definition ddciicon.h:36
bool isNull() const
Definition ddciicon.h:40
DCI图标调色板
Definition ddciiconpalette.h:21
Definition ddciicon.h:68
Theme
DCI图标主题
Definition ddciicon.h:76
IconMatchedFlag
DCI图标匹配参数
Definition ddciicon.h:83
DDciIcon(const DCORE_NAMESPACE::DDciFile *dciFile)
指定DCI文件的构造函数
Mode
DCI图标模式
Definition ddciicon.h:70
IconAttibute
DCI图标属性
Definition ddciicon.h:80
void swap(DDciIcon &other) noexcept
交换两个DDciIcon对象
Definition ddciicon.h:100
DCI图标调色板