2011-10-29 21:19:51 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 by Marco MArtin <mart@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Library General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 1.1
|
|
|
|
import org.kde.plasma.core 0.1 as PlasmaCore
|
|
|
|
import org.kde.qtextracomponents 0.1
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
|
2011-10-29 21:41:45 +02:00
|
|
|
property bool valid: false
|
2011-10-29 21:19:51 +02:00
|
|
|
|
2011-10-29 21:41:45 +02:00
|
|
|
property string source
|
|
|
|
|
|
|
|
onSourceChanged: {
|
|
|
|
if (source == "") {
|
|
|
|
imageLoader.sourceComponent = null
|
|
|
|
valid = false
|
|
|
|
}
|
2011-10-29 21:19:51 +02:00
|
|
|
|
2011-10-29 21:41:45 +02:00
|
|
|
svgIcon.imagePath = "icons/"+root.source.split("-")[0]
|
|
|
|
if (svgIcon.isValid() && svgIcon.hasElement(root.source)) {
|
2011-10-29 21:19:51 +02:00
|
|
|
imageLoader.sourceComponent = svgComponent
|
2011-10-29 21:41:45 +02:00
|
|
|
} else if (root.source.indexOf(".") == -1 && root.source.indexOf(":") == -1) {
|
2011-10-29 21:19:51 +02:00
|
|
|
imageLoader.sourceComponent = iconComponent
|
|
|
|
} else {
|
|
|
|
imageLoader.sourceComponent = imageComponent
|
|
|
|
}
|
2011-10-29 21:41:45 +02:00
|
|
|
valid = true
|
|
|
|
}
|
|
|
|
|
|
|
|
//FIXME: iconloader sizes coming from plasma
|
|
|
|
implicitWidth: 16
|
|
|
|
implicitHeight: 16
|
|
|
|
|
|
|
|
PlasmaCore.Svg {
|
|
|
|
id: svgIcon
|
2011-10-29 21:19:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: imageLoader
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: svgComponent
|
|
|
|
|
|
|
|
PlasmaCore.SvgItem {
|
|
|
|
svg: svgIcon
|
2011-10-29 21:41:45 +02:00
|
|
|
elementId: root.source
|
2011-10-29 21:19:51 +02:00
|
|
|
anchors.fill: parent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: iconComponent
|
|
|
|
|
|
|
|
QIconItem {
|
2011-10-29 21:41:45 +02:00
|
|
|
icon: QIcon(root.source)
|
2011-10-29 21:19:51 +02:00
|
|
|
smooth: true
|
|
|
|
anchors.fill: parent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: imageComponent
|
|
|
|
|
|
|
|
Image {
|
2011-10-29 21:41:45 +02:00
|
|
|
source: root.source
|
2011-10-29 21:19:51 +02:00
|
|
|
sourceSize.width: width
|
|
|
|
sourceSize.height: height
|
|
|
|
fillMode: Image.PreserveAspectFit
|
|
|
|
smooth: true
|
|
|
|
anchors.fill: parent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|