Freeciv-3.3: /fast/freeciv/nightly/main/tools/ruledit/edit_impr.cpp Source File

Freeciv-3.3

Loading...
Searching...
No Matches
edit_impr.cpp
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18// Qt
19#include <QCheckBox>
20#include <QGridLayout>
21#include <QLineEdit>
22#include <QMenu>
23#include <QPushButton>
24#include <QSpinBox>
25#include <QToolButton>
26
27// common
28#include "improvement.h"
29
30// ruledit
31#include "helpeditor.h"
32#include "ruledit.h"
33#include "ruledit_qt.h"
34#include "tab_tech.h"
35
36#include "edit_impr.h"
37
38
39#define FLAGROWS 15
40
41/**********************************************************************/
44edit_impr::edit_impr(ruledit_gui *ui_in, struct impr_type *impr_in) : values_dlg()
45{
46 QHBoxLayout *main_layout = new QHBoxLayout(this);
47 QGridLayout *impr_layout = new QGridLayout();
48 QLabel *label;
49 QPushButton *button;
50 QMenu *menu;
51 int row;
52 int rowcount;
53 int column;
54
55 ui = ui_in;
56 impr = impr_in;
57
58 flag_layout = new QGridLayout();
59
60 setWindowTitle(QString::fromUtf8(improvement_rule_name(impr)));
61
62 label = new QLabel(QString::fromUtf8(R__("Build Cost")));
63 label->setParent(this);
64
65 bcost = new QSpinBox(this);
66 bcost->setRange(0, 10000);
67 connect(bcost, SIGNAL(valueChanged(int)), this, SLOT(set_bcost_value(int)));
68
69 row = 0;
70 impr_layout->addWidget(label, row, 0);
71 impr_layout->addWidget(bcost, row++, 1);
72
73 label = new QLabel(QString::fromUtf8(R__("Upkeep")));
74 label->setParent(this);
75
76 upkeep = new QSpinBox(this);
77 upkeep->setRange(0, 1000);
78 connect(upkeep, SIGNAL(valueChanged(int)), this, SLOT(set_upkeep_value(int)));
79
80 impr_layout->addWidget(label, row, 0);
81 impr_layout->addWidget(upkeep, row++, 1);
82
83 label = new QLabel(QString::fromUtf8(R__("Genus")));
84 label->setParent(this);
85 genus_button = new QToolButton();
86 genus_button->setParent(this);
87 genus_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
88 genus_button->setPopupMode(QToolButton::MenuButtonPopup);
89 menu = new QMenu();
90 connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(genus_menu(QAction *)));
91
92 genus_iterate(genus) {
93 menu->addAction(impr_genus_id_name(genus));
94 } genus_iterate_end;
95
96 genus_button->setMenu(menu);
97
98 impr_layout->addWidget(label, row, 0);
99 impr_layout->addWidget(genus_button, row++, 1);
100
101 label = new QLabel(QString::fromUtf8(R__("Graphics tag")));
102 label->setParent(this);
103
104 gfx_tag = new QLineEdit(this);
105 connect(gfx_tag, SIGNAL(returnPressed()), this, SLOT(gfx_tag_given()));
106
107 impr_layout->addWidget(label, row, 0);
108 impr_layout->addWidget(gfx_tag, row++, 1);
109
110 label = new QLabel(QString::fromUtf8(R__("Alt graphics tag")));
111 label->setParent(this);
112
113 gfx_tag_alt = new QLineEdit(this);
114 connect(gfx_tag_alt, SIGNAL(returnPressed()), this, SLOT(gfx_tag_alt_given()));
115
116 impr_layout->addWidget(label, row, 0);
117 impr_layout->addWidget(gfx_tag_alt, row++, 1);
118
119 label = new QLabel(QString::fromUtf8(R__("Second alt gfx tag")));
120 label->setParent(this);
121
122 gfx_tag_alt2 = new QLineEdit(this);
123 connect(gfx_tag_alt2, SIGNAL(returnPressed()), this, SLOT(gfx_tag_alt2_given()));
124
125 impr_layout->addWidget(label, row, 0);
126 impr_layout->addWidget(gfx_tag_alt2, row++, 1);
127
128 label = new QLabel(QString::fromUtf8(R__("Sound tag")));
129 label->setParent(this);
130
131 sound_tag = new QLineEdit(this);
132 connect(sound_tag, SIGNAL(returnPressed()), this, SLOT(sound_tag_given()));
133
134 impr_layout->addWidget(label, row, 0);
135 impr_layout->addWidget(sound_tag, row++, 1);
136
137 label = new QLabel(QString::fromUtf8(R__("Alt sound tag")));
138 label->setParent(this);
139
140 sound_tag_alt = new QLineEdit(this);
141 connect(sound_tag_alt, SIGNAL(returnPressed()), this, SLOT(sound_tag_alt_given()));
142
143 impr_layout->addWidget(label, row, 0);
144 impr_layout->addWidget(sound_tag_alt, row++, 1);
145
146 label = new QLabel(QString::fromUtf8(R__("Second alt sound tag")));
147 label->setParent(this);
148
149 sound_tag_alt2 = new QLineEdit(this);
150 connect(sound_tag_alt2, SIGNAL(returnPressed()), this, SLOT(sound_tag_alt2_given()));
151
152 impr_layout->addWidget(label, row, 0);
153 impr_layout->addWidget(sound_tag_alt2, row++, 1);
154
155 button = new QPushButton(QString::fromUtf8(R__("Helptext")), this);
156 connect(button, SIGNAL(pressed()), this, SLOT(helptext()));
157 impr_layout->addWidget(button, row++, 1);
158
159 rowcount = 0;
160 column = 0;
161 for (int i = 0; i < IF_COUNT; i++) {
162 enum impr_flag_id flag = (enum impr_flag_id)i;
163 QCheckBox *check = new QCheckBox();
164
165 label = new QLabel(impr_flag_id_name(flag));
166 flag_layout->addWidget(label, rowcount, column + 1);
167
168 check->setChecked(BV_ISSET(impr->flags, flag));
169 flag_layout->addWidget(check, rowcount, column);
170
171 if (++rowcount >= FLAGROWS) {
172 column += 2;
173 rowcount = 0;
174 }
175 }
176
177 refresh();
178
179 main_layout->addLayout(impr_layout);
180 main_layout->addLayout(flag_layout);
181
182 setLayout(main_layout);
183}
184
185/**********************************************************************/
188 void edit_impr::closeEvent(QCloseEvent *cevent)
189{
190 int rowcount;
191 int column;
192
193 close_help();
194
195 // Save values from text fields.
196 gfx_tag_given();
197 gfx_tag_alt_given();
198 gfx_tag_alt2_given();
199 sound_tag_given();
200 sound_tag_alt_given();
201 sound_tag_alt2_given();
202
203 BV_CLR_ALL(impr->flags);
204 rowcount = 0;
205 column = 0;
206 for (int i = 0; i < IF_COUNT; i++) {
207 QCheckBox *check = static_cast< QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
208
209 if (check->isChecked()) {
210 BV_SET(impr->flags, i);
211 }
212
213 if (++rowcount >= FLAGROWS) {
214 rowcount = 0;
215 column += 2;
216 }
217 }
218
219 impr->ruledit_dlg = nullptr;
220}
221
222/**********************************************************************/
225 void edit_impr::refresh()
226{
227 bcost->setValue(impr->build_cost);
228 upkeep->setValue(impr->upkeep);
229 genus_button->setText(impr_genus_id_name(impr->genus));
230 gfx_tag->setText(impr->graphic_str);
231 gfx_tag_alt->setText(impr->graphic_alt);
232 gfx_tag_alt2->setText(impr->graphic_alt2);
233 sound_tag->setText(impr->soundtag);
234 sound_tag_alt->setText(impr->soundtag_alt);
235 sound_tag_alt2->setText(impr->soundtag_alt2);
236}
237
238/**********************************************************************/
241 void edit_impr::set_bcost_value(int value)
242{
243 impr->build_cost = value;
244
245 refresh();
246}
247
248/**********************************************************************/
251 void edit_impr::set_upkeep_value(int value)
252{
253 impr->upkeep = value;
254
255 refresh();
256}
257
258/**********************************************************************/
261 void edit_impr::genus_menu(QAction *action)
262{
263 QByteArray gn_bytes;
264 enum impr_genus_id genus;
265
266 gn_bytes = action->text().toUtf8();
267 genus = impr_genus_id_by_name(gn_bytes.data(), fc_strcasecmp);
268
269 impr->genus = genus;
270
271 refresh();
272}
273
274/**********************************************************************/
277 void edit_impr::gfx_tag_given()
278{
279 QByteArray tag_bytes = gfx_tag->text().toUtf8();
280
281 sz_strlcpy(impr->graphic_str, tag_bytes);
282}
283
284/**********************************************************************/
287 void edit_impr::gfx_tag_alt_given()
288{
289 QByteArray tag_bytes = gfx_tag_alt->text().toUtf8();
290
291 sz_strlcpy(impr->graphic_alt, tag_bytes);
292}
293
294/**********************************************************************/
297 void edit_impr::gfx_tag_alt2_given()
298{
299 QByteArray tag_bytes = gfx_tag_alt2->text().toUtf8();
300
301 sz_strlcpy(impr->graphic_alt2, tag_bytes);
302}
303
304/**********************************************************************/
307 void edit_impr::sound_tag_given()
308{
309 QByteArray tag_bytes = sound_tag->text().toUtf8();
310
311 sz_strlcpy(impr->soundtag, tag_bytes);
312}
313
314/**********************************************************************/
317 void edit_impr::sound_tag_alt_given()
318{
319 QByteArray tag_bytes = sound_tag_alt->text().toUtf8();
320
321 sz_strlcpy(impr->soundtag_alt, tag_bytes);
322}
323
324/**********************************************************************/
327 void edit_impr::sound_tag_alt2_given()
328{
329 QByteArray tag_bytes = sound_tag_alt2->text().toUtf8();
330
331 sz_strlcpy(impr->soundtag_alt2, tag_bytes);
332}
333
334/**********************************************************************/
337 void edit_impr::helptext()
338{
339 open_help(&impr->helptext);
340}
BV_CLR_ALL
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
BV_SET
#define BV_SET(bv, bit)
Definition bitvector.h:81
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
edit_impr::upkeep
QSpinBox * upkeep
Definition edit_impr.h:46
edit_impr::set_upkeep_value
void set_upkeep_value(int value)
Definition edit_impr.cpp:251
edit_impr::genus_menu
void genus_menu(QAction *action)
Definition edit_impr.cpp:261
edit_impr::sound_tag_alt2_given
void sound_tag_alt2_given()
Definition edit_impr.cpp:327
edit_impr::set_bcost_value
void set_bcost_value(int value)
Definition edit_impr.cpp:241
edit_impr::edit_impr
edit_impr(ruledit_gui *ui_in, struct impr_type *impr_in)
Definition edit_impr.cpp:44
edit_impr::gfx_tag_alt_given
void gfx_tag_alt_given()
Definition edit_impr.cpp:287
edit_impr::sound_tag_alt
QLineEdit * sound_tag_alt
Definition edit_impr.h:52
edit_impr::gfx_tag
QLineEdit * gfx_tag
Definition edit_impr.h:48
edit_impr::bcost
QSpinBox * bcost
Definition edit_impr.h:45
edit_impr::impr
struct impr_type * impr
Definition edit_impr.h:44
edit_impr::helptext
void helptext()
Definition edit_impr.cpp:337
edit_impr::refresh
void refresh()
Definition edit_impr.cpp:225
edit_impr::genus_button
QToolButton * genus_button
Definition edit_impr.h:47
edit_impr::sound_tag
QLineEdit * sound_tag
Definition edit_impr.h:51
edit_impr::sound_tag_alt_given
void sound_tag_alt_given()
Definition edit_impr.cpp:317
edit_impr::sound_tag_given
void sound_tag_given()
Definition edit_impr.cpp:307
edit_impr::gfx_tag_alt
QLineEdit * gfx_tag_alt
Definition edit_impr.h:49
edit_impr::ui
ruledit_gui * ui
Definition edit_impr.h:43
edit_impr::flag_layout
QGridLayout * flag_layout
Definition edit_impr.h:55
edit_impr::gfx_tag_alt2
QLineEdit * gfx_tag_alt2
Definition edit_impr.h:50
edit_impr::sound_tag_alt2
QLineEdit * sound_tag_alt2
Definition edit_impr.h:53
edit_impr::gfx_tag_alt2_given
void gfx_tag_alt2_given()
Definition edit_impr.cpp:297
edit_impr::closeEvent
void closeEvent(QCloseEvent *cevent)
Definition edit_impr.cpp:188
edit_impr::gfx_tag_given
void gfx_tag_given()
Definition edit_impr.cpp:277
ruledit_gui
Definition ruledit_qt.h:97
values_dlg
Definition values_dlg.h:28
values_dlg::close_help
void close_help()
Definition values_dlg.cpp:60
values_dlg::open_help
void open_help(struct strvec **help)
Definition values_dlg.cpp:38
incite_cost
char * incite_cost
Definition comments.c:74
FLAGROWS
#define FLAGROWS
Definition edit_extra.cpp:35
edit_impr.h
R__
#define R__(String)
Definition fcintl.h:75
helpeditor.h
improvement_rule_name
const char * improvement_rule_name(const struct impr_type *pimprove)
Definition improvement.c:252
improvement.h
genus_iterate_end
#define genus_iterate_end
Definition improvement.h:224
genus_iterate
#define genus_iterate(_p)
Definition improvement.h:218
ruledit.h
ruledit_qt.h
action
Definition actions.h:106
impr_type
Definition improvement.h:50
impr_type::build_cost
int build_cost
Definition improvement.h:60
impr_type::graphic_str
char graphic_str[MAX_LEN_NAME]
Definition improvement.h:55
impr_type::upkeep
int upkeep
Definition improvement.h:61
impr_type::graphic_alt2
char graphic_alt2[MAX_LEN_NAME]
Definition improvement.h:57
impr_type::genus
enum impr_genus_id genus
Definition improvement.h:63
impr_type::graphic_alt
char graphic_alt[MAX_LEN_NAME]
Definition improvement.h:56
impr_type::soundtag_alt
char soundtag_alt[MAX_LEN_NAME]
Definition improvement.h:67
impr_type::soundtag_alt2
char soundtag_alt2[MAX_LEN_NAME]
Definition improvement.h:68
impr_type::helptext
struct strvec * helptext
Definition improvement.h:65
impr_type::flags
bv_impr_flags flags
Definition improvement.h:64
impr_type::soundtag
char soundtag[MAX_LEN_NAME]
Definition improvement.h:66
impr_type::ruledit_dlg
void * ruledit_dlg
Definition improvement.h:54
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:189
tab_tech.h