From 0a88273e0d5899ad215f459b2ab60528919f8118 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 17 Nov 2020 11:38:33 +0100 Subject: [PATCH] [plasmalnf] Replace combobox with a view --- src/modules/plasmalnf/PlasmaLnfPage.cpp | 36 ++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index cf1330912..20c2a5569 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -17,8 +17,7 @@ #include "utils/Logger.h" #include "utils/Retranslator.h" -#include - +#include #include #include @@ -44,17 +43,24 @@ PlasmaLnfPage::PlasmaLnfPage( Config* config, QWidget* parent ) } ) connect( this, &PlasmaLnfPage::plasmaThemeSelected, config, &Config::setTheme ); - QComboBox* box = new QComboBox(); - box->setModel( m_config->themeModel() ); - ui->verticalLayout->addWidget( box ); - - connect( box, QOverload< int >::of( &QComboBox::currentIndexChanged ), [this]( int index ) { - auto* model = m_config->themeModel(); - auto id = model->data( model->index( index, 0 ), ThemesModel::KeyRole ).toString(); - cDebug() << "ComboBox selected" << index << id; - if ( !id.isEmpty() ) - { - emit plasmaThemeSelected( id ); - } - } ); + QListView* view = new QListView( this ); + view->setUniformItemSizes( true ); + view->setModel( m_config->themeModel() ); + ui->verticalLayout->addWidget( view ); + + connect( view->selectionModel(), + &QItemSelectionModel::selectionChanged, + [this]( const QItemSelection& selected, const QItemSelection& ) { + auto i = selected.indexes(); + if ( !i.isEmpty() ) + { + auto* model = m_config->themeModel(); + auto id = model->data( i.first(), ThemesModel::KeyRole ).toString(); + cDebug() << "View selected" << selected << id; + if ( !id.isEmpty() ) + { + emit plasmaThemeSelected( id ); + } + } + } ); }