Freeciv21
Develop your civilization from humble roots to a global empire
citybar.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 2020 Freeciv21 contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 
12 #pragma once
13 
14 #include <memory>
15 
16 // Qt
17 #include <QStringList>
18 
19 // Forward declarations
20 class QPainter;
21 class QPointF;
22 class QRect;
23 class QString;
24 class QTextDocument;
25 
26 struct city;
27 struct option;
28 
33 public:
34  virtual ~citybar_painter() = default;
35 
40  virtual QRect paint(QPainter &painter, const QPointF &position,
41  const city *pcity) const = 0;
42 
46  virtual bool has_flag() const { return true; }
47 
51  virtual bool has_units() const { return true; }
52 
56  virtual bool has_size() const { return true; }
57 
58  static QStringList available();
59  static const QVector<QString> *available_vector(const option *);
60  static void option_changed(option *opt);
61  static citybar_painter *current();
62 
63 private:
64  static void set_current(const QString &name);
65 
66  static std::unique_ptr<citybar_painter> s_current;
67 };
68 
73 public:
74  QRect paint(QPainter &painter, const QPointF &position,
75  const city *pcity) const override;
76 
77  bool has_flag() const override { return false; }
78  bool has_units() const override { return false; }
79  bool has_size() const override { return false; }
80 };
81 
86 public:
87  QRect paint(QPainter &painter, const QPointF &position,
88  const city *pcity) const override;
89 };
90 
95 public:
96  QRect paint(QPainter &painter, const QPointF &position,
97  const city *pcity) const override;
98 };
Abstraction for city bars of various styles.
Definition: citybar.h:32
virtual bool has_size() const
Returns whether the city size is shown in the bar.
Definition: citybar.h:56
static void option_changed(option *opt)
Called by the option code when the option has changed.
Definition: citybar.cpp:286
static const QVector< QString > * available_vector(const option *)
Returns the list of all available city bar styles.
Definition: citybar.cpp:271
static void set_current(const QString &name)
Sets the current city bar style.
Definition: citybar.cpp:307
static QStringList available()
Returns the list of all available city bar styles.
Definition: citybar.cpp:261
virtual QRect paint(QPainter &painter, const QPointF &position, const city *pcity) const =0
Draws a city bar under the given position.
static std::unique_ptr< citybar_painter > s_current
Pointer to the city bar painter currently in use.
Definition: citybar.h:66
static citybar_painter * current()
Returns the current painter (never null).
Definition: citybar.cpp:295
virtual bool has_flag() const
Returns whether the flag is shown in the bar.
Definition: citybar.h:46
virtual ~citybar_painter()=default
virtual bool has_units() const
Returns whether the units inside are shown in the bar.
Definition: citybar.h:51
A polished city bar, more like certain commercial game.
Definition: citybar.h:94
QRect paint(QPainter &painter, const QPointF &position, const city *pcity) const override
Draws the "polished" city bar.
Definition: citybar.cpp:603
A simple city bar that draws simple text on the map.
Definition: citybar.h:72
bool has_units() const override
Returns whether the units inside are shown in the bar.
Definition: citybar.h:78
bool has_flag() const override
Returns whether the flag is shown in the bar.
Definition: citybar.h:77
bool has_size() const override
Returns whether the city size is shown in the bar.
Definition: citybar.h:79
QRect paint(QPainter &painter, const QPointF &position, const city *pcity) const override
Draws a simple city bar.
Definition: citybar.cpp:334
The traditional box-based city bar.
Definition: citybar.h:85
QRect paint(QPainter &painter, const QPointF &position, const city *pcity) const override
Draws the traditional city bar with a dark background, two lines of text and colored borders.
Definition: citybar.cpp:434
const char * name
Definition: inputfile.cpp:118
Definition: city.h:291
The base class for options.
Definition: options.cpp:209