Freeciv21
Develop your civilization from humble roots to a global empire
line_of_text Class Reference

Helper class to create a line of text. More...

+ Collaboration diagram for line_of_text:

Classes

struct  block
 

Public Member Functions

void add_spacer ()
 Adds a spacer to the line. More...
 
void add_icon (const QPixmap *icon, const QMargins &margins=QMargins())
 Adds an icon to the line. More...
 
void add_text (const QString &text, const QTextCharFormat &format, bool shadow=true, const QMargins &margins=QMargins())
 Adds text to the line with the given format. More...
 
void set_text_shadow_brush (const QBrush &brush)
 
double ideal_width () const
 Returns the ideal line width (the sum of the width of all blocks) More...
 
void do_layout (double width=0)
 Lays out the line to fill the given width. More...
 
double height () const
 
QSizeF size () const
 
void paint (QPainter &p, const QPointF &top_left) const
 Paints the line at the given position. More...
 

Private Attributes

QBrush m_shadow_brush
 
QSizeF m_size
 
std::vector< blockm_blocks
 

Detailed Description

Helper class to create a line of text.

It's a lot like a dumbed down version of the Qt rich text engine, but handles a few things that we need and are not easy in Qt.

A line of text is a series of blocks. Each block contains either an icon (QPixmap) or a string and its attributes. In addition, "spacer" blocks can be added to add a stretchable space between items.

Definition at line 46 of file citybar.cpp.

Member Function Documentation

◆ add_icon()

void line_of_text::add_icon ( const QPixmap *  icon,
const QMargins &  margins = QMargins() 
)

Adds an icon to the line.

It will be centered vertically.

Definition at line 94 of file citybar.cpp.

Referenced by traditional_citybar_painter::paint(), and polished_citybar_painter::paint().

◆ add_spacer()

void line_of_text::add_spacer ( )

Adds a spacer to the line.

Spacers have zero width by default and expand as needed to fill the available space.

Definition at line 85 of file citybar.cpp.

Referenced by traditional_citybar_painter::paint().

◆ add_text()

void line_of_text::add_text ( const QString &  text,
const QTextCharFormat &  format,
bool  shadow = true,
const QMargins &  margins = QMargins() 
)

Adds text to the line with the given format.

Text items are aligned on their baseline and centered vertically.

Definition at line 107 of file citybar.cpp.

Referenced by simple_citybar_painter::paint(), traditional_citybar_painter::paint(), and polished_citybar_painter::paint().

◆ do_layout()

void line_of_text::do_layout ( double  width = 0)

Lays out the line to fill the given width.

Additional space is added between central blocks as required to fill the available space. If the width is zero (the default), no spacing is added between items.

Do not specify a width between zero and width().

Definition at line 152 of file citybar.cpp.

Referenced by simple_citybar_painter::paint(), traditional_citybar_painter::paint(), and polished_citybar_painter::paint().

◆ height()

double line_of_text::height ( ) const
inline

◆ ideal_width()

double line_of_text::ideal_width ( ) const

Returns the ideal line width (the sum of the width of all blocks)

Definition at line 135 of file citybar.cpp.

Referenced by do_layout(), simple_citybar_painter::paint(), and traditional_citybar_painter::paint().

◆ paint()

void line_of_text::paint ( QPainter &  p,
const QPointF &  top_left 
) const

Paints the line at the given position.

The state of the painter is altered.

Definition at line 226 of file citybar.cpp.

Referenced by simple_citybar_painter::paint(), traditional_citybar_painter::paint(), and polished_citybar_painter::paint().

◆ set_text_shadow_brush()

void line_of_text::set_text_shadow_brush ( const QBrush &  brush)
inline

Definition at line 66 of file citybar.cpp.

Referenced by simple_citybar_painter::paint().

◆ size()

QSizeF line_of_text::size ( ) const
inline

Definition at line 71 of file citybar.cpp.

Referenced by height(), and polished_citybar_painter::paint().

Member Data Documentation

◆ m_blocks

std::vector<block> line_of_text::m_blocks
private

Definition at line 78 of file citybar.cpp.

Referenced by add_icon(), add_spacer(), add_text(), do_layout(), ideal_width(), and paint().

◆ m_shadow_brush

QBrush line_of_text::m_shadow_brush
private

Definition at line 75 of file citybar.cpp.

Referenced by paint(), and set_text_shadow_brush().

◆ m_size

QSizeF line_of_text::m_size
private

Definition at line 77 of file citybar.cpp.

Referenced by do_layout(), and size().