Add support for qrc icons to StyleItem

BUG: 427449

diff --git plugin/kquickstyleitem.cpp plugin/kquickstyleitem.cpp
index b1cf5b1..f280661 100644
--- plugin/kquickstyleitem.cpp
+++ plugin/kquickstyleitem.cpp
@@ -179,14 +179,8 @@ void KQuickStyleItem::initStyleOption()
         QStyleOptionButton *opt = qstyleoption_cast<QStyleOptionButton*>(m_styleoption);
         opt->text = text();
 
-        const QVariant icon = m_properties[QStringLiteral("icon")];
-        if (icon.canConvert<QIcon>()) {
-            opt->icon = icon.value<QIcon>();
-        } else if (icon.canConvert<QUrl>() && icon.value<QUrl>().isLocalFile()) {
-            opt->icon = QIcon(icon.value<QUrl>().toLocalFile());
-        } else if (icon.canConvert<QString>()) {
-            opt->icon = m_theme->iconFromTheme(icon.value<QString>(), m_properties[QStringLiteral("iconColor")].value<QColor>());
-        }
+        opt->icon = iconFromIconProperty();
+
         auto iconSize = QSize(m_properties[QStringLiteral("iconWidth")].toInt(), m_properties[QStringLiteral("iconHeight")].toInt());
         if (iconSize.isEmpty()) {
             int e = KQuickStyleItem::style()->pixelMetric(QStyle::PM_ButtonIconSize, m_styleoption, nullptr);
@@ -303,12 +297,9 @@ void KQuickStyleItem::initStyleOption()
 
         opt->activeSubControls = QStyle::SC_ToolButton;
         opt->text = text();
-        const QVariant icon = m_properties[QStringLiteral("icon")];
-        if (icon.canConvert<QIcon>()) {
-            opt->icon = icon.value<QIcon>();
-        } else if (icon.canConvert<QString>()) {
-            opt->icon = m_theme->iconFromTheme(icon.value<QString>(), m_properties[QStringLiteral("iconColor")].value<QColor>());
-        }
+
+        opt->icon = iconFromIconProperty();
+
         auto iconSize = QSize(m_properties[QStringLiteral("iconWidth")].toInt(), m_properties[QStringLiteral("iconHeight")].toInt());
         if (iconSize.isEmpty()) {
             int e = KQuickStyleItem::style()->pixelMetric(QStyle::PM_ToolBarIconSize, m_styleoption, nullptr);
@@ -483,8 +474,7 @@ void KQuickStyleItem::initStyleOption()
                                                           QStyleOptionMenuItem::NonExclusive;
                 }
             }
-            if (m_properties[QStringLiteral("icon")].canConvert<QIcon>())
-                opt->icon = m_properties[QStringLiteral("icon")].value<QIcon>();
+            opt->icon = iconFromIconProperty();
             setProperty("_q_showUnderlined", m_hints[QStringLiteral("showUnderlined")].toBool());
 
             const QFont font = qApp->font(m_itemType == ComboBoxItem ?"QComboMenuItem" : "QMenu");
@@ -507,14 +497,8 @@ void KQuickStyleItem::initStyleOption()
             opt->state |= QStyle::State_NoChange;
         opt->text = text();
 
-        const QVariant icon = m_properties[QStringLiteral("icon")];
-        if (icon.canConvert<QIcon>()) {
-            opt->icon = icon.value<QIcon>();
-        } else if (icon.canConvert<QUrl>() && icon.value<QUrl>().isLocalFile()) {
-            opt->icon = QIcon(icon.value<QUrl>().toLocalFile());
-        } else if (icon.canConvert<QString>()) {
-            opt->icon = m_theme->iconFromTheme(icon.value<QString>(), m_properties[QStringLiteral("iconColor")].value<QColor>());
-        }
+        opt->icon = iconFromIconProperty();
+
         auto iconSize = QSize(m_properties[QStringLiteral("iconWidth")].toInt(), m_properties[QStringLiteral("iconHeight")].toInt());
         if (iconSize.isEmpty()) {
             int e = KQuickStyleItem::style()->pixelMetric(QStyle::PM_ButtonIconSize, m_styleoption, nullptr);
@@ -742,6 +726,35 @@ void KQuickStyleItem::initStyleOption()
 
 }
 
+QIcon KQuickStyleItem::iconFromIconProperty() const
+{
+    QIcon icon;
+    const QVariant iconProperty = m_properties[QStringLiteral("icon")];
+    switch(iconProperty.type()){
+    case QVariant::Icon:
+        icon = iconProperty.value<QIcon>();
+        break;
+    case QVariant::Url:
+    case QVariant::String: {
+        QString iconSource = iconProperty.toString();
+        if (iconSource.startsWith(QLatin1String("qrc:/"))) {
+            iconSource = iconSource.mid(3);
+        } else if (iconSource.startsWith(QLatin1String("file:/"))) {
+            iconSource = QUrl(iconSource).path();
+        }
+        if (iconSource.contains(QLatin1String("/"))) {
+            icon = QIcon(iconSource);
+        } else {
+            icon = m_theme->iconFromTheme(iconSource, m_properties[QStringLiteral("iconColor")].value<QColor>());
+        }
+    }
+        break;
+    default:
+        break;
+    }
+    return icon;
+}
+
 const char* KQuickStyleItem::classNameForItem() const
 {
     switch(m_itemType) {
diff --git plugin/kquickstyleitem_p.h plugin/kquickstyleitem_p.h
index 5dbfebf..80c0958 100644
--- plugin/kquickstyleitem_p.h
+++ plugin/kquickstyleitem_p.h
@@ -256,6 +256,7 @@ protected:
     bool eventFilter(QObject *watched, QEvent *event) override;
 
 private:
+    QIcon iconFromIconProperty() const;
     const char* classNameForItem() const;
     QSize sizeFromContents(int width, int height);
     qreal baselineOffset();
