Line data Source code
1 : #include <QColorDialog>
2 : #include <QSettings>
3 : #include <QStringList>
4 :
5 : #include "dbe/Preferences.hpp"
6 : #include "dbe/StyleUtility.hpp"
7 :
8 : #include "ui_Preferences.h"
9 :
10 : namespace dbe {
11 :
12 0 : Preferences::Preferences(QWidget* parent)
13 : : QDialog(parent)
14 0 : , m_ui(new Ui::Preferences)
15 : {
16 0 : m_ui->setupUi(this);
17 0 : setObjectName("Preferences");
18 :
19 0 : QSettings settings;
20 0 : auto item = new QListWidgetItem("Attribute Foreground");
21 0 : item->setToolTip("Foreground colour for attributes");
22 0 : item->setForeground(settings.value("attribute/foreground").value<QColor>());
23 0 : m_ui->attribute_list->addItem(item);
24 :
25 0 : item = new QListWidgetItem("Attribute Background");
26 0 : item->setToolTip("Normal background colour for attributes");
27 0 : item->setBackground(settings.value("attribute/background").value<QColor>());
28 0 : m_ui->attribute_list->addItem(item);
29 :
30 0 : item = new QListWidgetItem("Attribute Default-Background");
31 0 : item->setToolTip("Background colour for attributes set to their default value");
32 0 : item->setBackground(settings.value("attribute/default-background").value<QColor>());
33 0 : m_ui->attribute_list->addItem(item);
34 :
35 0 : item = new QListWidgetItem("Relationship Foreground");
36 0 : item->setToolTip("Foreground colour for relationships");
37 0 : item->setForeground(settings.value("relationship/foreground").value<QColor>());
38 0 : m_ui->relationship_list->addItem(item);
39 :
40 0 : item = new QListWidgetItem("Relationship Background");
41 0 : item->setToolTip("background colour for relationships");
42 0 : item->setBackground(settings.value("relationship/background").value<QColor>());
43 0 : m_ui->relationship_list->addItem(item);
44 :
45 0 : item = new QListWidgetItem("Readonly Foreground");
46 0 : item->setToolTip("Foreground text colour for readonly items");
47 0 : item->setForeground(settings.value("readonly/foreground").value<QColor>());
48 0 : m_ui->read_only_list->addItem(item);
49 :
50 0 : item = new QListWidgetItem("Readonly Background");
51 0 : item->setToolTip("Background text colour for readonly items");
52 0 : item->setBackground(settings.value("readonly/background").value<QColor>());
53 0 : m_ui->read_only_list->addItem(item);
54 :
55 0 : connect(m_ui->attribute_list, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(set_color(QListWidgetItem*)));
56 0 : connect(m_ui->relationship_list, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(set_color(QListWidgetItem*)));
57 0 : connect(m_ui->read_only_list, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(set_color(QListWidgetItem*)));
58 0 : }
59 :
60 : void
61 0 : Preferences::set_color(QListWidgetItem* item)
62 : {
63 0 : QSettings settings;
64 0 : QStringList text = item->text().toLower().split(" ");
65 0 : settings.beginGroup(text.at(0));
66 :
67 0 : auto color = settings.value(text.at(1)).value<QColor>();
68 0 : auto title = QString("Select color for ") + item->text();
69 0 : color = QColorDialog::getColor(color, nullptr, title);
70 :
71 0 : if (color.isValid()) {
72 0 : settings.setValue(text.at(1), color);
73 0 : StyleUtility::InitColorManagement();
74 : }
75 0 : }
76 : } // namespace dbe
|