Manages application fonts using a singleton pattern.
More...
#include <font_manager.h>
|
| 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.
|
| |
|
| | 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.
|
| |
|
| QMap< QString, QString > | font_families_ |
| | Map storing the mapping between logical font names and actual font family names.
|
| |
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.
◆ FontManager()
| FontManager::FontManager |
( |
QObject * | parent = nullptr | ) |
|
|
inlineexplicitprivate |
Private constructor to enforce the singleton pattern.
- Parameters
-
| parent | Optional parent QObject. |
◆ ~FontManager()
| FontManager::~FontManager |
( |
| ) |
|
|
overrideprivatedefault |
Private default destructor.
◆ 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_name | The logical name of the font. |
| point_size | The desired point size for the font. Defaults to 10. |
| weight | The desired font weight (e.g., QFont::Normal, QFont::Bold). Defaults to QFont::Normal. |
- Returns
- A QFont object configured with the specified parameters.
◆ 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_name | The 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.
◆ GetInstance()
◆ 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.
◆ 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_name | The logical name to associate with this font. |
| font_path | The path to the font file (.ttf). |
- Returns
- True if the font was loaded successfully and a family name was retrieved, false otherwise.
◆ 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_
Static pointer to the singleton instance.
The documentation for this class was generated from the following files: