DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dtkwidget_global.h
1// SPDX-FileCopyrightText: 2015 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#pragma once
6
7#include <dtkcore_global.h>
8#include <dtkwidget_config.h>
9
10#include <QtCore/QMetaMethod>
11
12#define DWIDGET_NAMESPACE Widget
13#define DTK_WIDGET_NAMESPACE DTK_NAMESPACE::Widget
14
15#define DWIDGET_BEGIN_NAMESPACE namespace DTK_NAMESPACE { namespace DWIDGET_NAMESPACE {
16#define DWIDGET_END_NAMESPACE }}
17#define DWIDGET_USE_NAMESPACE using namespace DTK_WIDGET_NAMESPACE;
18
19#if defined(DTK_STATIC_LIB)
20void inline dtk_windget_init_resource()
21{
22 Q_INIT_RESOURCE(icons);
23 Q_INIT_RESOURCE(dui_theme_dark);
24 Q_INIT_RESOURCE(dui_theme_light);
25 // TODO: use marco create by dtk_build
26#if defined(DTK_STATIC_TRANSLATION)
27 Q_INIT_RESOURCE(dtkwidget_translations);
28#endif
29}
30#endif
31
32namespace Dtk
33{
34namespace Widget
35{
36
37#if defined(DTK_STATIC_LIB)
38#define DWIDGET_INIT_RESOURCE() \
39 do { \
40 dtk_windget_init_resource(); \
41 } while (0)
42#endif
43
44}
45}
46
47#if defined(DTK_STATIC_LIB)
48# define LIBDTKWIDGETSHARED_EXPORT
49#else
50#if defined(LIBDTKWIDGET_LIBRARY)
51# define LIBDTKWIDGETSHARED_EXPORT Q_DECL_EXPORT
52#else
53# define LIBDTKWIDGETSHARED_EXPORT Q_DECL_IMPORT
54#endif
55#endif
56
57#define DTKWIDGET_DECL_DEPRECATED D_DECL_DEPRECATED
58
59#define D_THEME_INIT_WIDGET(className, ...) do{\
60 DThemeManager * manager = DThemeManager::instance(); \
61 {const QString &sheet = this->styleSheet() + manager->getQssForWidget(#className, this); \
62 if (!sheet.isEmpty()) this->setStyleSheet(sheet); \
63 } \
64 connect(manager, &DThemeManager::themeChanged, this, [this, manager] (QString) { \
65 const QString &sheet = manager->getQssForWidget(#className, this); \
66 if (!sheet.isEmpty()) this->setStyleSheet(sheet); \
67 });\
68 connect(manager, &DThemeManager::widgetThemeChanged, this, [this, manager] (QWidget *w, QString) { \
69 if (w == this) this->setStyleSheet(manager->getQssForWidget(#className, this)); \
70 }); \
71 QStringList list = QString(#__VA_ARGS__).replace(" ", "").split(",");\
72 const QMetaObject *self = metaObject();\
73 Q_FOREACH (const QString &str, list) {\
74 if(str.isEmpty())\
75 continue;\
76 connect(this, self->property(self->indexOfProperty(str.toLatin1().data())).notifySignal(),\
77 manager, manager->metaObject()->method(manager->metaObject()->indexOfMethod("updateQss()")));\
78 } \
79 } while (0);