use IconLoader

This commit is contained in:
Marco Martin 2011-10-29 21:41:45 +02:00
parent be1068709a
commit f32fc24694
4 changed files with 32 additions and 24 deletions

View File

@ -105,16 +105,14 @@ Item {
bottomMargin: surface.margins.bottom bottomMargin: surface.margins.bottom
} }
Image { IconLoader {
id: icon id: icon
anchors { anchors {
fill: label.text ? undefined : parent verticalCenter: parent.verticalCenter
top: label.text ? parent.top : undefined
left: label.text ? parent.left : undefined left: label.text ? parent.left : undefined
bottom: label.text ? parent.bottom : undefined horizontalCenter: label.text ? undefined : parent.horizontalCenter
} }
fillMode: Image.PreserveAspectFit
} }
Text { Text {
@ -123,7 +121,7 @@ Item {
anchors { anchors {
top: parent.top top: parent.top
bottom: parent.bottom bottom: parent.bottom
left: icon.right left: icon.valid ? icon.right : parent.left
right: parent.right right: parent.right
} }
font.capitalization: theme.defaultFont.capitalization font.capitalization: theme.defaultFont.capitalization

View File

@ -24,21 +24,33 @@ import org.kde.qtextracomponents 0.1
Item { Item {
id: root id: root
property string iconSource property bool valid: false
PlasmaCore.Svg { property string source
id: svgIcon
onSourceChanged: {
if (source == "") {
imageLoader.sourceComponent = null
valid = false
} }
onIconSourceChanged: { svgIcon.imagePath = "icons/"+root.source.split("-")[0]
svgIcon.imagePath = "icons/"+root.iconSource.split("-")[0] if (svgIcon.isValid() && svgIcon.hasElement(root.source)) {
if (svgIcon.isValid() && svgIcon.hasElement(root.iconSource)) {
imageLoader.sourceComponent = svgComponent imageLoader.sourceComponent = svgComponent
} else if (root.iconSource.indexOf(".") == -1 && root.iconSource.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
} }
valid = true
}
//FIXME: iconloader sizes coming from plasma
implicitWidth: 16
implicitHeight: 16
PlasmaCore.Svg {
id: svgIcon
} }
Loader { Loader {
@ -50,7 +62,7 @@ Item {
PlasmaCore.SvgItem { PlasmaCore.SvgItem {
svg: svgIcon svg: svgIcon
elementId: root.iconSource elementId: root.source
anchors.fill: parent anchors.fill: parent
} }
} }
@ -59,7 +71,7 @@ Item {
id: iconComponent id: iconComponent
QIconItem { QIconItem {
icon: QIcon(root.iconSource) icon: QIcon(root.source)
smooth: true smooth: true
anchors.fill: parent anchors.fill: parent
} }
@ -69,7 +81,7 @@ Item {
id: imageComponent id: imageComponent
Image { Image {
source: root.iconSource source: root.source
sourceSize.width: width sourceSize.width: width
sourceSize.height: height sourceSize.height: height
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit

View File

@ -51,7 +51,7 @@ Item {
property bool checked: internal.tabGroup != null && internal.tabGroup.currentTab == tab property bool checked: internal.tabGroup != null && internal.tabGroup.currentTab == tab
property bool pressed: mouseArea.pressed == true && mouseArea.containsMouse property bool pressed: mouseArea.pressed == true && mouseArea.containsMouse
property alias text: label.text property alias text: label.text
property alias iconSource: imageLoader.iconSource property alias iconSource: imageLoader.source
signal clicked signal clicked

View File

@ -116,16 +116,14 @@ Item {
bottomMargin: surface.margins.bottom bottomMargin: surface.margins.bottom
} }
Image { IconLoader {
id: icon id: icon
anchors { anchors {
fill: label.text ? undefined : parent verticalCenter: parent.verticalCenter
top: label.text ? parent.top : undefined
left: label.text ? parent.left : undefined left: label.text ? parent.left : undefined
bottom: label.text ? parent.bottom : undefined horizontalCenter: label.text ? undefined : parent.horizontalCenter
} }
fillMode: Image.PreserveAspectFit
} }
Text { Text {
@ -134,7 +132,7 @@ Item {
anchors { anchors {
top: parent.top top: parent.top
bottom: parent.bottom bottom: parent.bottom
left: icon.right left: icon.valid ? icon.right : parent.left
right: parent.right right: parent.right
} }
font.capitalization: theme.defaultFont.capitalization font.capitalization: theme.defaultFont.capitalization