Add support for static platformtheme plugins
ClosedPublic

Authored by masonm on Feb 7 2020, 7:55 PM.

Details

Summary

PlatformTheme::qmlAttachedProperties is currently not looking for static KirigamiPluginFactory plugins. This change will search for static plugins for static builds, otherwise it will search shared object plugins.

It also includes a fix for missing QIcon header.

Test Plan

Register a custom, static KirigamiPluginFactory plugin using Q_IMPORT_PLUGIN and verify the attached properties work as expected. For example, regardless of what the style is set to when building with KIRIGAMI_BUILD_TYPE_STATIC below the theme should load with bright-green components:

// In main.cpp

#ifdef KIRIGAMI_BUILD_TYPE_STATIC
#include <kirigami/src/kirigamiplugin.h>
#include <KirigamiThemes/Default/defaulttheme.h>
Q_IMPORT_PLUGIN(DefaultThemeFactory)
#endif

int main(int argc, char argv[]) {

  // ...
  
#ifdef KIRIGAMI_BUILD_TYPE_STATIC
    KirigamiPlugin::registerTypes();
#endif

  // ...
  
}

// In KirigamiThemes/Default/defaulttheme.h

#ifndef DEFAULTTHEME_H
#define DEFAULTTHEME_H

#include "../KirigamiThemes_global.h"
#include <KirigamiPluginFactory>

class KIRIGAMITHEMES_EXPORT DefaultTheme : public Kirigami::PlatformTheme
{
    Q_OBJECT
    QPalette lightPalette;

public:
    explicit DefaultTheme(QObject* parent = nullptr);
};

class KIRIGAMITHEMES_EXPORT DefaultThemeFactory
        : public Kirigami::KirigamiPluginFactory
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID KirigamiPluginFactory_iid)
    Q_INTERFACES(Kirigami::KirigamiPluginFactory)

public:
    explicit DefaultThemeFactory(QObject* parent = nullptr)
        : Kirigami::KirigamiPluginFactory(parent)
    {
    }

    Kirigami::PlatformTheme *createPlatformTheme(QObject *parent) override;
};

#endif


// In KirigamiThemes/Default/defaulttheme.cpp

#include "defaulttheme.h"

DefaultTheme::DefaultTheme(QObject* parent) : Kirigami::PlatformTheme(parent)
{
    for (auto group : {QPalette::Active, QPalette::Inactive, QPalette::Disabled}) {
        lightPalette.setColor(group, QPalette::WindowText, "#00FF00");
        lightPalette.setColor(group, QPalette::Window, "#00FF00");
        lightPalette.setColor(group, QPalette::Base, "#00FF00");
        lightPalette.setColor(group, QPalette::Text, "#00FF00");
        lightPalette.setColor(group, QPalette::Button, "#00FF00");
        lightPalette.setColor(group, QPalette::ButtonText, "#00FF00");
        lightPalette.setColor(group, QPalette::Highlight, "#00FF00");
        lightPalette.setColor(group, QPalette::HighlightedText, "#00FF00");
        lightPalette.setColor(group, QPalette::ToolTipBase, "#00FF00");
        lightPalette.setColor(group, QPalette::ToolTipText, "#00FF00");
        lightPalette.setColor(group, QPalette::Link, "#00FF00");
        lightPalette.setColor(group, QPalette::LinkVisited, "#00FF00");
    }

    setTextColor(lightPalette.color(QPalette::Active, QPalette::WindowText));
    setBackgroundColor(lightPalette.color(QPalette::Active, QPalette::Window));
    setHighlightColor(lightPalette.color(QPalette::Active, QPalette::Highlight));
    setHighlightedTextColor(lightPalette.color(QPalette::Active, QPalette::HighlightedText));
    setLinkColor(lightPalette.color(QPalette::Active, QPalette::Link));
    setVisitedLinkColor(lightPalette.color(QPalette::Active, QPalette::LinkVisited));
}

Kirigami::PlatformTheme *DefaultThemeFactory::createPlatformTheme(QObject *parent)
{
    return new DefaultTheme(parent);
}

Diff Detail

Repository
R169 Kirigami
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
masonm requested review of this revision.Feb 7 2020, 7:55 PM
masonm created this revision.
mart accepted this revision.Feb 10 2020, 9:50 AM
This revision is now accepted and ready to land.Feb 10 2020, 9:50 AM
This revision was automatically updated to reflect the committed changes.