~nick-dedekind/unity8/indicators.hint-interval

« back to all changes in this revision

Viewing changes to qml/Components/RatingStyle.qml

  • Committer: Nick Dedekind
  • Date: 2014-03-07 15:54:57 UTC
  • mfrom: (638.1.118 unity8)
  • Revision ID: nicholas.dedekind@gmail.com-20140307155457-f0s1zu5ll2czt3rq
merged with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2014 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
import QtQuick 2.0
 
18
import Ubuntu.Components 0.1
 
19
 
 
20
Row {
 
21
    anchors.fill: parent
 
22
 
 
23
    Repeater {
 
24
        id: repeater
 
25
        model: styledItem.size
 
26
 
 
27
        property int indexHalfValue: {
 
28
            var integerPart = Math.floor(styledItem.effectiveValue);
 
29
            var fractionalPart = styledItem.effectiveValue - integerPart;
 
30
 
 
31
            if (fractionalPart < 0.5) return -1;
 
32
            else return integerPart;
 
33
        }
 
34
        property url urlIconEmpty: styledItem.urlIconEmpty || "graphics/icon_star_empty.png"
 
35
        property url urlIconFull: styledItem.urlIconFull || "graphics/icon_star_full.png"
 
36
        property url urlIconHalf: styledItem.urlIconHalf || "graphics/icon_star_half.png"
 
37
 
 
38
        Image {
 
39
            opacity: styledItem.value < 0 ? 0.4 : 1 // Let's make the stars look inactive for a not-set value
 
40
            source: {
 
41
                if (index === repeater.indexHalfValue) return repeater.urlIconHalf;
 
42
                else if (index < styledItem.effectiveValue) return repeater.urlIconFull;
 
43
                else return repeater.urlIconEmpty;
 
44
            }
 
45
        }
 
46
    }
 
47
}