2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2017-12-03 18:47:41 +01:00
|
|
|
*
|
2020-08-22 01:19:58 +02:00
|
|
|
* SPDX-FileCopyrightText: 2017-2018 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2019 Collabora Ltd <arnaud.ferraris@collabora.com>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2017-12-03 18:47:41 +01:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2017-12-03 18:47:41 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PlasmaLnfPage.h"
|
|
|
|
|
2020-11-16 23:36:32 +01:00
|
|
|
#include "Config.h"
|
2017-12-03 18:47:41 +01:00
|
|
|
#include "ui_page_plasmalnf.h"
|
|
|
|
|
2020-08-22 01:19:58 +02:00
|
|
|
#include "Settings.h"
|
2017-12-03 18:47:41 +01:00
|
|
|
#include "utils/Logger.h"
|
|
|
|
#include "utils/Retranslator.h"
|
|
|
|
|
2020-11-17 12:41:50 +01:00
|
|
|
#include <QHeaderView>
|
2020-11-30 11:19:00 +01:00
|
|
|
#include <QListView>
|
2020-11-17 12:41:50 +01:00
|
|
|
#include <QStyledItemDelegate>
|
2020-11-30 11:19:00 +01:00
|
|
|
|
|
|
|
class ThemeDelegate : public QStyledItemDelegate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using QStyledItemDelegate::QStyledItemDelegate;
|
|
|
|
|
|
|
|
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const override;
|
|
|
|
// The size of the item is constant
|
|
|
|
QSize sizeHint( const QStyleOptionViewItem&, const QModelIndex& ) const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
QSize
|
|
|
|
ThemeDelegate::sizeHint( const QStyleOptionViewItem&, const QModelIndex& ) const
|
|
|
|
{
|
|
|
|
QSize image( ThemesModel::imageSize() );
|
|
|
|
return { 3 * image.width(), image.height() };
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThemeDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
|
|
|
{
|
|
|
|
auto label = index.data( ThemesModel::LabelRole ).toString();
|
|
|
|
auto description = index.data( ThemesModel::DescriptionRole ).toString();
|
|
|
|
auto image_v = index.data( ThemesModel::ImageRole );
|
|
|
|
QPixmap image = image_v.canConvert< QPixmap >() ? qvariant_cast< QPixmap >( image_v ) : QPixmap();
|
|
|
|
|
|
|
|
// The delegate paints three "columns", each of which takes 1/3
|
|
|
|
// of the space: label, description and screenshot.
|
|
|
|
QRect labelRect( option.rect );
|
|
|
|
labelRect.setWidth( labelRect.width() / 3 );
|
|
|
|
|
|
|
|
QStyleOptionButton rbOption;
|
|
|
|
rbOption.state |= QStyle::State_Enabled | QStyle::State_On;
|
|
|
|
rbOption.rect = labelRect;
|
|
|
|
rbOption.text = label;
|
|
|
|
option.widget->style()->drawControl( QStyle::CE_RadioButton, &rbOption, painter, option.widget );
|
|
|
|
|
|
|
|
labelRect.moveLeft( labelRect.width() );
|
|
|
|
option.widget->style()->drawItemText(
|
|
|
|
painter, labelRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextWordWrap, option.palette, false, description );
|
|
|
|
|
|
|
|
labelRect.moveLeft( 2 * labelRect.width() );
|
|
|
|
option.widget->style()->drawItemPixmap( painter, labelRect, Qt::AlignHCenter | Qt::AlignVCenter, image );
|
|
|
|
}
|
2017-12-03 21:34:06 +01:00
|
|
|
|
2020-11-17 14:32:50 +01:00
|
|
|
|
2020-11-16 23:36:32 +01:00
|
|
|
PlasmaLnfPage::PlasmaLnfPage( Config* config, QWidget* parent )
|
2017-12-03 18:47:41 +01:00
|
|
|
: QWidget( parent )
|
|
|
|
, ui( new Ui::PlasmaLnfPage )
|
2020-11-16 23:36:32 +01:00
|
|
|
, m_config( config )
|
2017-12-03 18:47:41 +01:00
|
|
|
{
|
|
|
|
ui->setupUi( this );
|
2020-08-22 01:19:58 +02:00
|
|
|
CALAMARES_RETRANSLATE( {
|
2017-12-03 18:47:41 +01:00
|
|
|
ui->retranslateUi( this );
|
2019-04-08 13:44:41 +02:00
|
|
|
if ( Calamares::Settings::instance()->isSetupMode() )
|
2020-08-22 01:19:58 +02:00
|
|
|
ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop. "
|
|
|
|
"You can also skip this step and configure the look-and-feel "
|
|
|
|
"once the system is set up. Clicking on a look-and-feel "
|
|
|
|
"selection will give you a live preview of that look-and-feel." ) );
|
2019-04-08 13:44:41 +02:00
|
|
|
else
|
2020-08-22 01:19:58 +02:00
|
|
|
ui->generalExplanation->setText( tr( "Please choose a look-and-feel for the KDE Plasma Desktop. "
|
|
|
|
"You can also skip this step and configure the look-and-feel "
|
|
|
|
"once the system is installed. Clicking on a look-and-feel "
|
|
|
|
"selection will give you a live preview of that look-and-feel." ) );
|
|
|
|
} )
|
2020-11-17 00:02:59 +01:00
|
|
|
|
2020-11-30 11:19:00 +01:00
|
|
|
auto* view = new QListView( this );
|
2020-11-28 16:53:35 +01:00
|
|
|
view->setModel( m_config->themeModel() );
|
2020-11-30 11:19:00 +01:00
|
|
|
view->setItemDelegate( new ThemeDelegate( view ) );
|
|
|
|
view->setUniformItemSizes( true );
|
2020-11-30 11:31:44 +01:00
|
|
|
view->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
|
2020-11-17 11:38:33 +01:00
|
|
|
ui->verticalLayout->addWidget( view );
|
|
|
|
|
|
|
|
connect( view->selectionModel(),
|
|
|
|
&QItemSelectionModel::selectionChanged,
|
|
|
|
[this]( const QItemSelection& selected, const QItemSelection& ) {
|
|
|
|
auto i = selected.indexes();
|
|
|
|
if ( !i.isEmpty() )
|
|
|
|
{
|
2020-11-17 14:32:50 +01:00
|
|
|
auto row = i.first().row();
|
2020-11-17 11:38:33 +01:00
|
|
|
auto* model = m_config->themeModel();
|
2020-11-17 14:32:50 +01:00
|
|
|
auto id = model->data( model->index( row, 0 ), ThemesModel::KeyRole ).toString();
|
2020-11-17 11:38:33 +01:00
|
|
|
if ( !id.isEmpty() )
|
|
|
|
{
|
2020-11-28 16:53:35 +01:00
|
|
|
m_config->setTheme( id );
|
2020-11-17 11:38:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
2017-12-12 17:40:10 +01:00
|
|
|
}
|