Freeciv21
Develop your civilization from humble roots to a global empire
top_bar.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 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 <QToolButton>
14 #include <QWidget>
15 
16 class QHBoxLayout;
17 class QPixmap;
18 
19 typedef void (*pfcn)();
20 
21 void top_bar_center_unit();
22 void top_bar_finish_turn();
27 void top_bar_units_view();
28 void top_bar_show_map();
29 
33 class national_budget_widget : public QToolButton {
34  Q_OBJECT
35 
36 public:
38  ~national_budget_widget() override;
39 
40  QSize sizeHint() const override;
41 
42 protected:
43  void paintEvent(QPaintEvent *event) override;
44 };
45 
50 class indicators_widget : public QToolButton {
51  Q_OBJECT
52 
53 public:
55  ~indicators_widget() override;
56 
57  QSize sizeHint() const override;
58 
59 protected:
60  void paintEvent(QPaintEvent *event) override;
61 };
62 
63 /***************************************************************************
64  Class representing single widget(icon) on top_bar
65 ***************************************************************************/
66 class top_bar_widget : public QToolButton {
67  Q_OBJECT
68 
69 public:
70  top_bar_widget(const QString &label, const QString &pg, pfcn func);
71  ~top_bar_widget() override;
72  int getPriority();
73  QPixmap *get_pixmap();
74  void paint(QPainter *painter, QPaintEvent *event);
75  void setCustomLabels(const QString &);
76  void setLabel(const QString &str);
77  void setLeftClick(pfcn func);
78  void setRightClick(pfcn func);
79  void setWheelDown(pfcn func);
80  void setWheelUp(pfcn func);
81 
82  bool blink;
84  QString page;
85 public slots:
86  void sblink();
87  void someSlot();
88 
89 protected:
90  void mousePressEvent(QMouseEvent *event) override;
91  void paintEvent(QPaintEvent *event) override;
92  void wheelEvent(QWheelEvent *event) override;
93 
94 private:
99  QTimer *timer;
100 };
101 
109 class gold_widget : public top_bar_widget {
110  Q_OBJECT
111  Q_PROPERTY(warning current_warning READ current_warning)
112 
113 public:
115  enum class warning {
116  no_warning = 0,
117  losing_money = 1,
118  low_on_funds = 2,
119  };
120  Q_ENUM(warning)
121 
122  gold_widget();
123  ~gold_widget() override;
124 
126  int income() const { return m_gold; }
127 
129  void set_income(int income)
130  {
131  m_income = income;
132  update_contents();
133  }
134 
136  int gold() const { return m_gold; }
137 
139  void set_gold(int gold)
140  {
141  m_gold = gold;
142  update_contents();
143  }
144 
146  warning current_warning() const { return m_warning; }
147 
148 protected:
149  void paintEvent(QPaintEvent *event) override;
150 
151 private:
152  void update_contents();
153 
154  int m_gold = 0, m_income = 0;
156 };
157 
158 /***************************************************************************
159  Freeciv21 top_bar
160 ***************************************************************************/
161 class top_bar : public QWidget {
162  Q_OBJECT
163 
164 public:
165  top_bar();
166  ~top_bar() override;
167  void addWidget(QWidget *fsw);
168  QList<QWidget *> objects;
169 
170 private:
171  QHBoxLayout *layout;
172 };
Top bar widget that shows the amount of gold owned by the current player, and their income.
Definition: top_bar.h:109
void set_income(int income)
Changes the gold amount shown by the widget.
Definition: top_bar.h:129
warning current_warning
Definition: top_bar.h:111
void update_contents()
Updates the displayed text after the gold or income changed.
Definition: top_bar.cpp:375
int income() const
Returns the incom as currently shown.
Definition: top_bar.h:126
gold_widget()
Constructor.
Definition: top_bar.cpp:360
warning current_warning() const
Retrieves the current warning.
Definition: top_bar.h:146
int gold() const
Returns the gold amount as currently shown.
Definition: top_bar.h:136
int m_income
Definition: top_bar.h:154
warning
Types of warnings displayed by gold_widget.
Definition: top_bar.h:115
@ no_warning
Used when no warning is shown.
@ low_on_funds
The current player will soon go bankrupt.
@ losing_money
The current player has negative gold income.
~gold_widget() override
Destructor.
Definition: top_bar.cpp:370
int m_gold
Definition: top_bar.h:154
void set_gold(int gold)
Changes the gold amount shown by the widget.
Definition: top_bar.h:139
warning m_warning
Definition: top_bar.h:155
void paintEvent(QPaintEvent *event) override
Renders the national budget widget.
Definition: top_bar.cpp:407
Top bar widget for indicators (global warming/nuclear winter/science/ government).
Definition: top_bar.h:50
QSize sizeHint() const override
Size hint.
Definition: top_bar.cpp:142
void paintEvent(QPaintEvent *event) override
Renders the indicators widget.
Definition: top_bar.cpp:166
indicators_widget()
Constructor.
Definition: top_bar.cpp:128
~indicators_widget() override
Destructor.
Definition: top_bar.cpp:137
Top bar widget for national budget.
Definition: top_bar.h:33
QSize sizeHint() const override
Size hint.
Definition: top_bar.cpp:62
void paintEvent(QPaintEvent *event) override
Renders the national budget widget.
Definition: top_bar.cpp:86
~national_budget_widget() override
Destructor.
Definition: top_bar.cpp:57
national_budget_widget()
Constructor.
Definition: top_bar.cpp:48
void paintEvent(QPaintEvent *event) override
Paint event for top bar widget.
Definition: top_bar.cpp:228
QPixmap * get_pixmap()
top_bar_widget(const QString &label, const QString &pg, pfcn func)
Sidewidget constructor.
Definition: top_bar.cpp:197
pfcn left_click
Definition: top_bar.h:98
bool blink
Definition: top_bar.h:82
void setWheelUp(pfcn func)
Sets callback for mouse wheel up.
Definition: top_bar.cpp:267
void setLabel(const QString &str)
pfcn wheel_down
Definition: top_bar.h:96
QTimer * timer
Definition: top_bar.h:99
void setRightClick(pfcn func)
Sets callback for mouse right click.
Definition: top_bar.cpp:257
void sblink()
Blinks current top_bar widget.
Definition: top_bar.cpp:302
void setWheelDown(pfcn func)
Sets callback for mouse wheel down.
Definition: top_bar.cpp:262
pfcn wheel_up
Definition: top_bar.h:97
~top_bar_widget() override
Sidewidget destructor.
Definition: top_bar.cpp:218
QString page
Definition: top_bar.h:84
void paint(QPainter *painter, QPaintEvent *event)
void someSlot()
Miscelanous slot, helping observe players currently, and changing science extra functionality might b...
Definition: top_bar.cpp:323
bool keep_blinking
Definition: top_bar.h:83
void wheelEvent(QWheelEvent *event) override
Mouse wheel event.
Definition: top_bar.cpp:288
pfcn right_click
Definition: top_bar.h:95
void setLeftClick(pfcn func)
Sets callback for mouse left click.
Definition: top_bar.cpp:252
void setCustomLabels(const QString &)
Sets custom text visible on top of sidewidget.
Definition: top_bar.cpp:223
void mousePressEvent(QMouseEvent *event) override
Mouse press event for sidewidget.
Definition: top_bar.cpp:272
void addWidget(QWidget *fsw)
Adds new top_bar widget.
Definition: top_bar.cpp:439
QHBoxLayout * layout
Definition: top_bar.h:171
top_bar()
Sidebar constructor.
Definition: top_bar.cpp:421
QList< QWidget * > objects
Definition: top_bar.h:168
~top_bar() override
Sidebar destructor.
enum event_type event
Definition: events.cpp:68
get_token_fn_t func
Definition: inputfile.cpp:119
void top_bar_right_click_diplomacy()
Right click for diplomacy Opens diplomacy meeting for player For observer popups menu.
Definition: top_bar.cpp:485
void top_bar_right_click_science()
Right click for science, allowing to choose current tech.
Definition: top_bar.cpp:525
void top_bar_units_view()
Click for units view, allowing to close/open.
Definition: top_bar.cpp:602
void(* pfcn)()
Definition: top_bar.h:19
void top_bar_indicators_menu()
Popups menu on indicators widget.
Definition: top_bar.cpp:471
void top_bar_left_click_science()
Left click for science, allowing to close/open.
Definition: top_bar.cpp:575
void top_bar_show_map()
Callback to show map.
Definition: top_bar.cpp:448
void top_bar_center_unit()
Callback to center on current unit.
Definition: top_bar.cpp:462
void top_bar_finish_turn()
Callback for finishing turn.
Definition: top_bar.cpp:457