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
}
Image {
IconLoader {
id: icon
anchors {
fill: label.text ? undefined : parent
top: label.text ? parent.top : undefined
verticalCenter: parent.verticalCenter
left: label.text ? parent.left : undefined
bottom: label.text ? parent.bottom : undefined
horizontalCenter: label.text ? undefined : parent.horizontalCenter
}
fillMode: Image.PreserveAspectFit
}
Text {
@ -123,7 +121,7 @@ Item {
anchors {
top: parent.top
bottom: parent.bottom
left: icon.right
left: icon.valid ? icon.right : parent.left
right: parent.right
}
font.capitalization: theme.defaultFont.capitalization

View File

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

View File

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

View File

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