diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 501827003..916e6db64 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -30,6 +30,7 @@ ThemeInfo::ThemeInfo( const KPluginMetaData& data ) : id( data.pluginId() ) , name( data.name() ) , description( data.description() ) + , widget( nullptr ) { } @@ -136,18 +137,27 @@ void PlasmaLnfPage::fillUi() return; } - if ( m_buttonGroup ) - delete m_buttonGroup; - m_buttonGroup = new QButtonGroup( this ); - m_buttonGroup->setExclusive( true ); + if ( !m_buttonGroup ) + { + m_buttonGroup = new QButtonGroup( this ); + m_buttonGroup->setExclusive( true ); + } int c = 1; // After the general explanation for ( auto& theme : m_enabledThemes ) { - ThemeWidget* w = new ThemeWidget( theme ); - m_buttonGroup->addButton( w->button() ); - ui->verticalLayout->insertWidget( c, w ); - connect( w, &ThemeWidget::themeSelected, this, &PlasmaLnfPage::plasmaThemeSelected); + if ( !theme.widget ) + { + ThemeWidget* w = new ThemeWidget( theme ); + m_buttonGroup->addButton( w->button() ); + ui->verticalLayout->insertWidget( c, w ); + connect( w, &ThemeWidget::themeSelected, this, &PlasmaLnfPage::plasmaThemeSelected); + theme.widget = w; + } + else + { + theme.widget->updateThemeName( theme ); + } ++c; } } diff --git a/src/modules/plasmalnf/ThemeInfo.h b/src/modules/plasmalnf/ThemeInfo.h index f11083485..b186b9be1 100644 --- a/src/modules/plasmalnf/ThemeInfo.h +++ b/src/modules/plasmalnf/ThemeInfo.h @@ -23,6 +23,7 @@ #include class KPluginMetaData; +class ThemeWidget; /** @brief describes a single plasma LnF theme. * @@ -37,18 +38,22 @@ struct ThemeInfo QString name; QString description; QString imagePath; + ThemeWidget* widget; ThemeInfo() + : widget( nullptr ) {} explicit ThemeInfo( const QString& _id ) : id( _id ) + , widget( nullptr ) { } explicit ThemeInfo( const QString& _id, const QString& image ) : id( _id ) , imagePath( image ) + , widget( nullptr ) {} // Defined in PlasmaLnfPage.cpp diff --git a/src/modules/plasmalnf/ThemeWidget.cpp b/src/modules/plasmalnf/ThemeWidget.cpp index c7256cce3..fac3980c5 100644 --- a/src/modules/plasmalnf/ThemeWidget.cpp +++ b/src/modules/plasmalnf/ThemeWidget.cpp @@ -29,6 +29,7 @@ ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) : QWidget( parent ) , m_check( new QRadioButton( info.name.isEmpty() ? info.id : info.name, parent ) ) + , m_description( new QLabel( info.description, parent ) ) , m_id( info.id ) { QHBoxLayout* layout = new QHBoxLayout( this ); @@ -44,7 +45,7 @@ ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) // Not found or not specified, so convert the name into some (horrible, likely) // color instead. image = QPixmap( image_size ); - uint hash_color = qHash( info.imagePath ); + uint hash_color = qHash( info.imagePath.isEmpty() ? info.id : info.imagePath ); cDebug() << "Theme image" << info.imagePath << "not found, hash" << hash_color; image.fill( QColor( QRgb( hash_color ) ) ); } @@ -54,7 +55,7 @@ ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) QLabel* image_label = new QLabel( this ); image_label->setPixmap( image ); layout->addWidget( image_label, 1 ); - layout->addWidget( new QLabel( info.description, this ), 3 ); + layout->addWidget( m_description, 3 ); connect( m_check, &QRadioButton::clicked, this, &ThemeWidget::clicked ); } @@ -71,3 +72,9 @@ ThemeWidget::button() const { return m_check; } + +void ThemeWidget::updateThemeName(const ThemeInfo& info) +{ + m_check->setText( info.name ); + m_description->setText( info.description ); +} diff --git a/src/modules/plasmalnf/ThemeWidget.h b/src/modules/plasmalnf/ThemeWidget.h index 42f064039..a6716ce72 100644 --- a/src/modules/plasmalnf/ThemeWidget.h +++ b/src/modules/plasmalnf/ThemeWidget.h @@ -22,6 +22,7 @@ #include class QAbstractButton; +class QLabel; class QRadioButton; struct ThemeInfo; @@ -34,6 +35,8 @@ public: QAbstractButton* button() const; + void updateThemeName( const ThemeInfo& info ); + signals: void themeSelected( const QString& id ); @@ -43,6 +46,7 @@ public slots: private: QString m_id; QRadioButton* m_check; + QLabel* m_description; } ; #endif