fix opacity issue with devices

This commit is contained in:
Peter Hartmann 2020-08-26 14:45:57 +02:00
parent 984c68ef45
commit 02d6315287
3 changed files with 43 additions and 10 deletions

View File

@ -2,9 +2,13 @@
#include "DaytimeSkin.h" #include "DaytimeSkin.h"
#include "RoundedIcon.h" #include "RoundedIcon.h"
#include <QskGraphic.h>
#include <QskGraphicLabel.h>
#include <QskGridBox.h> #include <QskGridBox.h>
#include <QskTextLabel.h> #include <QskTextLabel.h>
#include <QImage>
namespace { namespace {
class Device : public QskLinearBox class Device : public QskLinearBox
{ {
@ -13,16 +17,38 @@ namespace {
: QskLinearBox(Qt::Vertical, parent) : QskLinearBox(Qt::Vertical, parent)
, m_name(name) , m_name(name)
{ {
auto fileName = name.toLower(); setAutoAddChildren(false);
fileName.replace(' ', '-');
auto* icon = new RoundedIcon(fileName, gradient, this); m_icon = new RoundedIcon(QString(), gradient, this);
icon->setOpacity(0.15); m_icon->setOpacity(0.15);
addItem(m_icon);
auto* textLabel = new QskTextLabel(name, this); auto* textLabel = new QskTextLabel(name, this);
textLabel->setAlignment(Qt::AlignHCenter); textLabel->setAlignment(Qt::AlignHCenter);
addItem(textLabel);
auto fileName = name.toLower();
fileName.replace(' ', '-');
fileName = ":/images/" + fileName + ".png";
QImage image( fileName );
auto graphic = QskGraphic::fromImage( image );
m_graphicLabel = new QskGraphicLabel( graphic, this );
}
protected:
void updateLayout() override
{
QskLinearBox::updateLayout();
m_graphicLabel->setSize( {36, 36});
m_graphicLabel->setPosition( { ( m_icon->width() - m_graphicLabel->width() ) / 2,
( m_icon->height() - m_graphicLabel->height() ) / 2 } );
} }
private: private:
QString m_name; QString m_name;
RoundedIcon* m_icon;
QskGraphicLabel* m_graphicLabel;
}; };
} }

View File

@ -17,13 +17,20 @@ RoundedIcon::RoundedIcon(const QString& iconName, const QskGradient& gradient, Q
setBoxShapeHint(Panel, 6 ); setBoxShapeHint(Panel, 6 );
QString fileName = ":/images/" + iconName + ".png"; QString fileName = ":/images/" + iconName + ".png";
QImage image( fileName );
auto graphic = QskGraphic::fromImage( image ); if(QFile::exists(fileName))
m_graphicLabel = new QskGraphicLabel( graphic, this ); {
QImage image( fileName );
auto graphic = QskGraphic::fromImage( image );
m_graphicLabel = new QskGraphicLabel( graphic, this );
}
} }
void RoundedIcon::updateLayout() void RoundedIcon::updateLayout()
{ {
m_graphicLabel->setSize( {36, 36}); if(m_graphicLabel)
m_graphicLabel->setPosition( { ( width() - m_graphicLabel->width() ) / 2, ( height() - m_graphicLabel->height() ) / 2 } ); {
m_graphicLabel->setSize( {36, 36});
m_graphicLabel->setPosition( { ( width() - m_graphicLabel->width() ) / 2, ( height() - m_graphicLabel->height() ) / 2 } );
}
} }

View File

@ -19,7 +19,7 @@ protected:
private: private:
QString m_iconName; QString m_iconName;
QskGradient m_gradient; QskGradient m_gradient;
QskGraphicLabel* m_graphicLabel; QskGraphicLabel* m_graphicLabel = nullptr;
}; };
#endif // ROUNDEDICON_H #endif // ROUNDEDICON_H