[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [libkdegames/viranch/popupitem] declarativeimports/qml: Paint the icon only if showIcon is true
From:       Viranch Mehta <viranch.mehta () gmail ! com>
Date:       2013-07-23 21:15:17
Message-ID: E1V1jvR-0004uw-OZ () scm ! kde ! org
[Download RAW message or body]

Git commit 4189049b56f4719508be85571eceb90053cc63be by Viranch Mehta.
Committed on 24/04/2013 at 09:19.
Pushed by viranch into branch 'viranch/popupitem'.

Paint the icon only if showIcon is true

M  +26   -20   declarativeimports/qml/PopupItem.qml

http://commits.kde.org/libkdegames/4189049b56f4719508be85571eceb90053cc63be

diff --git a/declarativeimports/qml/PopupItem.qml b/declarativeimports/qml/PopupItem.qml
index ba8dbec..0049cd3 100644
--- a/declarativeimports/qml/PopupItem.qml
+++ b/declarativeimports/qml/PopupItem.qml
@@ -24,8 +24,16 @@ Rectangle {
     property alias text: message.text
     property alias textColor: message.color
     property alias messageTimeout: hideTimer.interval
-    property alias icon: icon.iconName
-    property alias showIcon: icon.visible
+    property string iconName: "dialog-information"
+    property bool showIcon: true
+    property QtObject iconComponent: Component {
+        Image {
+            source: "image://icon/"+background.iconName
+            width: 32
+            height: 32
+            smooth: true
+        }
+    }
     property alias hideOnMouseClick: mouseArea.enabled
     property alias sharpness: background.radius
     property alias backgroundColor: background.color
@@ -37,30 +45,28 @@ Rectangle {
     property int margin: 15
     property int iconTextMargin: showIcon ? 10 : 0
 
-    color: "#181513"
-    opacity: 0
-    width: icon.paintedWidth + iconTextMargin + message.paintedWidth + margin*2
-    height: Math.max(icon.paintedHeight, message.paintedHeight) + margin*2
-
-    Image {
-        id: icon
-        property string iconName: "dialog-information"
-        source: "image://icon/"+iconName
-        width: visible ? 32 : 0
-        height: visible ? 32 : 0
-        anchors {
-            left: parent.left
-            leftMargin: parent.margin
-            verticalCenter: parent.verticalCenter
+    Component.onCompleted: {
+        if (showIcon) {
+            icon = iconComponent.createObject(background);
+            icon.anchors.left = background.left;
+            icon.anchors.leftMargin = margin;
+            icon.anchors.verticalCenter = background.verticalCenter;
+            width = icon.paintedWidth + iconTextMargin + message.paintedWidth + margin*2;
+            height = Math.max(icon.paintedWidth, message.paintedHeight) + margin*2;
+        } else {
+            width = message.paintedWidth + margin*2;
+            height = message.paintedHeight + margin*2;
         }
-        smooth: true
     }
 
+    color: "#181513"
+    opacity: 0
+
     Text {
         id: message
         anchors {
-            left: icon.right
-            leftMargin: parent.iconTextMargin
+            right: parent.right
+            rightMargin: parent.margin
             verticalCenter: parent.verticalCenter
         }
         color: "white"

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic