support qicons as icon source

This commit is contained in:
Marco Martin 2011-12-28 18:49:55 +01:00
parent 0a3b3d849c
commit 1348d9d2a9

View File

@ -46,10 +46,15 @@ Item {
property bool valid: false property bool valid: false
property string source property variant source
onSourceChanged: { onSourceChanged: {
if (source == "") { //is it a qicon?
if (typeof source != "string") {
imageLoader.sourceComponent = iconComponent
valid = true
return
} else if (source == "") {
imageLoader.sourceComponent = null imageLoader.sourceComponent = null
valid = false valid = false
} }
@ -61,7 +66,7 @@ Item {
if (svgIcon.isValid() && svgIcon.hasElement(root.source)) { if (svgIcon.isValid() && svgIcon.hasElement(root.source)) {
imageLoader.sourceComponent = svgComponent imageLoader.sourceComponent = svgComponent
} else if (root.source.indexOf(".") == -1 && root.source.indexOf(":") == -1) { } else if ((root.source.indexOf(".") == -1 && root.source.indexOf(":") == -1)) {
imageLoader.sourceComponent = iconComponent imageLoader.sourceComponent = iconComponent
} else { } else {
imageLoader.sourceComponent = imageComponent imageLoader.sourceComponent = imageComponent
@ -112,7 +117,7 @@ Item {
id: iconComponent id: iconComponent
QIconItem { QIconItem {
icon: QIcon(root.source) icon: (typeof source == "string") ? QIcon(root.source) : root.source
smooth: true smooth: true
anchors.fill: parent anchors.fill: parent
} }