Line data Source code
1 : #include "dbe/SchemaStyle.hpp"
2 :
3 : #include <QColor>
4 : #include <QColorDialog>
5 : #include <QFontDialog>
6 : #include <QSettings>
7 :
8 : namespace dbse {
9 :
10 0 : void SchemaStyle::load() {
11 0 : QSettings settings;
12 :
13 0 : settings.beginGroup("default");
14 0 : if (!settings.contains("background")) {
15 0 : QColor color = Qt::white;
16 0 : settings.setValue("background", color);
17 : }
18 0 : if (!settings.contains("foreground")) {
19 0 : QColor color = Qt::black;
20 0 : settings.setValue("foreground", color);
21 : }
22 0 : settings.endGroup();
23 :
24 0 : settings.beginGroup("active_file");
25 0 : if (!settings.contains("background")) {
26 0 : QColor color = Qt::white;
27 0 : settings.setValue("background", color);
28 : }
29 0 : if (!settings.contains("foreground")) {
30 0 : QColor color = Qt::blue;
31 0 : settings.setValue("foreground", color);
32 : }
33 0 : settings.endGroup();
34 :
35 0 : settings.beginGroup("highlight");
36 0 : if (!settings.contains("background")) {
37 0 : QColor color = Qt::white;
38 0 : settings.setValue("background", color);
39 : }
40 0 : if (!settings.contains("foreground")) {
41 0 : QColor color = Qt::magenta;
42 0 : settings.setValue("foreground", color);
43 : }
44 0 : settings.endGroup();
45 :
46 0 : settings.beginGroup("inherited");
47 0 : if (!settings.contains("background")) {
48 0 : QColor color = Qt::white;
49 0 : settings.setValue("background", color);
50 : }
51 0 : if (!settings.contains("foreground")) {
52 0 : QColor color {0x804040};
53 0 : settings.setValue("foreground", color);
54 : }
55 0 : settings.endGroup();
56 :
57 0 : settings.beginGroup("readonly");
58 0 : if (!settings.contains("background")) {
59 0 : QColor color = Qt::gray;
60 0 : settings.setValue("background", color);
61 : }
62 0 : if (!settings.contains("foreground")) {
63 0 : QColor color = Qt::darkRed;
64 0 : settings.setValue("foreground", color);
65 : }
66 0 : settings.endGroup();
67 :
68 0 : settings.beginGroup("error");
69 0 : if (!settings.contains("background")) {
70 0 : QColor color = Qt::white;
71 0 : settings.setValue("background", color);
72 : }
73 0 : if (!settings.contains("foreground")) {
74 0 : QColor color = Qt::red;
75 0 : settings.setValue("foreground", color);
76 : }
77 0 : settings.endGroup();
78 :
79 0 : settings.beginGroup("note");
80 0 : if (!settings.contains("background")) {
81 0 : QColor color {0xfff0ff};
82 0 : settings.setValue("background", color);
83 : }
84 0 : if (!settings.contains("foreground")) {
85 0 : QColor color = Qt::black;
86 0 : settings.setValue("foreground", color);
87 : }
88 0 : settings.endGroup();
89 :
90 0 : settings.beginGroup("line");
91 0 : if (!settings.contains("background")) {
92 0 : QColor color = Qt::black;
93 0 : settings.setValue("background", color);
94 : }
95 0 : if (!settings.contains("foreground")) {
96 0 : QColor color = Qt::black;
97 0 : settings.setValue("foreground", color);
98 : }
99 0 : settings.endGroup();
100 :
101 0 : }
102 :
103 0 : QColor SchemaStyle::get_color(const QString& item,
104 : const QString& group) {
105 0 : QSettings settings;
106 0 : return settings.value(group+"/"+item).value<QColor>();
107 0 : }
108 :
109 0 : QColor SchemaStyle::set_color(const QString& item,
110 : const QString& group) {
111 0 : QSettings settings;
112 0 : settings.beginGroup(group);
113 0 : auto color = settings.value(item).value<QColor>();
114 :
115 0 : color = QColorDialog::getColor(color, nullptr,
116 0 : QString("Set "+item+" color for "+group));
117 :
118 0 : if (color.isValid()) {
119 0 : settings.setValue(item, color);
120 : }
121 0 : return color;
122 0 : }
123 :
124 :
125 0 : QFont SchemaStyle::get_font(const QString& group) {
126 0 : QSettings settings;
127 0 : QString key{group+"/font"};
128 0 : if (settings.contains(key)) {
129 0 : return settings.value(key).value<QFont>();
130 : }
131 0 : return QFont("Helvetica [Cronyx]", 9);
132 0 : }
133 :
134 0 : QFont SchemaStyle::set_font(const QString& group) {
135 0 : QFont font = QFontDialog::getFont(nullptr, get_font(group),
136 : nullptr,
137 0 : QString("Select " + group + " font"));
138 0 : QSettings settings;
139 0 : settings.beginGroup(group);
140 0 : settings.setValue("font", font);
141 0 : return font;
142 0 : }
143 :
144 : } // namespace dbse
|