[plasmalnf] Demand-load image for a theme
This commit is contained in:
parent
58ea40c14d
commit
faa1cb6b65
@ -10,22 +10,30 @@ find_package(ECM ${ECM_VERSION} REQUIRED NO_MODULE)
|
||||
set( lnf_ver 5.41 )
|
||||
|
||||
find_package( KF5Config ${lnf_ver} )
|
||||
find_package( KF5Plasma ${lnf_ver} )
|
||||
find_package( KF5Package ${lnf_ver} )
|
||||
set_package_properties(
|
||||
KF5Config PROPERTIES
|
||||
PURPOSE "For finding default Plasma Look-and-Feel"
|
||||
)
|
||||
|
||||
find_package( KF5Plasma ${lnf_ver} )
|
||||
set_package_properties(
|
||||
KF5Plasma PROPERTIES
|
||||
PURPOSE "For Plasma Look-and-Feel selection"
|
||||
)
|
||||
|
||||
find_package( KF5Package ${lnf_ver} )
|
||||
set_package_properties(
|
||||
KF5Package PROPERTIES
|
||||
PURPOSE "For Plasma Look-and-Feel selection"
|
||||
)
|
||||
|
||||
if ( KF5Plasma_FOUND AND KF5Package_FOUND )
|
||||
find_package( KF5ItemModels ${lnf_ver} )
|
||||
set_package_properties(
|
||||
KF5ItemModels PROPERTIES
|
||||
PURPOSE "For Plasma Look-and-Feel display"
|
||||
)
|
||||
|
||||
if ( KF5Plasma_FOUND AND KF5Package_FOUND AND KF5ItemModels_FOUND )
|
||||
calamares_add_plugin( plasmalnf
|
||||
TYPE viewmodule
|
||||
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
||||
@ -43,6 +51,7 @@ if ( KF5Plasma_FOUND AND KF5Package_FOUND )
|
||||
page_plasmalnf.ui
|
||||
LINK_PRIVATE_LIBRARIES
|
||||
calamaresui
|
||||
KF5::ItemModels
|
||||
KF5::Package
|
||||
KF5::Plasma
|
||||
SHARED_LIB
|
||||
|
@ -17,10 +17,47 @@
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/Retranslator.h"
|
||||
|
||||
#include <KExtraColumnsProxyModel>
|
||||
|
||||
#include <QHeaderView>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QTableView>
|
||||
|
||||
class ThemeColumns : public KExtraColumnsProxyModel
|
||||
{
|
||||
public:
|
||||
ThemeColumns( QObject* parent );
|
||||
|
||||
QVariant extraColumnData( const QModelIndex& parent, int row, int extraColumn, int role ) const override;
|
||||
};
|
||||
|
||||
ThemeColumns::ThemeColumns( QObject* parent )
|
||||
: KExtraColumnsProxyModel( parent )
|
||||
{
|
||||
appendColumn();
|
||||
appendColumn();
|
||||
}
|
||||
|
||||
QVariant
|
||||
ThemeColumns::extraColumnData( const QModelIndex& parent, int row, int extraColumn, int role ) const
|
||||
{
|
||||
if ( role != Qt::DisplayRole )
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
switch ( extraColumn )
|
||||
{
|
||||
case 0:
|
||||
return sourceModel()->data( sourceModel()->index( row, 0 ), ThemesModel::DescriptionRole );
|
||||
case 1:
|
||||
return sourceModel()->data( sourceModel()->index( row, 0 ), ThemesModel::ImageRole );
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
|
||||
PlasmaLnfPage::PlasmaLnfPage( Config* config, QWidget* parent )
|
||||
: QWidget( parent )
|
||||
, ui( new Ui::PlasmaLnfPage )
|
||||
@ -43,9 +80,11 @@ PlasmaLnfPage::PlasmaLnfPage( Config* config, QWidget* parent )
|
||||
connect( this, &PlasmaLnfPage::plasmaThemeSelected, config, &Config::setTheme );
|
||||
|
||||
QTableView* view = new QTableView( this );
|
||||
ThemeColumns* model = new ThemeColumns( this );
|
||||
model->setSourceModel( m_config->themeModel() );
|
||||
view->setModel( model );
|
||||
view->verticalHeader()->hide();
|
||||
view->horizontalHeader()->hide();
|
||||
view->setModel( m_config->themeModel() );
|
||||
ui->verticalLayout->addWidget( view );
|
||||
|
||||
connect( view->selectionModel(),
|
||||
@ -54,8 +93,9 @@ PlasmaLnfPage::PlasmaLnfPage( Config* config, QWidget* parent )
|
||||
auto i = selected.indexes();
|
||||
if ( !i.isEmpty() )
|
||||
{
|
||||
auto row = i.first().row();
|
||||
auto* model = m_config->themeModel();
|
||||
auto id = model->data( i.first(), ThemesModel::KeyRole ).toString();
|
||||
auto id = model->data( model->index( row, 0 ), ThemesModel::KeyRole ).toString();
|
||||
cDebug() << "View selected" << selected << id;
|
||||
if ( !id.isEmpty() )
|
||||
{
|
||||
|
@ -8,9 +8,17 @@
|
||||
*/
|
||||
#include "ThemeInfo.h"
|
||||
|
||||
#include "Branding.h"
|
||||
#include "utils/CalamaresUtilsGui.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
#include <KPackage/Package>
|
||||
#include <KPackage/PackageLoader>
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QPixmap>
|
||||
|
||||
/** @brief describes a single plasma LnF theme.
|
||||
*
|
||||
* A theme description has an id, which is really the name of the desktop
|
||||
@ -24,6 +32,7 @@ struct ThemeInfo
|
||||
QString name;
|
||||
QString description;
|
||||
QString imagePath;
|
||||
mutable QPixmap pixmap;
|
||||
bool show = true;
|
||||
|
||||
ThemeInfo() {}
|
||||
@ -42,6 +51,9 @@ struct ThemeInfo
|
||||
explicit ThemeInfo( const KPluginMetaData& );
|
||||
|
||||
bool isValid() const { return !id.isEmpty(); }
|
||||
|
||||
/// @brief Fill in the pixmap member based on imagePath
|
||||
QPixmap loadImage() const;
|
||||
};
|
||||
|
||||
class ThemeInfoList : public QList< ThemeInfo >
|
||||
@ -128,6 +140,8 @@ ThemesModel::data( const QModelIndex& index, int role ) const
|
||||
return item.show;
|
||||
case DescriptionRole:
|
||||
return item.description;
|
||||
case ImageRole:
|
||||
return item.loadImage();
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
@ -198,6 +212,39 @@ ThemesModel::showOnlyThemes( const QMap< QString, QString >& onlyThese )
|
||||
emit dataChanged( index( 0, 0 ), index( m_themes->count() - 1 ), { ShownRole } );
|
||||
}
|
||||
|
||||
/**
|
||||
* Massage the given @p path to the most-likely
|
||||
* path that actually contains a screenshot. For
|
||||
* empty image paths, returns the QRC path for an
|
||||
* empty screenshot. Returns blank if the path
|
||||
* doesn't exist anywhere in the search paths.
|
||||
*/
|
||||
static QString
|
||||
munge_imagepath( const QString& path )
|
||||
{
|
||||
if ( path.isEmpty() )
|
||||
{
|
||||
return ":/view-preview.png";
|
||||
}
|
||||
|
||||
if ( path.startsWith( '/' ) )
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
if ( QFileInfo::exists( path ) )
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
QFileInfo fi( QDir( Calamares::Branding::instance()->componentDirectory() ), path );
|
||||
if ( fi.exists() )
|
||||
{
|
||||
return fi.absoluteFilePath();
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
ThemeInfo::ThemeInfo( const KPluginMetaData& data )
|
||||
: id( data.pluginId() )
|
||||
@ -205,3 +252,34 @@ ThemeInfo::ThemeInfo( const KPluginMetaData& data )
|
||||
, description( data.description() )
|
||||
{
|
||||
}
|
||||
|
||||
QPixmap
|
||||
ThemeInfo::loadImage() const
|
||||
{
|
||||
if ( pixmap.isNull() )
|
||||
{
|
||||
|
||||
const QSize image_size { qMax( 12 * CalamaresUtils::defaultFontHeight(), 120 ),
|
||||
qMax( 8 * CalamaresUtils::defaultFontHeight(), 80 ) };
|
||||
|
||||
const QString path = munge_imagepath( imagePath );
|
||||
cDebug() << "Loading initial image for" << id << imagePath << "->" << path;
|
||||
QPixmap image( path );
|
||||
if ( image.isNull() )
|
||||
{
|
||||
// Not found or not specified, so convert the name into some (horrible, likely)
|
||||
// color instead.
|
||||
image = QPixmap( image_size );
|
||||
auto hash_color = qHash( imagePath.isEmpty() ? id : imagePath );
|
||||
cDebug() << Logger::SubEntry << "Theme image" << imagePath << "not found, hash" << hash_color;
|
||||
image.fill( QColor( QRgb( hash_color ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
cDebug() << Logger::SubEntry << "Theme image" << image.size();
|
||||
}
|
||||
|
||||
pixmap = image.scaled( image_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
|
||||
}
|
||||
return pixmap;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user