-
Notifications
You must be signed in to change notification settings - Fork 0
/
ElaApplication.cpp
109 lines (99 loc) · 2.52 KB
/
ElaApplication.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "ElaApplication.h"
#include <QApplication>
#include <QCursor>
#include <QFontDatabase>
#include <QWidget>
#include "ElaTheme.h"
#include "private/ElaApplicationPrivate.h"
Q_SINGLETON_CREATE_CPP(ElaApplication)
ElaApplication::ElaApplication(QObject* parent)
: QObject{parent}, d_ptr(new ElaApplicationPrivate())
{
Q_D(ElaApplication);
d->q_ptr = this;
d->_pIsEnableMica = false;
d->_pMicaImagePath = ":/include/Image/MicaBase.png";
d->_themeMode = eTheme->getThemeMode();
connect(eTheme, &ElaTheme::themeModeChanged, d, &ElaApplicationPrivate::onThemeModeChanged);
}
ElaApplication::~ElaApplication()
{
}
void ElaApplication::setIsEnableMica(bool isEnable)
{
Q_D(ElaApplication);
d->_pIsEnableMica = isEnable;
if (isEnable)
{
d->_initMicaBaseImage(QImage(d->_pMicaImagePath));
}
else
{
d->onThemeModeChanged(d->_themeMode);
Q_EMIT pIsEnableMicaChanged();
}
}
bool ElaApplication::getIsEnableMica() const
{
Q_D(const ElaApplication);
return d->_pIsEnableMica;
}
void ElaApplication::setMicaImagePath(QString micaImagePath)
{
Q_D(ElaApplication);
d->_pMicaImagePath = micaImagePath;
d->_initMicaBaseImage(QImage(d->_pMicaImagePath));
Q_EMIT pMicaImagePathChanged();
}
QString ElaApplication::getMicaImagePath() const
{
Q_D(const ElaApplication);
return d->_pMicaImagePath;
}
void ElaApplication::init()
{
QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
QFontDatabase::addApplicationFont(":/include/Font/ElaAwesome.ttf");
//默认字体
QFont font = qApp->font();
font.setPixelSize(13);
font.setFamily("Microsoft YaHei");
font.setHintingPreference(QFont::PreferNoHinting);
qApp->setFont(font);
}
void ElaApplication::syncMica(QWidget* widget, bool isSync)
{
Q_D(ElaApplication);
if (!widget)
{
return;
}
if (isSync)
{
widget->installEventFilter(d);
d->_micaWidgetList.append(widget);
if (d->_pIsEnableMica)
{
d->_updateMica(widget, false);
}
}
else
{
widget->removeEventFilter(d);
d->_micaWidgetList.removeOne(widget);
}
}
bool ElaApplication::containsCursorToItem(QWidget* item)
{
if (!item || !item->isVisible())
{
return false;
}
auto point = item->window()->mapFromGlobal(QCursor::pos());
QRectF rect = QRectF(item->mapTo(item->window(), QPoint(0, 0)), item->size());
if (rect.contains(point))
{
return true;
}
return false;
}