KGameThemeProvider Class

Manages KGameTheme instances. More...

Header: #include <KGameThemeProvider>
Inherits: QObject

Properties

Public Functions

KGameThemeProvider(const QByteArray &configKey = QByteArrayLiteral("Theme"), QObject *parent = nullptr)
void addTheme(KGameTheme *theme)
const KGameTheme *currentTheme() const
QString currentThemeName() const
const KGameTheme *defaultTheme() const
(since 7.4) void discoverThemes(const QString &directory, const QString &defaultThemeName = QStringLiteral("default"), const QMetaObject *themeClass = nullptr)
virtual QPixmap generatePreview(const KGameTheme *theme, QSize size)
QString name() const
void rediscoverThemes()
void setDeclarativeEngine(const QString &name, QQmlEngine *engine)
void setDefaultTheme(const KGameTheme *theme)
QList<const KGameTheme *> themes() const

Public Slots

void setCurrentTheme(const KGameTheme *theme)

Signals

void currentThemeChanged(const KGameTheme *theme)
void currentThemeNameChanged(const QString &themeName)
void nameChanged(const QString &name)

Detailed Description

A theme provider manages KGameTheme instances, and maintains a selection of the currentTheme(). It can automatically coordinate its selection with a KGameRenderer instance.

Note: KGameThemeProvider instances store selections in the application config, in the group [KgTheme]. This is documented here because this information is relevant for kconfig_

Property Documentation

currentTheme : const KGameTheme*

This property holds the currently selected theme, or 0 if the provider does not contain any themes.

After the KGameThemeProvider instance has been created, the current theme will not be determined until currentTheme() is called for the first time. This allows the application developer to set up the theme provider before it restores the theme selection from the configuration file.

Access functions:

const KGameTheme *currentTheme() const
void setCurrentTheme(const KGameTheme *theme)

Notifier signal:

void currentThemeChanged(const KGameTheme *theme)

[read-only] currentThemeName : QString

This property holds the name of the current theme.

Access functions:

QString currentThemeName() const

Notifier signal:

void currentThemeNameChanged(const QString &themeName)

[read-only] name : QString

This property holds the name of the KGameThemeProvider object. This name can be used as QML element ID to reference the object inside QML.

Access functions:

QString name() const

Notifier signal:

void nameChanged(const QString &name)

Member Function Documentation

[explicit] KGameThemeProvider::KGameThemeProvider(const QByteArray &configKey = QByteArrayLiteral("Theme"), QObject *parent = nullptr)

Constructor. If you don't want KGameThemeProvider to store the current theme selection in the application config file automatically, set configKey to an empty QByteArray.

If there are multiple KGameThemeProvider instances, make sure they use different config keys to avoid collisions.

void KGameThemeProvider::addTheme(KGameTheme *theme)

Adds a theme to this instance. The theme provider takes ownership of theme.

[signal] void KGameThemeProvider::currentThemeChanged(const KGameTheme *theme)

Emitted when the current theme changes to theme.

Note: Notifier signal for property currentTheme.

See also setCurrentTheme.

[signal] void KGameThemeProvider::currentThemeNameChanged(const QString &themeName)

Emitted when the name of the current theme changes to themeName.

Note: Notifier signal for property currentThemeName.

const KGameTheme *KGameThemeProvider::defaultTheme() const

Returns the default theme, or 0 if the provider does not contain any themes.

See also setDefaultTheme().

[since 7.4] void KGameThemeProvider::discoverThemes(const QString &directory, const QString &defaultThemeName = QStringLiteral("default"), const QMetaObject *themeClass = nullptr)

Reads theme description files from a standard location. The directory argument is passed to QStandardPaths like this:

QStandardPaths::locateAll(QStandardPaths::AppDataLocation, directory, QStandardPaths::LocateDirectory)

The typical usage is to install theme description files in

${KDE_INSTALL_DATADIR}/<appname>/themes

and then call:

themeProvider.discoverThemes(QStringLiteral("themes"));

If a themeClass's QMetaObject is given, the created themes will be instances of this KGameTheme subclass. The themeClass must export (with the Q_INVOKABLE marker) a constructor with the same signature as the KGameTheme constructor. defaultThemeName will be listed first.

This function was introduced in 7.4.

[virtual] QPixmap KGameThemeProvider::generatePreview(const KGameTheme *theme, QSize size)

Generate a preview pixmap for the given theme. The application will typically want to reimplement this to load the given theme into a KGameRenderer and then arrange some sprites into a preview.

size is the maximal allowed size.

The default implementation tries to load a preview image from KGameTheme::previewPath(), and resizes the result to fit in size.

[signal] void KGameThemeProvider::nameChanged(const QString &name)

Emitted when the name of the provider changes to name.

Note: Notifier signal for property name.

void KGameThemeProvider::rediscoverThemes()

After this provider has been set up with discoverThemes(), this method may be used to read additional themes which were added since the discoverThemes() call. This is especially useful for KNewStuff integration.

[slot] void KGameThemeProvider::setCurrentTheme(const KGameTheme *theme)

Selects a new theme. The given theme must already have been added to this instance.

Note: Setter function for property currentTheme.

See also currentTheme().

void KGameThemeProvider::setDeclarativeEngine(const QString &name, QQmlEngine *engine)

Registers this KGameThemeProvider with engine's root context with ID name and constructs a KGameImageProvider corresponding to this KGameThemeProvider and adds it to the QML engine, also with name, which will receive sprite requests.

void KGameThemeProvider::setDefaultTheme(const KGameTheme *theme)

Usually this will be set automatically by discoverThemes(). Call this before the first call to currentTheme(), it won't have any effect afterwards. theme must already have been added to this instance.

See also defaultTheme().

QList<const KGameTheme *> KGameThemeProvider::themes() const

Returns the themes in this provider.