From f62018ca5f03f44342528d035aa7b45ae438cd1a Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 3 Apr 2017 10:57:48 +0200 Subject: An Icon component that requests icons from the kube image provider --- components/mail/contents/ui/Mail.qml | 2 +- components/package/contents/ui/Icon.qml | 54 +++++++++++++++++++++++++++++++++ components/qmldir | 1 + 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 components/package/contents/ui/Icon.qml (limited to 'components') diff --git a/components/mail/contents/ui/Mail.qml b/components/mail/contents/ui/Mail.qml index 6779cd10..3978098f 100644 --- a/components/mail/contents/ui/Mail.qml +++ b/components/mail/contents/ui/Mail.qml @@ -294,7 +294,7 @@ Controls2.ApplicationWindow { color: KubeTheme.Colors.highlightedTextColor } - ToolButton { + KubeComponents.Icon { id: statusIcon visible: false iconName: "" diff --git a/components/package/contents/ui/Icon.qml b/components/package/contents/ui/Icon.qml new file mode 100644 index 00000000..dfddfa6a --- /dev/null +++ b/components/package/contents/ui/Icon.qml @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2017 Christian Mollekopf, + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, 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 General Public License for more details. + * + * You should have received a copy of the GNU 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 2.7 + +Item { + id: root + property string iconName + property url iconSource + property alias implicitHeight: image.implicitHeight + property alias implicitWidth: image.implicitWidth + property alias status: image.status + width: implicitWidth + height: implicitHeight + + onIconNameChanged: setImageSource() + onIconSourceChanged: setImageSource() + + function setImageSource() { + // Icon names have precedence over icon URLs + if (root.iconName.indexOf("/") != -1) + image.source = root.iconName; + else if (root.iconName != "") + image.source = "image://kube/" + root.iconName; + else if (root.iconSource != "") + image.source = root.iconSource; + else + image.source = ""; + } + + Image { + id: image + anchors.fill: parent + sourceSize.width: width + sourceSize.height: height + cache: true + smooth: true + } +} diff --git a/components/qmldir b/components/qmldir index 94ac9caf..24c93d94 100644 --- a/components/qmldir +++ b/components/qmldir @@ -12,3 +12,4 @@ OverlayDialog 1.0 OverlayDialog.qml Outbox 1.0 Outbox.qml People 1.0 People.qml Notification 1.0 Notification.qml +Icon 1.0 Icon.qml -- cgit v1.2.3