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