[plasmalnf] Fallback for image-not-found

- calculate a hash of the filename, and use that
 - makes it possible to distinguish different screenshots
   even when the image file is missing / badly configured
 - most colors will be dreadful
main
Adriaan de Groot 7 years ago
parent 2db485bb33
commit 3f258d4bd9

@ -20,6 +20,8 @@
#include "ThemeInfo.h"
#include "utils/Logger.h"
#include <QHBoxLayout>
#include <QLabel>
#include <QRadioButton>
@ -33,7 +35,25 @@ ThemeWidget::ThemeWidget(const ThemeInfo& info, QWidget* parent)
this->setLayout( layout );
layout->addWidget( m_check, 1 );
layout->addWidget( new QLabel( "Image", this ), 1 );
constexpr QSize image_size{240, 160};
QPixmap image( info.imagePath );
if ( image.isNull() )
{
// Not found or not specified, so convert the name into some (horrible, likely)
// color instead.
image = QPixmap( image_size );
uint hash_color = qHash( info.imagePath );
cDebug() << "Theme image" << info.imagePath << "not found, hash" << hash_color;
image.fill( QColor( QRgb( hash_color ) ) );
}
else
image.scaled( image_size );
QLabel* image_label = new QLabel( this );
image_label->setPixmap( image );
layout->addWidget( image_label, 1 );
layout->addWidget( new QLabel( info.description, this ), 3 );
connect( m_check, &QRadioButton::clicked, this, &ThemeWidget::clicked );

Loading…
Cancel
Save