cf::ui::widget::application_support::Application¶
Application class with integrated theme and animation management. More...
#include <application.h>
Inherits from QApplication
Inherited by cf::ui::widget::material::MaterialApplication
Public Types¶
| Name | |
|---|---|
| using std::function< std::unique_ptr< components::ICFAnimationManagerFactory >(constcore::ICFTheme &, QObject *)> | AnimationFactoryMaker Animation factory creator function type. |
Public Signals¶
| Name | |
|---|---|
| void | themeChanged(constcore::ICFTheme & newTheme) Signal emitted when the theme changes. |
| void | animationsEnabledChanged(bool enabled) Signal emitted when animation enabled state changes. |
Public Functions¶
| Name | |
|---|---|
| Application(int & argc, char ** argv) Constructor with standard QApplication arguments. |
|
| ~Application() override Destructor. |
|
| Application(constApplication & ) =delete | |
| Application & | operator=(constApplication & ) =delete |
| Application(Application && ) =delete | |
| Application & | operator=(Application && ) =delete |
| constcore::ICFTheme & | theme(const std::string & themeToken) const Get a theme by token name. |
| void | setTheme(const std::string & themeToken) Set the active theme by token. |
| constcore::ICFTheme & | currentTheme() const Get the current active theme. |
| cf::WeakPtr< components::ICFAbstractAnimation > | animation(const std::string & animationToken) Get an animation by token name. |
| void | setAnimationsEnabled(bool enabled) Set global animation enabled state. |
| bool | animationsEnabled() const Check if animations are globally enabled. |
| Application * | instance() Get the singleton Application instance. |
| core::ThemeManager * | themeManager() Get the ThemeManager singleton. |
| cf::WeakPtr< components::ICFAnimationManagerFactory > | animationFactory() Get the animation factory. |
| bool | registerAnimationFactoryType(const std::string & themePrefix, AnimationFactoryMaker maker) Register an animation factory type for a theme prefix. |
| void | unregisterAnimationFactoryType(const std::string & themePrefix) Unregister an animation factory type. |
Protected Functions¶
| Name | |
|---|---|
| virtual void | init() Initialize the application. |
Detailed Description¶
Application class with integrated theme and animation management.
Exceptions:
- None (all errors return invalid WeakPtr or throw from ThemeManager)
Since: 0.1
Note: Thread-safe for concurrent reads.
Warning: The animation factory is owned by Application; WeakPtr may become invalid if the application is destroyed.
Extends QApplication to provide unified access to ThemeManager and CFMaterialAnimationFactory. Replaces standard QApplication in main().
int main(int argc, char* argv[]) {
using namespace cf::ui::widget::application_support;
Application app(argc, argv);
app.setTheme("theme.material.light");
MyWidget w;
w.show();
return app.exec();
}
// Access animations from anywhere
auto fadeIn = Application::animation("md.animation.fadeIn");
if (fadeIn) {
fadeIn->setTargetWidget(myWidget);
fadeIn->start();
}
Public Types Documentation¶
using AnimationFactoryMaker¶
using cf::ui::widget::application_support::Application::AnimationFactoryMaker = std::function<std::unique_ptr<components::ICFAnimationManagerFactory>(const core::ICFTheme&, QObject*)>;
Animation factory creator function type.
Since: 0.1
Function signature for creating animation factories dynamically. Used with registerAnimationFactoryType for registering new animation factory implementations.
Public Signals Documentation¶
signal themeChanged¶
Signal emitted when the theme changes.
Parameters:
- newTheme Reference to the newly activated theme.
Since: 0.1
Note: Forwards ThemeManager::themeChanged signal.
Warning: None
signal animationsEnabledChanged¶
Signal emitted when animation enabled state changes.
Parameters:
- enabled The new enabled state.
Since: 0.1
Public Functions Documentation¶
function Application¶
Constructor with standard QApplication arguments.
Parameters:
- argc Argument count (reference for Qt compatibility).
- argv Argument values.
Exceptions:
- None
Since: 0.1
Note: Initializes animation factory with current theme.
Warning: None
function ~Application¶
Destructor.
Since: 0.1
All owned resources are cleaned up. The animation factory is destroyed before theme cleanup (since it holds theme references).
function Application¶
function operator=¶
function Application¶
function operator=¶
function theme¶
Get a theme by token name.
Parameters:
- themeToken Theme identifier (e.g., "theme.material.light").
Exceptions:
- May throw if theme not found.
Return: Reference to the theme.
Since: 0.1
Note: None
Warning: None
function setTheme¶
Set the active theme by token.
Parameters:
- themeToken Theme identifier.
Exceptions:
- None
Since: 0.1
Note: Emits themeChanged signal after successful theme change.
Warning: Theme must have been registered via ThemeManager::insert_one().
function currentTheme¶
Get the current active theme.
Exceptions:
- May throw if no theme is set.
Return: Reference to the current theme.
Since: 0.1
function animation¶
Get an animation by token name.
Parameters:
- animationToken Animation identifier (e.g., "md.animation.fadeIn").
Exceptions:
- None
Return: WeakPtr to the animation, or invalid WeakPtr if:
- Token is not found in mapping
- Animation type is not supported
- Animations are globally disabled
Since: 0.1
Note: The returned WeakPtr may become invalid if the factory is destroyed or the theme changes.
Warning: Always check validity before use.
Retrieves an animation from the animation factory using token-based lookup. Tokens are resolved through the token mapping system.
auto anim = Application::animation("md.animation.fadeIn");
if (anim) {
anim->setTargetWidget(myWidget);
anim->start();
}
function setAnimationsEnabled¶
Set global animation enabled state.
Parameters:
- enabled true to enable animations, false to disable.
Exceptions:
- None
Since: 0.1
Note: Emits animationsEnabledChanged signal.
Warning: None
When disabled, animation() returns invalid WeakPtr. Existing animations continue to run; only new creations are affected.
// Disable animations during heavy processing
Application::setAnimationsEnabled(false);
// ... do heavy work ...
Application::setAnimationsEnabled(true);
function animationsEnabled¶
Check if animations are globally enabled.
Return: true if animations are enabled, false otherwise.
Since: 0.1
function instance¶
Get the singleton Application instance.
Return: Pointer to Application instance, or nullptr if not created.
Since: 0.1
function themeManager¶
Get the ThemeManager singleton.
Return: Pointer to ThemeManager.
Since: 0.1
Convenience method equivalent to ThemeManager::instance().
function animationFactory¶
Get the animation factory.
Return: WeakPtr to the animation factory, or invalid WeakPtr if Application instance doesn't exist.
Since: 0.1
function registerAnimationFactoryType¶
static bool registerAnimationFactoryType(
const std::string & themePrefix,
AnimationFactoryMaker maker
)
Register an animation factory type for a theme prefix.
Parameters:
- themePrefix Theme prefix to match (e.g., "theme.material"). This matches all themes starting with this prefix (e.g., "theme.material.light", "theme.material.dark").
- maker Factory function that creates the animation factory.
Exceptions:
- None
Return: true if registration succeeded, false if prefix already exists.
Since: 0.1
Note: The default Material factory is pre-registered.
Warning: Register with a unique prefix to avoid conflicts.
Associates a theme prefix (e.g., "theme.material") with a factory creation function. When a theme matching this prefix is activated, the registered factory is used.
// Register a Fluent-style animation factory
Application::registerAnimationFactoryType("theme.fluent",
[](const ICFTheme& theme, QObject* parent) {
return std::make_unique<FluentAnimationFactory>(theme, parent);
});
// Now when theme "theme.fluent.dark" is active, the Fluent factory is used
app.setTheme("theme.fluent.dark");
function unregisterAnimationFactoryType¶
Unregister an animation factory type.
Parameters:
- themePrefix Theme prefix to unregister.
Exceptions:
- None
Since: 0.1
Note: The default Material factory cannot be unregistered.
Warning: None
Removes a previously registered animation factory for the given theme prefix. If a theme with this prefix is currently active, the factory is replaced with the default.
Protected Functions Documentation¶
function init¶
Initialize the application.
Since: 0.1
Note: The default implementation initializes animation factory.
Warning: When overriding, always call base init() at the end.
Reimplemented by: cf::ui::widget::material::MaterialApplication::init
Called by constructor after base class setup. Derived classes can override this to register themes before calling base init().
class MyApplication : public Application {
protected:
void init() override {
// Register themes first
registerMyThemes();
// Then call base init
Application::init();
}
};
Updated on 2026-03-09 at 10:14:00 +0000