From 254933a4888aff9c28cfc02f9dac357f51b5b889 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 16 Nov 2020 21:28:37 +0100 Subject: [PATCH] [plasmalnf] Prep-work for loading the themes into the model --- src/modules/plasmalnf/ThemeInfo.cpp | 39 +++++++++++++++++++++++++++++ src/modules/plasmalnf/ThemeInfo.h | 13 ++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/modules/plasmalnf/ThemeInfo.cpp b/src/modules/plasmalnf/ThemeInfo.cpp index 41bffd1f0..2cf389a7c 100644 --- a/src/modules/plasmalnf/ThemeInfo.cpp +++ b/src/modules/plasmalnf/ThemeInfo.cpp @@ -60,6 +60,45 @@ ThemesModel::roleNames() const return { { LabelRole, "label" }, { KeyRole, "key" } }; } +void +ThemesModel::setThemeImage( const QString& id, const QString& imagePath ) +{ + auto* theme = m_themes.findById( id ); + if ( theme ) + { + theme->imagePath = imagePath; + } +} + +void +ThemesModel::setThemeImage( const QMap< QString, QString >& images ) +{ + for ( const auto& k : images ) + { + setThemeImage( k, images[ k ] ); + } +} + +void +ThemesModel::showTheme( const QString& id, bool show ) +{ + auto* theme = m_themes.findById( id ); + if ( theme ) + { + theme->show = show; + } +} + +void +ThemesModel::showTheme( const QMap< QString, QString >& onlyThese ) +{ + for ( auto& t : m_themes ) + { + t.show = onlyThese.contains( t.id ); + } +} + + ThemeInfo::ThemeInfo( const KPluginMetaData& data ) : id( data.pluginId() ) , name( data.name() ) diff --git a/src/modules/plasmalnf/ThemeInfo.h b/src/modules/plasmalnf/ThemeInfo.h index a44c41858..3ac83c771 100644 --- a/src/modules/plasmalnf/ThemeInfo.h +++ b/src/modules/plasmalnf/ThemeInfo.h @@ -31,6 +31,7 @@ struct ThemeInfo QString description; QString imagePath; ThemeWidget* widget; + bool show = true; ThemeInfo() : widget( nullptr ) @@ -108,6 +109,18 @@ public: const ThemeInfo* findById( const QString& id ) const { return m_themes.findById( id ); } + /// @brief Set the screenshot to go with the given @p id + void setThemeImage( const QString& id, const QString& imagePath ); + + /// @brief Call setThemeImage( key, value ) for all keys in @p images + void setThemeImage( const QMap< QString, QString >& images ); + + /// @brief Set whether to show the given theme @p id (or not) + void showTheme( const QString& id, bool show = true ); + + /// @brief Shows the keys in the @p onlyThese map, and hides the rest + void showTheme( const QMap< QString, QString >& onlyThese ); + private: ThemeInfoList m_themes; };