跳转至

cf::ui::core::ThemeManager

Singleton manager for CF UI theme registration and application. More...

#include <theme_manager.h>

Inherits from QObject

Public Types

Name
using std::function< std::unique_ptr< ThemeFactory >()> InstallerMaker
Function type for creating ThemeFactory instances.

Public Signals

Name
void themeChanged(constICFTheme & new_theme)
Signal emitted when the theme changes.

Public Functions

Name
ThemeManager & instance()
Gets the singleton ThemeManager instance.
constICFTheme & theme(const std::string & name) const
Gets a theme by name.
bool insert_one(const std::string & name, InstallerMaker make_one)
Registers a theme factory with a name.
void remove_one(const std::string & name)
Removes a theme factory by name.
void install_widget(QWidget * w)
Installs a widget for theme updates.
void remove_widget(QWidget * w)
Removes a widget from theme updates.
void setThemeTo(const std::string & name, bool doBroadcast =true)
Sets the current active theme.
const std::string & currentThemeName() const
Get the current active theme name.

Detailed Description

class cf::ui::core::ThemeManager;

Singleton manager for CF UI theme registration and application.

Note: Singleton instance accessed via instance().

Warning: None

ThemeManager manages theme factory registration, theme creation, and application of themes to widgets. Emits signals when the theme changes.

auto& manager = ThemeManager::instance();
manager.insert_one("my_theme", []() { return std::make_unique<MyFactory>(); });
manager.install_widget(my_widget);
manager.setThemeTo("my_theme");

Public Types Documentation

using InstallerMaker

using cf::ui::core::ThemeManager::InstallerMaker =  std::function<std::unique_ptr<ThemeFactory>()>;

Function type for creating ThemeFactory instances.

Public Signals Documentation

signal themeChanged

void themeChanged(
    constICFTheme & new_theme
)

Signal emitted when the theme changes.

Parameters:

  • new_theme Reference to the newly activated theme.

Since: N/A

Note: None

Warning: None

Public Functions Documentation

function instance

static ThemeManager & instance()

Gets the singleton ThemeManager instance.

Exceptions:

  • None

Return: Reference to the singleton instance.

Since: N/A

Note: Thread-safe initialization.

Warning: None

function theme

constICFTheme & theme(
    const std::string & name
) const

Gets a theme by name.

Parameters:

  • name Name of the theme to retrieve.

Exceptions:

  • May throw if theme not found.

Return: Reference to the requested theme.

Since: N/A

Note: Theme is created on first access and cached.

Warning: Theme must have been registered via insert_one().

function insert_one

bool insert_one(
    const std::string & name,
    InstallerMaker make_one
)

Registers a theme factory with a name.

Parameters:

  • name Name identifier for the theme.
  • make_one Factory function that creates ThemeFactory instances.

Exceptions:

  • None

Return: true if registration succeeded, false on duplicate name.

Since: N/A

Note: The factory function is called when creating themes.

Warning: None

function remove_one

void remove_one(
    const std::string & name
)

Removes a theme factory by name.

Parameters:

  • name Name of the theme to remove.

Exceptions:

  • None

Since: N/A

Note: Does not affect currently active theme.

Warning: None

function install_widget

void install_widget(
    QWidget * w
)

Installs a widget for theme updates.

Parameters:

  • w Pointer to the widget to install.

Exceptions:

  • None

Since: N/A

Note: Installed widgets receive theme change notifications.

Warning: None

function remove_widget

void remove_widget(
    QWidget * w
)

Removes a widget from theme updates.

Parameters:

  • w Pointer to the widget to remove.

Exceptions:

  • None

Since: N/A

Note: The widget no longer receives theme change notifications.

Warning: None

function setThemeTo

void setThemeTo(
    const std::string & name,
    bool doBroadcast =true
)

Sets the current active theme.

Parameters:

  • name Name of the theme to activate.

Exceptions:

  • None

Since: N/A

Note: Emits themeChanged signal after successful theme change.

Warning: Theme must have been registered via insert_one().

function currentThemeName

const std::string & currentThemeName() const

Get the current active theme name.

Exceptions:

  • None

Return: Reference to the current theme name.

Since: N/A

Note: Returns empty string if no theme has been set.

Warning: None


Updated on 2026-03-09 at 10:14:00 +0000