Freeciv-3.1: /fast/freeciv/nightly/S3_1/tools/ruledit/edit_impr.cpp Source File

Freeciv-3.1

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__("Sound tag")));
120 label->setParent(this);
121
122 sound_tag = new QLineEdit(this);
123 connect(sound_tag, SIGNAL(returnPressed()), this, SLOT(sound_tag_given()));
124
125 impr_layout->addWidget(label, row, 0);
126 impr_layout->addWidget(sound_tag, row++, 1);
127
128 label = new QLabel(QString::fromUtf8(R__("Alt sound tag")));
129 label->setParent(this);
130
131 sound_tag_alt = new QLineEdit(this);
132 connect(sound_tag_alt, SIGNAL(returnPressed()), this, SLOT(sound_tag_alt_given()));
133
134 impr_layout->addWidget(label, row, 0);
135 impr_layout->addWidget(sound_tag_alt, row++, 1);
136
137 button = new QPushButton(QString::fromUtf8(R__("Helptext")), this);
138 connect(button, SIGNAL(pressed()), this, SLOT(helptext()));
139 impr_layout->addWidget(button, row++, 1);
140
141 rowcount = 0;
142 column = 0;
143 for (int i = 0; i < IF_COUNT; i++) {
144 enum impr_flag_id flag = (enum impr_flag_id)i;
145 QCheckBox *check = new QCheckBox();
146
147 label = new QLabel(impr_flag_id_name(flag));
148 flag_layout->addWidget(label, rowcount, column + 1);
149
150 check->setChecked(BV_ISSET(impr->flags, flag));
151 flag_layout->addWidget(check, rowcount, column);
152
153 if (++rowcount >= FLAGROWS) {
154 column += 2;
155 rowcount = 0;
156 }
157 }
158
159 refresh();
160
161 main_layout->addLayout(impr_layout);
162 main_layout->addLayout(flag_layout);
163
164 setLayout(main_layout);
165}
166
167/**********************************************************************/
170 void edit_impr::closeEvent(QCloseEvent *cevent)
171{
172 int rowcount;
173 int column;
174
175 close_help();
176
177 // Save values from text fields.
178 gfx_tag_given();
179 gfx_tag_alt_given();
180 sound_tag_given();
181 sound_tag_alt_given();
182
183 BV_CLR_ALL(impr->flags);
184 rowcount = 0;
185 column = 0;
186 for (int i = 0; i < IF_COUNT; i++) {
187 QCheckBox *check = static_cast<QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
188
189 if (check->isChecked()) {
190 BV_SET(impr->flags, i);
191 }
192
193 if (++rowcount >= FLAGROWS) {
194 rowcount = 0;
195 column += 2;
196 }
197 }
198
199 impr->ruledit_dlg = nullptr;
200}
201
202/**********************************************************************/
205 void edit_impr::refresh()
206{
207 bcost->setValue(impr->build_cost);
208 upkeep->setValue(impr->upkeep);
209 genus_button->setText(impr_genus_id_name(impr->genus));
210 gfx_tag->setText(impr->graphic_str);
211 gfx_tag_alt->setText(impr->graphic_alt);
212 sound_tag->setText(impr->soundtag);
213 sound_tag_alt->setText(impr->soundtag_alt);
214}
215
216/**********************************************************************/
219 void edit_impr::set_bcost_value(int value)
220{
221 impr->build_cost = value;
222
223 refresh();
224}
225
226/**********************************************************************/
229 void edit_impr::set_upkeep_value(int value)
230{
231 impr->upkeep = value;
232
233 refresh();
234}
235
236/**********************************************************************/
239 void edit_impr::genus_menu(QAction *action)
240{
241 QByteArray gn_bytes;
242 enum impr_genus_id genus;
243
244 gn_bytes = action->text().toUtf8();
245 genus = impr_genus_id_by_name(gn_bytes.data(), fc_strcasecmp);
246
247 impr->genus = genus;
248
249 refresh();
250}
251
252/**********************************************************************/
255 void edit_impr::gfx_tag_given()
256{
257 QByteArray tag_bytes = gfx_tag->text().toUtf8();
258
259 sz_strlcpy(impr->graphic_str, tag_bytes);
260}
261
262/**********************************************************************/
265 void edit_impr::gfx_tag_alt_given()
266{
267 QByteArray tag_bytes = gfx_tag_alt->text().toUtf8();
268
269 sz_strlcpy(impr->graphic_alt, tag_bytes);
270}
271
272/**********************************************************************/
275 void edit_impr::sound_tag_given()
276{
277 QByteArray tag_bytes = sound_tag->text().toUtf8();
278
279 sz_strlcpy(impr->soundtag, tag_bytes);
280}
281
282/**********************************************************************/
285 void edit_impr::sound_tag_alt_given()
286{
287 QByteArray tag_bytes = sound_tag_alt->text().toUtf8();
288
289 sz_strlcpy(impr->soundtag_alt, tag_bytes);
290}
291
292/**********************************************************************/
295 void edit_impr::helptext()
296{
297 open_help(&impr->helptext);
298}
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:229
edit_impr::genus_menu
void genus_menu(QAction *action)
Definition edit_impr.cpp:239
edit_impr::set_bcost_value
void set_bcost_value(int value)
Definition edit_impr.cpp:219
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:265
edit_impr::sound_tag_alt
QLineEdit * sound_tag_alt
Definition edit_impr.h:51
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:295
edit_impr::refresh
void refresh()
Definition edit_impr.cpp:205
edit_impr::genus_button
QToolButton * genus_button
Definition edit_impr.h:47
edit_impr::sound_tag
QLineEdit * sound_tag
Definition edit_impr.h:50
edit_impr::sound_tag_alt_given
void sound_tag_alt_given()
Definition edit_impr.cpp:285
edit_impr::sound_tag_given
void sound_tag_given()
Definition edit_impr.cpp:275
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:53
edit_impr::closeEvent
void closeEvent(QCloseEvent *cevent)
Definition edit_impr.cpp:170
edit_impr::gfx_tag_given
void gfx_tag_given()
Definition edit_impr.cpp:255
ruledit_gui
Definition ruledit_qt.h:96
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
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:250
improvement.h
genus_iterate_end
#define genus_iterate_end
Definition improvement.h:230
genus_iterate
#define genus_iterate(_p)
Definition improvement.h:224
ruledit.h
ruledit_qt.h
action
Definition actions.h:379
impr_type
Definition improvement.h:68
impr_type::build_cost
int build_cost
Definition improvement.h:77
impr_type::graphic_str
char graphic_str[MAX_LEN_NAME]
Definition improvement.h:73
impr_type::upkeep
int upkeep
Definition improvement.h:78
impr_type::genus
enum impr_genus_id genus
Definition improvement.h:80
impr_type::graphic_alt
char graphic_alt[MAX_LEN_NAME]
Definition improvement.h:74
impr_type::soundtag_alt
char soundtag_alt[MAX_LEN_NAME]
Definition improvement.h:84
impr_type::helptext
struct strvec * helptext
Definition improvement.h:82
impr_type::flags
bv_impr_flags flags
Definition improvement.h:81
impr_type::soundtag
char soundtag[MAX_LEN_NAME]
Definition improvement.h:83
impr_type::ruledit_dlg
void * ruledit_dlg
Definition improvement.h:72
fc_strcasecmp
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:161
tab_tech.h