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)
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 ***********************************************************************/
15 #include <fc_config.h>
19 #include "fc_client.h"
20 #include "qtg_cxxside.h"
24 /**************************************************************************
25 Dialog constructor for changing rates with sliders.
26 Automatic destructor will clean qobjects, so there is no one
27 **************************************************************************/
28 tax_rates_dialog::tax_rates_dialog(QWidget
*parent
)
34 some_label
= new QLabel
;
35 tax_label
= new QLabel
;
36 sci_label
= new QLabel
;
37 lux_label
= new QLabel
;
38 tax_checkbox
= new QCheckBox
;
39 sci_checkbox
= new QCheckBox
;
40 lux_checkbox
= new QCheckBox
;
41 tax_slider
= new QSlider
;
42 sci_slider
= new QSlider
;
43 lux_slider
= new QSlider
;
44 button_box
= new QDialogButtonBox
;
45 cancel_button
= new QPushButton
;
46 ok_button
= new QPushButton
;
48 tax
= client
.conn
.playing
->economic
.tax
/ 10;
49 lux
= client
.conn
.playing
->economic
.luxury
/ 10;
50 sci
= client
.conn
.playing
->economic
.science
/ 10;
52 if (NULL
!= client
.conn
.playing
) {
53 max
= get_player_bonus(client
.conn
.playing
, EFT_MAX_RATES
);
58 setWindowTitle(_("Select tax, luxury and science rates"));
59 QVBoxLayout
*main_layout
= new QVBoxLayout
;
61 // FIXME: Translations support.
62 str
= QString::fromUtf8
63 (government_name_for_player(client
.conn
.playing
)) + " "
64 + "max rate: " + QString::number(max
) + "%";
66 some_label
->setText(str
);
67 main_layout
->addWidget(some_label
);
68 main_layout
->addSpacing(20);
71 QGroupBox
* group_box
= new QGroupBox("Tax");
72 QHBoxLayout
*group_box_layout
= new QHBoxLayout
;
73 QHBoxLayout
*some_layout
= new QHBoxLayout
;
74 tax_slider
->setMaximum(max
/ 10);
75 tax_slider
->setMinimum(0);
76 tax_slider
->setValue(tax
);
77 tax_slider
->setOrientation(Qt::Horizontal
);
78 connect(tax_slider
, SIGNAL(valueChanged(int)),
79 SLOT(slot_set_value(int)));
80 group_box_layout
->addWidget(tax_slider
);
81 str
= QString::number(tax_slider
->value() * 10) + "%"; // FIXME: Translations
82 tax_label
->setText(str
);
83 group_box_layout
->addWidget(tax_label
);
84 group_box_layout
->addSpacing(20);
86 some_label
= new QLabel
;
87 some_label
->setText(str
);
88 group_box_layout
->addWidget(some_label
);
89 group_box_layout
->addWidget(tax_checkbox
);
90 group_box
->setLayout(group_box_layout
);
91 main_layout
->addWidget(group_box
);
94 group_box
= new QGroupBox("Science");
95 group_box_layout
= new QHBoxLayout
;
96 some_layout
= new QHBoxLayout
;
97 sci_slider
->setMaximum(max
/ 10);
98 sci_slider
->setMinimum(0);
99 sci_slider
->setValue(sci
);
100 sci_slider
->setOrientation(Qt::Horizontal
);
101 connect(sci_slider
, SIGNAL(valueChanged (int)),
102 SLOT(slot_set_value (int)));
103 group_box_layout
->addWidget(sci_slider
);
104 str
= QString::number(sci_slider
->value() * 10) + "%";
105 sci_label
->setText(str
);
106 group_box_layout
->addWidget(sci_label
);
107 group_box_layout
->addSpacing(20);
109 some_label
= new QLabel
;
110 some_label
->setText(str
);
111 group_box_layout
->addWidget(some_label
);
112 group_box_layout
->addWidget(sci_checkbox
);
113 group_box
->setLayout(group_box_layout
);
114 main_layout
->addWidget(group_box
);
117 group_box
= new QGroupBox("Luxury");
118 group_box_layout
= new QHBoxLayout
;
119 some_layout
= new QHBoxLayout
;
120 lux_slider
->setMaximum(max
/ 10);
121 lux_slider
->setMinimum(0);
122 lux_slider
->setValue(lux
);
123 lux_slider
->setOrientation(Qt::Horizontal
);
124 connect(lux_slider
, SIGNAL(valueChanged(int)),
125 SLOT(slot_set_value(int)));
126 group_box_layout
->addWidget(lux_slider
);
127 str
= QString::number(lux_slider
->value() * 10) + "%";
128 lux_label
->setText(str
);
129 group_box_layout
->addWidget(lux_label
);
130 group_box_layout
->addSpacing(20);
132 some_label
= new QLabel
;
133 some_label
->setText(str
);
134 group_box_layout
->addWidget(some_label
);
135 group_box_layout
->addWidget(lux_checkbox
);
136 group_box
->setLayout(group_box_layout
);
137 main_layout
->addWidget(group_box
);
139 some_layout
= new QHBoxLayout
;
140 cancel_button
->setText(_("Cancel"));
141 ok_button
->setText(_("Ok"));
142 connect(cancel_button
, SIGNAL(pressed()),
143 SLOT(slot_cancel_button_pressed()));
144 connect(ok_button
, SIGNAL(pressed()),
145 SLOT(slot_ok_button_pressed()));
146 some_layout
->addWidget(cancel_button
);
147 some_layout
->addWidget(ok_button
);
149 main_layout
->addSpacing(20);
150 main_layout
->addLayout(some_layout
);
151 setLayout(main_layout
);
155 /**************************************************************************
156 Slot in dialog executed by qt-signal setValue() when moving sliders.
157 **************************************************************************/
158 void tax_rates_dialog::slot_set_value(int i
)
162 qo
= (QSlider
*) QObject::sender();
165 if (qo
== tax_slider
) {
167 tax_label
->setText(QString::number(10 * tax
) + "%");
171 if (qo
== sci_slider
) {
173 sci_label
->setText(QString::number(10 * tax
) + "%");
177 if (qo
== lux_slider
) {
179 lux_label
->setText(QString::number(10 * tax
) + "%");
183 if (sci
+ tax
+ lux
!= 10) {
187 str
= QString::number(lux_slider
->value() * 10) + "%";
188 lux_label
->setText (str
);
189 str
= QString::number(tax_slider
->value() * 10) + "%";
190 tax_label
->setText(str
);
191 str
= QString::number(sci_slider
->value() * 10) + "%";
192 sci_label
->setText(str
);
196 /**************************************************************************
197 Checks if rates are correct and moves other rates.
198 **************************************************************************/
199 void tax_rates_dialog::check(QString qo
)
206 if (NULL
!= client
.conn
.playing
) {
207 maxrate
= get_player_bonus(client
.conn
.playing
, EFT_MAX_RATES
) / 10;
212 tax_lock
= tax_checkbox
->isChecked();
213 sci_lock
= sci_checkbox
->isChecked();
214 lux_lock
= lux_checkbox
->isChecked();
218 lux
= MIN(MAX(10 - tax
- sci
, 0), maxrate
);
222 sci
= MIN(MAX(10 - tax
- lux
, 0), maxrate
);
225 if (sci
+ tax
+ lux
!= 10) {
226 tax_slider
->setValue(MIN(MAX(10 - lux
- sci
, 0), maxrate
));
228 } else if (qo
== "LUX") {
231 tax
= MIN(MAX(10 - lux
- sci
, 0), maxrate
);
235 sci
= MIN(MAX(10 - lux
- tax
, 0), maxrate
);
238 if (sci
+ tax
+ lux
!= 10) {
239 lux_slider
->setValue(MIN(MAX(10 - tax
- sci
, 0), maxrate
));
241 } else if (qo
== "SCI") {
243 lux
= MIN(MAX(10 - tax
- sci
, 0), maxrate
);
247 tax
= MIN(MAX(10 - lux
- sci
, 0), maxrate
);
250 if (sci
+ tax
+ lux
!= 10) {
251 sci_slider
->setValue(MIN(MAX(10 - tax
- lux
, 0), maxrate
));
255 tax_slider
->setValue(tax
);
256 lux_slider
->setValue(lux
);
257 sci_slider
->setValue(sci
);
260 /***************************************************************************
261 When cancel in qtpushbutton pressed selfdestruction :D.
262 ***************************************************************************/
263 void tax_rates_dialog::slot_cancel_button_pressed()
268 /***************************************************************************
269 When ok in qpushbutton pressed send info to server and selfdestroy :D.
270 ***************************************************************************/
271 void tax_rates_dialog::slot_ok_button_pressed()
273 dsend_packet_player_rates(&client
.conn
, 10 * tax
, 10 * lux
, 10 * sci
);
277 /**************************************************************************
278 Popup (or raise) the (tax/science/luxury) rates selection dialog.
279 **************************************************************************/
280 void popup_rates_dialog(void)
282 tax_rates_dialog
* trd
= new tax_rates_dialog(gui()->central_wdg
);