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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#include "FieldStyleFactory.h"
const QString FieldStyleFactory::DefaultStyle = "Normal";
FieldStyleFactory::FieldStyleFactory()
{
cardBgColor.setNamedColor("white");
initStyles();
}
void FieldStyleFactory::initStyles()
{
setStyle(DefaultStyle, FieldStyle());
setStyle("Example", {"", 14, false, false, "", "", "", true, "blue"});
setStyle("Transcription", {"Arial", 0, false, false, "", "/", "/"});
setStyle("Big", {"Arial", 26});
setStyle("Color1", {"", 0, true, false, "red"});
setStyle("Color2", {"", 0, true, false, "blue"});
}
FieldStyleFactory* FieldStyleFactory::inst()
{
static FieldStyleFactory factory;
return &factory;
}
void FieldStyleFactory::setStyle(const QString& aStyleName, FieldStyle aStyle )
{
styles[aStyleName] = aStyle;
if(!stylesNames.contains( aStyleName ))
stylesNames << aStyleName;
}
void FieldStyleFactory::load()
{
QSettings settings;
settings.beginGroup("Styles");
cardBgColor.setNamedColor(
settings.value("bg-color", cardBgColor.name()).toString());
foreach(QString styleName,
settings.value("list", getStyleNames()).toStringList())
loadStyle(settings, styleName);
settings.endGroup();
}
void FieldStyleFactory::loadStyle(QSettings& settings, const QString& styleName)
{
FieldStyle curStyle;
settings.beginGroup(styleName);
FieldStyle defaultStyle = getStyle(styleName);
loadStyleMainProperties(settings, curStyle, defaultStyle);
loadKeywordStyle(settings, curStyle, defaultStyle);
settings.endGroup();
setStyle(styleName, curStyle);
}
void FieldStyleFactory::loadStyleMainProperties(const QSettings& settings,
FieldStyle& curStyle, const FieldStyle& defaultStyle)
{
curStyle.font.setFamily(
settings.value("font-family", defaultStyle.font.family()).toString());
curStyle.font.setPointSize(
settings.value("font-size", defaultStyle.font.pointSize()).toInt());
curStyle.font.setBold(
settings.value("font-bold", defaultStyle.font.bold()).toBool());
curStyle.font.setItalic(
settings.value("font-italic", defaultStyle.font.italic()).toBool());
curStyle.color.setNamedColor(
settings.value("color", defaultStyle.color.name()).toString());
curStyle.prefix = settings.value("prefix", defaultStyle.prefix).toString();
curStyle.suffix = settings.value("suffix", defaultStyle.suffix).toString();
curStyle.hasKeyword = settings.value("keyword", defaultStyle.hasKeyword).toBool();
}
void FieldStyleFactory::loadKeywordStyle(const QSettings& settings, FieldStyle& curStyle,
const FieldStyle& defaultStyle)
{
if(!curStyle.hasKeyword)
return;
curStyle.keywordBold =
settings.value("keyword/font-bold", defaultStyle.keywordBold).toBool();
curStyle.keywordItalic =
settings.value("keyword/font-italic", defaultStyle.keywordItalic).toBool();
curStyle.keywordColor.setNamedColor(
settings.value("keyword/color", defaultStyle.keywordColor.name()).toString());
}
void FieldStyleFactory::save()
{
QSettings settings;
settings.beginGroup("Styles");
settings.remove(""); // Remove old user settings
if(cardBgColor != FieldStyleFactory().cardBgColor)
settings.setValue("bg-color", cardBgColor.name());
foreach(QString styleName, getStyleNames())
saveStyle(settings, styleName);
settings.endGroup();
}
void FieldStyleFactory::saveStyle(QSettings& settings, const QString& styleName)
{
const FieldStyle curStyle = getStyle(styleName);
const FieldStyle defaultStyle = FieldStyleFactory().getStyle(styleName);
settings.beginGroup( styleName );
saveStyleMainProperties(settings, curStyle, defaultStyle);
saveKeywordStyle(settings, curStyle, defaultStyle);
settings.endGroup();
}
void FieldStyleFactory::saveStyleMainProperties(QSettings& settings, const FieldStyle& curStyle,
const FieldStyle& defaultStyle)
{
if(curStyle.font.family() != defaultStyle.font.family())
settings.setValue("font-family", curStyle.font.family());
if(curStyle.font.pointSize() != defaultStyle.font.pointSize())
settings.setValue("font-size", curStyle.font.pointSize());
if(curStyle.font.bold() != defaultStyle.font.bold())
settings.setValue("font-bold", curStyle.font.bold());
if(curStyle.font.italic() != defaultStyle.font.italic())
settings.setValue("font-italic", curStyle.font.italic());
if(curStyle.color != defaultStyle.color)
settings.setValue("color", curStyle.color.name());
if(curStyle.prefix != defaultStyle.prefix)
settings.setValue("prefix", curStyle.prefix);
if(curStyle.suffix != defaultStyle.suffix)
settings.setValue("suffix", curStyle.suffix);
if(curStyle.hasKeyword != defaultStyle.hasKeyword)
settings.setValue("keyword", curStyle.hasKeyword);
}
void FieldStyleFactory::saveKeywordStyle(QSettings& settings, const FieldStyle& curStyle,
const FieldStyle& defaultStyle)
{
if(!curStyle.hasKeyword)
return;
if(!defaultStyle.hasKeyword ||
curStyle.keywordBold != defaultStyle.keywordBold)
settings.setValue("keyword/font-bold", curStyle.keywordBold);
if(!defaultStyle.hasKeyword ||
curStyle.keywordItalic != defaultStyle.keywordItalic)
settings.setValue("keyword/font-italic", curStyle.keywordItalic);
if(!defaultStyle.hasKeyword ||
curStyle.keywordColor != defaultStyle.keywordColor)
settings.setValue("keyword/color", curStyle.keywordColor.name());
}
|