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