webperimental: killstack decides stack protects.
[freeciv.git] / client / gui-qt / dialogs.h
blob971bb40fa7afc1d82403d881ca2972eeaab18eaf
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 ***********************************************************************/
14 #ifndef FC__DIALOGS_H
15 #define FC__DIALOGS_H
17 #ifdef HAVE_CONFIG_H
18 #include <fc_config.h>
19 #endif
21 extern "C" {
22 #include "dialogs_g.h"
25 // Qt
26 #include <QDialog>
27 #include <QMessageBox>
28 #include <QVariant>
30 // gui-qt
31 #include "fonts.h"
32 #include "hudwidget.h"
33 #include "mapview.h"
35 class QComboBox;
36 class QGridLayout;
37 class QGroupBox;
38 class QItemSelection;
39 class QRadioButton;
40 class QSignalMapper;
41 class QTableView;
42 class QTableWidget;
43 class QTextEdit;
44 class QWidget;
46 typedef void (*pfcn_void)(QVariant, QVariant);
47 void update_nationset_combo();
48 void popup_races_dialog(struct player *pplayer);
49 void restart_notify_dialogs();
52 class qdef_act
54 Q_DISABLE_COPY(qdef_act);
56 private:
57 explicit qdef_act();
58 static qdef_act* m_instance;
59 int vs_city;
60 int vs_unit;
61 public:
62 static qdef_act* action();
63 static void drop();
64 void vs_city_set(int i);
65 void vs_unit_set(int i);
66 int vs_city_get();
67 int vs_unit_get();
70 /***************************************************************************
71 Nonmodal message box for disbanding units
72 ***************************************************************************/
73 class disband_box : public hud_message_box
75 Q_OBJECT
76 struct unit_list *cpunits;
77 public:
78 explicit disband_box(struct unit_list *punits, QWidget *parent = 0);
79 ~disband_box();
80 private slots:
81 void disband_clicked();
84 /***************************************************************************
85 Dialog for goto popup
86 ***************************************************************************/
87 class notify_goto : public QMessageBox
89 Q_OBJECT
90 QPushButton *goto_but;
91 QPushButton *inspect_but;
92 QPushButton *close_but;
93 struct tile *gtile;
94 public:
95 notify_goto(const char *headline, const char *lines,
96 const struct text_tag_list *tags, struct tile *ptile,
97 QWidget *parent);
99 private slots:
100 void goto_tile();
101 void inspect_city();
104 /***************************************************************************
105 Dialog for selecting nation, style and leader leader
106 ***************************************************************************/
107 class races_dialog:public QDialog
109 Q_OBJECT
110 QGridLayout *main_layout;
111 QTableWidget *nation_tabs;
112 QList<QWidget*> *nations_tabs_list;
113 QTableWidget *selected_nation_tabs;
114 QComboBox *leader_name;
115 QComboBox *qnation_set;
116 QRadioButton *is_male;
117 QRadioButton *is_female;
118 QTableWidget *styles;
119 QTextEdit *description;
120 QPushButton *ok_button;
121 QPushButton *random_button;
123 public:
124 races_dialog(struct player *pplayer, QWidget *parent = 0);
125 ~races_dialog();
126 void refresh();
127 void update_nationset_combo();
129 private slots:
130 void set_index(int index);
131 void nation_selected(const QItemSelection &sl, const QItemSelection &ds);
132 void style_selected(const QItemSelection &sl, const QItemSelection &ds);
133 void group_selected(const QItemSelection &sl, const QItemSelection &ds);
134 void nationset_changed(int index);
135 void leader_selected(int index);
136 void ok_pressed();
137 void cancel_pressed();
138 void random_pressed();
140 private:
141 int selected_nation;
142 int selected_style;
143 int selected_sex;
144 struct player *tplayer;
145 int last_index;
148 /***************************************************************************
149 Widget around map view to display informations like demographics report,
150 top 5 cities, traveler's report.
151 ***************************************************************************/
152 class notify_dialog:public fcwidget
154 Q_OBJECT
155 public:
156 notify_dialog(const char *caption, const char *headline,
157 const char *lines, QWidget *parent = 0);
158 virtual void update_menu();
159 ~notify_dialog();
160 void restart();
161 protected:
162 void mousePressEvent(QMouseEvent *event);
163 void mouseMoveEvent(QMouseEvent *event);
164 void mouseReleaseEvent(QMouseEvent *event);
165 private:
166 void paintEvent(QPaintEvent *paint_event);
167 void calc_size(int &x, int&y);
168 close_widget *cw;
169 QLabel *label;
170 QVBoxLayout *layout;
171 QString qcaption;
172 QString qheadline;
173 QStringList qlist;
174 QFont small_font;
175 QPoint cursor;
178 /***************************************************************************
179 Transparent widget for selecting units
180 TODO Add some simple scrollbars (just paint it during paint event,
181 if 'more' is true->scroll visible and would depend on show_line
182 ***************************************************************************/
183 class units_select: public fcwidget
185 Q_OBJECT
186 QPixmap *pix;
187 QPixmap *h_pix; /** pixmap for highlighting */
188 QSize item_size; /** size of each pixmap of unit */
189 QList<unit*> unit_list; /** storing units only for drawing, for rest units
190 * iterate utile->units */
191 QFont ufont;
192 QFont info_font;
193 int row_count;
194 close_widget *cw;
195 public:
196 units_select(struct tile *ptile, QWidget *parent);
197 ~units_select();
198 void update_menu();
199 void update_units();
200 void create_pixmap();
201 tile *utile;
202 protected:
203 void paint(QPainter *painter, QPaintEvent *event);
204 void paintEvent(QPaintEvent *event);
205 void mousePressEvent(QMouseEvent *event);
206 void keyPressEvent(QKeyEvent *event);
207 void mouseMoveEvent(QMouseEvent *event);
208 void wheelEvent(QWheelEvent *event);
209 void closeEvent(QCloseEvent *event);
210 private slots:
211 void update_img();
212 private:
213 bool more;
214 int show_line;
215 int highligh_num;
218 /**************************************************************************
219 A QPushButton that includes data like function to call and parmeters
220 **************************************************************************/
221 class Choice_dialog_button: public QPushButton
223 Q_OBJECT
224 pfcn_void func;
225 QVariant data1, data2;
226 public:
227 Choice_dialog_button(const QString title, pfcn_void func_in,
228 QVariant data1_in, QVariant data2_in);
229 pfcn_void getFunc();
230 QVariant getData1();
231 QVariant getData2();
232 void setData1(QVariant wariat);
233 void setData2(QVariant wariat);
236 /***************************************************************************
237 Simple choice dialog, allowing choosing one of set actions
238 ***************************************************************************/
239 class choice_dialog: public QWidget
241 Q_OBJECT
242 QPushButton *target_unit_button;
243 QSignalMapper *signal_mapper;
244 QVBoxLayout *layout;
245 QHBoxLayout *unit_skip;
246 QList<Choice_dialog_button *> buttons_list;
247 QList<Choice_dialog_button *> last_buttons_stack;
248 QList<Choice_dialog_button *> action_button_map;
249 void (*run_on_close)(int);
250 void switch_target();
251 public:
252 choice_dialog(const QString title, const QString text,
253 QWidget *parent = NULL,
254 void (*run_on_close_in)(int) = NULL);
255 ~choice_dialog();
256 void set_layout();
257 void add_item(QString title, pfcn_void func, QVariant data1,
258 QVariant data2, QString tool_tip, const int button_id);
259 void show_me();
260 void stack_button(Choice_dialog_button *button);
261 void unstack_all_buttons();
262 QVBoxLayout *get_layout();
263 Choice_dialog_button *get_identified_button(const int id);
264 int unit_id;
265 int target_id[ATK_COUNT];
266 struct unit* targeted_unit;
267 void update_dialog(const struct act_prob *act_probs);
268 public slots:
269 void execute_action(const int action);
270 private slots:
271 void prev_unit();
272 void next_unit();
275 void popup_revolution_dialog(struct government *government = NULL);
276 void revolution_response(struct government *government);
277 void popup_upgrade_dialog(struct unit_list *punits);
278 void popup_disband_dialog(struct unit_list *punits);
279 bool try_default_unit_action(QVariant q1, QVariant q2);
280 bool try_default_city_action(QVariant q1, QVariant q2);
282 #endif /* FC__DIALOGS_H */