an item to load icons
still private, load icons either by absolute path, icon name, svg
This commit is contained in:
parent
9bcc260757
commit
be1068709a
81
declarativeimports/plasmacomponents/qml/IconLoader.qml
Normal file
81
declarativeimports/plasmacomponents/qml/IconLoader.qml
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
property string iconSource
|
||||||
|
|
||||||
|
PlasmaCore.Svg {
|
||||||
|
id: svgIcon
|
||||||
|
}
|
||||||
|
|
||||||
|
onIconSourceChanged: {
|
||||||
|
svgIcon.imagePath = "icons/"+root.iconSource.split("-")[0]
|
||||||
|
if (svgIcon.isValid() && svgIcon.hasElement(root.iconSource)) {
|
||||||
|
imageLoader.sourceComponent = svgComponent
|
||||||
|
} else if (root.iconSource.indexOf(".") == -1 && root.iconSource.indexOf(":") == -1) {
|
||||||
|
imageLoader.sourceComponent = iconComponent
|
||||||
|
} else {
|
||||||
|
imageLoader.sourceComponent = imageComponent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loader {
|
||||||
|
id: imageLoader
|
||||||
|
anchors.fill: parent
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: svgComponent
|
||||||
|
|
||||||
|
PlasmaCore.SvgItem {
|
||||||
|
svg: svgIcon
|
||||||
|
elementId: root.iconSource
|
||||||
|
anchors.fill: parent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: iconComponent
|
||||||
|
|
||||||
|
QIconItem {
|
||||||
|
icon: QIcon(root.iconSource)
|
||||||
|
smooth: true
|
||||||
|
anchors.fill: parent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Component {
|
||||||
|
id: imageComponent
|
||||||
|
|
||||||
|
Image {
|
||||||
|
source: root.iconSource
|
||||||
|
sourceSize.width: width
|
||||||
|
sourceSize.height: height
|
||||||
|
fillMode: Image.PreserveAspectFit
|
||||||
|
smooth: true
|
||||||
|
anchors.fill: parent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
**
|
**
|
||||||
**
|
|
||||||
** Copyright 2011 Marco Martin <mart@kde.org>
|
** Copyright 2011 Marco Martin <mart@kde.org>
|
||||||
**
|
**
|
||||||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||||
@ -52,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.source
|
property alias iconSource: imageLoader.iconSource
|
||||||
|
|
||||||
signal clicked
|
signal clicked
|
||||||
|
|
||||||
@ -105,58 +104,18 @@ Item {
|
|||||||
verticalAlignment: Text.AlignVCenter
|
verticalAlignment: Text.AlignVCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
Loader {
|
IconLoader {
|
||||||
// imageLoader acts as wrapper for Image and Icon items. The Image item is
|
|
||||||
// shown when the source points to a image (jpg, png). Icon item is used for
|
|
||||||
// locigal theme icons which are colorised.
|
|
||||||
id: imageLoader
|
id: imageLoader
|
||||||
|
|
||||||
property url source
|
|
||||||
property string iconId: source.toString()
|
|
||||||
|
|
||||||
//FIXME: icon sizes in Theme
|
//FIXME: icon sizes in Theme
|
||||||
width : 16
|
width : 16
|
||||||
height : 16
|
height : 16
|
||||||
sourceComponent: {
|
|
||||||
if (iconId)
|
|
||||||
return iconComponent
|
|
||||||
if (source.toString())
|
|
||||||
return imageComponent
|
|
||||||
return undefined
|
|
||||||
}
|
|
||||||
anchors {
|
anchors {
|
||||||
left: internal.portrait ? undefined : parent.left
|
left: internal.portrait ? undefined : parent.left
|
||||||
horizontalCenter: internal.portrait ? parent.horizontalCenter : undefined
|
horizontalCenter: internal.portrait ? parent.horizontalCenter : undefined
|
||||||
verticalCenter: internal.portrait ? undefined : parent.verticalCenter
|
verticalCenter: internal.portrait ? undefined : parent.verticalCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
Component {
|
|
||||||
id: imageComponent
|
|
||||||
|
|
||||||
Image {
|
|
||||||
id: image
|
|
||||||
|
|
||||||
objectName: "image"
|
|
||||||
source: imageLoader.iconId ? "" : imageLoader.source
|
|
||||||
sourceSize.width: width
|
|
||||||
sourceSize.height: height
|
|
||||||
fillMode: Image.PreserveAspectFit
|
|
||||||
smooth: true
|
|
||||||
anchors.fill: parent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Component {
|
|
||||||
id: iconComponent
|
|
||||||
|
|
||||||
Image {
|
|
||||||
id: icon
|
|
||||||
|
|
||||||
objectName: "icon"
|
|
||||||
anchors.fill: parent
|
|
||||||
source: imageLoader.iconId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import QtQuick 1.0
|
import QtQuick 1.1
|
||||||
import org.kde.plasma.core 0.1 as PlasmaCore
|
import org.kde.plasma.core 0.1 as PlasmaCore
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
@ -64,8 +64,9 @@ Item {
|
|||||||
button.forceActiveFocus();
|
button.forceActiveFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
width: Math.max(50, icon.width + label.paintedWidth + surface.margins.left + surface.margins.right)
|
implicitWidth: Math.max(50, icon.width + label.paintedWidth + surface.margins.left + surface.margins.right)
|
||||||
height: Math.max(20, Math.max(icon.height, label.paintedHeight) + surface.margins.top + surface.margins.bottom)
|
implicitHeight: Math.max(20, Math.max(icon.height, label.paintedHeight) + surface.margins.top + surface.margins.bottom)
|
||||||
|
|
||||||
// TODO: needs to define if there will be specific graphics for
|
// TODO: needs to define if there will be specific graphics for
|
||||||
// disabled buttons
|
// disabled buttons
|
||||||
opacity: enabled ? 1.0 : 0.5
|
opacity: enabled ? 1.0 : 0.5
|
||||||
|
Loading…
Reference in New Issue
Block a user