Freeciv-3.3: /fast/freeciv/nightly/main/tools/ruledit/edit_tech.cpp Source File

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/**********************************************************************/
43edit_tech::edit_tech(ruledit_gui *ui_in, struct advance *tech_in) : values_dlg()
44{
45 QHBoxLayout *main_layout = new QHBoxLayout(this);
46 QGridLayout *tech_layout = new QGridLayout();
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
56 flag_layout = new QGridLayout();
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);
84 connect(gfx_tag_alt, SIGNAL(returnPressed()), this, SLOT(gfx_tag_alt_given()));
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/**********************************************************************/
122 void edit_tech::closeEvent(QCloseEvent *cevent)
123{
124 int rowcount;
125 int column;
126
127 close_help();
128
129 // Save values from text fields.
130 gfx_tag_given();
131 gfx_tag_alt_given();
132
133 BV_CLR_ALL(tech->flags);
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/**********************************************************************/
155 void edit_tech::refresh()
156{
157 cost->setValue(tech->cost);
158 gfx_tag->setText(tech->graphic_str);
159 gfx_tag_alt->setText(tech->graphic_alt);
160}
161
162/**********************************************************************/
165 void edit_tech::set_cost_value(int value)
166{
167 tech->cost = value;
168
169 refresh();
170}
171
172/**********************************************************************/
175 void edit_tech::gfx_tag_given()
176{
177 QByteArray tag_bytes = gfx_tag->text().toUtf8();
178
179 sz_strlcpy(tech->graphic_str, tag_bytes);
180}
181
182/**********************************************************************/
185 void edit_tech::gfx_tag_alt_given()
186{
187 QByteArray tag_bytes = gfx_tag_alt->text().toUtf8();
188
189 sz_strlcpy(tech->graphic_alt, tag_bytes);
190}
191
192/**********************************************************************/
195 void edit_tech::helptext()
196{
197 open_help(tech->helptext);
198}
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_tech::ui
ruledit_gui * ui
Definition edit_tech.h:43
edit_tech::set_cost_value
void set_cost_value(int value)
Definition edit_tech.cpp:165
edit_tech::tech
struct advance * tech
Definition edit_tech.h:44
edit_tech::edit_tech
edit_tech(ruledit_gui *ui_in, struct advance *tech_in)
Definition edit_tech.cpp:43
edit_tech::cost
QSpinBox * cost
Definition edit_tech.h:45
edit_tech::gfx_tag_given
void gfx_tag_given()
Definition edit_tech.cpp:175
edit_tech::gfx_tag
QLineEdit * gfx_tag
Definition edit_tech.h:46
edit_tech::refresh
void refresh()
Definition edit_tech.cpp:155
edit_tech::gfx_tag_alt_given
void gfx_tag_alt_given()
Definition edit_tech.cpp:185
edit_tech::helptext
void helptext()
Definition edit_tech.cpp:195
edit_tech::flag_layout
QGridLayout * flag_layout
Definition edit_tech.h:49
edit_tech::gfx_tag_alt
QLineEdit * gfx_tag_alt
Definition edit_tech.h:47
edit_tech::closeEvent
void closeEvent(QCloseEvent *cevent)
Definition edit_tech.cpp:122
ruledit_gui
Definition ruledit_qt.h:97
values_dlg
Definition values_dlg.h:28
values_dlg::close_help
void close_help()
Definition values_dlg.cpp:47
values_dlg::open_help
void open_help(struct strvec *help)
Definition values_dlg.cpp:35
incite_cost
char * incite_cost
Definition comments.c:74
FLAGROWS
#define FLAGROWS
Definition edit_extra.cpp:35
edit_tech.h
R__
#define R__(String)
Definition fcintl.h:75
helpeditor.h
ruledit.h
ruledit_qt.h
advance
Definition tech.h:124
advance::ruledit_dlg
void * ruledit_dlg
Definition tech.h:127
advance::cost
double cost
Definition tech.h:150
advance::helptext
struct strvec * helptext
Definition tech.h:140
advance::flags
bv_tech_flags flags
Definition tech.h:139
advance::graphic_str
char graphic_str[MAX_LEN_NAME]
Definition tech.h:128
advance::graphic_alt
char graphic_alt[MAX_LEN_NAME]
Definition tech.h:129
sz_strlcpy
#define sz_strlcpy(dest, src)
Definition support.h:189
advance_rule_name
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:309
tech.h