This repository was archived by the owner on May 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStyleContainer.cpp
More file actions
128 lines (105 loc) · 2.99 KB
/
StyleContainer.cpp
File metadata and controls
128 lines (105 loc) · 2.99 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "StyleContainer.h"
StyleContainer::StyleContainer(QObject* parent)
:QObject(parent)
{
}
StyleContainer::~StyleContainer()
{
}
StyleContainer StyleContainer::styles(nullptr);
void StyleContainer::startListen()
{
mutex.lock();
watcher.addPath(GetConfig::getConfigFilePath("skin"));
watcher.addPath(GetStyle::getStyleFilePath(GetConfig::getStyleName()));
watcher.addPath(GetTrans::getTransFilePath(GetConfig::getTransName()));
connect(&(this->watcher), &QFileSystemWatcher::fileChanged, this, &StyleContainer::on_config_changed);
GetConfig::refreshConfigs(this->styleObject);
GetConfig::refreshTranslates(this->translateObject);
mutex.unlock();
}
StyleContainer& StyleContainer::getContainer()
{
return StyleContainer::styles;
}
void StyleContainer::on_config_changed(const QString& path)
{
Q_UNUSED(path);
mutex.lock();
watcher.removePaths(watcher.files());
watcher.addPath(GetConfig::getConfigFilePath("skin"));
watcher.addPath(GetStyle::getStyleFilePath(GetConfig::getStyleName()));
watcher.addPath(GetTrans::getTransFilePath(GetConfig::getTransName()));
GetConfig::refreshConfigs(this->styleObject);
GetConfig::refreshTranslates(this->translateObject);
mutex.unlock();
this->refreshPix();
emit this->resource_refresh();
}
neb::CJsonObject& StyleContainer::getStyleObject()
{
mutex.lock();
mutex.unlock();
return this->styleObject;
}
neb::CJsonObject& StyleContainer::getTransObject()
{
mutex.lock();
mutex.unlock();
return this->translateObject;
}
void StyleContainer::refreshPix()
{
auto styleSrcFun = [&](QString path)->QString
{
return QString(
QCoreApplication::applicationDirPath() +
QString("/themes/") +
path
);
};
for (int i = 0; i < this->sourceMap.size(); i++) {
mutex.lock();
this->sourceMap[this->sourceMap.keys().at(i)].load(this->paths.value(this->sourceMap.keys().at(i)));
mutex.unlock();
}
for (int i = 0; i < this->sourceMap.size(); i++) {
this->scalePix(this->sourceMap.keys().at(i), this->scales.value(this->sourceMap.keys().at(i)));
}
}
void StyleContainer::loadPix(QString name, QString path)
{
auto styleSrcFun = [&](QString path)->QString
{
return QString(
QCoreApplication::applicationDirPath() +
QString("/themes/") +
path
);
};
QPixmap pixtemp;
mutex.lock();
pixtemp.load(styleSrcFun(path));
mutex.unlock();
this->sourceMap.insert(name, pixtemp);
if (!this->scales.contains(name)) {
this->scales.insert(name, 1);
}
this->paths.insert(name, path);
this->scalePix(name, this->scales.value(name));
}
void StyleContainer::scalePix(QString name, double s)
{
if (s != this->scales.value(name) || !this->scaleMap.contains(name)) {
QPixmap tempMap = this->sourceMap.value(name);
this->scaleMap.insert(name, tempMap.scaled(tempMap.width() * s, tempMap.height() * s, Qt::AspectRatioMode::KeepAspectRatio, Qt::TransformationMode::SmoothTransformation));
}
}
QPixmap& StyleContainer::getPix(QString name)
{
return this->scaleMap[name];
}
QPixmap& StyleContainer::getSourcePix(QString name)
{
return this->sourceMap[name];
}