forked from laserpants/qt-material-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiconbuttonsettingseditor.cpp
85 lines (72 loc) · 2.65 KB
/
iconbuttonsettingseditor.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 "iconbuttonsettingseditor.h"
#include <QColorDialog>
#include <qtmaterialiconbutton.h>
#include <lib/qtmaterialtheme.h>
IconButtonSettingsEditor::IconButtonSettingsEditor(QWidget *parent)
: QWidget(parent),
ui(new Ui::IconButtonSettingsForm),
m_button(new QtMaterialIconButton(QtMaterialTheme::icon("toggle", "star")))
{
init();
}
IconButtonSettingsEditor::~IconButtonSettingsEditor()
{
delete ui;
}
IconButtonSettingsEditor::IconButtonSettingsEditor(QtMaterialIconButton *button, QWidget *parent)
: QWidget(parent),
ui(new Ui::IconButtonSettingsForm),
m_button(button)
{
init();
}
void IconButtonSettingsEditor::setupForm()
{
ui->disabledCheckBox->setChecked(!m_button->isEnabled());
ui->useThemeColorsCheckBox->setChecked(m_button->useThemeColors());
ui->sizeSpinBox->setValue(m_button->iconSize().width());
}
void IconButtonSettingsEditor::updateWidget()
{
m_button->setDisabled(ui->disabledCheckBox->isChecked());
m_button->setUseThemeColors(ui->useThemeColorsCheckBox->isChecked());
m_button->setIconSize(QSize(ui->sizeSpinBox->value(), ui->sizeSpinBox->value()));
}
void IconButtonSettingsEditor::selectColor()
{
QColorDialog dialog;
if (dialog.exec()) {
QColor color = dialog.selectedColor();
QString senderName = sender()->objectName();
if ("colorToolButton" == senderName) {
m_button->setColor(color);
ui->colorLineEdit->setText(color.name(QColor::HexRgb));
} else if ("disabledColorToolButton" == senderName) {
m_button->setDisabledColor(color);
ui->disabledColorLineEdit->setText(color.name(QColor::HexRgb));
}
}
setupForm();
}
void IconButtonSettingsEditor::init()
{
QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
QWidget *widget = new QWidget;
layout->addWidget(widget);
QWidget *canvas = new QWidget;
canvas->setStyleSheet("QWidget { background: white; }");
layout->addWidget(canvas);
ui->setupUi(widget);
layout->setContentsMargins(20, 20, 20, 20);
layout = new QVBoxLayout;
canvas->setLayout(layout);
layout->addWidget(m_button);
layout->setAlignment(m_button, Qt::AlignCenter);
setupForm();
connect(ui->disabledCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateWidget()));
connect(ui->useThemeColorsCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateWidget()));
connect(ui->colorToolButton, SIGNAL(clicked(bool)), this, SLOT(selectColor()));
connect(ui->disabledColorToolButton, SIGNAL(clicked(bool)), this, SLOT(selectColor()));
connect(ui->sizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateWidget()));
}