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 #ifndef FC__REPODLGS_H
15 #define FC__REPODLGS_H
16 
17 #ifdef HAVE_CONFIG_H
18 #include <fc_config.h>
19 #endif
20 
21 extern "C" {
22 #include "repodlgs_g.h"
23 }
24 
25 // client
26 #include "climisc.h"
27 
28 // gui-qt
29 #include "fonts.h"
30 #include "mapview.h"
31 
32 // Qt
33 #include <QLabel>
34 #include <QPushButton>
35 #include <QWidget>
36 
37 class progress_bar;
38 class QComboBox;
39 class QGridLayout;
40 class QGroupBox;
41 class QHBoxLayout;
42 class QItemSelection;
43 class QPushButton;
44 class QScrollArea;
45 class QTableWidget;
46 class QTableWidgetItem;
47 
48 class unittype_item: public QFrame {
49 
50   Q_OBJECT
51 
52   bool entered;
53   int unit_scroll;
54   QLabel label_pix;
55 
56 public:
57   unittype_item(QWidget *parent, unit_type *ut);
58   ~unittype_item();
59   void init_img();
60   QLabel food_upkeep;
61   QLabel gold_upkeep;
62   QLabel label_info_active;
63   QLabel label_info_inbuild;
64   QLabel label_info_unit;
65   QLabel shield_upkeep;
66   QPushButton upgrade_button;
67 
68 private:
69   unit_type *utype;
70 
71 private slots:
72   void upgrade_units();
73 
74 protected:
75   void enterEvent(QEvent *event);
76   void leaveEvent(QEvent *event);
77   void paintEvent(QPaintEvent *event);
78   void wheelEvent(QWheelEvent *event);
79 };
80 
81 class units_reports: public fcwidget {
82 
83   Q_DISABLE_COPY(units_reports);
84   Q_OBJECT
85 
86   close_widget *cw;
87   explicit units_reports();
88   QHBoxLayout *scroll_layout;
89   QScrollArea *scroll;
90   QWidget scroll_widget;
91   static units_reports *m_instance;
92 
93 public:
94   ~units_reports();
95   static units_reports *instance();
96   static void drop();
97   void clear_layout();
98   void init_layout();
99   void update_units(bool show = false);
100   void add_item(unittype_item *item);
101   virtual void update_menu();
102   QHBoxLayout *layout;
103   QList<unittype_item *> unittype_list;
104 
105 protected:
106   void paintEvent(QPaintEvent *event);
107 };
108 
109 /****************************************************************************
110   Helper item for comboboxes, holding string of tech and its id
111 ****************************************************************************/
112 struct qlist_item {
113   QString tech_str;
114   Tech_type_id id;
115 };
116 
117 /****************************************************************************
118   Helper item for research diagram, about drawn rectangles and what
119   tech/unit/improvement they point to.
120 ****************************************************************************/
121 class req_tooltip_help
122 {
123 public:
124   req_tooltip_help();
125   QRect rect;
126   Tech_type_id tech_id;
127   struct unit_type *tunit;
128   struct impr_type *timpr;
129   struct government *tgov;
130 };
131 /****************************************************************************
132   Custom widget representing research diagram in science_report
133 ****************************************************************************/
134 class research_diagram: public QWidget
135 {
136   Q_OBJECT
137 
138 public:
139   research_diagram(QWidget *parent = 0);
140   ~research_diagram();
141   void update_reqtree();
142   void reset();
143   QSize size();
144 private slots:
145   void show_tooltip();
146 private:
147   void mousePressEvent(QMouseEvent *event);
148   void mouseMoveEvent(QMouseEvent *event);
149   void paintEvent(QPaintEvent *event);
150   void create_tooltip_help();
151   struct canvas *pcanvas;
152   struct reqtree *req;
153   bool timer_active;
154   int width;
155   int height;
156   QList<req_tooltip_help*> tt_help;
157   QPoint tooltip_pos;
158   QString tooltip_text;
159   QRect tooltip_rect;
160 
161 };
162 
163 /****************************************************************************
164   Widget embedded as tab on game view (F6 default)
165   Uses string "SCI" to mark it as opened
166   You can check it using if (gui()->is_repo_dlg_open("SCI"))
167 ****************************************************************************/
168 class science_report: public QWidget
169 {
170   Q_OBJECT
171 
172   QComboBox *goal_combo;
173   QComboBox *researching_combo;
174   QGridLayout *sci_layout;
175   progress_bar *progress;
176   QLabel *info_label;
177   QLabel *progress_label;
178   QList<qlist_item> *curr_list;
179   QList<qlist_item> *goal_list;
180   research_diagram *res_diag;
181   QScrollArea *scroll;
182 
183 public:
184   science_report();
185   ~science_report();
186   void update_report();
187   void init(bool raise);
188   void redraw();
189   void reset_tree();
190 
191 private:
192   void update_reqtree();
193   int index;
194 
195 private slots:
196   void current_tech_changed(int index);
197   void goal_tech_changed(int index);
198 };
199 
200 
201 /****************************************************************************
202   Tab widget to display economy report (F5)
203 ****************************************************************************/
204 class eco_report: public QWidget
205 {
206   Q_OBJECT
207   QPushButton *disband_button;
208   QPushButton *sell_button;
209   QPushButton *sell_redun_button;
210   QTableWidget *eco_widget;
211   QLabel *eco_label;
212 
213 public:
214   eco_report();
215   ~eco_report();
216   void update_report();
217   void init();
218 
219 private:
220   int index;
221   int curr_row;
222   int max_row;
223   cid uid;
224   int counter;
225 
226 private slots:
227   void disband_units();
228   void sell_buildings();
229   void sell_redundant();
230   void selection_changed(const QItemSelection &sl,
231                          const QItemSelection &ds);
232 };
233 
234 /****************************************************************************
235   Tab widget to display economy report (F5)
236 ****************************************************************************/
237 class endgame_report: public QWidget
238 {
239   Q_OBJECT
240   QTableWidget *end_widget;
241 
242 public:
243   endgame_report(const struct packet_endgame_report *packet);
244   ~endgame_report();
245   void update_report(const struct packet_endgame_player *packet);
246   void init();
247 
248 private:
249   int index;
250   int players;
251 
252 };
253 
254 
255 bool comp_less_than(const qlist_item &q1, const qlist_item &q2);
256 void popdown_economy_report();
257 void popdown_units_report();
258 void popdown_science_report();
259 void popdown_endgame_report();
260 void popup_endgame_report();
261 void toggle_units_report(bool);
262 
263 #endif /* FC__REPODLGS_H */
264