[plasmalnf] Prevent duplicate widgets
- Only create widgets for themes once - Update visible texts as needed
This commit is contained in:
parent
3f258d4bd9
commit
cf39dddbf3
@ -30,6 +30,7 @@ ThemeInfo::ThemeInfo( const KPluginMetaData& data )
|
|||||||
: id( data.pluginId() )
|
: id( data.pluginId() )
|
||||||
, name( data.name() )
|
, name( data.name() )
|
||||||
, description( data.description() )
|
, description( data.description() )
|
||||||
|
, widget( nullptr )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,18 +137,27 @@ void PlasmaLnfPage::fillUi()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_buttonGroup )
|
if ( !m_buttonGroup )
|
||||||
delete m_buttonGroup;
|
{
|
||||||
m_buttonGroup = new QButtonGroup( this );
|
m_buttonGroup = new QButtonGroup( this );
|
||||||
m_buttonGroup->setExclusive( true );
|
m_buttonGroup->setExclusive( true );
|
||||||
|
}
|
||||||
|
|
||||||
int c = 1; // After the general explanation
|
int c = 1; // After the general explanation
|
||||||
for ( auto& theme : m_enabledThemes )
|
for ( auto& theme : m_enabledThemes )
|
||||||
{
|
{
|
||||||
ThemeWidget* w = new ThemeWidget( theme );
|
if ( !theme.widget )
|
||||||
m_buttonGroup->addButton( w->button() );
|
{
|
||||||
ui->verticalLayout->insertWidget( c, w );
|
ThemeWidget* w = new ThemeWidget( theme );
|
||||||
connect( w, &ThemeWidget::themeSelected, this, &PlasmaLnfPage::plasmaThemeSelected);
|
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;
|
++c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
class KPluginMetaData;
|
class KPluginMetaData;
|
||||||
|
class ThemeWidget;
|
||||||
|
|
||||||
/** @brief describes a single plasma LnF theme.
|
/** @brief describes a single plasma LnF theme.
|
||||||
*
|
*
|
||||||
@ -37,18 +38,22 @@ struct ThemeInfo
|
|||||||
QString name;
|
QString name;
|
||||||
QString description;
|
QString description;
|
||||||
QString imagePath;
|
QString imagePath;
|
||||||
|
ThemeWidget* widget;
|
||||||
|
|
||||||
ThemeInfo()
|
ThemeInfo()
|
||||||
|
: widget( nullptr )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
explicit ThemeInfo( const QString& _id )
|
explicit ThemeInfo( const QString& _id )
|
||||||
: id( _id )
|
: id( _id )
|
||||||
|
, widget( nullptr )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
explicit ThemeInfo( const QString& _id, const QString& image )
|
explicit ThemeInfo( const QString& _id, const QString& image )
|
||||||
: id( _id )
|
: id( _id )
|
||||||
, imagePath( image )
|
, imagePath( image )
|
||||||
|
, widget( nullptr )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
// Defined in PlasmaLnfPage.cpp
|
// Defined in PlasmaLnfPage.cpp
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent)
|
ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent)
|
||||||
: QWidget( parent )
|
: QWidget( parent )
|
||||||
, m_check( new QRadioButton( info.name.isEmpty() ? info.id : info.name, parent ) )
|
, m_check( new QRadioButton( info.name.isEmpty() ? info.id : info.name, parent ) )
|
||||||
|
, m_description( new QLabel( info.description, parent ) )
|
||||||
, m_id( info.id )
|
, m_id( info.id )
|
||||||
{
|
{
|
||||||
QHBoxLayout* layout = new QHBoxLayout( this );
|
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)
|
// Not found or not specified, so convert the name into some (horrible, likely)
|
||||||
// color instead.
|
// color instead.
|
||||||
image = QPixmap( image_size );
|
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;
|
cDebug() << "Theme image" << info.imagePath << "not found, hash" << hash_color;
|
||||||
image.fill( QColor( QRgb( 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 );
|
QLabel* image_label = new QLabel( this );
|
||||||
image_label->setPixmap( image );
|
image_label->setPixmap( image );
|
||||||
layout->addWidget( image_label, 1 );
|
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 );
|
connect( m_check, &QRadioButton::clicked, this, &ThemeWidget::clicked );
|
||||||
}
|
}
|
||||||
@ -71,3 +72,9 @@ ThemeWidget::button() const
|
|||||||
{
|
{
|
||||||
return m_check;
|
return m_check;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ThemeWidget::updateThemeName(const ThemeInfo& info)
|
||||||
|
{
|
||||||
|
m_check->setText( info.name );
|
||||||
|
m_description->setText( info.description );
|
||||||
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class QAbstractButton;
|
class QAbstractButton;
|
||||||
|
class QLabel;
|
||||||
class QRadioButton;
|
class QRadioButton;
|
||||||
|
|
||||||
struct ThemeInfo;
|
struct ThemeInfo;
|
||||||
@ -34,6 +35,8 @@ public:
|
|||||||
|
|
||||||
QAbstractButton* button() const;
|
QAbstractButton* button() const;
|
||||||
|
|
||||||
|
void updateThemeName( const ThemeInfo& info );
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void themeSelected( const QString& id );
|
void themeSelected( const QString& id );
|
||||||
|
|
||||||
@ -43,6 +46,7 @@ public slots:
|
|||||||
private:
|
private:
|
||||||
QString m_id;
|
QString m_id;
|
||||||
QRadioButton* m_check;
|
QRadioButton* m_check;
|
||||||
|
QLabel* m_description;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user