DtkDeclarative
DTK Declarative module
载入中...
搜索中...
未找到
dqmlglobalobject_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 DQMLGLOBALOBJECT_P_H
6#define DQMLGLOBALOBJECT_P_H
7
8#include <dtkdeclarative_global.h>
9
10#include <DPlatformThemeProxy>
11#include <DWindowManagerHelper>
12#include <DGuiApplicationHelper>
13#include <DDciIconPalette>
14#include <DObject>
15
16#include <QQuickWindow>
17#include <QQmlComponent>
18#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
19#include <QPainter>
20#endif
21
22#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
23QT_BEGIN_NAMESPACE
24class QQuickPalette;
25QT_END_NAMESPACE
26#endif
27
28DGUI_BEGIN_NAMESPACE
29class DFontManager;
30DGUI_END_NAMESPACE
31
32DGUI_USE_NAMESPACE
33
34DQUICK_BEGIN_NAMESPACE
35
36class DColor
37{
38 Q_GADGET
39#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
40 QML_ANONYMOUS
41 QML_NAMED_ELEMENT(Color)
42 QML_UNCREATABLE("Color is only available as enums.")
43#endif
44public:
45 enum Type : quint8 {
46 Invalid = 0,
47 Highlight,
48 HighlightedText
49 };
50 Q_ENUM(Type)
51
52 DColor() {}
53 inline DColor(const QColor &color) {
54 data.color.value = color;
55 }
56#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
57 DColor(const QJSValue &params) : DColor(QColor(params.toString())) { }
58#endif
59 DColor(Type type);
60 inline DColor(const DColor &other) {
61 memcpy(static_cast<void*>(&data), static_cast<const void*>(&other.data), sizeof(Data));
62 }
63 inline DColor(DColor &&other) {
64 operator =(other);
65 }
66
67 [[nodiscard]] bool isValid() const noexcept;
68 [[nodiscard]] bool isTypedColor() const noexcept;
69 [[nodiscard]] quint8 type() const noexcept;
70
71 bool operator==(const DColor &c) const noexcept;
72 bool operator!=(const DColor &c) const noexcept;
73 inline DColor &operator=(const QColor &color) {
74 data.color.value = color;
75 return *this;
76 }
77 inline DColor &operator=(const DColor &other) {
78 memcpy(static_cast<void*>(&data), static_cast<const void*>(&other.data), sizeof(Data));
79 return *this;
80 }
81 inline DColor &operator=(DColor &&other) {
82 data.hue = std::move(other.data.hue);
83 data.saturation = std::move(other.data.saturation);
84 data.lightness = std::move(other.data.lightness);
85 data.opacity = std::move(other.data.opacity);
86 data.color.value = std::move(other.data.color.value);
87 return *this;
88 }
89
90 Q_INVOKABLE QColor toColor(const QPalette &palette) const;
91 Q_INVOKABLE QColor color() const;
92 Q_INVOKABLE DTK_QUICK_NAMESPACE::DColor hue(qint8 floatValue) const;
93 Q_INVOKABLE DTK_QUICK_NAMESPACE::DColor saturation(qint8 floatValue) const;
94 Q_INVOKABLE DTK_QUICK_NAMESPACE::DColor lightness(qint8 floatValue) const;
95 Q_INVOKABLE DTK_QUICK_NAMESPACE::DColor opacity(qint8 floatValue) const;
96
97private:
98 struct Data {
99 qint8 hue = 0;
100 qint8 saturation = 0;
101 qint8 lightness = 0;
102 qint8 opacity = 0;
103
104 union Color {
105 #ifdef Q_COMPILER_UNIFORM_INIT
106 Color() {} // doesn't init anything, thus can't be constexpr
107 #endif
108 quint8 type; // DQMLGlobalObject::TypedColor
109 QColor value = QColor();
110 } color;
111 } data;
112};
113
114class DQuickDciIcon;
117class DQMLGlobalObject : public QObject, public DTK_CORE_NAMESPACE::DObject
118{
119 Q_OBJECT
120
121 Q_PROPERTY(bool hasBlurWindow READ hasBlurWindow NOTIFY hasBlurWindowChanged)
122 Q_PROPERTY(bool hasComposite READ hasComposite NOTIFY hasCompositeChanged)
123 Q_PROPERTY(bool hasNoTitlebar READ hasNoTitlebar NOTIFY hasNoTitlebarChanged)
124 Q_PROPERTY(bool hasAnimation READ hasAnimation NOTIFY hasAnimationChanged)
125 Q_PROPERTY(bool isSoftwareRender READ isSoftwareRender FINAL CONSTANT)
126 Q_PROPERTY(DTK_GUI_NAMESPACE::DWindowManagerHelper::WMName windowManagerName READ windowManagerName CONSTANT)
127 Q_PROPERTY(DTK_GUI_NAMESPACE::DGuiApplicationHelper::ColorType themeType READ themeType NOTIFY themeTypeChanged)
128 Q_PROPERTY(QString windowManagerNameString READ windowManagerNameString CONSTANT)
129 Q_PROPERTY(DPlatformThemeProxy *platformTheme READ platformTheme FINAL CONSTANT)
130 Q_PROPERTY(DTK_GUI_NAMESPACE::DFontManager *fontManager READ fontManager FINAL CONSTANT)
131#if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0)
132 Q_PROPERTY(QPalette palette READ palette NOTIFY paletteChanged)
133 Q_PROPERTY(QPalette inactivePalette READ inactivePalette NOTIFY inactivePaletteChanged)
134#else
135 Q_PROPERTY(QQuickPalette* palette READ quickPalette NOTIFY paletteChanged)
136 Q_PROPERTY(QQuickPalette* inactivePalette READ inactiveQuickPalette NOTIFY inactivePaletteChanged)
137#endif
138 Q_PROPERTY(QString deepinDistributionOrgLogo READ deepinDistributionOrgLogo CONSTANT)
139 Q_PROPERTY(QString deepinWebsiteName READ deepinWebsiteName CONSTANT)
140 Q_PROPERTY(QString deepinWebsiteLink READ deepinWebsiteLink CONSTANT)
141#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
142 QML_NAMED_ELEMENT(DTK)
143 QML_SINGLETON
144#endif
145
146public:
147 explicit DQMLGlobalObject(QObject *parent = nullptr);
148 ~DQMLGlobalObject() override;
149
150 static DQMLGlobalObject *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
151 {
152 Q_UNUSED(qmlEngine)
153 Q_UNUSED(jsEngine)
154 return new DQMLGlobalObject;
155 }
156
157 enum ControlState {
158 NormalState,
159 HoveredState,
160 PressedState,
161 DisabledState,
162 InactiveState
163 };
164 Q_ENUM(ControlState)
165
166 enum ZOrder {
167 BottomOrder = -99,
168 BelowOrder = -1,
169 NormalOrder = 0,
170 AboveOrder = 1,
171 TopOrder = 99
172 };
173 Q_ENUM(ZOrder)
174
175 enum PopupMode {
176 AutoMode,
177 WindowMode,
178 EmbedMode
179 };
180 Q_ENUM(PopupMode)
181
182#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
183 enum class CompositionMode {
184 Source = QPainter::CompositionMode_Source,
185 SourceOver = QPainter::CompositionMode_SourceOver,
186 Destination = QPainter::CompositionMode_Destination,
187 DestinationOver = QPainter::CompositionMode_DestinationOver,
188 Clear = QPainter::CompositionMode_Clear,
189 };
190 Q_ENUM(CompositionMode)
191#endif
192
193 bool hasBlurWindow() const;
194 bool hasComposite() const;
195 bool hasNoTitlebar() const;
196 static bool hasAnimation();
197 static bool isSoftwareRender();
198
199 DWindowManagerHelper::WMName windowManagerName() const;
200 QString windowManagerNameString() const;
201
202 DGuiApplicationHelper::ColorType themeType() const;
203
204 DPlatformThemeProxy *platformTheme() const;
205 DFontManager *fontManager() const;
206
207 QPalette palette() const;
208 QPalette inactivePalette() const;
209#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
210 QQuickPalette *quickPalette() const;
211 QQuickPalette *inactiveQuickPalette() const;
212#endif
213
214 Q_INVOKABLE QColor blendColor(const QColor &substrate, const QColor &superstratum);
215 Q_INVOKABLE DTK_QUICK_NAMESPACE::DColor makeColor(DTK_QUICK_NAMESPACE::DColor::Type type);
216 Q_INVOKABLE DTK_QUICK_NAMESPACE::DColor makeColor(const QColor &color);
217 Q_INVOKABLE QUrl makeShadowImageUrl(qreal boxSize, qreal cornerRadius, qreal shadowBlur,
218 QColor color, qreal xOffset, qreal yOffset, qreal spread,
219 bool hollow, bool inner);
220 Q_INVOKABLE QUrl makeShadowImageUrl(qreal boxSize, qreal topLeftRadius, qreal topRightRadius, qreal bottomLeftRadius, qreal bottomRightRadius,
221 qreal shadowBlur, QColor color, qreal xOffset, qreal yOffset, qreal spread,
222 bool hollow, bool inner);
223
224 Q_INVOKABLE DTK_GUI_NAMESPACE::DGuiApplicationHelper::ColorType toColorType(const QColor &color);
225 Q_INVOKABLE QColor selectColor(const QColor &windowColor, const QColor &light, const QColor &dark);
226
227 QString deepinWebsiteName() const;
228 QString deepinWebsiteLink() const;
229 QString deepinDistributionOrgLogo() const;
230
231 Q_INVOKABLE QPoint cursorPosition() const;
232
233 Q_INVOKABLE DTK_QUICK_NAMESPACE::DQuickDciIcon makeIcon(const QJSValue &qicon, const QJSValue &iconExtra);
234#if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0)
235 Q_INVOKABLE DTK_GUI_NAMESPACE::DDciIconPalette makeIconPalette(const QPalette &palette);
236#else
237 Q_INVOKABLE DTK_GUI_NAMESPACE::DDciIconPalette makeIconPalette(const QQuickPalette *palette);
238#endif
239
240 Q_INVOKABLE bool sendMessage(QObject *target, const QString &content, const QString &iconName = QString(), int duration = 4000, const QString &msgId = QString());
241 Q_INVOKABLE bool sendMessage(QObject *target, QQmlComponent *delegate, const QVariant &message, int duration = 4000, const QString &msgId = QString());
242 Q_INVOKABLE void closeMessage(DTK_QUICK_NAMESPACE::FloatingMessageContainer *message);
243 Q_INVOKABLE void closeMessage(QObject *target, const QString &msgId);
244 Q_INVOKABLE void sendSystemMessage(const QString &summary, const QString &body = QString(),
245 const QString &appIcon = QString(), const QStringList &actions = QStringList(),
246 const QVariantMap hints = QVariantMap(), const int timeout = 3000, const uint replaceId = 0);
247
248 static void setPopupMode(const PopupMode mode);
249 static bool loadTranslator();
250
251#if QT_VERSION_MAJOR > 5
252 static QSGRootNode *getRootNode(QQuickItem *item);
253 static int &QSGNode_subtreeRenderableCount(QSGNode *node);
254 static QSGNode* &QSGNode_firstChild(QSGNode *node);
255 static QSGNode* &QSGNode_lastChild(QSGNode *node);
256 static QSGNode* &QSGNode_parent(QSGNode *node);
257#endif
258
259
260Q_SIGNALS:
261 void hasBlurWindowChanged();
262 void hasCompositeChanged();
263 void hasNoTitlebarChanged();
264 void hasAnimationChanged();
265 void paletteChanged();
266 void inactivePaletteChanged();
267 void themeTypeChanged(DTK_GUI_NAMESPACE::DGuiApplicationHelper::ColorType themeType);
268
269
270private:
271 D_DECLARE_PRIVATE(DQMLGlobalObject)
272 D_PRIVATE_SLOT(void _q_onPaletteChanged())
273};
274
275DQUICK_END_NAMESPACE
276Q_DECLARE_METATYPE(DTK_QUICK_NAMESPACE::DColor)
277
278#endif // DQMLGLOBALOBJECT_P_H
DTK 项目中统一的颜色类型. @details Color 是DTK 中为了适配 QPalette 部分颜色角色枚举,适配 Qt 的基础的颜色以及所有 的 RGB 的颜色值。除此之外,该类能很好的兼容...
提供一个全局的DTK 对象,保证QML中能够获取DTK 的相关枚举和函数.
Definition dqmlglobalobject_p.h:37
一个代理类,用于导出dtkgui的DPlatformTheme类的功能到QML使用,功能和接口基本和DPlatformTheme一致
Definition dplatformthemeproxy.h:19
Definition dqmlglobalobject_p_p.h:17
Definition dqmlglobalobject_p.h:118
A dci icon type for qml.
Definition dquickdciicon_p.h:23
Definition dmessagemanager_p.h:16
Definition dqmlglobalobject_p.h:104