Wavelength
Privacy-focused, cross-platform, and open-source communication application
Loading...
Searching...
No Matches
FontManager Class Referencefinal

Manages application fonts using a singleton pattern. More...

#include <font_manager.h>

Inheritance diagram for FontManager:
Collaboration diagram for FontManager:

Public Member Functions

QFont GetFont (const QString &font_name, int point_size=10, int weight=QFont::Normal)
 Creates a QFont object with the specified logical name, size, and weight.
 
QString GetFontFamily (const QString &font_name)
 Retrieves the actual font family name associated with a logical font name.
 
bool Initialize ()
 Initializes the FontManager by loading fonts from predefined paths.
 

Static Public Member Functions

static FontManagerGetInstance ()
 Gets the singleton instance of the FontManager.
 

Private Member Functions

 FontManager (QObject *parent=nullptr)
 Private constructor to enforce the singleton pattern.
 
bool LoadFont (const QString &font_name, const QString &font_path)
 Loads a single font file into the application using QFontDatabase.
 
 ~FontManager () override=default
 Private default destructor.
 

Private Attributes

QMap< QString, QString > font_families_
 Map storing the mapping between logical font names and actual font family names.
 

Static Private Attributes

static FontManagerinstance_ = nullptr
 Static pointer to the singleton instance.
 

Detailed Description

Manages application fonts using a singleton pattern.

This class is responsible for loading fonts from specified directories and providing access to them throughout the application. It ensures that fonts are loaded only once.

Constructor & Destructor Documentation

◆ FontManager()

FontManager::FontManager ( QObject * parent = nullptr)
inlineexplicitprivate

Private constructor to enforce the singleton pattern.

Parameters
parentOptional parent QObject.
Here is the caller graph for this function:

◆ ~FontManager()

FontManager::~FontManager ( )
overrideprivatedefault

Private default destructor.

Member Function Documentation

◆ GetFont()

QFont FontManager::GetFont ( const QString & font_name,
int point_size = 10,
int weight = QFont::Normal )

Creates a QFont object with the specified logical name, size, and weight.

Uses GetFontFamily to resolve the logical name and then construct a QFont object.

Parameters
font_nameThe logical name of the font.
point_sizeThe desired point size for the font. Defaults to 10.
weightThe desired font weight (e.g., QFont::Normal, QFont::Bold). Defaults to QFont::Normal.
Returns
A QFont object configured with the specified parameters.
Here is the call graph for this function:

◆ GetFontFamily()

QString FontManager::GetFontFamily ( const QString & font_name)

Retrieves the actual font family name associated with a logical font name.

If the requested logical font name is found, its corresponding system family name is returned. Otherwise, a warning is logged, and the default system font family is returned.

Parameters
font_nameThe logical name of the font (e.g., "BlenderPro", "Lato").
Returns
The actual font family name (e.g., "Blender Pro Book") or the default font family name if not found.
Here is the caller graph for this function:

◆ GetInstance()

FontManager * FontManager::GetInstance ( )
static

Gets the singleton instance of the FontManager.

Returns
Pointer to the singleton FontManager instance.
Here is the call graph for this function:

◆ Initialize()

bool FontManager::Initialize ( )

Initializes the FontManager by loading fonts from predefined paths.

Searches for font files (.ttf) within specific subdirectories ("BlenderPro", "Lato", "Poppins") located in resource paths (application resources, relative paths).

Returns
True if all expected font families were loaded successfully, false otherwise.
Here is the call graph for this function:

◆ LoadFont()

bool FontManager::LoadFont ( const QString & font_name,
const QString & font_path )
private

Loads a single font file into the application using QFontDatabase.

Attempts to add the font file at the given path. If successful, it retrieves the font family name and stores the mapping in font_families_.

Parameters
font_nameThe logical name to associate with this font.
font_pathThe path to the font file (.ttf).
Returns
True if the font was loaded successfully and a family name was retrieved, false otherwise.
Here is the caller graph for this function:

Member Data Documentation

◆ font_families_

QMap<QString, QString> FontManager::font_families_
private

Map storing the mapping between logical font names and actual font family names.

Key: Logical font name (e.g., "Poppins").

Value: Actual font family name loaded by QFontDatabase (e.g., "Poppins Regular").

◆ instance_

FontManager * FontManager::instance_ = nullptr
staticprivate

Static pointer to the singleton instance.


The documentation for this class was generated from the following files: