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