Freeciv-3.1
Loading...
Searching...
No Matches
hudwidget.h
Go to the documentation of this file.
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__HUDWIDGET_H
15#define FC__HUDWIDGET_H
16
17// Needed for the moc-generated meta file
18#ifdef HAVE_CONFIG_H
19#include <fc_config.h>
20#endif
21
22// Qt
23#include <QDialog>
24#include <QElapsedTimer>
25#include <QEnterEvent>
26#include <QLabel>
27#include <QLineEdit>
28#include <QMessageBox>
29#include <QRubberBand>
30#include <QTableWidget>
31
32// common
33#include "unit.h"
34
35// gui-qt
36#include "shortcuts.h"
37
38class move_widget;
39class QComboBox;
40class QHBoxLayout;
41class QIcon;
42class QLabel;
43class QRadioButton;
44class QVBoxLayout;
45struct tile;
46struct unit;
47struct unit_list;
48
51
52/****************************************************************************
53 Custom message box with animated background
54****************************************************************************/
55class hud_message_box: public QMessageBox
56{
57 Q_OBJECT
58 QElapsedTimer m_timer;
59
60public:
61 hud_message_box(QWidget *parent);
63 int set_text_title(QString s1, QString s2, bool return_exec = false);
64
65protected:
66 void paintEvent(QPaintEvent *event);
67 void timerEvent(QTimerEvent *event);
68 void keyPressEvent(QKeyEvent *event);
69private:
71 QString text;
72 QString title;
73 QFontMetrics *fm_text;
74 QFontMetrics *fm_title;
75 QFont f_text;
76 QString cs1, cs2;
77 QFont f_title;
78 int top;
79 int mult;
80};
81
82/****************************************************************************
83 Class for showing text on screen
84****************************************************************************/
85class hud_text: public QWidget
86{
87 Q_OBJECT
88public:
89 hud_text(QString s, int time_secs, QWidget *parent);
90 ~hud_text();
91 void show_me();
92protected:
93 void paintEvent(QPaintEvent *event);
94 void timerEvent(QTimerEvent *event);
95private:
96 void center_me();
100 QString text;
101 QElapsedTimer m_timer;
102 QFontMetrics *fm_text;
103 QFont f_text;
104 QFont f_title;
105};
106
107/****************************************************************************
108 Custom input box with animated background
109****************************************************************************/
110class hud_input_box: public QDialog
111{
112 Q_OBJECT
113 QElapsedTimer m_timer;
114
115public:
116 hud_input_box(QWidget *parent);
118 void set_text_title_definput(QString s1, QString s2, QString def_input);
119 QLineEdit input_edit;
120
121protected:
122 void paintEvent(QPaintEvent *event);
123 void timerEvent(QTimerEvent *event);
124private:
126 QString text;
127 QString title;
128 QFontMetrics *fm_text;
129 QFontMetrics *fm_title;
130 QFont f_text;
131 QString cs1, cs2;
132 QFont f_title;
133 int top;
134 int mult;
135};
136
137/****************************************************************************
138 Custom label to center on current unit
139****************************************************************************/
140class click_label : public QLabel
141{
142 Q_OBJECT
143public:
144 click_label();
145signals:
147private slots:
148 void on_clicked();
149protected:
150 void mousePressEvent(QMouseEvent *e);
151};
152
153/****************************************************************************
154 Single action on unit actions
155****************************************************************************/
156class hud_action : public QWidget
157{
158 Q_OBJECT
160 bool focus;
161public:
162 hud_action(QWidget *parent);
163 ~hud_action();
164 void set_pixmap(QPixmap *p);
166signals:
169protected:
170 void paintEvent(QPaintEvent *event);
171 void mousePressEvent(QMouseEvent *e);
172 void mouseMoveEvent(QMouseEvent *event);
173 void leaveEvent(QEvent *event);
174#ifndef FC_QT5_MODE
175 void enterEvent(QEnterEvent *event);
176#else // FC_QT5_MODE
177 void enterEvent(QEvent *event);
178#endif // FC_QT5_MODE
179private slots:
180 void on_clicked();
181 void on_right_clicked();
182};
183
184/****************************************************************************
185 List of unit actions
186****************************************************************************/
187class unit_actions: public QWidget
188{
189 Q_OBJECT
190public:
191 unit_actions(QWidget *parent, unit *punit);
193 void init_layout();
194 int update_actions();
195 void clear_layout();
196 QHBoxLayout *layout;
197 QList<hud_action *> actions;
198private:
200};
201
202/****************************************************************************
203 Widget showing current unit, tile and possible actions
204****************************************************************************/
205class hud_units: public QFrame
206{
207 Q_OBJECT
211 QFont *ufont;
212 QHBoxLayout *main_layout;
214public:
215 hud_units(QWidget *parent);
216 ~hud_units();
217 void update_actions(unit_list *punits);
218protected:
219 void moveEvent(QMoveEvent *event);
220private:
222 unit_list *ul_units;
224};
225
226/****************************************************************************
227 Widget allowing load units on transport
228****************************************************************************/
229class hud_unit_loader : public QTableWidget
230{
231 QList<unit * > transports;
232 Q_OBJECT
233public:
234 hud_unit_loader(struct unit *pcargo, struct tile *ptile);
236 void show_me();
237protected slots:
238 void selection_changed(const QItemSelection&, const QItemSelection&);
239private:
240 struct unit *cargo;
241 struct tile *qtile;
242};
243
244/****************************************************************************
245 Widget allowing quick select given type of units
246****************************************************************************/
247class unit_hud_selector : public QFrame
248{
249 Q_OBJECT
250 QVBoxLayout *main_layout;
251 QComboBox *unit_sel_type;
252 QPushButton *select;
253 QPushButton *cancel;
254public:
255 unit_hud_selector(QWidget *parent);
257 void show_me();
258private slots:
259 void select_units(int x = 0);
260 void select_units(bool x);
261 void uhs_select();
262 void uhs_cancel();
263protected:
264 void keyPressEvent(QKeyEvent *event);
265private:
266 bool activity_filter(struct unit *punit);
267 bool hp_filter(struct unit *punit);
268 bool island_filter(struct unit *punit);
269 bool type_filter(struct unit *punit);
270
271 QRadioButton *any_activity;
272 QRadioButton *fortified;
273 QRadioButton *idle;
274 QRadioButton *sentried;
275
276 QRadioButton *any;
277 QRadioButton *full_mp;
278 QRadioButton *full_hp;
279 QRadioButton *full_hp_mp;
280
281 QRadioButton *this_tile;
282 QRadioButton *this_continent;
283 QRadioButton *main_continent;
284 QRadioButton *anywhere;
285
286 QRadioButton *this_type;
287 QRadioButton *any_type;
289};
290
291/****************************************************************************
292 Widget showing one combat result
293****************************************************************************/
294class hud_unit_combat : public QWidget
295{
296 Q_OBJECT
297public:
298 hud_unit_combat(int attacker_unit_id, int defender_unit_id,
299 int attacker_hp, int defender_hp,
300 bool make_att_veteran, bool make_def_veteran,
301 float scale, QWidget *parent);
303 bool get_focus();
304 void set_fading(float fade);
305 void set_scale(float scale);
306protected:
307 void paintEvent(QPaintEvent *event);
308 void mousePressEvent(QMouseEvent *e);
309 void leaveEvent(QEvent *event);
310#ifndef FC_QT5_MODE
311 void enterEvent(QEnterEvent *event);
312#else // FC_QT5_MODE
313 void enterEvent(QEvent *event);
314#endif // FC_QT5_MODE
315private:
316 void init_images(bool redraw = false);
323 struct unit *attacker;
324 struct unit *defender;
328 bool focus;
329 float fading;
331 QImage dimg, aimg;
332};
333
334/****************************************************************************
335 Widget for resizing other widgets
336****************************************************************************/
337class scale_widget : public QRubberBand
338{
339 Q_OBJECT
340public:
341 scale_widget(Shape s, QWidget *p = 0);
342 float scale;
343protected:
344 void paintEvent(QPaintEvent *event);
345 void mousePressEvent(QMouseEvent *event);
346private:
347 int size;
348 QPixmap plus;
349 QPixmap minus;
350};
351
352
353/****************************************************************************
354 Widget showing combat log
355****************************************************************************/
356class hud_battle_log : public QWidget
357{
358 Q_OBJECT
359 QVBoxLayout *main_layout;
360 QList<hud_unit_combat*> lhuc;
361public:
362 hud_battle_log(QWidget *parent);
365 void set_scale(float s);
366 float scale;
367protected:
368 void paintEvent(QPaintEvent *event);
369 void moveEvent(QMoveEvent *event);
370 void timerEvent(QTimerEvent *event);
371 void showEvent(QShowEvent *event);
372private:
373 void update_size();
374 void te_inner();
375
378 QElapsedTimer m_timer;
379};
380
381#endif /* FC__HUDWIDGET_H */
382
void left_clicked()
void mousePressEvent(QMouseEvent *e)
void on_clicked()
void paintEvent(QPaintEvent *event)
void leaveEvent(QEvent *event)
void mousePressEvent(QMouseEvent *e)
void on_clicked()
void mouseMoveEvent(QMouseEvent *event)
void right_clicked()
QPixmap * action_pixmap
Definition hudwidget.h:159
void on_right_clicked()
void enterEvent(QEnterEvent *event)
shortcut_id action_shortcut
Definition hudwidget.h:165
void left_clicked()
void set_pixmap(QPixmap *p)
move_widget * mw
Definition hudwidget.h:377
QList< hud_unit_combat * > lhuc
Definition hudwidget.h:360
QElapsedTimer m_timer
Definition hudwidget.h:378
void add_combat_info(hud_unit_combat *huc)
QVBoxLayout * main_layout
Definition hudwidget.h:359
void moveEvent(QMoveEvent *event)
void timerEvent(QTimerEvent *event)
scale_widget * sw
Definition hudwidget.h:376
void paintEvent(QPaintEvent *event)
void set_scale(float s)
void showEvent(QShowEvent *event)
QString cs1
Definition hudwidget.h:131
void set_text_title_definput(QString s1, QString s2, QString def_input)
void paintEvent(QPaintEvent *event)
QElapsedTimer m_timer
Definition hudwidget.h:113
QString cs2
Definition hudwidget.h:131
void timerEvent(QTimerEvent *event)
QFontMetrics * fm_text
Definition hudwidget.h:128
QLineEdit input_edit
Definition hudwidget.h:119
QFontMetrics * fm_title
Definition hudwidget.h:129
QString text
Definition hudwidget.h:126
QString title
Definition hudwidget.h:127
QFontMetrics * fm_text
Definition hudwidget.h:73
QString title
Definition hudwidget.h:72
QElapsedTimer m_timer
Definition hudwidget.h:58
void timerEvent(QTimerEvent *event)
void paintEvent(QPaintEvent *event)
int set_text_title(QString s1, QString s2, bool return_exec=false)
void keyPressEvent(QKeyEvent *event)
QFontMetrics * fm_title
Definition hudwidget.h:74
QElapsedTimer m_timer
Definition hudwidget.h:101
QString text
Definition hudwidget.h:100
void timerEvent(QTimerEvent *event)
QFont f_text
Definition hudwidget.h:103
int timeout
Definition hudwidget.h:98
void center_me()
QFont f_title
Definition hudwidget.h:104
QRect bound_rect
Definition hudwidget.h:97
void show_me()
void paintEvent(QPaintEvent *event)
QFontMetrics * fm_text
Definition hudwidget.h:102
int m_animate_step
Definition hudwidget.h:99
void set_fading(float fade)
struct unit * defender
Definition hudwidget.h:324
void leaveEvent(QEvent *event)
void mousePressEvent(QMouseEvent *e)
void paintEvent(QPaintEvent *event)
void init_images(bool redraw=false)
struct unit * attacker
Definition hudwidget.h:323
const struct unit_type * type_attacker
Definition hudwidget.h:325
void set_scale(float scale)
struct tile * center_tile
Definition hudwidget.h:327
const struct unit_type * type_defender
Definition hudwidget.h:326
void enterEvent(QEnterEvent *event)
struct tile * qtile
Definition hudwidget.h:241
struct unit * cargo
Definition hudwidget.h:240
void selection_changed(const QItemSelection &, const QItemSelection &)
QList< unit * > transports
Definition hudwidget.h:231
QLabel text_label
Definition hudwidget.h:210
void update_actions(unit_list *punits)
void moveEvent(QMoveEvent *event)
click_label unit_label
Definition hudwidget.h:208
QFont * ufont
Definition hudwidget.h:211
click_label tile_label
Definition hudwidget.h:209
move_widget * mw
Definition hudwidget.h:221
unit_list * ul_units
Definition hudwidget.h:222
tile * current_tile
Definition hudwidget.h:223
QHBoxLayout * main_layout
Definition hudwidget.h:212
unit_actions * unit_icons
Definition hudwidget.h:213
void paintEvent(QPaintEvent *event)
void mousePressEvent(QMouseEvent *event)
QPixmap minus
Definition hudwidget.h:349
QPixmap plus
Definition hudwidget.h:348
void clear_layout()
QList< hud_action * > actions
Definition hudwidget.h:197
void init_layout()
unit * current_unit
Definition hudwidget.h:199
int update_actions()
QHBoxLayout * layout
Definition hudwidget.h:196
QRadioButton * this_continent
Definition hudwidget.h:282
QComboBox * unit_sel_type
Definition hudwidget.h:251
QRadioButton * sentried
Definition hudwidget.h:274
void keyPressEvent(QKeyEvent *event)
QVBoxLayout * main_layout
Definition hudwidget.h:250
QRadioButton * anywhere
Definition hudwidget.h:284
QRadioButton * main_continent
Definition hudwidget.h:283
QRadioButton * full_hp_mp
Definition hudwidget.h:279
QPushButton * cancel
Definition hudwidget.h:253
bool island_filter(struct unit *punit)
bool type_filter(struct unit *punit)
QRadioButton * full_mp
Definition hudwidget.h:277
void select_units(int x=0)
QRadioButton * fortified
Definition hudwidget.h:272
QRadioButton * this_tile
Definition hudwidget.h:281
QRadioButton * any_type
Definition hudwidget.h:287
QRadioButton * any_activity
Definition hudwidget.h:271
QPushButton * select
Definition hudwidget.h:252
QRadioButton * any
Definition hudwidget.h:276
bool activity_filter(struct unit *punit)
bool hp_filter(struct unit *punit)
QRadioButton * full_hp
Definition hudwidget.h:278
QRadioButton * this_type
Definition hudwidget.h:286
QRadioButton * idle
Definition hudwidget.h:273
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:73
enum event_type event
Definition events.c:81
int Unit_type_id
Definition fc_types.h:352
bool has_player_unit_type(Unit_type_id utype)
Definition hudwidget.cpp:60
void show_new_turn_info()
struct player_slot * slots
Definition player.c:50
shortcut_id
Definition shortcuts.h:33
Definition tile.h:49
Definition unit.h:138