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-11-17 22:06:09 +01:00
|
|
|
svgIcon.imagePath = "toolbar-icons/"+root.source.split("-")[0]
|
|
|
|
if (!svgIcon.isValid() || !svgIcon.hasElement(root.source)) {
|
|
|
|
svgIcon.imagePath = "icons/"+root.source.split("-")[0]
|
|
|
|
}
|
|
|
|
|
2011-10-29 21:41:45 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2011-10-30 19:07:58 +01:00
|
|
|
implicitWidth: theme.smallIconSize
|
|
|
|
implicitHeight: theme.smallIconSize
|
2011-10-29 21:41:45 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|