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 ***********************************************************************/
17 #include <fc_config.h>
21 #include <QItemDelegate>
37 #define NUM_INFO_FIELDS 13
49 #include <QProgressBar>
50 #include <QTableWidget>
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
64 explicit fc_tooltip(QObject
*parent
= NULL
): QObject(parent
) {}
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
77 QElapsedTimer m_timer
;
82 progress_bar(QWidget
*parent
);
84 void mousePressEvent(QMouseEvent
*event
) {
89 void paintEvent(QPaintEvent
*event
);
90 void timerEvent(QTimerEvent
*event
);
91 void resizeEvent(QResizeEvent
*event
);
99 /****************************************************************************
100 Single item on unit_info in city dialog representing one unit
101 ****************************************************************************/
102 class unit_item
: public QLabel
105 QAction
*disband_action
;
106 QAction
*change_home
;
108 QAction
*activate_and_close
;
114 QAction
*unload_trans
;
118 unit_item(QWidget
*parent
,struct unit
*punit
, bool supp
= false, int happy_cost
= 0);
125 void contextMenuEvent(QContextMenuEvent
*ev
);
126 void create_actions();
132 void change_homecity();
133 void activate_unit();
134 void activate_and_close_dialog();
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
157 unit_info(bool supp
);
159 void add_item(unit_item
*item
);
164 QList
<unit_item
*> unit_list
;
171 /****************************************************************************
172 Single item on unit_info in city dialog representing one unit
173 ****************************************************************************/
174 class impr_item
: public QLabel
179 impr_item(QWidget
*parent
,struct impr_type
*building
, struct city
*pcity
);
184 struct impr_type
*impr
;
185 struct canvas
*impr_pixmap
;
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
202 impr_info(QWidget
*parent
);
204 void add_item(impr_item
*item
);
206 void update_buildings();
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
221 QPixmap zoomed_pixmap
;
224 city_map(QWidget
*parent
);
226 void set_pixmap(struct city
*pcity
, float z
);
228 void mousePressEvent(QMouseEvent
*event
);
229 void paintEvent(QPaintEvent
*event
);
241 QSize
minimumSizeHint();
243 void context_menu(QPoint point
);
246 /****************************************************************************
247 Item delegate for production popup
248 ****************************************************************************/
249 class city_production_delegate
: public QItemDelegate
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;
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
279 production_item(struct universal
*ptarget
, QObject
*parent
);
281 inline int columnCount() const {
284 QVariant
data() const;
288 struct universal
*target
;
291 /***************************************************************************
292 City production model
293 ***************************************************************************/
294 class city_production_model
: public QAbstractListModel
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 {
304 return (qCeil(static_cast<float>(city_target_list
.size()) / 3));
306 int columnCount(const QModelIndex
&parent
= QModelIndex()) const {
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
);
318 QList
<production_item
*> city_target_list
;
326 /****************************************************************************
327 Class for popup avaialable production
328 ****************************************************************************/
329 class production_widget
: public QTableView
333 city_production_model
*list_model
;
334 city_production_delegate
*c_p_d
;
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();
343 void prod_selected(const QItemSelection
&sl
, const QItemSelection
&ds
);
346 void mousePressEvent(QMouseEvent
*event
);
347 bool eventFilter(QObject
*obj
, QEvent
*ev
);
350 struct city
*pw_city
;
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
368 city_label(int type
, QWidget
*parent
= 0);
369 void set_city(struct city
*pcity
);
376 void mousePressEvent(QMouseEvent
*event
);
379 /****************************************************************************
381 ****************************************************************************/
382 class city_dialog
: public QDialog
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
;
396 QVBoxLayout
*left_layout
;
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
;
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
;
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
;
441 QSlider
*slider_tab
[2 * O_LAST
+ 2];
444 city_dialog(QWidget
*parent
= 0);
446 void setup_ui(struct city
*qcity
);
453 int current_building
;
455 void update_building();
456 void update_info_label();
457 void update_buy_button();
458 void update_citizens();
459 void update_improvements();
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();
471 void production_changed(int index
);
473 void show_targets_worklist();
474 void show_happiness();
476 void dbl_click_p(QTableWidgetItem
*item
);
478 void item_selected(const QItemSelection
&sl
, const QItemSelection
&ds
);
479 void clear_worklist();
480 void save_worklist();
482 void worklist_down();
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
);
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
);
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 */