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_VALUE_TYPE(dcolor)
41#endif
42public:
43 enum Type : quint8 {
44 Invalid = 0,
45 Highlight,
46 HighlightedText
47 };
48 Q_ENUM(Type)
49
50 DColor() {}
51 inline DColor(const QColor &color) {
52 data.color.value = color;
53 }
54#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
55 DColor(const QJSValue &params) : DColor(QColor(params.toString())) { }
56#endif
57 DColor(Type type);
58 inline DColor(const DColor &other) {
59 memcpy(static_cast<void*>(&data), static_cast<const void*>(&other.data), sizeof(Data));
60 }
61 inline DColor(DColor &&other) {
62 operator =(other);
63 }
64
65 [[nodiscard]] bool isValid() const noexcept;
66 [[nodiscard]] bool isTypedColor() const noexcept;
67 [[nodiscard]] quint8 type() const noexcept;
68
69 bool operator==(const DColor &c) const noexcept;
70 bool operator!=(const DColor &c) const noexcept;
71 inline DColor &operator=(const QColor &color) {
72 data.color.value = color;
73 return *this;
74 }
75 inline DColor &operator=(const DColor &other) {
76 memcpy(static_cast<void*>(&data), static_cast<const void*>(&other.data), sizeof(Data));
77 return *this;
78 }
79 inline DColor &operator=(DColor &&other) {
80 data.hue = std::move(other.data.hue);
81 data.saturation = std::move(other.data.saturation);
82 data.lightness = std::move(other.data.lightness);
83 data.opacity = std::move(other.data.opacity);
84 data.color.value = std::move(other.data.color.value);
85 return *this;
86 }
87
88 Q_INVOKABLE QColor toColor(const QPalette &palette) const;
89 Q_INVOKABLE QColor color() const;
90 Q_INVOKABLE DTK_QUICK_NAMESPACE::DColor hue(qint8 floatValue) const;
91 Q_INVOKABLE DTK_QUICK_NAMESPACE::DColor saturation(qint8 floatValue) const;
92 Q_INVOKABLE DTK_QUICK_NAMESPACE::DColor lightness(qint8 floatValue) const;
93 Q_INVOKABLE DTK_QUICK_NAMESPACE::DColor opacity(qint8 floatValue) const;
94
95private:
96 struct Data {
97 qint8 hue = 0;
98 qint8 saturation = 0;
99 qint8 lightness = 0;
100 qint8 opacity = 0;
101
102 union Color {
103 #ifdef Q_COMPILER_UNIFORM_INIT
104 Color() {} // doesn't init anything, thus can't be constexpr
105 #endif
106 quint8 type; // DQMLGlobalObject::TypedColor
107 QColor value = QColor();
108 } color;
109 } data;
110};
111
112class DQuickDciIcon;
115class DQMLGlobalObject : public QObject, public DTK_CORE_NAMESPACE::DObject
116{
117 Q_OBJECT
118
119 Q_PROPERTY(bool hasBlurWindow READ hasBlurWindow NOTIFY hasBlurWindowChanged)
120 Q_PROPERTY(bool hasComposite READ hasComposite NOTIFY hasCompositeChanged)
121 Q_PROPERTY(bool hasNoTitlebar READ hasNoTitlebar NOTIFY hasNoTitlebarChanged)
122 Q_PROPERTY(bool hasAnimation READ hasAnimation NOTIFY hasAnimationChanged)
123 Q_PROPERTY(bool isSoftwareRender READ isSoftwareRender FINAL CONSTANT)
124 Q_PROPERTY(DTK_GUI_NAMESPACE::DWindowManagerHelper::WMName windowManagerName READ windowManagerName CONSTANT)
125 Q_PROPERTY(DTK_GUI_NAMESPACE::DGuiApplicationHelper::ColorType themeType READ themeType NOTIFY themeTypeChanged)
126 Q_PROPERTY(QString windowManagerNameString READ windowManagerNameString CONSTANT)
127 Q_PROPERTY(DPlatformThemeProxy *platformTheme READ platformTheme FINAL CONSTANT)
128 Q_PROPERTY(DTK_GUI_NAMESPACE::DFontManager *fontManager READ fontManager FINAL CONSTANT)
129#if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0)
130 Q_PROPERTY(QPalette palette READ palette NOTIFY paletteChanged)
131 Q_PROPERTY(QPalette inactivePalette READ inactivePalette NOTIFY inactivePaletteChanged)
132#else
133 Q_PROPERTY(QQuickPalette* palette READ quickPalette NOTIFY paletteChanged)
134 Q_PROPERTY(QQuickPalette* inactivePalette READ inactiveQuickPalette NOTIFY inactivePaletteChanged)
135#endif
136 Q_PROPERTY(QString deepinDistributionOrgLogo READ deepinDistributionOrgLogo CONSTANT)
137 Q_PROPERTY(QString deepinWebsiteName READ deepinWebsiteName CONSTANT)
138 Q_PROPERTY(QString deepinWebsiteLink READ deepinWebsiteLink CONSTANT)
139#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
140 QML_NAMED_ELEMENT(DTK)
141 QML_SINGLETON
142#endif
143
144public:
145 explicit DQMLGlobalObject(QObject *parent = nullptr);
146 ~DQMLGlobalObject() override;
147
148 static DQMLGlobalObject *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
149 {
150 Q_UNUSED(qmlEngine)
151 Q_UNUSED(jsEngine)
152 return new DQMLGlobalObject;
153 }
154
155 enum ControlState {
156 NormalState,
157 HoveredState,
158 PressedState,
159 DisabledState,
160 InactiveState
161 };
162 Q_ENUM(ControlState)
163
164 enum ZOrder {
165 BottomOrder = -99,
166 BelowOrder = -1,
167 NormalOrder = 0,
168 AboveOrder = 1,
169 TopOrder = 99
170 };
171 Q_ENUM(ZOrder)
172
173 enum PopupMode {
174 AutoMode,
175 WindowMode,
176 EmbedMode
177 };
178 Q_ENUM(PopupMode)
179
180#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
181 enum class CompositionMode {
182 Source = QPainter::CompositionMode_Source,
183 SourceOver = QPainter::CompositionMode_SourceOver,
184 Destination = QPainter::CompositionMode_Destination,
185 DestinationOver = QPainter::CompositionMode_DestinationOver,
186 Clear = QPainter::CompositionMode_Clear,
187 };
188 Q_ENUM(CompositionMode)
189#endif
190
191 bool hasBlurWindow() const;
192 bool hasComposite() const;
193 bool hasNoTitlebar() const;
194 static bool hasAnimation();
195 static bool isSoftwareRender();
196
197 DWindowManagerHelper::WMName windowManagerName() const;
198 QString windowManagerNameString() const;
199
200 DGuiApplicationHelper::ColorType themeType() const;
201
202 DPlatformThemeProxy *platformTheme() const;
203 DFontManager *fontManager() const;
204
205 QPalette palette() const;
206 QPalette inactivePalette() const;
207#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
208 QQuickPalette *quickPalette() const;
209 QQuickPalette *inactiveQuickPalette() const;
210#endif
211
212 Q_INVOKABLE QColor blendColor(const QColor &substrate, const QColor &superstratum);
213 Q_INVOKABLE DTK_QUICK_NAMESPACE::DColor makeColor(DTK_QUICK_NAMESPACE::DColor::Type type);
214 Q_INVOKABLE DTK_QUICK_NAMESPACE::DColor makeColor(const QColor &color);
215 Q_INVOKABLE QUrl makeShadowImageUrl(qreal boxSize, qreal cornerRadius, qreal shadowBlur,
216 QColor color, qreal xOffset, qreal yOffset, qreal spread,
217 bool hollow, bool inner);
218 Q_INVOKABLE QUrl makeShadowImageUrl(qreal boxSize, qreal topLeftRadius, qreal topRightRadius, qreal bottomLeftRadius, qreal bottomRightRadius,
219 qreal shadowBlur, QColor color, qreal xOffset, qreal yOffset, qreal spread,
220 bool hollow, bool inner);
221
222 Q_INVOKABLE DTK_GUI_NAMESPACE::DGuiApplicationHelper::ColorType toColorType(const QColor &color);
223 Q_INVOKABLE QColor selectColor(const QColor &windowColor, const QColor &light, const QColor &dark);
224
225 QString deepinWebsiteName() const;
226 QString deepinWebsiteLink() const;
227 QString deepinDistributionOrgLogo() const;
228
229 Q_INVOKABLE QPoint cursorPosition() const;
230
231 Q_INVOKABLE DTK_QUICK_NAMESPACE::DQuickDciIcon makeIcon(const QJSValue &qicon, const QJSValue &iconExtra);
232#if QT_VERSION <= QT_VERSION_CHECK(6, 0, 0)
233 Q_INVOKABLE DTK_GUI_NAMESPACE::DDciIconPalette makeIconPalette(const QPalette &palette);
234#else
235 Q_INVOKABLE DTK_GUI_NAMESPACE::DDciIconPalette makeIconPalette(const QQuickPalette *palette);
236#endif
237
238 Q_INVOKABLE bool sendMessage(QObject *target, const QString &content, const QString &iconName = QString(), int duration = 4000, const QString &msgId = QString());
239 Q_INVOKABLE bool sendMessage(QObject *target, QQmlComponent *delegate, const QVariant &message, int duration = 4000, const QString &msgId = QString());
240 Q_INVOKABLE void closeMessage(DTK_QUICK_NAMESPACE::FloatingMessageContainer *message);
241 Q_INVOKABLE void closeMessage(QObject *target, const QString &msgId);
242 Q_INVOKABLE void sendSystemMessage(const QString &summary, const QString &body = QString(),
243 const QString &appIcon = QString(), const QStringList &actions = QStringList(),
244 const QVariantMap hints = QVariantMap(), const int timeout = 3000, const uint replaceId = 0);
245
246 static void setPopupMode(const PopupMode mode);
247 static bool loadTranslator();
248
249#if QT_VERSION_MAJOR > 5
250 static QSGRootNode *getRootNode(QQuickItem *item);
251 static int &QSGNode_subtreeRenderableCount(QSGNode *node);
252 static QSGNode* &QSGNode_firstChild(QSGNode *node);
253 static QSGNode* &QSGNode_lastChild(QSGNode *node);
254 static QSGNode* &QSGNode_parent(QSGNode *node);
255#endif
256
257
258Q_SIGNALS:
259 void hasBlurWindowChanged();
260 void hasCompositeChanged();
261 void hasNoTitlebarChanged();
262 void hasAnimationChanged();
263 void paletteChanged();
264 void inactivePaletteChanged();
265 void themeTypeChanged(DTK_GUI_NAMESPACE::DGuiApplicationHelper::ColorType themeType);
266
267
268private:
269 D_DECLARE_PRIVATE(DQMLGlobalObject)
270 D_PRIVATE_SLOT(void _q_onPaletteChanged())
271};
272
273DQUICK_END_NAMESPACE
274Q_DECLARE_METATYPE(DTK_QUICK_NAMESPACE::DColor)
275
276#endif // DQMLGLOBALOBJECT_P_H
提供一个全局的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:116
A dci icon type for qml.
Definition dquickdciicon_p.h:23
Definition dmessagemanager_p.h:16
Definition dqmlglobalobject_p.h:102