Freeciv21
Develop your civilization from humble roots to a global empire
view_map.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2023 Freeciv21 and Freeciv contributors. This file is
3  part of Freeciv21. Freeciv21 is free software: you can redistribute it
4  and/or modify it under the terms of the GNU General Public License as
5  published by the Free Software Foundation, either version 3 of the
6  License, or (at your option) any later version. You should have received
7  a copy of the GNU General Public License along with Freeciv21. If not,
8  see https://www.gnu.org/licenses/.
9 **************************************************************************/
10 #pragma once
11 
12 // Qt
13 #include <QFrame>
14 #include <QLabel>
15 #include <QPointer>
16 #include <QPropertyAnimation>
17 #include <QQueue>
18 #include <QThread>
19 #include <QTimer>
20 
21 // client
22 #include "shortcuts.h"
23 #include "tileset/tilespec.h"
24 #include "tileset_debugger.h"
25 
26 class QEvent;
27 class QFocusEvent;
28 class QKeyEvent;
29 class QMouseEvent;
30 class QObject;
31 class QPaintEvent;
32 class QPainter;
33 
34 class fcwidget;
35 namespace freeciv {
36 class renderer;
37 }
38 
39 bool is_point_in_area(int x, int y, int px, int py, int pxe, int pye);
40 void draw_calculated_trade_routes(QPainter *painter);
41 
42 /**************************************************************************
43  QWidget used for displaying map
44 **************************************************************************/
45 class map_view : public QWidget {
46  Q_OBJECT
47  Q_PROPERTY(
48  double scale READ scale WRITE set_scale_now NOTIFY scale_changed);
49 
50  // Ought to be a private slot
51  friend void debug_tile(tile *tile);
52 
53  void shortcut_released(Qt::MouseButton mb);
54 
55 public:
56  map_view();
57 
58  QPoint find_place(const QSize &size) const;
59 
60  void update_cursor(enum cursor_type);
61 
62  void hide_all_fcwidgets();
63  void show_all_fcwidgets();
64 
65  double scale() const;
66 
68 
69 signals:
70  void scale_changed(double scale) const;
71 
72 public slots:
73  void center_on_tile(tile *tile, bool animate = true);
74 
75  void zoom_in();
76  void zoom_reset();
77  void zoom_out();
78  void set_scale(double scale, bool animate = true);
79 
80  void show_debugger();
81  void hide_debugger();
82 
83  void shortcut_pressed(shortcut_id key);
84 
85 protected:
86  void paintEvent(QPaintEvent *event) override;
87  void keyPressEvent(QKeyEvent *event) override;
88  void mousePressEvent(QMouseEvent *event) override;
89  void mouseReleaseEvent(QMouseEvent *event) override;
90  void mouseMoveEvent(QMouseEvent *event) override;
91  void focusOutEvent(QFocusEvent *event) override;
92  void leaveEvent(QEvent *event) override;
93  void resizeEvent(QResizeEvent *event) override;
94  void wheelEvent(QWheelEvent *event) override;
95 
96 private slots:
97  void set_scale_now(double scale);
98  void timer_event();
99 
100 private:
101  int cursor_frame{0};
102  int cursor;
104  double m_scale = 1;
105  std::unique_ptr<QPropertyAnimation> m_origin_animation;
106  std::unique_ptr<QPropertyAnimation> m_scale_animation;
107 
108  QPointer<freeciv::tileset_debugger> m_debugger = nullptr;
109  std::vector<QPointer<fcwidget>> m_hidden_fcwidgets;
110 };
111 
112 /**************************************************************************
113  Information label about clicked tile
114 **************************************************************************/
115 class info_tile : public QLabel {
116  Q_OBJECT
118 
119 public:
120  static info_tile *i(struct tile *p = nullptr);
121  static void drop();
122  static bool shown();
123 
124  struct tile *itile;
125 
126 private:
127  info_tile(struct tile *ptile, QWidget *parent = 0);
129  void calc_size();
130 };
131 
132 void popdown_tile_info();
133 void popup_tile_info(struct tile *ptile);
134 bool mapview_is_frozen();
135 
136 void show_city_desc(QPixmap *pcanvas, int canvas_x, int canvas_y,
137  struct city *pcity, int *width, int *height);
Renders the map on widgets.
Definition: renderer.h:20
A dialog to perform debugging of the tileset.
Q_DISABLE_COPY(info_tile)
static info_tile * m_instance
Definition: view_map.h:128
static void drop()
Deletes current instance.
Definition: view_map.cpp:657
void calc_size()
Calculates size of info_tile and moves it to be fully visible.
Definition: view_map.cpp:625
struct tile * itile
Definition: view_map.h:124
static info_tile * i(struct tile *p=nullptr)
Returns given instance.
Definition: view_map.cpp:671
info_tile(struct tile *ptile, QWidget *parent=0)
Constructor for info_tile.
Definition: view_map.cpp:612
static bool shown()
Check if the info tile is currently shown.
Definition: view_map.cpp:666
void mouseReleaseEvent(QMouseEvent *event) override
Mouse release event for map_view.
Definition: mapctrl.cpp:408
void paintEvent(QPaintEvent *event) override
Slot inherited from QPixamp.
Definition: view_map.cpp:350
double m_scale
Definition: view_map.h:104
int cursor_frame
Definition: view_map.h:101
int cursor
Definition: view_map.h:102
void scale_changed(double scale) const
void mousePressEvent(QMouseEvent *event) override
Mouse buttons handler for map_view.
Definition: mapctrl.cpp:400
void resizeEvent(QResizeEvent *event) override
The widget has been resized.
Definition: view_map.cpp:364
void set_scale_now(double scale)
Sets the map scale immediately without doing any animation.
Definition: view_map.cpp:269
void keyPressEvent(QKeyEvent *event) override
Keyboard handler for map_view.
Definition: mapctrl.cpp:95
std::unique_ptr< QPropertyAnimation > m_scale_animation
Definition: view_map.h:106
void timer_event()
Timer for cursor.
Definition: view_map.cpp:312
map_view()
Constructor for map.
Definition: view_map.cpp:130
void zoom_out()
Zooms out by 20%.
Definition: view_map.cpp:243
void center_on_tile(tile *tile, bool animate=true)
Centers the view on a tile.
Definition: view_map.cpp:197
void update_cursor(enum cursor_type)
Updates cursor.
Definition: view_map.cpp:152
void zoom_reset()
Resets the zoom level.
Definition: view_map.cpp:238
std::vector< QPointer< fcwidget > > m_hidden_fcwidgets
Definition: view_map.h:109
friend void debug_tile(tile *tile)
Callback to set the tile being debugged.
Definition: view_map.cpp:757
void hide_all_fcwidgets()
Hides all fcwidgets (reports etc).
Definition: view_map.cpp:170
void focusOutEvent(QFocusEvent *event) override
Focus lost event.
Definition: view_map.cpp:332
freeciv::renderer * m_renderer
Definition: view_map.h:103
QPoint find_place(const QSize &size) const
Finds a suitable location for a widget of the given size, avoiding overlap with other widgets.
Definition: view_map.cpp:398
void show_all_fcwidgets()
Shows all fcwidgets (reports etc).
Definition: view_map.cpp:184
void leaveEvent(QEvent *event) override
Leave event.
Definition: view_map.cpp:341
void show_debugger()
Opens the tileset debugger.
Definition: view_map.cpp:278
void wheelEvent(QWheelEvent *event) override
The user wants to scroll.
Definition: view_map.cpp:373
freeciv::tileset_debugger * debugger() const
Definition: view_map.h:67
void hide_debugger()
Closes the tileset debugger if it is open.
Definition: view_map.cpp:301
std::unique_ptr< QPropertyAnimation > m_origin_animation
Definition: view_map.h:105
void set_scale(double scale, bool animate=true)
Sets the map scale.
Definition: view_map.cpp:253
void mouseMoveEvent(QMouseEvent *event) override
Mouse movement handler for map_view.
Definition: mapctrl.cpp:416
void zoom_in()
Zooms in by 20%.
Definition: view_map.cpp:233
void shortcut_pressed(shortcut_id key)
Pressed mouse or keyboard.
Definition: mapctrl.cpp:182
double scale
Definition: view_map.h:48
QPointer< freeciv::tileset_debugger > m_debugger
Definition: view_map.h:108
void shortcut_released(Qt::MouseButton mb)
Released mouse buttons.
Definition: mapctrl.cpp:372
enum event_type event
Definition: events.cpp:68
Definition: path.cpp:10
shortcut_id
Definition: shortcuts.h:33
size_t size
Definition: specvec.h:64
Definition: city.h:291
Definition: tile.h:42
cursor_type
Definition: tilespec.h:154
void popup_tile_info(struct tile *ptile)
Popups information label tile.
Definition: view_map.cpp:682
bool mapview_is_frozen()
Return whether the map should be drawn or not.
Definition: view_map.cpp:607
void popdown_tile_info()
Popdowns information label tile.
Definition: view_map.cpp:702
void show_city_desc(QPixmap *pcanvas, int canvas_x, int canvas_y, struct city *pcity, int *width, int *height)
Draw a description for the given city.
Definition: view_map.cpp:733
bool is_point_in_area(int x, int y, int px, int py, int pxe, int pye)
void draw_calculated_trade_routes(QPainter *painter)
Draws calculated trade routes.
Definition: view_map.cpp:65