From 8b3f71af40b784ee903e9118cc73437a47303d88 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 13 Dec 2017 10:28:31 -0500 Subject: [PATCH] [plasmalnf] Widget for showing theme info - Radio button + group for button action - Use a (still very primitive) widget for displaying theme information --- src/modules/plasmalnf/CMakeLists.txt | 1 + src/modules/plasmalnf/PlasmaLnfPage.cpp | 36 ++++++++--------- src/modules/plasmalnf/PlasmaLnfPage.h | 8 ++-- src/modules/plasmalnf/ThemeWidget.cpp | 52 +++++++++++++++++++++++++ src/modules/plasmalnf/ThemeWidget.h | 48 +++++++++++++++++++++++ src/modules/plasmalnf/page_plasmalnf.ui | 5 +-- 6 files changed, 125 insertions(+), 25 deletions(-) create mode 100644 src/modules/plasmalnf/ThemeWidget.cpp create mode 100644 src/modules/plasmalnf/ThemeWidget.h diff --git a/src/modules/plasmalnf/CMakeLists.txt b/src/modules/plasmalnf/CMakeLists.txt index 61b44862f..f752755a5 100644 --- a/src/modules/plasmalnf/CMakeLists.txt +++ b/src/modules/plasmalnf/CMakeLists.txt @@ -9,6 +9,7 @@ calamares_add_plugin( plasmalnf PlasmaLnfViewStep.cpp PlasmaLnfPage.cpp PlasmaLnfJob.cpp + ThemeWidget.cpp UI page_plasmalnf.ui LINK_PRIVATE_LIBRARIES diff --git a/src/modules/plasmalnf/PlasmaLnfPage.cpp b/src/modules/plasmalnf/PlasmaLnfPage.cpp index 60ba79d68..e93002855 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.cpp +++ b/src/modules/plasmalnf/PlasmaLnfPage.cpp @@ -19,6 +19,7 @@ #include "PlasmaLnfPage.h" #include "ui_page_plasmalnf.h" +#include "ThemeWidget.h" #include "utils/Logger.h" #include "utils/Retranslator.h" @@ -47,6 +48,7 @@ static ThemeInfoList plasma_themes() PlasmaLnfPage::PlasmaLnfPage( QWidget* parent ) : QWidget( parent ) , ui( new Ui::PlasmaLnfPage ) + , m_buttonGroup( nullptr ) { ui->setupUi( this ); CALAMARES_RETRANSLATE( @@ -57,22 +59,6 @@ PlasmaLnfPage::PlasmaLnfPage( QWidget* parent ) fillUi(); } ) - - QObject::connect( ui->lnfCombo, &QComboBox::activated, this, &PlasmaLnfPage::activated ); -} - -void -PlasmaLnfPage::activated( int index ) -{ - if ( ( index < 0 ) || ( index > m_enabledThemes.length() ) ) - { - cDebug() << "Plasma LNF index" << index << "out of range."; - return; - } - - const ThemeInfo& lnf = m_enabledThemes.at( index ); - cDebug() << "Changed to" << index << lnf.id << lnf.name; - emit plasmaThemeSelected( lnf.id ); } void @@ -138,9 +124,23 @@ void PlasmaLnfPage::winnowThemes() void PlasmaLnfPage::fillUi() { - ui->lnfCombo->clear(); + if ( m_enabledThemes.isEmpty() ) + { + return; + } + + if ( m_buttonGroup ) + delete m_buttonGroup; + m_buttonGroup = new QButtonGroup( this ); + m_buttonGroup->setExclusive( true ); + + int c = 1; // After the general explanation for ( auto& theme : m_enabledThemes ) { - ui->lnfCombo->addItem( theme.name ); + ThemeWidget* w = new ThemeWidget( theme ); + m_buttonGroup->addButton( w->button() ); + ui->verticalLayout->insertWidget( c, w ); + connect( w, &ThemeWidget::themeSelected, this, &PlasmaLnfPage::plasmaThemeSelected); + ++c; } } diff --git a/src/modules/plasmalnf/PlasmaLnfPage.h b/src/modules/plasmalnf/PlasmaLnfPage.h index 6e9f36242..59fffc93a 100644 --- a/src/modules/plasmalnf/PlasmaLnfPage.h +++ b/src/modules/plasmalnf/PlasmaLnfPage.h @@ -19,12 +19,14 @@ #ifndef PLASMALNFPAGE_H #define PLASMALNFPAGE_H +#include #include #include #include #include #include "ThemeInfo.h" +#include "ThemeWidget.h" namespace Ui { @@ -40,9 +42,6 @@ public: void setLnfPath( const QString& path ); void setEnabledThemes( const ThemeInfoList& themes ); -public slots: - void activated( int index ); - signals: void plasmaThemeSelected( const QString& id ); @@ -57,6 +56,9 @@ private: Ui::PlasmaLnfPage* ui; QString m_lnfPath; ThemeInfoList m_enabledThemes; + + QButtonGroup *m_buttonGroup; + QList< ThemeWidget* > m_widgets; }; #endif //PLASMALNFPAGE_H diff --git a/src/modules/plasmalnf/ThemeWidget.cpp b/src/modules/plasmalnf/ThemeWidget.cpp new file mode 100644 index 000000000..2261c2c4f --- /dev/null +++ b/src/modules/plasmalnf/ThemeWidget.cpp @@ -0,0 +1,52 @@ +/* === This file is part of Calamares - === + * + * Copyright 2017, Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#include "ThemeWidget.h" + +#include "ThemeInfo.h" + +#include +#include +#include + +ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent) + : QWidget( parent ) + , m_check( new QRadioButton( info.name.isEmpty() ? info.id : info.name, parent ) ) + , m_id( info.id ) +{ + QHBoxLayout* layout = new QHBoxLayout( this ); + this->setLayout( layout ); + + layout->addWidget( m_check ); + layout->addWidget( new QLabel( "Image", this ) ); + + connect( m_check, &QRadioButton::clicked, this, &ThemeWidget::clicked ); +} + +void +ThemeWidget::clicked( bool checked ) +{ + if ( checked ) + emit themeSelected( m_id ); +} + +QAbstractButton* +ThemeWidget::button() const +{ + return m_check; +} diff --git a/src/modules/plasmalnf/ThemeWidget.h b/src/modules/plasmalnf/ThemeWidget.h new file mode 100644 index 000000000..837d362f4 --- /dev/null +++ b/src/modules/plasmalnf/ThemeWidget.h @@ -0,0 +1,48 @@ +/* === This file is part of Calamares - === + * + * Copyright 2017, Adriaan de Groot + * + * Calamares is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Calamares is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Calamares. If not, see . + */ + +#ifndef PLASMALNF_THEMEWIDGET_H +#define PLASMALNF_THEMEWIDGET_H + +#include + +class QAbstractButton; +class QRadioButton; +class ThemeInfo; + +class ThemeWidget : public QWidget +{ + Q_OBJECT +public: + explicit ThemeWidget( const ThemeInfo& info, QWidget* parent = nullptr ); + + QAbstractButton* button() const; + +signals: + void themeSelected( const QString& id ); + +public slots: + void clicked( bool ); + +private: + QString m_id; + QRadioButton* m_check; +} ; + +#endif + diff --git a/src/modules/plasmalnf/page_plasmalnf.ui b/src/modules/plasmalnf/page_plasmalnf.ui index 340527ad0..dfb906c22 100644 --- a/src/modules/plasmalnf/page_plasmalnf.ui +++ b/src/modules/plasmalnf/page_plasmalnf.ui @@ -13,7 +13,7 @@ Form - + @@ -28,9 +28,6 @@ margin-left: 2em; - - -