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/**********************************************************************/
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));
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/**********************************************************************/
170void edit_impr::closeEvent(QCloseEvent *cevent)
171{
172 int rowcount;
173 int column;
174
175 close_help();
176
177 // Save values from text fields.
182
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/**********************************************************************/
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);
214}
215
216/**********************************************************************/
220{
221 impr->build_cost = value;
222
223 refresh();
224}
225
226/**********************************************************************/
230{
231 impr->upkeep = value;
232
233 refresh();
234}
235
236/**********************************************************************/
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/**********************************************************************/
256{
257 QByteArray tag_bytes = gfx_tag->text().toUtf8();
258
259 sz_strlcpy(impr->graphic_str, tag_bytes);
260}
261
262/**********************************************************************/
266{
267 QByteArray tag_bytes = gfx_tag_alt->text().toUtf8();
268
269 sz_strlcpy(impr->graphic_alt, tag_bytes);
270}
271
272/**********************************************************************/
276{
277 QByteArray tag_bytes = sound_tag->text().toUtf8();
278
279 sz_strlcpy(impr->soundtag, tag_bytes);
280}
281
282/**********************************************************************/
286{
287 QByteArray tag_bytes = sound_tag_alt->text().toUtf8();
288
289 sz_strlcpy(impr->soundtag_alt, tag_bytes);
290}
291
292/**********************************************************************/
#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 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:51
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:50
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:53
void closeEvent(QCloseEvent *cevent)
void gfx_tag_given()
void close_help()
void open_help(struct strvec **help)
#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:77
char graphic_str[MAX_LEN_NAME]
Definition improvement.h:73
enum impr_genus_id genus
Definition improvement.h:80
char graphic_alt[MAX_LEN_NAME]
Definition improvement.h:74
char soundtag_alt[MAX_LEN_NAME]
Definition improvement.h:84
struct strvec * helptext
Definition improvement.h:82
bv_impr_flags flags
Definition improvement.h:81
char soundtag[MAX_LEN_NAME]
Definition improvement.h:83
void * ruledit_dlg
Definition improvement.h:72
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
#define sz_strlcpy(dest, src)
Definition support.h:167