[libcalamaresui] Add branding-aware function for loading image by name
This commit is contained in:
parent
1438729b72
commit
75ce391e7e
@ -186,6 +186,7 @@ Branding::Branding( const QString& brandingFilePath,
|
|||||||
loadStrings( m_images, doc, "images",
|
loadStrings( m_images, doc, "images",
|
||||||
[&]( const QString& s ) -> QString
|
[&]( const QString& s ) -> QString
|
||||||
{
|
{
|
||||||
|
// See also image()
|
||||||
const QString imageName( expand( s ) );
|
const QString imageName( expand( s ) );
|
||||||
QFileInfo imageFi( componentDir.absoluteFilePath( imageName ) );
|
QFileInfo imageFi( componentDir.absoluteFilePath( imageName ) );
|
||||||
if ( !imageFi.exists() )
|
if ( !imageFi.exists() )
|
||||||
@ -314,6 +315,22 @@ Branding::image( Branding::ImageEntry imageEntry, const QSize& size ) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPixmap
|
||||||
|
Branding::image(const QString& imageName, const QSize& size) const
|
||||||
|
{
|
||||||
|
QDir componentDir( componentDirectory() );
|
||||||
|
QFileInfo imageFi( componentDir.absoluteFilePath( imageName ) );
|
||||||
|
if ( !imageFi.exists() )
|
||||||
|
{
|
||||||
|
const auto icon = QIcon::fromTheme( imageName );
|
||||||
|
// Not found, bail out with the filename used
|
||||||
|
if ( icon.isNull() )
|
||||||
|
return QPixmap();
|
||||||
|
return icon.pixmap( size );
|
||||||
|
}
|
||||||
|
return ImageRegistry::instance()->pixmap( imageFi.absoluteFilePath(), size );
|
||||||
|
}
|
||||||
|
|
||||||
QString
|
QString
|
||||||
Branding::stylesheet() const
|
Branding::stylesheet() const
|
||||||
{
|
{
|
||||||
|
@ -123,6 +123,16 @@ public:
|
|||||||
QString styleString( Branding::StyleEntry styleEntry ) const;
|
QString styleString( Branding::StyleEntry styleEntry ) const;
|
||||||
QString imagePath( Branding::ImageEntry imageEntry ) const;
|
QString imagePath( Branding::ImageEntry imageEntry ) const;
|
||||||
QPixmap image( Branding::ImageEntry imageEntry, const QSize& size ) const;
|
QPixmap image( Branding::ImageEntry imageEntry, const QSize& size ) const;
|
||||||
|
|
||||||
|
/** @brief Look up an image in the branding directory or as an icon
|
||||||
|
*
|
||||||
|
* The @p name is checked in the branding directory: if it is an image
|
||||||
|
* file, return the pixmap from that file, at the requested size.
|
||||||
|
* If it isn't a file, look it up as an icon name in the current theme.
|
||||||
|
* May return a null pixmap if nothing is found.
|
||||||
|
*/
|
||||||
|
QPixmap image( const QString& name, 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