-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsettingsform.cpp
156 lines (120 loc) · 4.21 KB
/
settingsform.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
145
146
147
148
149
150
151
152
153
154
155
156
#include "settingsform.h"
#include <QDebug>
#include <QPushButton>
#include <QVBoxLayout>
SettingsForm::SettingsForm(QWidget *parent) : QDialog(parent)
{
settingsResult="";
TIM1ON=new QCheckBox;
TIM1DURATION=new QLineEdit;
QValidator *validator = new QIntValidator(1, 9999, this);
TIM1DURATION->setValidator(validator);
CNT1ON=new QCheckBox;
CNT1EDGE=new QComboBox;
CNT1RELOAD=new QLineEdit;
CNT2ON=new QCheckBox;
CNT2EDGE=new QComboBox;
CNT2RELOAD=new QLineEdit;
CNT1RELOAD->setValidator(validator);
CNT2RELOAD->setValidator(validator);
CNT1EDGE->addItem("RISING");
CNT1EDGE->addItem("FALLING");
CNT2EDGE->addItem("RISING");
CNT2EDGE->addItem("FALLING");
TIM1DURATION->setEnabled(0);
CNT1EDGE->setEnabled(0);
CNT1RELOAD->setEnabled(0);
CNT2EDGE->setEnabled(0);
CNT2RELOAD->setEnabled(0);
layout = new QFormLayout;
layout->addRow(tr("&TIM1ON"), TIM1ON);
layout->addRow(tr("&TIM1DURATION"), TIM1DURATION);
layout->addRow(tr("&CNT1ON"), CNT1ON);
layout->addRow(tr("&CNT1EDGE"),CNT1EDGE);
layout->addRow(tr("&CNT1RELOAD"), CNT1RELOAD);
layout->addRow(tr("&CNT2ON"), CNT2ON);
layout->addRow(tr("&CNT2EDGE"),CNT2EDGE);
layout->addRow(tr("&CNT2RELOAD"), CNT2RELOAD);
connect(TIM1ON,SIGNAL(stateChanged(int)),this,SLOT(setTIM1(int)));
connect(CNT1ON,SIGNAL(stateChanged(int)),this,SLOT(setCNT1(int)));
connect(CNT2ON,SIGNAL(stateChanged(int)),this,SLOT(setCNT2(int)));
buttonBox = new QDialogButtonBox;
buttonBox->addButton(tr("Apply"),
QDialogButtonBox::AcceptRole);
buttonBox->addButton(tr("Close"),
QDialogButtonBox::RejectRole);
buttonBox->addButton(QDialogButtonBox::Reset);
connect(buttonBox, SIGNAL(accepted()),
this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()),
this, SLOT(reject()));
connect(buttonBox->button(QDialogButtonBox::Reset),
SIGNAL(clicked()), this, SLOT(reset()));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(layout);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Settings"));
}
void SettingsForm::reset()
{
TIM1ON->setCheckState(Qt::CheckState::Unchecked);
CNT1ON->setCheckState(Qt::CheckState::Unchecked);
CNT2ON->setCheckState(Qt::CheckState::Unchecked);
TIM1DURATION->setEnabled(0);
TIM1DURATION->clear();
CNT1EDGE->setEnabled(0);
CNT1EDGE->setCurrentIndex(0);
CNT1RELOAD->setEnabled(0);
CNT1RELOAD->clear();
CNT2EDGE->setCurrentIndex(0);
CNT2EDGE->setEnabled(0);
CNT2RELOAD->setEnabled(0);
CNT2RELOAD->clear();
}
void SettingsForm::setTIM1(int state)
{
TIM1DURATION->setEnabled(state);
}
void SettingsForm::setCNT1(int state)
{
CNT1EDGE->setEnabled(state);
CNT1RELOAD->setEnabled(state);
}
void SettingsForm::setCNT2(int state)
{
CNT2EDGE->setEnabled(state);
CNT2RELOAD->setEnabled(state);
}
void SettingsForm::accept()
{
settingsResult.clear();
if(TIM1ON->checkState()==Qt::CheckState::Checked){
settingsResult.append("#define TIM1ON ");
settingsResult.append("1\n");
settingsResult.append("#define TIM1DURATION ");
settingsResult.append(TIM1DURATION->text());
settingsResult.append("\n");
}
if(CNT1ON->checkState()==Qt::CheckState::Checked){
settingsResult.append("#define CNT1ON ");
settingsResult.append("1\n");
settingsResult.append("#define CNT1EDGE ");
settingsResult.append(CNT1EDGE->currentText());
settingsResult.append("\n");
settingsResult.append("#define CNT1RELOAD ");
settingsResult.append(CNT1RELOAD->text());
settingsResult.append("\n");
}
if(CNT2ON->checkState()==Qt::CheckState::Checked){
settingsResult.append("#define CNT2ON ");
settingsResult.append("1\n");
settingsResult.append("#define CNT2EDGE ");
settingsResult.append(CNT2EDGE->currentText());
settingsResult.append("\n");
settingsResult.append("#define CNT2RELOAD ");
settingsResult.append(CNT2RELOAD->text());
settingsResult.append("\n");
}
qDebug()<<settingsResult<<endl;
}