-
Notifications
You must be signed in to change notification settings - Fork 0
/
PreferencesDialog.cpp
85 lines (71 loc) · 3.03 KB
/
PreferencesDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <QFontDialog>
#include <QColor>
#include <QPainter>
#include <QIcon>
#include <iostream>
#include <QColorDialog>
#include "PreferencesDialog.hpp"
#include "ui_PreferencesDialog.h"
#include "Preferences.hpp"
PreferencesDialog::PreferencesDialog(Preferences* preferences):
QDialog(), preferences_(preferences), ui_(new Ui::Dialog)
{
ui_ -> setupUi(this);
auto fontButton = findChild<QPushButton*>("FontButton");
fontButton -> setText(preferences_ -> font.family() + ":" +
QString::number(preferences_ -> font.pointSize()));
connect(fontButton, &QPushButton::clicked,
[=] {
bool ok;
QFont font = QFontDialog::getFont(&ok, preferences_ -> font, this);
if(ok) {
preferences_ -> font = font;
fontButton -> setText(preferences_ -> font.family() + ":" +
QString::number(preferences_ -> font.pointSize()));
}
});
auto textColorButton = findChild<QPushButton*>("TextColorButton");
textColorButton -> setIcon(QIcon(CreateColorPixmap(preferences_ -> textColor)));
connect(textColorButton, &QPushButton::clicked,
[=] {
auto color = QColorDialog::getColor(preferences_ -> textColor, this);
if(color.isValid()) preferences_ -> textColor = color;
textColorButton -> setIcon(QIcon(CreateColorPixmap(preferences_ -> textColor)));
});
auto backgroundColorButton = findChild<QPushButton*>("BackgroundButton");
backgroundColorButton -> setIcon(QIcon(CreateColorPixmap(preferences_ -> backgroundColor)));
connect(backgroundColorButton, &QPushButton::clicked,
[=] {
auto color = QColorDialog::getColor(preferences_ -> backgroundColor, this);
if(color.isValid()) preferences_ -> backgroundColor = color;
backgroundColorButton -> setIcon(QIcon(CreateColorPixmap(preferences_ -> backgroundColor)));
});
auto lineSpinBox = findChild<QSpinBox*>("LineSpinBox");
lineSpinBox -> setValue(preferences_ -> line);
connect(lineSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
[=] {
preferences_ -> line = lineSpinBox -> value();
});
auto marginSpinBox = findChild<QSpinBox*>("MarginSpinBox");
marginSpinBox -> setValue(preferences_ -> margine);
connect(marginSpinBox, QOverload<int>::of(&QSpinBox::valueChanged),
[=] {
preferences_ -> margine = marginSpinBox -> value();
});
auto buttonBox = findChild<QDialogButtonBox*>("buttonBox");
connect(buttonBox, &QDialogButtonBox::accepted, this, &PreferencesDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &PreferencesDialog::reject);
}
QPixmap PreferencesDialog::CreateColorPixmap(const QColor& color)
{
QPixmap pixmap(100, 100);
pixmap.fill(color);
QPainter painter(&pixmap);
painter.setPen(QColor(100,100,100,255));
painter.drawRect(0, 0, pixmap.height() - 1, pixmap.width() - 1);
return pixmap;
}
PreferencesDialog::~PreferencesDialog()
{
delete ui_;
}