forked from 4lex4/scantailor-advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorSchemeManager.cpp
43 lines (36 loc) · 1.24 KB
/
ColorSchemeManager.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
#include "ColorSchemeManager.h"
#include <QtGui/QFont>
#include <QtWidgets/QApplication>
std::unique_ptr<ColorSchemeManager> ColorSchemeManager::m_instance = nullptr;
ColorSchemeManager* ColorSchemeManager::instance() {
if (m_instance == nullptr) {
m_instance.reset(new ColorSchemeManager());
}
return m_instance.get();
}
void ColorSchemeManager::setColorScheme(const ColorScheme& colorScheme) {
if (QStyle* style = colorScheme.getStyle()) {
qApp->setStyle(style);
}
qApp->setPalette(colorScheme.getPalette());
if (std::unique_ptr<QString> styleSheet = colorScheme.getStyleSheet()) {
qApp->setStyleSheet(*styleSheet);
}
m_colorParams = colorScheme.getColorParams();
}
QBrush ColorSchemeManager::getColorParam(const ColorScheme::ColorParam colorParam, const QBrush& defaultBrush) const {
const auto it = m_colorParams.find(colorParam);
if (it != m_colorParams.end()) {
return QBrush(it->second, defaultBrush.style());
} else {
return defaultBrush;
}
}
QColor ColorSchemeManager::getColorParam(ColorScheme::ColorParam colorParam, const QColor& defaultColor) const {
const auto it = m_colorParams.find(colorParam);
if (it != m_colorParams.end()) {
return it->second;
} else {
return defaultColor;
}
}