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