ThemeSupport

Since: BlackBerry 10.0.0

#include <bb/cascades/ThemeSupport>

A class containing theme related functionality.

This class offers functionality to obtain the current theme and listen for theme related changes.

Each theme has a VisualStyle that determines the colors used for controls and the default container background. The two visual styles are VisualStyle::Bright and VisualStyle::Dark, the default being Bright.

No caption available

To change the application's theme to Dark specify the following configuration value in the application's bar-descriptor.xml file.

<env var="CASCADES_THEME" value="dark"/>

Here are some examples for how to check the VisualStyle of the currently set theme for the application:

C++:
void ThemeTest()
{
    Label* pLabel = Label::create();

    ThemeSupport* pThemeSupport = Application::instance()->themeSupport();
    Theme* pTheme = pThemeSupport->theme();
    ColorTheme* pColTheme = pTheme->colorTheme();

    switch(pColTheme->style()) {
        case VisualStyle::Bright:
            pLabel->setText("Theme: Bright");
            break;

        case VisualStyle::Dark:
            pLabel->setText("Theme: Dark");
            break;

        default:
            pLabel->setText("Theme: Unknown");
            break;
    }
}
QML:
Container {
    id: cont1

    function themeStyleToString(style){
        switch(style) {
            case VisualStyle.Bright:    return "Theme: Bright"
            case VisualStyle.Dark:      return "Theme: Dark"
        }
        return "Theme: UNKNOWN :("
    }

    Label {
        id: themeLabel;
        text: cont1.themeStyleToString(Application.themeSupport.theme.colorTheme.style)
    }
}


Overview

QML properties

theme: bb::cascades::Theme [read-only]

QML signals

Properties Index

Public Functions Index

Q_INVOKABLE voidsetPrimaryColor (const bb::cascades::Color &primary, const bb::cascades::Color &primaryBase=bb::cascades::Color())
Q_INVOKABLE voidsetVisualStyle (bb::cascades::VisualStyle::Type visualStyle)
Q_INVOKABLE voidsetVisualStyleAndPrimaryColor (bb::cascades::VisualStyle::Type visualStyle, const bb::cascades::Color &primary, const bb::cascades::Color &primaryBase=bb::cascades::Color())
bb::cascades::Theme *theme () const

Signals Index

voidthemeChanged (const bb::cascades::Theme *theme)

Properties

bb::cascades::Theme theme[read-only]

Provides access to the current theme used in the application.

See also:

Theme, Themes

Since:

BlackBerry 10.0.0

Public Functions

Q_INVOKABLE void setPrimaryColor (

Sets the primary color for the application.

The primary color along with the primaryBase color (also known as the brand colors) are used by the framework to provide accents on the UI components. Typically these colors are specified in the bar-descriptor, but you can also call this function to change them at run-time.

Warning!

Changing the primary colors is resource intensive. Whenever possible specify the primary colors in the bar-descriptor and refrain from excessive use of this function.

See also:

setVisualStyleAndPrimaryColor() if you also want to change the visual style at the same time.

Parameters
primary

The primary color used to provide accents on the UI components. The alpha channel of the color is always ignored. If it is a null color, niether the primary or primary base color is changed.

primaryBase

An optional color used together with the primary color. It should always be darker than the primary color. The alpha channel of the color is always ignored. By default, it is a null color, letting the framework calculate it for you.

Since:

BlackBerry 10.3.0

Q_INVOKABLE void setVisualStyle (

Sets the visual style for the application.

The visual style defines most of the visual characteristics of the theme. Typically it is specified in the bar-descriptor, but you can also call this function to change it at run-time.

Warning!

Changing the visual style is resource intensive. Whenever possible specify the primary colors in the bar-descriptor and refrain from excessive use of this function.

See also:

setVisualStyleAndPrimaryColor() if you also want to change the primary color at the same time.

This does not affect any default global settings for the platform and so must be used every time the application is started or otherwise intended to change it's appearance. You typically do this after creating the Application and before creating any controls.

The application developer is responsible for reading and writing this setting on app startup if necessary.

Parameters
visualStyle

The VisualStyle to set.

See also:

VisualStyle

Since:

BlackBerry 10.3.0

Q_INVOKABLE void setVisualStyleAndPrimaryColor (

Sets the visual style and primary color for the application.

The visual style defines most of the visual characteristics of the theme. The primary color along with the primaryBase color (also known as the brand colors) are used by the framework to provide accents on the UI components. Typically these values are specified in the bar-descriptor, but you can also call this function to change them at run-time.

Warning!

Changing the visual style and primary colors is resource intensive. Whenever possible specify these values in the bar-descriptor and refrain from excessive use of this function.

Parameters
visualStyle

The VisualStyle to set.

primary

The primary color used to provide accents on the UI components. The alpha channel of the color is always ignored. If it is a null color, niether the primary or primary base color is changed.

primaryBase

An optional color used together with the primary color. It should always be darker than the primary color. The alpha channel of the color is always ignored. By default, it is a null color, letting the framework calculate it for you.

Since:

BlackBerry 10.3.0

bb::cascades::Theme * theme ()

Retrieves the current theme.

Ownership of the returned object is not transferred.

Return:

The application's theme.

See also:

Theme

Since:

BlackBerry 10.0.0

Signals

void themeChanged (

Emitted when the theme for this application has changed.

Parameters
theme

a new theme or 0 if there was an error

Since:

BlackBerry 10.0.0

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus