/
definegamedialog.h
178 lines (142 loc) · 5.34 KB
/
definegamedialog.h
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
/* This source file is part of Cooperation, an implementation of the
* Prisoner's Dilemna game.
*
* Copyright (C) 2012 by Nathan Geffen
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DEFINEGAMEDIALOGUE_H
#define DEFINEGAMEDIALOGUE_H
#include <map>
#include <vector>
#include <QtGui>
using namespace std;
/**
* Small pushbutton class that brings up Qt color select dialog
*/
class ColorPickButton : public QPushButton
{
public:
ColorPickButton( int i, QWidget *parent ) :
QPushButton(parent), index_(i) { setText( tr("Choose color") ); }
int getIndex() const { return index_; }
private:
int index_;
};
/** This class handles the main dialog in the GUI, that is used to set the
* parameters of a new game.
*/
class DefineGameDialog : public QDialog
{
Q_OBJECT
public:
DefineGameDialog(QWidget* parent = 0);
/** Sets the number of iterations for the game.
*/
void setIterations(int i) { iterationsEdit_->setValue(i); }
/** Sets the random seed for the game.
*/
void setRandomSeed( int i ) { randomSeedEdit_->setValue(i); }
/** Specify how frequently the competitor widgets are updated.
*
* Set the parameter to 1 for an update after every iteration.
*/
void setUpdateFrequency(int i) { updateFrequencyEdit_->setValue(i); }
/** Choose an update methodology that corresponds to an entry in the
* in the DisplayMethodology.
*/
void setUpdateStyle(int i) { updateStyleCombo_->setCurrentIndex(i); }
/** Tells the dialog how many of each competitor there are when it starts up.
*
* @param[in] nCompetitorsMap a map from QString to int where the key is
* the name of a competitor in the registeredCompetitors global
* variable and the integer is the number of competitors.
*/
void setCompetitors( const map<QString, int> nCompetitorsMap );
/** Tells the dialog what color to initiate each competitor type to.
*
* @param[in] colors a map from QString to QColor where the key is
* the name of a competitor in the registeredCompetitors global
* variable and the integer is the number of competitors.
*/
void setCompetitorColors( const map<QString, QColor>& colors );
/** Sets the dialog's initial time in milliseconds between each iteration of
* the game.
*/
void setTimer(int i) { timerEdit_->setValue(i); }
/** Convenience function to set the dialog's initial number of competitors
* for each competitor to the same number.
*/
void setNumberForAllCompetitors( int i );
/** Returns the number of iterations set on the dialog by the user.
*/
int getIterations() const { return iterationsEdit_->text().toInt(); }
/** Returns the random seed set on the dialog by the user.
*/
int getRandomSeed() const { return randomSeedEdit_->text().toInt(); }
/** Returns the frequency with which the competitor widgets must be updated,
* as set on the dialog by the user.
*/
int getUpdateFrequency() const { return updateFrequencyEdit_->text().toInt(); }
/** Returns the update style specified by the user on the dialog.
*/
int getUpdateStyle() const { return updateStyleCombo_->currentIndex(); }
/** Returns the time between iterations specified by the user on the
* dialog.
*/
int getTimer() const { return timerEdit_->text().toInt(); }
/** Returns a vector of integers with each integer representing the number of
* competitors for a particular competitor type in the global variable
* registeredCompetitors.
*/
vector<int> getCompetitors() const;
/** Returns a map from QString to QColor of competitor type names and their
* corresponding color as specified by the user on the dialog..
*/
map<QString, QColor> getCompetitorColors() const;
signals:
/** This signal is generated when a user clicks one of the choose color
* pushbuttons.
*
* Its parameter corresponds to the index of the pushbutton.
*/
void specificButtonClicked( int );
private slots:
void colorButtonClicked();
void runColorDialog( int );
void setLineEditColor( QString );
private:
void setLineEditColor( QLineEdit* edit );
QSpinBox* nCompetitorsSpinBox( int i );
QGridLayout* layout_;
QGridLayout* competitorLayout_;
QHBoxLayout* buttonLayout_;
QPushButton* apply_;
QPushButton* cancel_;
QLabel* iterationsLabel_;
QSpinBox* iterationsEdit_;
QLabel* randomSeedLabel_;
QSpinBox* randomSeedEdit_;
QLabel* updateFrequencyLabel_;
QSpinBox* updateFrequencyEdit_;
QLabel* updateStyleLabel_;
QComboBox* updateStyleCombo_;
QLabel* timerLabel_;
QSpinBox* timerEdit_;
vector <QLabel*> competitorLabels_;
vector <QSpinBox*> competitorNumbers_;
vector <QLineEdit*> competitorColors_;
vector <ColorPickButton*> colorButtons_;
};
#endif // DEFINEGAMEDIALOGUE_H