DtkDeclarative
DTK Declarative module
载入中...
搜索中...
未找到
dquickimageprovider_p.h
1// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DQUICKIMAGEPROVIDER_P_H
6#define DQUICKIMAGEPROVIDER_P_H
7
8#include <QQuickImageProvider>
9
10#include <dtkdeclarative_global.h>
11
12DQUICK_BEGIN_NAMESPACE
13
14class DQuickIconProvider : public QQuickImageProvider
15{
16public:
18
19protected:
20 QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
21};
22
23class DQuickDciIconProvider : public QQuickImageProvider
24{
25public:
27
28protected:
29 QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
30};
31
32class ShadowImage;
33class DQuickShadowProvider : public QQuickImageProvider
34{
35public:
38
39 enum Type : quint8 {
40 Rectangle = 0,
41 Circular = 1,
42
43 Inner = 2
44 };
45
46 struct ShadowConfig {
47 quint8 type;
48 qreal cornerRadius;
49 qreal blurRadius;
50 qreal spread;
51 qreal boxSize;
52
53 ShadowConfig() {}
54 ShadowConfig(const ShadowConfig &other)
55 : type(other.type)
56 , cornerRadius(other.cornerRadius)
57 , blurRadius(other.blurRadius)
58 , spread(other.spread)
59 , boxSize(other.boxSize) {}
60
61 inline bool isInner() const {
62 return type & Inner;
63 }
64 inline bool isCircular() const {
65 return type & Circular;
66 }
67 inline QString toString() const {
68 return QString("%1.%2.%3.%4.%5").arg(type).arg(cornerRadius).arg(blurRadius).arg(spread).arg(boxSize);
69 }
70
71 inline ShadowConfig &operator=(const ShadowConfig &other) {
72 type = other.type;
73 cornerRadius = other.cornerRadius;
74 blurRadius = other.blurRadius;
75 spread = other.spread;
76
77 return *this;
78 }
79
80 inline bool operator==(const ShadowConfig &other) const {
81 return type == other.type
82 && qFuzzyCompare(cornerRadius, other.cornerRadius)
83 && qFuzzyCompare(blurRadius, other.blurRadius)
84 && qFuzzyCompare(spread, other.spread)
85 && qFuzzyCompare(boxSize, other.boxSize);
86 }
87 inline bool operator!=(const ShadowConfig &other) const {
88 return !operator==(other);
89 }
90
91 friend Q_CORE_EXPORT uint qHash(const ShadowConfig &config, uint seed) noexcept;
92 };
93
94 static QUrl toUrl(qreal boxSize, qreal cornerRadius, qreal shadowBlur, QColor color,
95 qreal xOffset, qreal yOffset, qreal spread, bool hollow, bool inner);
96
97protected:
98 QImage requestImage(const QString &id, QSize *size, const QSize &requestedSize) override;
99
100 inline static QString getShadowFilePath(const DQuickShadowProvider::ShadowConfig &config)
101 {
102 return ":/dtk/declarative/shadow/" + config.toString() + ".png";
103 }
104 ShadowImage *getRawShadow(const ShadowConfig &config);
105
106private:
107 friend class ShadowImage;
108 QHash<ShadowConfig, ShadowImage*> cache;
109};
110
111inline uint qHash(const DTK_QUICK_NAMESPACE::DQuickShadowProvider::ShadowConfig &config, uint seed = 0) noexcept {
112 return QT_PREPEND_NAMESPACE(qHash)(static_cast<uint>(config.type), seed) ^
113 QT_PREPEND_NAMESPACE(qHash)(config.cornerRadius, seed) ^
114 QT_PREPEND_NAMESPACE(qHash)(config.blurRadius, seed) ^
115 QT_PREPEND_NAMESPACE(qHash)(config.spread, seed);
116}
117
118DQUICK_END_NAMESPACE
119
120#endif // DQUICKIMAGEPROVIDER_P_H
Definition dquickimageprovider_p.h:24
Definition dquickimageprovider_p.h:15
Definition dquickimageprovider_p.h:34
Definition dquickimageprovider.cpp:276
Definition dquickimageprovider_p.h:46