-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathsettingspage.cpp
262 lines (208 loc) · 8.49 KB
/
settingspage.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
This file is part of MagRead.
MagRead is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MagRead is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with MagRead. If not, see <http://www.gnu.org/licenses/>.
Written by Jeffrey Malone <[email protected]>
http://blog.tehinterweb.com
*/
#include "settingspage.h"
#include <QDebug>
SettingsPage::SettingsPage() {
widget = new QWidget;
layout = new QVBoxLayout;
widget->setLayout( layout );
settings = new QSettings;
if( !settings->contains( "formatCredit" ) )
resetAll( false );
makeGeneralBox();
makeAudioBox();
resetButton = new QPushButton( "Reset to defaults" );
layout->addWidget( resetButton );
connect( resetButton, SIGNAL( clicked() ), this, SLOT( resetAll() ) );
setWidget( widget );
setWidgetResizable( true );
}
void SettingsPage::makeGeneralBox() {
generalBox = new QGroupBox( "General Settings" );
generalLayout = new QVBoxLayout;
formatCredit = new QCheckBox( "Format Bank Cards" );
generalLayout->addWidget( formatCredit );
if( settings->value( "formatCredit" ) == true )
formatCredit->setCheckState( Qt::Checked );
connect( formatCredit, SIGNAL( stateChanged( int ) ), this, SLOT( formatCredit_checked( int ) ) );
formatAAMVA = new QCheckBox( "Format AAMVA Cards" );
generalLayout->addWidget( formatAAMVA );
if( settings->value( "formatAAMVA" ) == true )
formatAAMVA->setCheckState( Qt::Checked );
connect( formatAAMVA, SIGNAL( stateChanged( int ) ), this, SLOT( formatAAMVA_checked( int ) ) );
#ifdef Q_WS_MAEMO_5
autoReorient = new QCheckBox( "Auto-reorient Screen" );//not symbian
generalLayout->addWidget( autoReorient );
if( settings->value( "autoReorient" ) == true )
autoReorient->setCheckState( Qt::Checked );
connect( autoReorient, SIGNAL( stateChanged( int ) ), this, SLOT( autoReorient_checked( int ) ) );
#endif
timeOutLabel = new QLabel( "Swipe Timeout: 10" );
generalLayout->addWidget( timeOutLabel );
timeOutSlider = new QSlider( Qt::Horizontal );
timeOutSlider->setTickInterval( 1 );
timeOutSlider->setRange( 0, 100 );
if( settings->contains( "timeOut" ) ) {
timeOutLabel->setText( QString( "Swipe Timeout: %1" ).arg( settings->value( "timeOut" ).toInt() ) );
timeOutSlider->setSliderPosition( settings->value( "timeOut" ).toInt() );
} else {
timeOutSlider->setSliderPosition( 10 );
}
connect( timeOutSlider, SIGNAL( valueChanged( int ) ), this, SLOT( timeOutChanged( int ) ) );
generalLayout->addWidget( timeOutSlider );
decodeMethodLabel = new QLabel( "Decoding Algorithm" );
generalLayout->addWidget( decodeMethodLabel );
decodeMethodIntersect = new QRadioButton( "Instersection Algorithm", this );
connect( decodeMethodIntersect, SIGNAL( toggled( bool ) ), this, SLOT( decodeMethodChanged( bool ) ) );
generalLayout->addWidget( decodeMethodIntersect );
decodeMethodWalk = new QRadioButton( "Walking Algorithm", this );
connect( decodeMethodWalk, SIGNAL( toggled( bool ) ), this, SLOT( decodeMethodChanged( bool ) ) );
generalLayout->addWidget( decodeMethodWalk );
if( settings->value( "algorithm" ).toString() == "intersect" )
decodeMethodIntersect->setChecked( true );
else
decodeMethodWalk->setChecked( true );
generalBox->setLayout( generalLayout );
layout->addWidget( generalBox );
}
void SettingsPage::formatCredit_checked( int state ) {
if( state == Qt::Checked )
settings->setValue( "formatCredit", true );
else
settings->setValue( "formatCredit", false );
}
void SettingsPage::formatAAMVA_checked( int state ) {
if( state == Qt::Checked )
settings->setValue( "formatAAMVA", true );
else
settings->setValue( "formatAAMVA", false );
}
void SettingsPage::autoReorient_checked( int state ) {
if( state == Qt::Checked )
settings->setValue( "autoReorient", true );
else
settings->setValue( "autoReorient", false );
#ifdef Q_WS_MAEMO_5
if( settings->value( "autoReorient" ) == true ) {
emit autoReorientSig( true );
} else {
emit autoReorientSig( false );
}
#endif
}
void SettingsPage::timeOutChanged( int value ) {
timeOutLabel->setText( QString( "Swipe Timeout: %1" ).arg( value ) );
settings->setValue( "timeOut", value );
}
void SettingsPage::decodeMethodChanged( bool checked ) {
Q_UNUSED( checked );
if( decodeMethodIntersect->isChecked() )
settings->setValue( "algorithm", "intersect" );
else
settings->setValue( "algorithm", "walk" );
}
void SettingsPage::makeAudioBox() {
audioBox = new QGroupBox( "Audio Settings" );
audioLayout = new QVBoxLayout;
audioLayout->addWidget( new QLabel( "Audio Input:" ) );
audioSource = new QComboBox;
QList<QAudioDeviceInfo> inputDevices = QAudioDeviceInfo::availableDevices( QAudio::AudioInput );
for( int i = 0; i < inputDevices.size(); i++ ) {
audioSource->addItem( inputDevices.at( i ).deviceName() );
}
audioLayout->addWidget( audioSource );
connect( audioSource, SIGNAL( currentIndexChanged( QString ) ), this, SLOT( audioDeviceChanged( QString ) ) );
normCBox = new QCheckBox( "Auto-Detect Normalzation" );
audioLayout->addWidget( normCBox );
connect( normCBox, SIGNAL( stateChanged( int ) ), this, SLOT( normChecked( int ) ) );
normLabel = new QLabel;
audioLayout->addWidget( normLabel );
normSlider = new QSlider( Qt::Horizontal );
normSlider->setTickInterval( 10 );
normSlider->setRange( -500, 500 );
audioLayout->addWidget( normSlider );
connect( normSlider, SIGNAL( valueChanged( int ) ), this, SLOT( normChanged( int ) ) );
if( settings->contains( "norm" ) )
normSlider->setSliderPosition( settings->value( "norm" ).toInt() );
else
normSlider->setSliderPosition( 0 );
if( !settings->contains( "normAuto" ) || settings->value( "normAuto" ) == true ) {
normCBox->setCheckState( Qt::Checked );
normSlider->setEnabled( false );
normLabel->setText( QString( "Normalization: Auto-Detect" ) );
} else {
normLabel->setText( QString( "Normalization: %1" ).arg( normSlider->value() ) );
}
silenceLabel = new QLabel( "Silence Theshold: 300" );
audioLayout->addWidget( silenceLabel );
silenceSlider = new QSlider( Qt::Horizontal );
silenceSlider->setTickInterval( 20 );
silenceSlider->setRange( 0, 1000 );
silenceSlider->setSliderPosition( 300 );
audioLayout->addWidget( silenceSlider );
connect( silenceSlider, SIGNAL( valueChanged( int ) ), this, SLOT( silenceChanged( int ) ) );
if( settings->contains( "silenceThreshold" ) ) {
silenceSlider->setSliderPosition( settings->value( "silenceThreshold" ).toInt() );
} else {
silenceSlider->setSliderPosition( 300 );
}
silenceLabel->setText( QString( "Silence Threshold: %1" ).arg( silenceSlider->value() ) );
audioBox->setLayout( audioLayout );
layout->addWidget( audioBox );
}
void SettingsPage::audioDeviceChanged( QString audioDevice ) {
settings->setValue( "audioDevice", audioDevice );
}
void SettingsPage::normChecked( int state ) {
if( state == Qt::Checked ) {
normSlider->setEnabled( false );
normLabel->setText( "Normalization: Auto-Detect" );
settings->setValue( "normAuto", true );
} else {
normSlider->setEnabled( true );
normLabel->setText( QString( "Normalization: %1" ).arg( normSlider->value() ) );
settings->setValue( "normAuto", false );
}
}
void SettingsPage::silenceChanged( int value ) {
silenceLabel->setText( QString( "Silence Threshold: %1" ).arg( value ) );
settings->setValue( "silenceThreshold", value );
}
void SettingsPage::normChanged( int value ) {
normLabel->setText( QString( "Normalization: %1" ).arg( value ) );
settings->setValue( "norm", value );
}
void SettingsPage::resetAll( bool updateGui ) {
settings->setValue( "formatCredit", true );
settings->setValue( "formatAAMVA", true );
settings->setValue( "autoReorient", true );
settings->setValue( "timeOut", 10 );
settings->setValue( "normAuto", true );
settings->setValue( "norm", 0 );
settings->setValue( "silenceThreshold", 300 );
if( updateGui ) {
formatCredit->setCheckState( Qt::Checked );
formatAAMVA->setCheckState( Qt::Checked );
#ifdef Q_WS_MAEMO5
autoReorient->setCheckState( Qt::Checked );
#endif
timeOutChanged( 10 );
normCBox->setCheckState( Qt::Checked );
normSlider->setSliderPosition( 0 );
normLabel->setText( "Normalization: Auto-Detect" );
silenceChanged( 300 );
}
}