diff --git a/examples/iot-dashboard/MyDevices.cpp b/examples/iot-dashboard/MyDevices.cpp index 5cc78960..c76ac166 100644 --- a/examples/iot-dashboard/MyDevices.cpp +++ b/examples/iot-dashboard/MyDevices.cpp @@ -2,9 +2,13 @@ #include "DaytimeSkin.h" #include "RoundedIcon.h" +#include +#include #include #include +#include + namespace { class Device : public QskLinearBox { @@ -13,16 +17,38 @@ namespace { : QskLinearBox(Qt::Vertical, parent) , m_name(name) { - auto fileName = name.toLower(); - fileName.replace(' ', '-'); - auto* icon = new RoundedIcon(fileName, gradient, this); - icon->setOpacity(0.15); + setAutoAddChildren(false); + + m_icon = new RoundedIcon(QString(), gradient, this); + m_icon->setOpacity(0.15); + addItem(m_icon); + auto* textLabel = new QskTextLabel(name, this); 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: QString m_name; + RoundedIcon* m_icon; + QskGraphicLabel* m_graphicLabel; }; } diff --git a/examples/iot-dashboard/RoundedIcon.cpp b/examples/iot-dashboard/RoundedIcon.cpp index fafc0108..5e226a07 100644 --- a/examples/iot-dashboard/RoundedIcon.cpp +++ b/examples/iot-dashboard/RoundedIcon.cpp @@ -17,13 +17,20 @@ RoundedIcon::RoundedIcon(const QString& iconName, const QskGradient& gradient, Q setBoxShapeHint(Panel, 6 ); QString fileName = ":/images/" + iconName + ".png"; - QImage image( fileName ); - auto graphic = QskGraphic::fromImage( image ); - m_graphicLabel = new QskGraphicLabel( graphic, this ); + + if(QFile::exists(fileName)) + { + QImage image( fileName ); + auto graphic = QskGraphic::fromImage( image ); + m_graphicLabel = new QskGraphicLabel( graphic, this ); + } } void RoundedIcon::updateLayout() { - m_graphicLabel->setSize( {36, 36}); - m_graphicLabel->setPosition( { ( width() - m_graphicLabel->width() ) / 2, ( height() - m_graphicLabel->height() ) / 2 } ); + if(m_graphicLabel) + { + m_graphicLabel->setSize( {36, 36}); + m_graphicLabel->setPosition( { ( width() - m_graphicLabel->width() ) / 2, ( height() - m_graphicLabel->height() ) / 2 } ); + } } diff --git a/examples/iot-dashboard/RoundedIcon.h b/examples/iot-dashboard/RoundedIcon.h index 7e37eb0b..97b95aa1 100644 --- a/examples/iot-dashboard/RoundedIcon.h +++ b/examples/iot-dashboard/RoundedIcon.h @@ -19,7 +19,7 @@ protected: private: QString m_iconName; QskGradient m_gradient; - QskGraphicLabel* m_graphicLabel; + QskGraphicLabel* m_graphicLabel = nullptr; }; #endif // ROUNDEDICON_H