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

List:       kde-commits
Subject:    [gluon] player/active/package/contents/ui: Add RatingItem
From:       Shantanu Tushar <shaan7in () gmail ! com>
Date:       2012-01-29 16:16:59
Message-ID: 20120129161659.28E3FA60A6 () git ! kde ! org
[Download RAW message or body]

Git commit 829d55901be5f995da884cb1cb442c0ff1676831 by Shantanu Tushar.
Committed on 29/01/2012 at 17:16.
Pushed by shantanu into branch 'master'.

Add RatingItem

M  +9    -14   player/active/package/contents/ui/CommentDelegate.qml
A  +92   -0    player/active/package/contents/ui/RatingItem.qml     [License: LGPL \
(v2.1+)]

http://commits.kde.org/gluon/829d55901be5f995da884cb1cb442c0ff1676831

diff --git a/player/active/package/contents/ui/CommentDelegate.qml \
b/player/active/package/contents/ui/CommentDelegate.qml index ebda43e..34acd1f 100644
--- a/player/active/package/contents/ui/CommentDelegate.qml
+++ b/player/active/package/contents/ui/CommentDelegate.qml
@@ -38,7 +38,7 @@ Item {
             anchors.fill: parent
             anchors.margins: 10
             spacing: 2
-            property real rowHeight: height/3 - 2*spacing
+            property real rowHeight: height/5 - 2*spacing
 
             Row {
                 width: parent.width
@@ -50,25 +50,20 @@ Item {
                     text: TitleRole
                 }
 
-                //Use Rating Item
-                PlasmaComponents.Label {
+                RatingItem {
                     id: ratingItem
                     height: parent.height
-                    width: 10
-                    text: RatingRole
+                    width: height*5
+                    rating: RatingRole
                 }
             }
 
-            Row {
+            PlasmaComponents.TextArea {
                 width: parent.width
-                height: parent.rowHeight
-
-                PlasmaComponents.TextArea {
-                    height: parent.height
-                    width: parent.width
-                    readOnly: true
-                    text: BodyRole
-                }
+                height: parent.rowHeight*4
+                wrapMode: TextEdit.Wrap
+                readOnly: true
+                text: BodyRole
             }
 
             Row {
diff --git a/player/active/package/contents/ui/RatingItem.qml \
b/player/active/package/contents/ui/RatingItem.qml new file mode 100644
index 0000000..2fc0195
--- /dev/null
+++ b/player/active/package/contents/ui/RatingItem.qml
@@ -0,0 +1,92 @@
+/******************************************************************************
+ * This file is part of the Gluon Development Platform
+ * Copyright (C) 2011 Shantanu Tushar <shaan7in@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+import QtQuick 1.0
+import org.kde.plasma.components 0.1 as PlasmaComponents
+
+Item {
+    id: ratingWidgetRootItem
+    property int rating: 0
+
+    Component {
+        id: ratingDelegate
+
+        Item {
+            height: ratingWidgetRootItem.height; width: \
ratingWidgetRootItem.width/ratingModel.count; +            \
PlasmaComponents.ToolButton { +                id: ratingButton
+                anchors.fill: parent
+
+                iconSource: value > 0 ? "rating" : "draw-star"
+                onClicked: console.log(index)
+            }
+        }
+    }
+
+    ListView {
+        id: ratingList
+        height: parent.height; width: parent.width;
+        anchors.right: parent.right;
+
+        orientation: ListView.Horizontal
+        model: ratingModel
+        delegate: ratingDelegate
+    }
+
+    ListModel {
+        id: ratingModel
+
+        ListElement {
+            value: 0
+        }
+        ListElement {
+            value: 0
+        }
+        ListElement {
+            value: 0
+        }
+        ListElement {
+            value: 0
+        }
+        ListElement {
+            value: 0
+        }
+    }
+
+    onRatingChanged: {
+        var tmp = rating;
+        var i = 0;
+        var ratingPerStar = 100/ratingModel.count;
+
+        //Clear all stars
+        for (j=0; j<ratingModel.count; ++j) {
+            ratingModel.get(j).value = 0;
+        }
+
+        while (tmp > 0) {
+            if (tmp > ratingPerStar) {
+                ratingModel.get(i).value = ratingPerStar;
+            } else {
+                ratingModel.get(i).value = tmp;
+            }
+            tmp -= ratingPerStar;
+            ++i;
+        }
+    }
+}
\ No newline at end of file


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

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