Freeciv-3.2
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/**********************************************************************/
45{
46 QHBoxLayout *main_layout = new QHBoxLayout(this);
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
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);
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));
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);
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);
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);
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);
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/**********************************************************************/
189{
190 int rowcount;
191 int column;
192
193 close_help();
194
195 // Save values from text fields.
202
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/**********************************************************************/
226{
227 bcost->setValue(impr->build_cost);
228 upkeep->setValue(impr->upkeep);
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);
236}
237
238/**********************************************************************/
242{
243 impr->build_cost = value;
244
245 refresh();
246}
247
248/**********************************************************************/
252{
253 impr->upkeep = value;
254
255 refresh();
256}
257
258/**********************************************************************/
262{
264 enum impr_genus_id genus;
265
266 gn_bytes = action->text().toUtf8();
268
269 impr->genus = genus;
270
271 refresh();
272}
273
274/**********************************************************************/
278{
279 QByteArray tag_bytes = gfx_tag->text().toUtf8();
280
282}
283
284/**********************************************************************/
293
294/**********************************************************************/
303
304/**********************************************************************/
308{
309 QByteArray tag_bytes = sound_tag->text().toUtf8();
310
312}
313
314/**********************************************************************/
323
324/**********************************************************************/
333
334/**********************************************************************/
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_SET(bv, bit)
Definition bitvector.h:81
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
QSpinBox * upkeep
Definition edit_impr.h:46
void set_upkeep_value(int value)
void genus_menu(QAction *action)
void sound_tag_alt2_given()
void set_bcost_value(int value)
edit_impr(ruledit_gui *ui_in, struct impr_type *impr_in)
Definition edit_impr.cpp:44
void gfx_tag_alt_given()
QLineEdit * sound_tag_alt
Definition edit_impr.h:52
QLineEdit * gfx_tag
Definition edit_impr.h:48
QSpinBox * bcost
Definition edit_impr.h:45
struct impr_type * impr
Definition edit_impr.h:44
void helptext()
void refresh()
QToolButton * genus_button
Definition edit_impr.h:47
QLineEdit * sound_tag
Definition edit_impr.h:51
void sound_tag_alt_given()
void sound_tag_given()
QLineEdit * gfx_tag_alt
Definition edit_impr.h:49
ruledit_gui * ui
Definition edit_impr.h:43
QGridLayout * flag_layout
Definition edit_impr.h:55
QLineEdit * gfx_tag_alt2
Definition edit_impr.h:50
QLineEdit * sound_tag_alt2
Definition edit_impr.h:53
void gfx_tag_alt2_given()
void closeEvent(QCloseEvent *cevent)
void gfx_tag_given()
void close_help()
void open_help(struct strvec **help)
char * incite_cost
Definition comments.c:75
#define FLAGROWS
#define R__(String)
Definition fcintl.h:75
const char * improvement_rule_name(const struct impr_type *pimprove)
#define genus_iterate_end
#define genus_iterate(_p)
int build_cost
Definition improvement.h:60
char graphic_str[MAX_LEN_NAME]
Definition improvement.h:55
char graphic_alt2[MAX_LEN_NAME]
Definition improvement.h:57
enum impr_genus_id genus
Definition improvement.h:63
char graphic_alt[MAX_LEN_NAME]
Definition improvement.h:56
char soundtag_alt[MAX_LEN_NAME]
Definition improvement.h:67
char soundtag_alt2[MAX_LEN_NAME]
Definition improvement.h:68
struct strvec * helptext
Definition improvement.h:65
bv_impr_flags flags
Definition improvement.h:64
char soundtag[MAX_LEN_NAME]
Definition improvement.h:66
void * ruledit_dlg
Definition improvement.h:54
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
#define sz_strlcpy(dest, src)
Definition support.h:195