Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-qt/mapview.h Source File

Freeciv-3.3

Loading...
Searching...
No Matches
mapview.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__MAPVIEW_H
15#define FC__MAPVIEW_H
16
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
24
25extern "C" {
26#include "mapview_g.h"
27}
28
29// gui-qt
30#include "fonts.h"
31
32// Qt
33#include <QFrame>
34#include <QLabel>
35#include <QMutex>
36#include <QQueue>
37#include <QThread>
38#include <QTimer>
39
40// Forward declarations
41class QMutex;
42class QPixmap;
43
44class minimap_view;
45
46bool is_point_in_area(int x, int y, int px, int py, int pxe, int pye);
47void unscale_point(double scale_factor, int &x, int &y);
48void draw_calculated_trade_routes(QPainter *painter);
49
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;
56};
57
58/**************************************************************************
59 Class to handle idle callbacks
60**************************************************************************/
61 class mr_idle : public QObject
62{
63 Q_OBJECT
64public:
65 mr_idle();
66 ~mr_idle();
67
68 void add_callback(call_me_back *cb);
69private slots:
70 void idling();
71private:
72 QQueue<call_me_back*> callback_list;
73 QTimer timer;
74};
75
76/**************************************************************************
77 QWidget used for displaying map
78**************************************************************************/
79 class map_view : public QWidget
80{
81 Q_OBJECT
82 void shortcut_pressed(int key);
83 void shortcut_released(Qt::MouseButton mb);
84public:
85 map_view();
86 void paint(QPainter *painter, QPaintEvent *event);
87 void find_place(int pos_x, int pos_y, int &w, int &h, int wdth, int hght,
88 int recursive_nr);
89 void resume_searching(int pos_x, int pos_y, int &w, int &h,
90 int wdth, int hght, int recursive_nr);
91 void update_cursor(enum cursor_type);
92 bool menu_click;
93
94protected:
95 void paintEvent(QPaintEvent *event);
96 void keyPressEvent(QKeyEvent *event);
97 void mousePressEvent(QMouseEvent *event);
98 void mouseReleaseEvent(QMouseEvent *event);
99 void mouseMoveEvent(QMouseEvent *event);
100 void focusOutEvent(QFocusEvent *event);
101 void leaveEvent(QEvent *event);
102private slots:
103 void timer_event();
104private:
105 void update_font(const QString &name, const QFont &font);
106
107 bool stored_autocenter;
108 int cursor_frame;
109 int cursor;
110
111};
112
113/**************************************************************************
114 Information label about clicked tile
115**************************************************************************/
116 class info_tile: public QLabel
117{
118 Q_OBJECT
119 QFont info_font;
120public:
121 info_tile(struct tile *ptile, QWidget *parent = 0);
122 struct tile *itile;
123protected:
124 void paintEvent(QPaintEvent *event);
125 void paint(QPainter *painter, QPaintEvent *event);
126private:
127 QStringList str_list;
128 void calc_size();
129 void update_font(const QString &name, const QFont &font);
130};
131
132/**************************************************************************
133 Widget allowing resizing other widgets
134**************************************************************************/
135 class resize_widget : public QLabel
136{
137 Q_OBJECT
138public:
139 resize_widget(QWidget* parent);
140 void put_to_corner();
141
142protected:
143 void mouseMoveEvent(QMouseEvent *event);
144 void mousePressEvent(QMouseEvent *event);
145private:
146 QPoint point;
147};
148
149
150/**************************************************************************
151 Widget allowing moving other widgets
152**************************************************************************/
153 class move_widget : public QLabel
154{
155 Q_OBJECT
156public:
157 move_widget(QWidget* parent);
158 void put_to_corner();
159
160protected:
161 void mouseMoveEvent(QMouseEvent *event);
162 void mousePressEvent(QMouseEvent *event);
163private:
164 QPoint point;
165};
166
167/**************************************************************************
168 Abstract class for widgets wanting to do custom action
169 when closing widgets is called (eg. update menu)
170**************************************************************************/
171 class fcwidget : public QFrame
172{
173 Q_OBJECT
174public:
175 virtual void update_menu() = 0;
176 bool was_destroyed;
177};
178
179/**************************************************************************
180 Widget allowing closing other widgets
181**************************************************************************/
182 class close_widget : public QLabel
183{
184 Q_OBJECT
185public:
186 close_widget(QWidget *parent);
187 void put_to_corner();
188protected:
189 void mousePressEvent(QMouseEvent *event);
190 void notify_parent();
191};
192
193/**************************************************************************
194 Thread helper for drawing minimap
195**************************************************************************/
196 class minimap_thread : public QThread
197{
198 Q_OBJECT
199public:
200 minimap_thread(QObject *parent = 0);
201 ~minimap_thread();
202 void render(double scale_factor, int width, int height);
203
204signals:
205 void rendered_image(const QImage &image);
206protected:
207 void run() Q_DECL_OVERRIDE;
208
209private:
210 int mini_width, mini_height;
211 double scale;
212 QMutex mutex;
213};
214
215/**************************************************************************
216 QLabel used for displaying overview (minimap)
217**************************************************************************/
218 class minimap_view: public fcwidget
219{
220 Q_OBJECT
221public:
222 minimap_view(QWidget *parent);
223 ~minimap_view();
224 void paint(QPainter *painter, QPaintEvent *event);
225 virtual void update_menu();
226 void update_image();
227 void reset();
228
229protected:
230 void paintEvent(QPaintEvent *event);
231 void resizeEvent(QResizeEvent *event);
232 void mousePressEvent(QMouseEvent *event);
233 void mouseMoveEvent(QMouseEvent *event);
234 void mouseReleaseEvent(QMouseEvent *event);
235 void wheelEvent(QWheelEvent *event);
236 void moveEvent(QMoveEvent *event);
237 void showEvent(QShowEvent *event);
238
239private slots:
240 void update_pixmap(const QImage &image);
241 void zoom_in();
242 void zoom_out();
243
244private:
245 void draw_viewport(QPainter *painter);
246 void scale(double factor);
247 void scale_point(int &x, int &y);
248 double scale_factor;
249 float w_ratio, h_ratio;
250 minimap_thread thread;
251 QBrush background;
252 QPixmap *pix;
253 QPoint cursor;
254 QPoint position;
255 resize_widget *rw;
256};
257
258
259void mapview_freeze(void);
260void mapview_thaw(void);
261bool mapview_is_frozen(void);
262void pixmap_put_overlay_tile(int canvas_x, int canvas_y,
263 struct sprite *ssprite);
264
265#endif // FC__MAPVIEW_H
height
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
canvas_y
struct canvas int int canvas_y
Definition canvas_g.h:43
canvas_x
struct canvas int canvas_x
Definition canvas_g.h:43
width
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
close_widget
Definition mapview.h:183
close_widget::put_to_corner
void put_to_corner()
Definition mapview.cpp:502
close_widget::mousePressEvent
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:510
close_widget::notify_parent
void notify_parent()
Definition mapview.cpp:524
fcwidget
Definition mapview.h:172
fcwidget::update_menu
virtual void update_menu()=0
fcwidget::was_destroyed
bool was_destroyed
Definition mapview.h:176
info_tile
Definition mapview.h:117
info_tile::update_font
void update_font(const QString &name, const QFont &font)
Definition mapview.cpp:1435
info_tile::calc_size
void calc_size()
Definition mapview.cpp:1367
info_tile::itile
struct tile * itile
Definition mapview.h:122
info_tile::paintEvent
void paintEvent(QPaintEvent *event)
Definition mapview.cpp:1423
info_tile::str_list
QStringList str_list
Definition mapview.h:127
info_tile::info_font
QFont info_font
Definition mapview.h:119
info_tile::paint
void paint(QPainter *painter, QPaintEvent *event)
Definition mapview.cpp:1406
map_view
Definition mapview.h:80
map_view::leaveEvent
void leaveEvent(QEvent *event)
Definition mapview.cpp:271
map_view::paintEvent
void paintEvent(QPaintEvent *event)
Definition mapview.cpp:279
map_view::menu_click
bool menu_click
Definition mapview.h:92
map_view::stored_autocenter
bool stored_autocenter
Definition mapview.h:107
map_view::cursor_frame
int cursor_frame
Definition mapview.h:108
map_view::keyPressEvent
void keyPressEvent(QKeyEvent *event)
Definition mapctrl.cpp:119
map_view::cursor
int cursor
Definition mapview.h:109
map_view::find_place
void find_place(int pos_x, int pos_y, int &w, int &h, int wdth, int hght, int recursive_nr)
Definition mapview.cpp:328
map_view::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *event)
Definition mapctrl.cpp:537
map_view::timer_event
void timer_event()
Definition mapview.cpp:231
map_view::map_view
map_view()
Definition mapview.cpp:196
map_view::update_cursor
void update_cursor(enum cursor_type)
Definition mapview.cpp:213
map_view::mousePressEvent
void mousePressEvent(QMouseEvent *event)
Definition mapctrl.cpp:521
map_view::update_font
void update_font(const QString &name, const QFont &font)
Definition mapview.cpp:252
map_view::resume_searching
void resume_searching(int pos_x, int pos_y, int &w, int &h, int wdth, int hght, int recursive_nr)
Definition mapview.cpp:301
map_view::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *event)
Definition mapctrl.cpp:529
map_view::paint
void paint(QPainter *painter, QPaintEvent *event)
Definition mapview.cpp:291
map_view::focusOutEvent
void focusOutEvent(QFocusEvent *event)
Definition mapview.cpp:263
map_view::shortcut_released
void shortcut_released(Qt::MouseButton mb)
Definition mapctrl.cpp:483
map_view::shortcut_pressed
void shortcut_pressed(int key)
Definition mapctrl.cpp:214
minimap_thread
Definition mapview.h:197
minimap_thread::mini_height
int mini_height
Definition mapview.h:210
minimap_thread::mini_width
int mini_width
Definition mapview.h:210
minimap_thread::rendered_image
void rendered_image(const QImage &image)
minimap_thread::~minimap_thread
~minimap_thread()
Definition mapview.cpp:755
minimap_thread::render
void render(double scale_factor, int width, int height)
Definition mapview.cpp:763
minimap_thread::scale
double scale
Definition mapview.h:211
minimap_thread::run
void run() Q_DECL_OVERRIDE
Definition mapview.cpp:775
minimap_thread::mutex
QMutex mutex
Definition mapview.h:212
minimap_view
Definition mapview.h:219
minimap_view::position
QPoint position
Definition mapview.h:254
minimap_view::cursor
QPoint cursor
Definition mapview.h:253
minimap_view::h_ratio
float h_ratio
Definition mapview.h:249
minimap_view::scale_factor
double scale_factor
Definition mapview.h:248
minimap_view::pix
QPixmap * pix
Definition mapview.h:252
minimap_view::rw
resize_widget * rw
Definition mapview.h:255
minimap_view::background
QBrush background
Definition mapview.h:251
minimap_view::thread
minimap_thread thread
Definition mapview.h:250
move_widget
Definition mapview.h:154
move_widget::put_to_corner
void put_to_corner()
Definition mapview.cpp:399
move_widget::mousePressEvent
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:417
move_widget::point
QPoint point
Definition mapview.h:164
move_widget::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *event)
Definition mapview.cpp:407
mr_idle
Definition mapview.h:62
mr_idle::idling
void idling()
Definition mapview.cpp:174
mr_idle::callback_list
QQueue< call_me_back * > callback_list
Definition mapview.h:72
mr_idle::add_callback
void add_callback(call_me_back *cb)
Definition mapview.cpp:188
mr_idle::~mr_idle
~mr_idle()
Definition mapview.cpp:161
mr_idle::timer
QTimer timer
Definition mapview.h:73
mr_idle::mr_idle
mr_idle()
Definition mapview.cpp:152
resize_widget
Definition mapview.h:136
resize_widget::put_to_corner
void put_to_corner()
Definition mapview.cpp:443
resize_widget::point
QPoint point
Definition mapview.h:146
resize_widget::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *event)
Definition mapview.cpp:452
resize_widget::mousePressEvent
void mousePressEvent(QMouseEvent *event)
Definition mapview.cpp:471
incite_cost
char * incite_cost
Definition comments.c:74
event
enum event_type event
Definition events.c:81
fonts.h
mapview_freeze
void mapview_freeze(void)
Definition mapview.c:373
unscale_point
void unscale_point(double scale_factor, int &x, int &y)
Definition mapview.cpp:713
pixmap_put_overlay_tile
void pixmap_put_overlay_tile(int canvas_x, int canvas_y, struct sprite *ssprite)
Definition mapview.cpp:1229
mapview_is_frozen
bool mapview_is_frozen(void)
Definition mapview.c:395
is_point_in_area
bool is_point_in_area(int x, int y, int px, int py, int pxe, int pye)
Definition mapview.cpp:71
draw_calculated_trade_routes
void draw_calculated_trade_routes(QPainter *painter)
Definition mapview.cpp:82
mapview_thaw
void mapview_thaw(void)
Definition mapview.c:381
name
const char * name
Definition inputfile.c:127
mapview_g.h
slots
struct player_slot * slots
Definition player.c:51
y
struct sprite int int y
Definition sprite_g.h:31
x
struct sprite int x
Definition sprite_g.h:31
call_me_back
Definition mapview.h:53
call_me_back::data
void * data
Definition mapview.h:55
callback
Definition gui_main.c:2405
sprite
Definition sprite.h:22
tile
Definition tile.h:50
cursor_type
cursor_type
Definition tilespec.h:289