forked from laserpants/qt-material-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogresssettingseditor.cpp
99 lines (85 loc) · 3.06 KB
/
progresssettingseditor.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
#include "progresssettingseditor.h"
#include <QColorDialog>
#include <qtmaterialprogress.h>
#include <lib/qtmaterialtheme.h>
ProgressSettingsEditor::ProgressSettingsEditor(QWidget *parent)
: QWidget(parent),
ui(new Ui::ProgressSettingsForm),
m_progress(new QtMaterialProgress)
{
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_progress);
layout->setAlignment(m_progress, Qt::AlignCenter);
setupForm();
connect(ui->disabledCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateWidget()));
connect(ui->progressTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateWidget()));
connect(ui->progressSlider, SIGNAL(valueChanged(int)), this, SLOT(updateWidget()));
connect(ui->useThemeColorsCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateWidget()));
connect(ui->progressColorToolButton, SIGNAL(pressed()), this, SLOT(selectColor()));
connect(ui->backgroundColorToolButton, SIGNAL(pressed()), this, SLOT(selectColor()));
ui->progressSlider->setRange(0, 100);
}
ProgressSettingsEditor::~ProgressSettingsEditor()
{
delete ui;
}
void ProgressSettingsEditor::setupForm()
{
switch (m_progress->progressType())
{
case Material::DeterminateProgress:
ui->progressTypeComboBox->setCurrentIndex(0);
break;
case Material::IndeterminateProgress:
ui->progressTypeComboBox->setCurrentIndex(1);
break;
default:
break;
}
ui->disabledCheckBox->setChecked(!m_progress->isEnabled());
ui->progressSlider->setValue(m_progress->value());
ui->useThemeColorsCheckBox->setChecked(m_progress->useThemeColors());
}
void ProgressSettingsEditor::updateWidget()
{
switch (ui->progressTypeComboBox->currentIndex())
{
case 0:
m_progress->setProgressType(Material::DeterminateProgress);
break;
case 1:
m_progress->setProgressType(Material::IndeterminateProgress);
break;
default:
break;
}
m_progress->setDisabled(ui->disabledCheckBox->isChecked());
m_progress->setValue(ui->progressSlider->value());
m_progress->setUseThemeColors(ui->useThemeColorsCheckBox->isChecked());
}
void ProgressSettingsEditor::selectColor()
{
QColorDialog dialog;
if (dialog.exec()) {
QColor color = dialog.selectedColor();
QString senderName = sender()->objectName();
if ("progressColorToolButton" == senderName) {
m_progress->setProgressColor(color);
ui->progressColorLineEdit->setText(color.name(QColor::HexRgb));
} else if ("backgroundColorToolButton" == senderName) {
m_progress->setBackgroundColor(color);
ui->backgroundColorLineEdit->setText(color.name(QColor::HexRgb));
}
}
setupForm();
}