Freeciv-3.2
Loading...
Searching...
No Matches
req_edit.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 <QGridLayout>
20#include <QLabel>
21#include <QMenu>
22#include <QPushButton>
23#include <QSpinBox>
24
25// utility
26#include "fcintl.h"
27
28// common
29#include "reqtext.h"
30#include "requirements.h"
31
32// ruledit
33#include "ruledit.h"
34#include "ruledit_qt.h"
35#include "univ_value.h"
36
37#include "req_edit.h"
38
39/**********************************************************************/
43 struct requirement_vector *preqs) : QDialog()
44{
45 QVBoxLayout *main_layout = new QVBoxLayout(this);
48 QPushButton *close_button;
49 QPushButton *add_button;
50 QPushButton *delete_button;
51 QMenu *menu;
52 QLabel *lbl;
53
54 ui = ui_in;
57
60
61 req_list = new QListWidget(this);
62
63 connect(req_list, SIGNAL(itemSelectionChanged()), this, SLOT(select_req()));
64 main_layout->addWidget(req_list);
65
66 lbl = new QLabel(R__("Type:"));
67 active_layout->addWidget(lbl, 0);
69 menu = new QMenu();
70 edit_type_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
71 edit_type_button->setPopupMode(QToolButton::MenuButtonPopup);
72 connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(req_type_menu(QAction *)));
73 edit_type_button->setMenu(menu);
75 struct universal dummy;
76
77 dummy.kind = univ_id;
78 if (universal_value_initial(&dummy)) {
79 menu->addAction(universals_n_name(univ_id));
80 }
82 active_layout->addWidget(edit_type_button, 1);
83
84 lbl = new QLabel(R__("Value:"));
85 active_layout->addWidget(lbl, 2);
87 edit_value_enum_menu = new QMenu();
88 edit_value_enum_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
89 edit_value_enum_button->setPopupMode(QToolButton::MenuButtonPopup);
93 edit_value_enum_menu->setVisible(false);
96 edit_value_nbr_field->setRange(-100000, 100000);
97 edit_value_nbr_field->setVisible(false);
98 connect(edit_value_nbr_field, SIGNAL(valueChanged(int)), this,
99 SLOT(univ_value_edit(int)));
100 active_layout->addWidget(edit_value_nbr_field, 4);
101
102 lbl = new QLabel(R__("Range:"));
103 active_layout->addWidget(lbl, 5);
105 menu = new QMenu();
106 edit_range_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
107 edit_range_button->setPopupMode(QToolButton::MenuButtonPopup);
108 connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(req_range_menu(QAction *)));
109 edit_range_button->setMenu(menu);
111 menu->addAction(req_range_name(range_id));
113 active_layout->addWidget(edit_range_button, 6);
114
116 menu = new QMenu();
117 edit_present_button->setToolButtonStyle(Qt::ToolButtonTextOnly);
118 edit_present_button->setPopupMode(QToolButton::MenuButtonPopup);
119 connect(menu, SIGNAL(triggered(QAction *)), this, SLOT(req_present_menu(QAction *)));
120 edit_present_button->setMenu(menu);
121 menu->addAction(R__("Allows"));
122 menu->addAction(R__("Prevents"));
123 active_layout->addWidget(edit_present_button, 7);
124
125 main_layout->addLayout(active_layout);
126
127 add_button = new QPushButton(QString::fromUtf8(R__("Add Requirement")), this);
128 connect(add_button, SIGNAL(pressed()), this, SLOT(add_now()));
129 reqedit_layout->addWidget(add_button, 0, 0);
130
131 delete_button = new QPushButton(QString::fromUtf8(R__("Delete Requirement")), this);
132 connect(delete_button, SIGNAL(pressed()), this, SLOT(delete_now()));
133 reqedit_layout->addWidget(delete_button, 1, 0);
134
135 close_button = new QPushButton(QString::fromUtf8(R__("Close")), this);
136 connect(close_button, SIGNAL(pressed()), this, SLOT(close_now()));
137 reqedit_layout->addWidget(close_button, 2, 0);
138
139 refresh();
140
141 main_layout->addLayout(reqedit_layout);
142
143 setLayout(main_layout);
144 setWindowTitle(target);
145}
146
147/**********************************************************************/
151{
152 char buf[512];
153
154 buf[0] = '\0';
155 if (!req_text_insert(buf, sizeof(buf), NULL, preq, VERB_ACTUAL, "")) {
156 if (preq->present) {
157 universal_name_translation(&preq->source, buf, sizeof(buf));
158 } else {
159 char buf2[256];
160
161 universal_name_translation(&preq->source, buf2, sizeof(buf2));
162 fc_snprintf(buf, sizeof(buf), R__("%s prevents"), buf2);
163 }
164 }
165
166 item->setText(QString::fromUtf8(buf));
167}
168
169/**********************************************************************/
173{
174 if (selected != nullptr) {
175 int i;
177
178 for (i = 0; (item = req_list->item(i)) != nullptr; i++) {
179 if (item->isSelected()) {
181 }
182 }
183 }
184}
185
186/**********************************************************************/
190{
191 int i = 0;
192
193 req_list->clear();
194
197
199
200 req_list->insertItem(i++, item);
201 if (selected == preq) {
202 item->setSelected(true);
203 }
205
206 fill_active();
207}
208
209/**********************************************************************/
213{
214 if (selected != nullptr) {
216 }
217}
218
219/**********************************************************************/
233
234/**********************************************************************/
238{
239 ui->unregister_req_edit(this);
240 done(0);
241}
242
243/**********************************************************************/
247{
248 int i = 0;
249
252
253 if (item != nullptr && item->isSelected()) {
254 selected = preq;
256 fill_active();
257 return;
258 }
260}
261
269
270/**********************************************************************/
273static void universal_value_cb(const char *value, bool current, void *cbdata)
274{
275 struct uvb_data *data = (struct uvb_data *)cbdata;
276
277 if (value == NULL) {
278 int kind, val;
279
280 universal_extraction(data->univ, &kind, &val);
281 data->number->setValue(val);
282 data->number->setVisible(true);
283 } else {
284 data->enum_button->setVisible(true);
285 data->menu->addAction(value);
286 if (current) {
287 data->enum_button->setText(value);
288 }
289 }
290}
291
292/**********************************************************************/
296{
297 if (selected != nullptr) {
298 struct uvb_data udata;
299
302 udata.enum_button = edit_value_enum_button;
304 udata.univ = &selected->source;
305 edit_value_enum_menu->clear();
306 edit_value_enum_button->setVisible(false);
307 edit_value_nbr_field->setVisible(false);
310 if (selected->present) {
311 edit_present_button->setText(R__("Allows"));
312 } else {
313 edit_present_button->setText(R__("Prevents"));
314 }
315 }
316}
317
318/**********************************************************************/
322{
323 QByteArray un_bytes = action->text().toUtf8();
324 enum universals_n univ = universals_n_by_name(un_bytes.data(),
326
327 if (selected != nullptr) {
328 selected->source.kind = univ;
331 }
332
333 refresh();
334}
335
336/**********************************************************************/
340{
341 QByteArray un_bytes = action->text().toUtf8();
344
345 if (selected != nullptr) {
348 }
349
350 refresh();
351}
352
353/**********************************************************************/
357{
358 if (selected != nullptr) {
359 /* FIXME: Should have more reliable implementation than checking
360 * against *translated* text */
361 if (action->text() == R__("Prevents")) {
363 } else {
365 }
367 }
368
369 refresh();
370}
371
372/**********************************************************************/
376{
377 if (selected != nullptr) {
378 QByteArray un_bytes = action->text().toUtf8();
379
381
383 refresh();
384 }
385}
386
387/**********************************************************************/
391{
392 if (selected != nullptr) {
393 char buf[32];
394
395 fc_snprintf(buf, sizeof(buf), "%d", value);
396
398 buf);
399
401
402 /* No full refresh() with fill_selected()
403 * as that would take focus out after every digit user types */
405 }
406}
407
408/**********************************************************************/
412{
413 struct requirement new_req;
414
416 false, true, false, 0);
417
419
420 refresh();
421
423}
424
425/**********************************************************************/
429{
430 if (selected != nullptr) {
431 size_t i;
432
433 for (i = 0; i < requirement_vector_size(req_vector); i++) {
436 break;
437 }
438 }
439
441
442 refresh();
443
445 }
446}
447
448/**********************************************************************/
453{
454 if (req_vector == vec) {
455 // The selected requirement may be gone
456
457 selected = nullptr;
460 selected = preq;
461 break;
462 }
464
465 if (selected == nullptr) {
466 // The currently selected requirement was deleted.
468 }
469
470 refresh();
471 }
472}
473
474/**********************************************************************/
struct requirement_vector * req_vector
Definition req_edit.h:45
ruledit_gui * ui
Definition req_edit.h:55
void req_present_menu(QAction *action)
Definition req_edit.cpp:356
void delete_now()
Definition req_edit.cpp:428
QToolButton * edit_value_enum_button
Definition req_edit.h:67
QToolButton * edit_present_button
Definition req_edit.h:71
void refresh()
Definition req_edit.cpp:189
struct requirement selected_values
Definition req_edit.h:60
void univ_value_enum_menu(QAction *action)
Definition req_edit.cpp:375
void close_now()
Definition req_edit.cpp:237
void incoming_req_vec_change(const requirement_vector *vec)
Definition req_edit.cpp:452
void univ_value_edit(int value)
Definition req_edit.cpp:390
QSpinBox * edit_value_nbr_field
Definition req_edit.h:69
QToolButton * edit_range_button
Definition req_edit.h:70
void fill_active()
Definition req_edit.cpp:295
void closeEvent(QCloseEvent *event)
Definition req_edit.cpp:477
struct requirement * selected
Definition req_edit.h:59
req_edit(ruledit_gui *ui_in, QString target, struct requirement_vector *preqs)
Definition req_edit.cpp:42
void req_vec_may_have_changed(const requirement_vector *vec)
QMenu * edit_value_enum_menu
Definition req_edit.h:68
void req_type_menu(QAction *action)
Definition req_edit.cpp:321
void update_selected()
Definition req_edit.cpp:212
void select_req()
Definition req_edit.cpp:246
QToolButton * edit_type_button
Definition req_edit.h:66
void clear_selected()
Definition req_edit.cpp:222
void refresh_item(QListWidgetItem *item, struct requirement *preq)
Definition req_edit.cpp:150
void req_range_menu(QAction *action)
Definition req_edit.cpp:339
void refresh_selected()
Definition req_edit.cpp:172
QListWidget * req_list
Definition req_edit.h:57
void add_now()
Definition req_edit.cpp:411
void unregister_req_edit(class req_edit *redit)
char * incite_cost
Definition comments.c:75
enum event_type event
Definition events.c:81
#define R__(String)
Definition fcintl.h:75
static void universal_value_cb(const char *value, bool current, void *cbdata)
Definition req_edit.cpp:273
bool req_text_insert(char *buf, size_t bufsz, struct player *pplayer, const struct requirement *preq, enum rt_verbosity verb, const char *prefix)
Definition reqtext.c:48
@ VERB_ACTUAL
Definition reqtext.h:20
void universal_extraction(const struct universal *source, int *kind, int *value)
bool are_requirements_equal(const struct requirement *req1, const struct requirement *req2)
void universal_value_from_str(struct universal *source, const char *value)
struct requirement req_from_values(int type, int range, bool survives, bool present, bool quiet, int value)
const char * universal_name_translation(const struct universal *psource, char *buf, size_t bufsz)
#define universals_iterate(_univ_)
#define requirement_vector_iterate_end
#define req_range_iterate_end
#define req_range_iterate(_range_)
#define requirement_vector_iterate(req_vec, preq)
#define universals_iterate_end
Definition climisc.h:82
struct universal item
Definition climisc.h:83
enum req_range range
struct universal source
enum universals_n kind
Definition fc_types.h:902
universals_u value
Definition fc_types.h:901
QSpinBox * number
Definition req_edit.cpp:264
QMenu * menu
Definition req_edit.cpp:266
QToolButton * enum_button
Definition req_edit.cpp:265
struct universal * univ
Definition req_edit.cpp:267
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct advance * advance
Definition fc_types.h:711
bool universal_value_initial(struct universal *src)
Definition univ_value.c:42
void universal_kind_values(struct universal *univ, univ_kind_values_cb cb, void *data)
Definition univ_value.c:264