/
configurator.cpp
121 lines (95 loc) · 3.33 KB
/
configurator.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
/*
* Filename: configurator.h
*
* Programmer: Daniel Brook (danb358 [at] gmail.com)
*
* Implementation, bindings, and other features of the configurator window
*
* Last Updated by Daniel Brook on 04-Jan-2013 at 9:30 AM
*/
#include "configurator.h"
#include "ui_configurator.h"
#include <QFile>
Configurator::Configurator(QWidget *parent) :
QDialog(parent),
ui(new Ui::Configurator)
{
ui->setupUi(this);
// Don't load the settings at instantiation. We want to reload it manually
// each time the reloadSettings() member function is called.
set = NULL;
///////////////////////////////////////////////////////////////////////////
// Enhancements on top of base widget rendering
///////////////////////////////////////////////////////////////////////////
/*
* Make the "OK" button trigger a write-out to the config file.
*
* (We don't really care about the cancel button, because each time this
* window is started (which is really just a "re-showing" of its single
* instance), we are *HOPING* that the caller triggers a reloadSettings()
* beforehand. Otherwise, the the displayed parameters won't be accurate.
*/
connect( ui->buttonBox, SIGNAL(accepted()),
this, SLOT(writeOut()) );
// Make the window NOT RESIZEABLE
window()->layout()->setSizeConstraint( QLayout::SetFixedSize );
}
Configurator::~Configurator()
{
delete ui;
}
void Configurator::reloadSettings( void )
{
// Go get the settings
set = new QSettings( "appConfig.ini", QSettings::IniFormat );
///////////////////////////////////////////////////////////////////////////
// ACTUALLY PULL THE SETTINGS IN HERE:
// How this works: basically a parameter is loaded in, then its
// corresponding widget is "setValue"d to that value. SIMPLE.
///////////////////////////////////////////////////////////////////////////
// colorCutoff
colorCutoff = set->value( "ColorCutoffInteger", "10" ).toString().toInt();
ui->spin_colorChange->setValue( colorCutoff );
// NO MORE SETTINGS IN THIS VERSION
// Clean up after ingesting all the settings
delete set;
set = NULL;
}
bool Configurator::fileWritable( void )
{
// Tries to open the file read/write. If unable, then false is returned.
QFile testing( "appConfig.ini" );
if (testing.open( QIODevice::ReadWrite ) == false)
return false;
if (testing.isWritable() == false)
return false;
return true;
}
/////////// ACCESSORS / MUTATORS //////////////////////
int Configurator::getColorCutoff( void ) const
{
return this->colorCutoff;
}
void Configurator::setColorCutoff( int cutoff )
{
if (cutoff <= 0) cutoff = 1;
this->colorCutoff = cutoff;
}
//////////// SLOTS ////////////////////////////////////
void Configurator::writeOut( void )
{
/*
* COLOR CUTOFF VALUE
*/
// Grab whatever is in the color cutoff spinbox and write it to the INI
int tempCC = ui->spin_colorChange->value();
QString tempColorCutoff;
tempColorCutoff.append( QString("%1").arg( tempCC ) );
set = new QSettings( "appConfig.ini", QSettings::IniFormat );
set->setValue( "ColorCutoffInteger", tempColorCutoff );
this->colorCutoff = tempCC; // Save it to this object, too!
// No other parameters in this version
// Clean up
delete set;
set = NULL;
}