Page Contents

Topics

Classes

LThemeable Class

#include <Layers/lthemeable.h>

Inherits: LObject

Public Functions

LThemeable()
LThemeable(const LThemeable& other)
void add_share_themeable(LThemeable* themeable)
virtual void apply_theme_item(LThemeItem* theme_item)
virtual std::vector<LThemeable*> child_themeables(bool recursive = false) = 0
LThemeItem* current_theme_item() const
virtual LString path() = 0
virtual void update() = 0

Detailed Description

An LThemeable is an LObject intended to be inherited alongside widget classes to provide them with functionality to apply Layers themes (see LTheme). LThemeable objects are also referred to as themeable widgets.

LAttribute objects owned by themeable widgets are called widget attributes.

Child themeables can be obtained through child_themeables(), which needs to be implemented by LThemeable subclasses.

Themeable Paths

A themeable path is a string that contains the names of the widgets that make up the themeable's hierarchy, as well as the themeable's name, separated by forward-slash (/) characters. The following is an example of a themeable path:

App/Main Window/Settings Menu

Themeable paths are used to match themeables with the correct LThemeItem objects whose paths should be the same. So, the above example would also be the path of the theme-item containing data for the Settings Menu in an LTheme.

A themeable's path can be obtained through path(), which needs to be implemented by LThemeable subclasses.

Applying Theme-Items

A theme-item is applied to a themeable through apply_theme_item(). This sets the item's theme attributes to the themeable's widget attributes.

In most cases, you will not have to manually call apply_theme_item() as long as the themeable is already a part of the application hierarchy when the application's theme changes.

However, if a themeable is initialized after the application's theme has been set, you may need to manually call apply_theme_item(). In these cases, it is usually helpful to obtain the parent themeable's current theme-item using the protected member variable m_current_theme_item, and then call LThemeItem::find_item() to obtain the desired theme-item to apply. The following is an example:

// From QLayers::QLThemeEditorDialog:
 
if (current_theme_item())
    attr_editor->apply_theme_item(
        current_theme_item()->find_item(
            "Attribute Editors"));

Sharing Theme-Items

A themeable can share its theme-item with other themeables. These other themeables are called share themeables and can be added using add_share_themeable(). When a theme-item is applied to the original themeable, the item is also applied to the share themeables.

This is useful for recursive widgets, which are widgets that have widgets of the same type as children.

Updating Widgets

The update() function needs to be implemented by LThemeable subclasses. It is should be used to make widget update calls.

Member Function Documentation

LThemeable()

Constructs a themeable.

LThemeable(const LThemeable& other)

Constructs a copy of the other themeable.

void add_share_themeable(LThemeable* themeable)

Adds themeable to the list of share themeables.

std::vector<LThemeable*> child_themeables(bool recursive = false)

Pure Virtual

Returns a list of child themeables.

LThemeItem* current_theme_item() const

Returns a pointer to the themeable's currently applied theme-item.

See also: apply_theme_item()

LString path()

Pure Virtual

Returns a string representing the themeable's path.

void update()

Pure Virtual

Updates the themeable widget.