[libcalamaresui] Convenience for 'give-me-one-of-these-icons'
This commit is contained in:
parent
1a6fb1c3d2
commit
87c8c3e6ee
@ -235,31 +235,35 @@ Branding::Branding( const QString& brandingFilePath, QObject* parent )
|
|||||||
{ QStringLiteral( "VARIANT" ), relInfo.variant() },
|
{ QStringLiteral( "VARIANT" ), relInfo.variant() },
|
||||||
{ QStringLiteral( "VARIANT_ID" ), relInfo.variantId() },
|
{ QStringLiteral( "VARIANT_ID" ), relInfo.variantId() },
|
||||||
{ QStringLiteral( "LOGO" ), relInfo.logo() } } };
|
{ QStringLiteral( "LOGO" ), relInfo.logo() } } };
|
||||||
auto expand = [&]( const QString& s ) -> QString {
|
auto expand = [ & ]( const QString& s ) -> QString
|
||||||
return KMacroExpander::expandMacros( s, relMap, QLatin1Char( '@' ) );
|
{ return KMacroExpander::expandMacros( s, relMap, QLatin1Char( '@' ) ); };
|
||||||
};
|
|
||||||
#else
|
#else
|
||||||
auto expand = []( const QString& s ) -> QString { return s; };
|
auto expand = []( const QString& s ) -> QString { return s; };
|
||||||
#endif
|
#endif
|
||||||
// Massage the strings, images and style sections.
|
// Massage the strings, images and style sections.
|
||||||
loadStrings( m_strings, doc, "strings", expand );
|
loadStrings( m_strings, doc, "strings", expand );
|
||||||
loadStrings( m_images, doc, "images", [&]( const QString& s ) -> QString {
|
loadStrings( m_images,
|
||||||
// See also image()
|
doc,
|
||||||
const QString imageName( expand( s ) );
|
"images",
|
||||||
QFileInfo imageFi( componentDir.absoluteFilePath( imageName ) );
|
[ & ]( const QString& s ) -> QString
|
||||||
if ( !imageFi.exists() )
|
{
|
||||||
{
|
// See also image()
|
||||||
const auto icon = QIcon::fromTheme( imageName );
|
const QString imageName( expand( s ) );
|
||||||
// Not found, bail out with the filename used
|
QFileInfo imageFi( componentDir.absoluteFilePath( imageName ) );
|
||||||
if ( icon.isNull() )
|
if ( !imageFi.exists() )
|
||||||
{
|
{
|
||||||
bail( m_descriptorPath,
|
const auto icon = QIcon::fromTheme( imageName );
|
||||||
QString( "Image file %1 does not exist." ).arg( imageFi.absoluteFilePath() ) );
|
// Not found, bail out with the filename used
|
||||||
}
|
if ( icon.isNull() )
|
||||||
return imageName; // Not turned into a path
|
{
|
||||||
}
|
bail(
|
||||||
return imageFi.absoluteFilePath();
|
m_descriptorPath,
|
||||||
} );
|
QString( "Image file %1 does not exist." ).arg( imageFi.absoluteFilePath() ) );
|
||||||
|
}
|
||||||
|
return imageName; // Not turned into a path
|
||||||
|
}
|
||||||
|
return imageFi.absoluteFilePath();
|
||||||
|
} );
|
||||||
loadStrings( m_style, doc, "style", []( const QString& s ) -> QString { return s; } );
|
loadStrings( m_style, doc, "style", []( const QString& s ) -> QString { return s; } );
|
||||||
|
|
||||||
m_uploadServer = uploadServerFromMap( CalamaresUtils::yamlMapToVariant( doc[ "uploadServer" ] ) );
|
m_uploadServer = uploadServerFromMap( CalamaresUtils::yamlMapToVariant( doc[ "uploadServer" ] ) );
|
||||||
@ -348,19 +352,38 @@ Branding::image( const QString& imageName, const QSize& size ) const
|
|||||||
{
|
{
|
||||||
QDir componentDir( componentDirectory() );
|
QDir componentDir( componentDirectory() );
|
||||||
QFileInfo imageFi( componentDir.absoluteFilePath( imageName ) );
|
QFileInfo imageFi( componentDir.absoluteFilePath( imageName ) );
|
||||||
if ( !imageFi.exists() )
|
if ( imageFi.exists() )
|
||||||
|
{
|
||||||
|
return ImageRegistry::instance()->pixmap( imageFi.absoluteFilePath(), size );
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
const auto icon = QIcon::fromTheme( imageName );
|
const auto icon = QIcon::fromTheme( imageName );
|
||||||
// Not found, bail out with the filename used
|
// Not found, bail out with the filename used
|
||||||
if ( icon.isNull() )
|
if ( !icon.isNull() )
|
||||||
{
|
{
|
||||||
return QPixmap();
|
return icon.pixmap( size );
|
||||||
}
|
}
|
||||||
return icon.pixmap( size );
|
|
||||||
}
|
}
|
||||||
return ImageRegistry::instance()->pixmap( imageFi.absoluteFilePath(), size );
|
return QPixmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPixmap
|
||||||
|
Branding::image( const QStringList& list, const QSize& size ) const
|
||||||
|
{
|
||||||
|
QDir componentDir( componentDirectory() );
|
||||||
|
for ( const QString& imageName : list )
|
||||||
|
{
|
||||||
|
auto p = image( imageName, size );
|
||||||
|
if ( !p.isNull() )
|
||||||
|
{
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QPixmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static QString
|
static QString
|
||||||
_stylesheet( const QDir& dir )
|
_stylesheet( const QDir& dir )
|
||||||
{
|
{
|
||||||
|
@ -198,6 +198,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
QPixmap image( const QString& name, const QSize& size ) const;
|
QPixmap image( const QString& name, const QSize& size ) const;
|
||||||
|
|
||||||
|
/** @brief Look up image with alternate names
|
||||||
|
*
|
||||||
|
* Calls image() for each name in the @p list and returns the first
|
||||||
|
* one that is non-null. May return a null pixmap if nothing is found.
|
||||||
|
*/
|
||||||
|
QPixmap image( const QStringList& list, const QSize& size ) const;
|
||||||
|
|
||||||
/** @brief Stylesheet to apply for this branding. May be empty.
|
/** @brief Stylesheet to apply for this branding. May be empty.
|
||||||
*
|
*
|
||||||
* The file is loaded every time this function is called, so
|
* The file is loaded every time this function is called, so
|
||||||
|
Loading…
Reference in New Issue
Block a user