Added translator comment about government overthrown message.
[freeciv.git] / client / gui-qt / mapview.h
blobf8136a9e31ced49f7b545356a0756dc54b1fb50a
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__MAPVIEW_H
15 #define FC__MAPVIEW_H
17 // In this case we have to include fc_config.h from header file.
18 // Some other headers we include demand that fc_config.h must be
19 // included also. Usually all source files include fc_config.h, but
20 // there's moc generated meta_mapview.cpp file which does not.
21 #ifdef HAVE_CONFIG_H
22 #include <fc_config.h>
23 #endif
25 extern "C" {
26 #include "mapview_g.h"
29 // gui-qt
30 #include "fonts.h"
32 // Qt
33 #include <QHBoxLayout>
34 #include <QLabel>
35 #include <QObject>
36 #include <QPushButton>
37 #include <QQueue>
38 #include <QTimer>
39 #include <QVariant>
40 #include <QWidget>
42 // Forward declarations
43 class QPixmap;
45 class minimap_view;
47 bool is_point_in_area(int x, int y, int px, int py, int pxe, int pye);
48 void draw_calculated_trade_routes(QPainter *painter);
50 /**************************************************************************
51 Struct used for idle callback to execute some callbacks later
52 **************************************************************************/
53 struct call_me_back {
54 void (*callback) (void *data);
55 void *data;
58 /**************************************************************************
59 Class to handle idle callbacks
60 **************************************************************************/
61 class mr_idle : public QObject
63 Q_OBJECT
64 public:
65 mr_idle();
66 void add_callback(call_me_back* cb);
67 QQueue<call_me_back*> callback_list;
68 private slots:
69 void idling();
70 private:
71 QTimer timer;
74 /**************************************************************************
75 QWidget used for displaying map
76 **************************************************************************/
77 class map_view : public QWidget
79 Q_OBJECT
80 void shortcut_pressed(int key);
81 void shortcut_released(Qt::MouseButton mb);
82 public:
83 map_view();
84 void paint(QPainter *painter, QPaintEvent *event);
85 void find_place(int pos_x, int pos_y, int &w, int &h, int wdth, int hght,
86 int recursive_nr);
87 void resume_searching(int pos_x,int pos_y,int &w, int &h,
88 int wdtht, int hght, int recursive_nr);
89 void update_cursor(enum cursor_type);
91 protected:
92 void paintEvent(QPaintEvent *event);
93 void keyPressEvent(QKeyEvent *event);
94 void mousePressEvent(QMouseEvent *event);
95 void mouseReleaseEvent(QMouseEvent *event);
96 void mouseMoveEvent(QMouseEvent *event);
97 void focusOutEvent(QFocusEvent *event);
98 void leaveEvent(QEvent *event);
99 private slots:
100 void timer_event();
101 private:
102 void update_font(const QString &name, const QFont &font);
104 int cursor_frame;
105 int cursor;
109 /**************************************************************************
110 Information label about clicked tile
111 **************************************************************************/
112 class info_tile: public QLabel
114 Q_OBJECT
115 QFont info_font;
116 public:
117 info_tile(struct tile *ptile, QWidget *parent = 0);
118 struct tile *itile;
119 protected:
120 void paintEvent(QPaintEvent *event);
121 void paint(QPainter *painter, QPaintEvent *event);
122 private:
123 QStringList str_list;
124 void calc_size();
125 void update_font(const QString &name, const QFont &font);
128 /**************************************************************************
129 Widget allowing resizing other widgets
130 **************************************************************************/
131 class resize_widget : public QLabel
133 Q_OBJECT
134 public:
135 resize_widget(QWidget* parent);
136 void put_to_corner();
138 protected:
139 void mouseMoveEvent(QMouseEvent *event);
140 void mousePressEvent(QMouseEvent *event);
141 private:
142 QPoint point;
146 /**************************************************************************
147 Widget allowing moving other widgets
148 **************************************************************************/
149 class move_widget : public QLabel
151 Q_OBJECT
152 public:
153 move_widget(QWidget* parent);
154 void put_to_corner();
156 protected:
157 void mouseMoveEvent(QMouseEvent *event);
158 void mousePressEvent(QMouseEvent *event);
159 private:
160 QPoint point;
163 /**************************************************************************
164 Abstract class for widgets wanting to do custom action
165 when closing widgets is called (eg. update menu)
166 **************************************************************************/
167 class fcwidget : public QFrame
169 Q_OBJECT
170 public:
171 virtual void update_menu() = 0;
172 bool was_destroyed;
175 /**************************************************************************
176 Widget allowing closing other widgets
177 **************************************************************************/
178 class close_widget : public QLabel
180 Q_OBJECT
181 public:
182 close_widget(QWidget *parent);
183 void put_to_corner();
184 protected:
185 void mousePressEvent(QMouseEvent *event);
186 void notify_parent();
189 /**************************************************************************
190 QLabel used for displaying overview (minimap)
191 **************************************************************************/
192 class minimap_view: public fcwidget
194 Q_OBJECT
195 public:
196 minimap_view(QWidget *parent);
197 ~minimap_view();
198 void paint(QPainter *painter, QPaintEvent *event);
199 virtual void update_menu();
200 void update_image();
201 void reset();
203 protected:
204 void paintEvent(QPaintEvent *event);
205 void resizeEvent(QResizeEvent *event);
206 void mousePressEvent(QMouseEvent *event);
207 void mouseMoveEvent(QMouseEvent *event);
208 void mouseReleaseEvent(QMouseEvent *event);
209 void wheelEvent(QWheelEvent *event);
210 void moveEvent(QMoveEvent *event);
211 void showEvent(QShowEvent *event);
213 private slots:
214 void zoom_in();
215 void zoom_out();
217 private:
218 void draw_viewport(QPainter *painter);
219 void scale(double factor);
220 void scale_point(int &x, int &y);
221 void unscale_point(int &x, int &y);
222 double scale_factor;
223 float w_ratio, h_ratio;
224 QBrush background;
225 QPixmap *pix;
226 QPoint cursor;
227 QPoint position;
228 resize_widget *rw;
232 void mapview_freeze(void);
233 void mapview_thaw(void);
234 bool mapview_is_frozen(void);
235 void pixmap_put_overlay_tile(int canvas_x, int canvas_y,
236 struct sprite *ssprite);
238 #endif /* FC__MAPVIEW_H */