DtkGui
DTK Gui module
载入中...
搜索中...
未找到
dguiapplicationhelper.h
浏览该文件的文档.
1// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DGUIAPPLICATIONHELPER_H
6#define DGUIAPPLICATIONHELPER_H
7
8#include <dtkgui_global.h>
9#include <DPalette>
10#include <DObject>
11
12#include <QGuiApplication>
13#include <QObject>
14
15DGUI_BEGIN_NAMESPACE
16
17class DPlatformTheme;
18class DFontManager;
19class DGuiApplicationHelperPrivate;
20class DGuiApplicationHelper : public QObject, public DCORE_NAMESPACE::DObject
21{
22 Q_OBJECT
23 D_DECLARE_PRIVATE(DGuiApplicationHelper)
24
25 Q_PROPERTY(ColorType themeType READ themeType NOTIFY themeTypeChanged)
26 Q_PROPERTY(ColorType paletteType READ paletteType WRITE setPaletteType NOTIFY paletteTypeChanged)
27 Q_PROPERTY(bool hasUserManual READ hasUserManual)
28
29public:
30 enum ColorType {
33 DarkType
34 };
35 Q_ENUM(ColorType)
36
37 enum SingleScope {
38 UserScope,
39 GroupScope,
40 WorldScope
41 };
42 Q_ENUM(SingleScope)
43
44 enum SizeMode {
45 NormalMode,
46 CompactMode
47 };
48 Q_ENUM(SizeMode)
49
50 enum Attribute {
51 UseInactiveColorGroup = 1 << 0,
52 ColorCompositing = 1 << 1,
53 DontSaveApplicationTheme = 1 << 2,
54
55 /* readonly flag */
56 ReadOnlyLimit = 1 << 22,
57 IsDeepinPlatformTheme = ReadOnlyLimit << 0,
58 IsDXcbPlatform = ReadOnlyLimit << 1,
59 IsXWindowPlatform = ReadOnlyLimit << 2,
60 IsTableEnvironment = ReadOnlyLimit << 3,
61 IsDeepinEnvironment = ReadOnlyLimit << 4,
62 IsSpecialEffectsEnvironment = ReadOnlyLimit << 5,
63 IsWaylandPlatform = ReadOnlyLimit << 6,
64 IsTreelandPlatform Q_DECL_ENUMERATOR_DEPRECATED_X("Use DGuiApplicationHelper::IsWaylandPlatform instead") = IsWaylandPlatform,
65 HasAnimations = ReadOnlyLimit << 7,
66 HasInWindowBlur = ReadOnlyLimit << 8,
67 };
68 Q_ENUM(Attribute)
69 Q_DECLARE_FLAGS(Attributes, Attribute)
70
71#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
72 typedef DGuiApplicationHelper *(*HelperCreator)();
73 D_DECL_DEPRECATED static void registerInstanceCreator(HelperCreator creator);
74#endif
75 static DGuiApplicationHelper *instance();
77
78 static QColor adjustColor(const QColor &base, qint8 hueFloat, qint8 saturationFloat, qint8 lightnessFloat,
79 qint8 redFloat, qint8 greenFloat, qint8 blueFloat, qint8 alphaFloat);
80 static QImage adjustColor(const QImage &base, qint8 hueFloat, qint8 saturationFloat, qint8 lightnessFloat,
81 qint8 redFloat, qint8 greenFloat, qint8 blueFloat, qint8 alphaFloat);
82 static QColor blendColor(const QColor &substrate, const QColor &superstratum);
83 static DPalette standardPalette(ColorType type);
84 static void generatePaletteColor(DPalette &base, QPalette::ColorRole role, ColorType type);
85 static void generatePaletteColor(DPalette &base, DPalette::ColorType role, ColorType type);
86 static void generatePalette(DPalette &base, ColorType type = UnknownType);
87 static DPalette fetchPalette(const DPlatformTheme *theme);
88#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
89 Q_DECL_DEPRECATED_X("Use UseInactiveColorGroup enum with setAttribute.") static void setUseInactiveColorGroup(bool on);
90 Q_DECL_DEPRECATED_X("Use ColorCompositing enum with setAttribute.") static void setColorCompositingEnabled(bool on);
91#endif
92 static bool isXWindowPlatform();
93 static bool isTabletEnvironment();
94 static bool isSpecialEffectsEnvironment();
95 static void setAttribute(Attribute attribute, bool enable);
96 static bool testAttribute(Attribute attribute);
97
98 DPlatformTheme *systemTheme() const;
99 DPlatformTheme *applicationTheme() const;
100#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
101 D_DECL_DEPRECATED DPlatformTheme *windowTheme(QWindow *window) const;
102#endif
103
104 DPalette applicationPalette() const;
105 DPalette applicationPalette(ColorType paletteType) const;
106 void setApplicationPalette(const DPalette &palette);
107#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
108 D_DECL_DEPRECATED DPalette windowPalette(QWindow *window) const;
109#endif
110
111 const DFontManager *fontManager() const;
112
113 static ColorType toColorType(const QColor &color);
114 static ColorType toColorType(const QPalette &palette);
115 ColorType themeType() const;
116 ColorType paletteType() const;
117
118 static bool setSingleInstance(const QString &key, SingleScope singleScope = UserScope);
119 static void setSingleInstanceInterval(int interval = 3000);
120#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
121 D_DECL_DEPRECATED static void setSingelInstanceInterval(int interval = 3000);
122#endif
123
124 // 获取帮助手册目录
125 static QStringList userManualPaths(const QString &appName);
126 bool hasUserManual() const;
127
128 static bool loadTranslator(const QString &fileName, const QString &appName, const QList<QLocale> &localeFallback = QList<QLocale>() << QLocale::system());
129 static bool loadTranslator(const QString &fileName, const QList<QString> &translateDirs, const QList<QLocale> &localeFallback);
130 static bool loadTranslator(const QList<QLocale> &localeFallback = QList<QLocale>() << QLocale::system());
131
132public Q_SLOTS:
133#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
134 D_DECL_DEPRECATED_X("Plase use setPaletteType") void setThemeType(ColorType themeType);
135#endif
136 void setPaletteType(ColorType paletteType);
137 void handleHelpAction();
138 static void openUrl(const QString &url);
139
140 DGuiApplicationHelper::SizeMode sizeMode() const;
141 void setSizeMode(const DGuiApplicationHelper::SizeMode mode);
142 void resetSizeMode();
143 static inline bool isCompactMode()
144 {
145 return instance()->sizeMode() == DGuiApplicationHelper::CompactMode;
146 }
147
148Q_SIGNALS:
149 void themeTypeChanged(ColorType themeType);
150 void paletteTypeChanged(ColorType paletteType);
151 void newProcessInstance(qint64 pid, const QStringList &arguments);
152 void fontChanged(const QFont &font);
155
156protected:
157 explicit DGuiApplicationHelper();
158 virtual void initialize();
159
160private:
161 D_PRIVATE_SLOT(void _q_initApplicationTheme(bool))
162 D_PRIVATE_SLOT(void _q_sizeModeChanged(int))
163 friend class _DGuiApplicationHelper;
164};
165
166DGUI_END_NAMESPACE
167
168#endif // DGUIAPPLICATIONHELPER_H
字体大小设置的一个类,系统默认只设置T6.
Definition dfontmanager.h:19
DGuiApplicationHelper 应用程序的 GUI ,如主题、调色板等.
Definition dguiapplicationhelper.h:21
static bool isCompactMode()
当前控件大小模式是否为紧凑模式。
Definition dguiapplicationhelper.h:143
ColorType
Definition dguiapplicationhelper.h:30
@ LightType
Definition dguiapplicationhelper.h:32
@ UnknownType
Definition dguiapplicationhelper.h:31
void applicationPaletteChanged()
通知调色板对象的改变。
void sizeModeChanged(DGuiApplicationHelper::SizeMode sizeMode)
通知控件大小模式发生改变。
void newProcessInstance(qint64 pid, const QStringList &arguments)
通知新进程的信息。
SizeMode
控件大小模式枚举包含 dtk支持的控件大小模式种类.
Definition dguiapplicationhelper.h:44
Attribute
Definition dguiapplicationhelper.h:50
DPalette继承并且扩展了 QPalette 类, 提供了dtk特有的特性.
Definition dpalette.h:17
ColorType
Definition dpalette.h:20
一个提供窗口主题的类.
Definition dplatformtheme.h:18