Freeciv-3.3
Loading...
Searching...
No Matches
edit_tech.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 "tech.h"
29
30// ruledit
31#include "helpeditor.h"
32#include "ruledit.h"
33#include "ruledit_qt.h"
34
35#include "edit_tech.h"
36
37
38#define FLAGROWS 7
39
40/**********************************************************************/
44{
45 QHBoxLayout *main_layout = new QHBoxLayout(this);
47 QLabel *label;
48 QPushButton *button;
49 int row;
50 int rowcount;
51 int column;
52
53 ui = ui_in;
54 tech = tech_in;
55
57
58 setWindowTitle(QString::fromUtf8(advance_rule_name(tech)));
59
60 label = new QLabel(QString::fromUtf8(R__("Cost")));
61 label->setParent(this);
62
63 cost = new QSpinBox(this);
64 cost->setRange(0, 10000);
65 connect(cost, SIGNAL(valueChanged(int)), this, SLOT(set_cost_value(int)));
66
67 row = 0;
68 tech_layout->addWidget(label, row, 0);
69 tech_layout->addWidget(cost, row++, 1);
70
71 label = new QLabel(QString::fromUtf8(R__("Graphics tag")));
72 label->setParent(this);
73
74 gfx_tag = new QLineEdit(this);
75 connect(gfx_tag, SIGNAL(returnPressed()), this, SLOT(gfx_tag_given()));
76
77 tech_layout->addWidget(label, row, 0);
78 tech_layout->addWidget(gfx_tag, row++, 1);
79
80 label = new QLabel(QString::fromUtf8(R__("Alt graphics tag")));
81 label->setParent(this);
82
83 gfx_tag_alt = new QLineEdit(this);
85
86 tech_layout->addWidget(label, row, 0);
87 tech_layout->addWidget(gfx_tag_alt, row++, 1);
88
89 button = new QPushButton(QString::fromUtf8(R__("Helptext")), this);
90 connect(button, SIGNAL(pressed()), this, SLOT(helptext()));
91 tech_layout->addWidget(button, row++, 1);
92
93 rowcount = 0;
94 column = 0;
95 for (int i = 0; i < TF_COUNT; i++) {
96 enum tech_flag_id flag = (enum tech_flag_id)i;
97 QCheckBox *check = new QCheckBox();
98
99 label = new QLabel(tech_flag_id_name(flag));
100 flag_layout->addWidget(label, rowcount, column + 1);
101
102 check->setChecked(BV_ISSET(tech->flags, flag));
103 flag_layout->addWidget(check, rowcount, column);
104
105 if (++rowcount >= FLAGROWS) {
106 column += 2;
107 rowcount = 0;
108 }
109 }
110
111 refresh();
112
113 main_layout->addLayout(tech_layout);
114 main_layout->addLayout(flag_layout);
115
116 setLayout(main_layout);
117}
118
119/**********************************************************************/
123{
124 int rowcount;
125 int column;
126
127 close_help();
128
129 // Save values from text fields.
132
134 rowcount = 0;
135 column = 0;
136 for (int i = 0; i < TF_COUNT; i++) {
137 QCheckBox *check = static_cast<QCheckBox *>(flag_layout->itemAtPosition(rowcount, column)->widget());
138
139 if (check->isChecked()) {
140 BV_SET(tech->flags, i);
141 }
142
143 if (++rowcount >= FLAGROWS) {
144 rowcount = 0;
145 column += 2;
146 }
147 }
148
149 tech->ruledit_dlg = nullptr;
150}
151
152/**********************************************************************/
156{
157 cost->setValue(tech->cost);
158 gfx_tag->setText(tech->graphic_str);
159 gfx_tag_alt->setText(tech->graphic_alt);
160}
161
162/**********************************************************************/
166{
167 tech->cost = value;
168
169 refresh();
170}
171
172/**********************************************************************/
176{
177 QByteArray tag_bytes = gfx_tag->text().toUtf8();
178
180}
181
182/**********************************************************************/
191
192/**********************************************************************/
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_SET(bv, bit)
Definition bitvector.h:89
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
ruledit_gui * ui
Definition edit_tech.h:43
void set_cost_value(int value)
struct advance * tech
Definition edit_tech.h:44
edit_tech(ruledit_gui *ui_in, struct advance *tech_in)
Definition edit_tech.cpp:43
QSpinBox * cost
Definition edit_tech.h:45
void gfx_tag_given()
QLineEdit * gfx_tag
Definition edit_tech.h:46
void refresh()
void gfx_tag_alt_given()
void helptext()
QGridLayout * flag_layout
Definition edit_tech.h:49
QLineEdit * gfx_tag_alt
Definition edit_tech.h:47
void closeEvent(QCloseEvent *cevent)
void close_help()
void open_help(struct strvec **help)
char * incite_cost
Definition comments.c:76
#define FLAGROWS
#define R__(String)
Definition fcintl.h:75
void * ruledit_dlg
Definition tech.h:122
double cost
Definition tech.h:145
struct strvec * helptext
Definition tech.h:135
bv_tech_flags flags
Definition tech.h:134
char graphic_str[MAX_LEN_NAME]
Definition tech.h:123
char graphic_alt[MAX_LEN_NAME]
Definition tech.h:124
#define sz_strlcpy(dest, src)
Definition support.h:195
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:309