Line data Source code
1 : #include <QSettings>
2 : #include <QStringList>
3 :
4 : #include "dbe/SchemaSettings.hpp"
5 : #include "dbe/SchemaStyle.hpp"
6 :
7 : #include "ui_SchemaSettings.h"
8 :
9 : using namespace dbse;
10 :
11 0 : SchemaSettings::SchemaSettings(QWidget* parent)
12 : : QDialog(parent)
13 0 : , m_ui(new Ui::SchemaSettings)
14 : {
15 0 : m_ui->setupUi(this);
16 0 : setObjectName("Settings");
17 :
18 0 : SchemaStyle::load();
19 :
20 0 : for (auto entry : QStringList{ "default/normal unhighlighted text",
21 : "active_file/items associated with the active file",
22 : "inherited/properties inherited from a parent class",
23 : "highlight/highlighted class",
24 : "readonly/items from a readonly file",
25 : "error/error messages",
26 : "note/notes on class diagrams",
27 0 : "line/lines showing inheritance or relationships between classes" }) {
28 0 : auto list = entry.split("/");
29 0 : auto group = list.at(0);
30 0 : auto fg_colour = SchemaStyle::get_color("foreground", group);
31 0 : auto bg_colour = SchemaStyle::get_color("background", group);
32 0 : for (auto fb : QStringList{ "Foreground", "Background" }) {
33 0 : auto item = new QListWidgetItem(group + " " + fb);
34 0 : item->setForeground(fg_colour);
35 0 : item->setBackground(bg_colour);
36 0 : if (list.size() > 1) {
37 0 : item->setToolTip(fb + " color for " + list.at(1));
38 : }
39 0 : m_ui->color_list->addItem(item);
40 0 : }
41 0 : }
42 :
43 0 : for (auto entry : QStringList{ "default/normal unhighlighted text",
44 : "highlight/highlighted class",
45 : "abstract/abstract base class",
46 : "note/notes on class diagrams",
47 0 : "line/lines showing inheritance or relationships between classes" }) {
48 0 : auto list = entry.split("/");
49 0 : auto group = list.at(0);
50 0 : auto item = new QListWidgetItem(group + " font");
51 0 : item->setFont(SchemaStyle::get_font(group));
52 0 : if (list.size() > 1) {
53 0 : item->setToolTip("Font for " + list.at(1));
54 : }
55 0 : m_ui->font_list->addItem(item);
56 0 : }
57 :
58 0 : connect(m_ui->color_list, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(set_color(QListWidgetItem*)));
59 0 : connect(m_ui->font_list, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(set_font(QListWidgetItem*)));
60 :
61 0 : QSettings settings;
62 0 : settings.beginGroup("view defaults");
63 0 : m_ui->abstract_button->setChecked(settings.value("highlight_abstract", false).toBool());
64 0 : connect(m_ui->abstract_button, SIGNAL(stateChanged(int)), this, SLOT(toggle_abstract(int)));
65 0 : m_ui->active_button->setChecked(settings.value("highlight_active", false).toBool());
66 0 : connect(m_ui->active_button, SIGNAL(stateChanged(int)), this, SLOT(toggle_active(int)));
67 0 : m_ui->inherited_button->setChecked(settings.value("show_inherited", false).toBool());
68 0 : connect(m_ui->inherited_button, SIGNAL(stateChanged(int)), this, SLOT(toggle_inherited(int)));
69 0 : m_ui->default_value_button->setChecked(settings.value("show_default", false).toBool());
70 0 : connect(m_ui->default_value_button, SIGNAL(stateChanged(int)), this, SLOT(toggle_default(int)));
71 0 : settings.endGroup();
72 :
73 0 : settings.beginGroup("MainWindow");
74 0 : m_ui->save_settings->setChecked(settings.value("saveLayout", false).toBool());
75 0 : connect(m_ui->save_settings, SIGNAL(stateChanged(int)), this, SLOT(toggle_save(int)));
76 0 : settings.endGroup();
77 0 : }
78 :
79 : void
80 0 : SchemaSettings::toggle_abstract(int state)
81 : {
82 0 : QSettings settings;
83 0 : settings.beginGroup("view defaults");
84 0 : settings.setValue("highlight_abstract", (state > 0));
85 0 : }
86 : void
87 0 : SchemaSettings::toggle_active(int state)
88 : {
89 0 : QSettings settings;
90 0 : settings.beginGroup("view defaults");
91 0 : settings.setValue("highlight_active", (state > 0));
92 0 : }
93 : void
94 0 : SchemaSettings::toggle_inherited(int state)
95 : {
96 0 : QSettings settings;
97 0 : settings.beginGroup("view defaults");
98 0 : settings.setValue("show_inherited", (state > 0));
99 0 : }
100 : void
101 0 : SchemaSettings::toggle_default(int state)
102 : {
103 0 : QSettings settings;
104 0 : settings.beginGroup("view defaults");
105 0 : settings.setValue("show_default", (state > 0));
106 0 : }
107 : void
108 0 : SchemaSettings::toggle_save(int state)
109 : {
110 0 : QSettings settings;
111 0 : settings.beginGroup("MainWindow");
112 0 : settings.setValue("saveLayout", (state > 0));
113 0 : }
114 :
115 : void
116 0 : SchemaSettings::set_color(QListWidgetItem* item)
117 : {
118 0 : QStringList text = item->text().toLower().split(" ");
119 0 : SchemaStyle::set_color(text.at(1), text.at(0));
120 0 : item->setForeground(SchemaStyle::get_color("foreground", text.at(0)));
121 0 : item->setBackground(SchemaStyle::get_color("background", text.at(0)));
122 0 : m_ui->color_list->update();
123 0 : emit settings_updated();
124 0 : }
125 : void
126 0 : SchemaSettings::set_font(QListWidgetItem* item)
127 : {
128 0 : QStringList text = item->text().toLower().split(" ");
129 0 : SchemaStyle::set_font(text.at(0));
130 0 : emit settings_updated();
131 0 : }
|