Added translator comment about government overthrown message.
[freeciv.git] / client / gui-qt / citydlg.h
blobae4b0f3d75ec7654c634016d44189e1db39620d3
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.
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 #ifndef FC__CITYDLG_H
14 #define FC__CITYDLG_H
16 #ifdef HAVE_CONFIG_H
17 #include <fc_config.h>
18 #endif
20 // Qt
21 #include <QItemDelegate>
23 class city_dialog;
24 class QComboBox;
25 class QDialog;
26 class QGridLayout;
27 class QLabel;
28 class QProgressBar;
29 class QPushButton;
30 class QSplitter;
31 class QTableView;
32 class QTableWidget;
33 class QTabWidget;
34 class QVariant;
35 class QVBoxLayout;
37 #define NUM_INFO_FIELDS 13
39 //common
40 #include "unittype.h"
42 // client
43 #include "canvas.h"
45 // gui-qt
46 #include "fonts.h"
48 // Qt
49 #include <QProgressBar>
50 #include <QTableWidget>
51 #include <QToolTip>
53 class QImage;
55 QString get_tooltip(QVariant qvar);
56 QString get_tooltip_improvement(impr_type *building);
57 QString get_tooltip_unit(struct unit_type *unit);
58 QString bold(QString text);
60 class fc_tooltip : public QObject
62 Q_OBJECT
63 public:
64 explicit fc_tooltip(QObject *parent = NULL): QObject(parent) {}
66 protected:
67 bool eventFilter(QObject *obj, QEvent *event);
71 /****************************************************************************
72 Custom progressbar with animated progress and right click event
73 ****************************************************************************/
74 class progress_bar: public QProgressBar
76 Q_OBJECT
77 QElapsedTimer m_timer;
78 signals:
79 void clicked();
81 public:
82 progress_bar(QWidget *parent);
83 ~progress_bar();
84 void mousePressEvent(QMouseEvent *event) {
85 emit clicked();
88 protected:
89 void paintEvent(QPaintEvent *event);
90 void timerEvent(QTimerEvent *event);
91 void resizeEvent(QResizeEvent *event);
92 private:
93 void create_region();
94 int m_animate_step;
95 QRegion reg;
96 QFont *sfont;
99 /****************************************************************************
100 Single item on unit_info in city dialog representing one unit
101 ****************************************************************************/
102 class unit_item: public QLabel
104 Q_OBJECT
105 QAction *disband_action;
106 QAction *change_home;
107 QAction *activate;
108 QAction *activate_and_close;
109 QAction *sentry;
110 QAction *fortify;
111 QAction *load;
112 QAction *unload;
113 QAction *upgrade;
114 QAction *unload_trans;
115 QMenu *unit_menu;
117 public:
118 unit_item(QWidget *parent ,struct unit *punit, bool supp = false, int happy_cost = 0);
119 ~unit_item();
120 void init_pix();
122 private:
123 struct unit *qunit;
124 QImage unit_img;
125 void contextMenuEvent(QContextMenuEvent *ev);
126 void create_actions();
127 int happy_cost;
128 bool supported;
130 private slots:
131 void disband();
132 void change_homecity();
133 void activate_unit();
134 void activate_and_close_dialog();
135 void sentry_unit();
136 void fortify_unit();
137 void upgrade_unit();
138 void load_unit();
139 void unload_unit();
140 void unload_all();
142 protected:
143 void mousePressEvent(QMouseEvent *event);
144 void leaveEvent(QEvent *event);
145 void enterEvent(QEvent *event);
148 /****************************************************************************
149 Shows list of units ( as labels - unit_info )
150 ****************************************************************************/
151 class unit_info: public QFrame
154 Q_OBJECT
156 public:
157 unit_info(bool supp);
158 ~unit_info();
159 void add_item(unit_item *item);
160 void init_layout();
161 void update_units();
162 void clear_layout();
163 QHBoxLayout *layout;
164 QList<unit_item *> unit_list;
166 private:
167 bool supports;
171 /****************************************************************************
172 Single item on unit_info in city dialog representing one unit
173 ****************************************************************************/
174 class impr_item: public QLabel
176 Q_OBJECT
178 public:
179 impr_item(QWidget *parent ,struct impr_type *building, struct city *pcity);
180 ~impr_item();
181 void init_pix();
183 private:
184 struct impr_type *impr;
185 struct canvas *impr_pixmap;
186 struct city *pcity;
188 protected:
189 void mouseDoubleClickEvent(QMouseEvent *event);
190 void leaveEvent(QEvent *event);
191 void enterEvent(QEvent *event);
195 /****************************************************************************
196 Shows list of improvemrnts
197 ****************************************************************************/
198 class impr_info: public QFrame
200 Q_OBJECT
201 public:
202 impr_info(QWidget *parent);
203 ~impr_info();
204 void add_item(impr_item *item);
205 void init_layout();
206 void update_buildings();
207 void clear_layout();
208 QHBoxLayout *layout;
209 QList<impr_item *> impr_list;
212 /****************************************************************************
213 Class used for showing tiles and workers view in city dialog
214 ****************************************************************************/
215 class city_map: public QWidget
218 Q_OBJECT
219 canvas *view;
220 canvas *miniview;
221 QPixmap zoomed_pixmap;
223 public:
224 city_map(QWidget *parent);
225 ~city_map();
226 void set_pixmap(struct city *pcity, float z);
227 private:
228 void mousePressEvent(QMouseEvent *event);
229 void paintEvent(QPaintEvent *event);
230 struct city *mcity;
231 int radius;
232 float zoom;
233 int wdth;
234 int hight;
235 int cutted_width;
236 int cutted_height;
237 int delta_x;
238 int delta_y;
239 protected:
240 QSize sizeHint();
241 QSize minimumSizeHint();
242 private slots:
243 void context_menu(QPoint point);
246 /****************************************************************************
247 Item delegate for production popup
248 ****************************************************************************/
249 class city_production_delegate: public QItemDelegate
251 Q_OBJECT
253 public:
254 city_production_delegate(QPoint sh, QObject *parent, struct city *city);
255 ~city_production_delegate() {}
256 void paint(QPainter *painter, const QStyleOptionViewItem &option,
257 const QModelIndex &index) const;
258 QSize sizeHint(const QStyleOptionViewItem &option,
259 const QModelIndex &index) const;
261 private:
262 int item_height;
263 QPoint pd;
264 struct city *pcity;
266 protected:
267 void drawFocus(QPainter *painter, const QStyleOptionViewItem &option,
268 const QRect &rect) const;
271 /****************************************************************************
272 Single item in production popup
273 ****************************************************************************/
274 class production_item: public QObject
276 Q_OBJECT
278 public:
279 production_item(struct universal *ptarget, QObject *parent);
280 ~production_item();
281 inline int columnCount() const {
282 return 1;
284 QVariant data() const;
285 bool setData();
287 private:
288 struct universal *target;
291 /***************************************************************************
292 City production model
293 ***************************************************************************/
294 class city_production_model : public QAbstractListModel
296 Q_OBJECT
298 public:
299 city_production_model(struct city *pcity, bool f, bool su, bool sw, bool sb,
300 QObject *parent = 0);
301 ~city_production_model();
302 inline int rowCount(const QModelIndex &index = QModelIndex()) const {
303 Q_UNUSED(index);
304 return (qCeil(static_cast<float>(city_target_list.size()) / 3));
306 int columnCount(const QModelIndex &parent = QModelIndex()) const {
307 Q_UNUSED(parent);
308 return 3;
310 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
311 bool setData(const QModelIndex &index, const QVariant &value,
312 int role = Qt::DisplayRole);
313 QPoint size_hint();
314 void populate();
315 QPoint sh;
317 private:
318 QList<production_item *> city_target_list;
319 struct city *mcity;
320 bool future_t;
321 bool show_units;
322 bool show_buildings;
323 bool show_wonders;
326 /****************************************************************************
327 Class for popup avaialable production
328 ****************************************************************************/
329 class production_widget: public QTableView
331 Q_OBJECT
333 city_production_model *list_model;
334 city_production_delegate *c_p_d;
336 public:
337 production_widget(QWidget *parent, struct city *pcity, bool future,
338 int when, int curr, bool show_units, bool buy = false,
339 bool show_wonders = true, bool show_buildings = true);
340 ~production_widget();
342 public slots:
343 void prod_selected(const QItemSelection &sl, const QItemSelection &ds);
345 protected:
346 void mousePressEvent(QMouseEvent *event);
347 bool eventFilter(QObject *obj, QEvent *ev);
349 private:
350 struct city *pw_city;
351 int when_change;
352 int curr_selection;
353 bool sh_units;
354 bool buy_it;
355 fc_tooltip *fc_tt;
359 /****************************************************************************
360 city_label is used only for showing citizens icons
361 and was created to catch mouse events
362 ****************************************************************************/
363 class city_label: public QLabel
365 Q_OBJECT
367 public:
368 city_label(int type, QWidget *parent = 0);
369 void set_city(struct city *pcity);
371 private:
372 struct city *pcity;
373 int type;
375 protected:
376 void mousePressEvent(QMouseEvent *event);
379 /****************************************************************************
380 City dialog
381 ****************************************************************************/
382 class city_dialog: public QDialog
385 Q_OBJECT
387 bool happines_shown;
388 QHBoxLayout *single_page_layout;
389 QHBoxLayout *happiness_layout;
390 QSplitter *prod_unit_splitter;
391 QSplitter *central_left_splitter;
392 QSplitter *central_splitter;
393 QHBoxLayout *leftbot_layout;
394 QWidget *prod_happ_widget;
395 QWidget *top_widget;
396 QVBoxLayout *left_layout;
397 city_map *view;
398 city_label *citizens_label;
399 city_label *lab_table[6];
400 QGridLayout *info_grid_layout;
401 QGroupBox *info_labels_group;
402 QGroupBox *happiness_group;
403 QWidget *happiness_widget;
404 QWidget *info_widget;
405 QLabel *qlt[NUM_INFO_FIELDS];
406 QLabel *cma_info_text;
407 QLabel *cma_result;
408 QLabel *cma_result_pix;
409 QGroupBox *supp_units;
410 QGroupBox *curr_units;
411 QGroupBox *curr_impr;
412 progress_bar *production_combo_p;
413 QTableWidget *p_table_p;
414 QTableWidget *nationality_table;
415 QTableWidget *cma_table;
416 QCheckBox *cma_celeb_checkbox;
417 QCheckBox *future_targets;
418 QCheckBox *show_units;
419 QCheckBox *show_buildings;
420 QCheckBox *show_wonders;
421 QRadioButton *r1, *r2, *r3, *r4;
422 QPushButton *button;
423 QPushButton *buy_button;
424 QPushButton *cma_enable_but;
425 QPushButton *next_city_but;
426 QPushButton *prev_city_but;
427 QPushButton *work_next_but;
428 QPushButton *work_prev_but;
429 QPushButton *work_add_but;
430 QPushButton *work_rem_but;
431 QPushButton *but_menu_worklist;
432 QPushButton *happiness_button;
433 QPushButton *zoom_in_button;
434 QPushButton *zoom_out_button;
435 QPixmap *citizen_pixmap;
436 unit_info *current_units;
437 unit_info *supported_units;
438 impr_info *city_buildings;
439 QPushButton *lcity_name;
440 int selected_row_p;
441 QSlider *slider_tab[2 * O_LAST + 2];
443 public:
444 city_dialog(QWidget *parent = 0);
445 ~city_dialog();
446 void setup_ui(struct city *qcity);
447 void refresh();
448 struct city *pcity;
449 int scroll_height;
450 float zoom;
452 private:
453 int current_building;
454 void update_title();
455 void update_building();
456 void update_info_label();
457 void update_buy_button();
458 void update_citizens();
459 void update_improvements();
460 void update_units();
461 void update_nation_table();
462 void update_cma_tab();
463 void update_disabled();
464 void update_sliders();
465 void update_prod_buttons();
466 void update_happiness_button();
468 private slots:
469 void next_city();
470 void prev_city();
471 void production_changed(int index);
472 void show_targets();
473 void show_targets_worklist();
474 void show_happiness();
475 void buy();
476 void dbl_click_p(QTableWidgetItem *item);
477 void delete_prod();
478 void item_selected(const QItemSelection &sl, const QItemSelection &ds);
479 void clear_worklist();
480 void save_worklist();
481 void worklist_up();
482 void worklist_down();
483 void worklist_del();
484 void display_worklist_menu(const QPoint &p);
485 void disband_state_changed(int state);
486 void cma_slider(int val);
487 void cma_celebrate_changed(int val);
488 void cma_remove();
489 void cma_enable();
490 void cma_changed();
491 void cma_selected(const QItemSelection &sl, const QItemSelection &ds);
492 void cma_double_clicked(int row, int column);
493 void cma_context_menu(const QPoint &p);
494 void save_cma();
495 void city_rename();
496 void zoom_in();
497 void zoom_out();
498 protected:
499 void showEvent(QShowEvent *event);
500 void hideEvent(QHideEvent *event);
501 void closeEvent(QCloseEvent *event);
504 void destroy_city_dialog();
505 void city_font_update();
507 #endif /* FC__CITYDLG_H */