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 : // QSettings settings(".dbse.config", QSettings::IniFormat);
12 0 : QSettings settings("dunedaq", "dbse");
13 :
14 0 : settings.beginGroup("default");
15 0 : if (!settings.contains("background")) {
16 0 : QColor color = Qt::white;
17 0 : settings.setValue("background", color);
18 : }
19 0 : if (!settings.contains("foreground")) {
20 0 : QColor color = Qt::black;
21 0 : settings.setValue("foreground", color);
22 : }
23 0 : settings.endGroup();
24 :
25 0 : settings.beginGroup("active_file");
26 0 : if (!settings.contains("background")) {
27 0 : QColor color = Qt::white;
28 0 : settings.setValue("background", color);
29 : }
30 0 : if (!settings.contains("foreground")) {
31 0 : QColor color = Qt::blue;
32 0 : settings.setValue("foreground", color);
33 : }
34 0 : settings.endGroup();
35 :
36 0 : settings.beginGroup("highlight");
37 0 : if (!settings.contains("background")) {
38 0 : QColor color = Qt::white;
39 0 : settings.setValue("background", color);
40 : }
41 0 : if (!settings.contains("foreground")) {
42 0 : QColor color = Qt::magenta;
43 0 : settings.setValue("foreground", color);
44 : }
45 0 : settings.endGroup();
46 :
47 0 : settings.beginGroup("inherited");
48 0 : if (!settings.contains("background")) {
49 0 : QColor color = Qt::white;
50 0 : settings.setValue("background", color);
51 : }
52 0 : if (!settings.contains("foreground")) {
53 0 : QColor color {0x804040};
54 0 : settings.setValue("foreground", color);
55 : }
56 0 : settings.endGroup();
57 :
58 0 : settings.beginGroup("readonly");
59 0 : if (!settings.contains("background")) {
60 0 : QColor color = Qt::gray;
61 0 : settings.setValue("background", color);
62 : }
63 0 : if (!settings.contains("foreground")) {
64 0 : QColor color = Qt::darkRed;
65 0 : settings.setValue("foreground", color);
66 : }
67 0 : settings.endGroup();
68 :
69 0 : settings.beginGroup("error");
70 0 : if (!settings.contains("background")) {
71 0 : QColor color = Qt::white;
72 0 : settings.setValue("background", color);
73 : }
74 0 : if (!settings.contains("foreground")) {
75 0 : QColor color = Qt::red;
76 0 : settings.setValue("foreground", color);
77 : }
78 0 : settings.endGroup();
79 :
80 0 : settings.beginGroup("note");
81 0 : if (!settings.contains("background")) {
82 0 : QColor color {0xfff0ff};
83 0 : settings.setValue("background", color);
84 : }
85 0 : if (!settings.contains("foreground")) {
86 0 : QColor color = Qt::black;
87 0 : settings.setValue("foreground", color);
88 : }
89 0 : settings.endGroup();
90 :
91 0 : settings.beginGroup("line");
92 0 : if (!settings.contains("background")) {
93 0 : QColor color = Qt::black;
94 0 : settings.setValue("background", color);
95 : }
96 0 : if (!settings.contains("foreground")) {
97 0 : QColor color = Qt::black;
98 0 : settings.setValue("foreground", color);
99 : }
100 0 : settings.endGroup();
101 :
102 0 : }
103 :
104 0 : QColor SchemaStyle::get_color(const QString& item,
105 : const QString& group) {
106 0 : QSettings settings("dunedaq", "dbse");
107 0 : return settings.value(group+"/"+item).value<QColor>();
108 0 : }
109 :
110 0 : QColor SchemaStyle::set_color(const QString& item,
111 : const QString& group) {
112 0 : QSettings settings("dunedaq", "dbse");
113 0 : settings.beginGroup(group);
114 0 : auto color = settings.value(item).value<QColor>();
115 :
116 0 : color = QColorDialog::getColor(color);
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("dunedaq", "dbse");
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 : QSettings settings("dunedaq", "dbse");
136 0 : settings.beginGroup(group);
137 0 : QFont font;
138 0 : if (settings.contains("font")) {
139 0 : font = settings.value("font").value<QFont>();
140 : }
141 : else {
142 0 : font = QFont("Helvetica [Cronyx]", 9);
143 : }
144 0 : font = QFontDialog::getFont(nullptr, font);
145 0 : settings.setValue("font", font);
146 0 : return font;
147 0 : }
148 :
149 : } // namespace dbse
|