forked from laserpants/qt-material-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradiobuttonsettingseditor.cpp
144 lines (125 loc) · 5.4 KB
/
radiobuttonsettingseditor.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include "radiobuttonsettingseditor.h"
#include <QVBoxLayout>
#include <QRadioButton>
#include <QColorDialog>
#include <qtmaterialradiobutton.h>
RadioButtonSettingsEditor::RadioButtonSettingsEditor(QWidget *parent)
: QWidget(parent),
ui(new Ui::RadioButtonSettingsForm),
m_radioButton1(new QtMaterialRadioButton),
m_radioButton2(new QtMaterialRadioButton),
m_radioButton3(new QtMaterialRadioButton)
{
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);
m_radioButton1->setText("Coffee");
m_radioButton2->setText("Tea");
m_radioButton3->setText("Algebraic Topology");
layout = new QVBoxLayout;
canvas->setLayout(layout);
canvas->setMaximumHeight(350);
QWidget *buttonWidget = new QWidget;
QVBoxLayout *buttonLayout = new QVBoxLayout;
buttonWidget->setLayout(buttonLayout);
layout->addWidget(buttonWidget);
buttonLayout->addWidget(m_radioButton1);
buttonLayout->addWidget(m_radioButton2);
buttonLayout->addWidget(m_radioButton3);
QSizePolicy policy;
policy.setHorizontalPolicy(QSizePolicy::Maximum);
buttonWidget->setSizePolicy(policy);
layout->setAlignment(Qt::AlignCenter);
layout->setMargin(0);
layout->setSpacing(0);
setupForm();
connect(ui->disabledCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateWidget()));
connect(ui->labelPositionComboBox_2, SIGNAL(currentIndexChanged(int)), this, SLOT(updateWidget()));
connect(ui->labelTextLineEdit_2, SIGNAL(textChanged(QString)), this, SLOT(updateWidget()));
connect(ui->useThemeColorsCheckBox_3, SIGNAL(toggled(bool)), this, SLOT(updateWidget()));
connect(ui->textColorToolButton_2, SIGNAL(pressed()), this, SLOT(selectColor()));
connect(ui->disabledColorToolButton_2, SIGNAL(pressed()), this, SLOT(selectColor()));
connect(ui->checkedColorToolButton_2, SIGNAL(pressed()), this, SLOT(selectColor()));
connect(ui->uncheckedColorToolButton_2, SIGNAL(pressed()), this, SLOT(selectColor()));
connect(ui->labelPositionComboBox_2, SIGNAL(currentIndexChanged(int)), this, SLOT(updateWidget()));
}
RadioButtonSettingsEditor::~RadioButtonSettingsEditor()
{
delete ui;
}
void RadioButtonSettingsEditor::setupForm()
{
switch (m_radioButton1->labelPosition())
{
case QtMaterialCheckable::LabelPositionLeft:
ui->labelPositionComboBox_2->setCurrentIndex(0);
break;
case QtMaterialCheckable::LabelPositionRight:
ui->labelPositionComboBox_2->setCurrentIndex(1);
break;
default:
break;
}
ui->disabledCheckBox->setChecked(!m_radioButton1->isEnabled());
ui->labelTextLineEdit_2->setText(m_radioButton1->text());
ui->useThemeColorsCheckBox_3->setChecked(m_radioButton1->useThemeColors());
}
void RadioButtonSettingsEditor::updateWidget()
{
switch (ui->labelPositionComboBox_2->currentIndex())
{
case 0:
m_radioButton1->setLabelPosition(QtMaterialCheckable::LabelPositionLeft);
m_radioButton2->setLabelPosition(QtMaterialCheckable::LabelPositionLeft);
m_radioButton3->setLabelPosition(QtMaterialCheckable::LabelPositionLeft);
break;
case 1:
m_radioButton1->setLabelPosition(QtMaterialCheckable::LabelPositionRight);
m_radioButton2->setLabelPosition(QtMaterialCheckable::LabelPositionRight);
m_radioButton3->setLabelPosition(QtMaterialCheckable::LabelPositionRight);
break;
default:
break;
}
m_radioButton1->setDisabled(ui->disabledCheckBox->isChecked());
m_radioButton1->setText(ui->labelTextLineEdit_2->text());
m_radioButton1->setUseThemeColors(ui->useThemeColorsCheckBox_3->isChecked());
m_radioButton2->setUseThemeColors(ui->useThemeColorsCheckBox_3->isChecked());
m_radioButton3->setUseThemeColors(ui->useThemeColorsCheckBox_3->isChecked());
}
void RadioButtonSettingsEditor::selectColor()
{
QColorDialog dialog;
if (dialog.exec()) {
QColor color = dialog.selectedColor();
QString senderName = sender()->objectName();
if ("textColorToolButton_2" == senderName) {
m_radioButton1->setTextColor(color);
m_radioButton2->setTextColor(color);
m_radioButton3->setTextColor(color);
ui->textColorLineEdit_2->setText(color.name(QColor::HexRgb));
} else if ("disabledColorToolButton_2" == senderName) {
m_radioButton1->setDisabledColor(color);
m_radioButton2->setDisabledColor(color);
m_radioButton3->setDisabledColor(color);
ui->disabledColorLineEdit_2->setText(color.name(QColor::HexRgb));
} else if ("checkedColorToolButton_2" == senderName) {
m_radioButton1->setCheckedColor(color);
m_radioButton2->setCheckedColor(color);
m_radioButton3->setCheckedColor(color);
ui->checkedColorLineEdit_2->setText(color.name(QColor::HexRgb));
} else if ("uncheckedColorToolButton_2" == senderName) {
m_radioButton1->setUncheckedColor(color);
m_radioButton2->setUncheckedColor(color);
m_radioButton3->setUncheckedColor(color);
ui->uncheckedColorLineEdit_2->setText(color.name(QColor::HexRgb));
}
}
setupForm();
}