Lomiri
Loading...
Searching...
No Matches
RatingStyle.qml
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
17import QtQuick 2.12
18import Lomiri.Components 1.3
19
20Row {
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 height: parent.height
40 fillMode: Image.PreserveAspectFit
41 sourceSize.height: height
42 opacity: styledItem.value < 0 ? 0.4 : 1 // Let's make the stars look inactive for a not-set value
43 source: {
44 if (index === repeater.indexHalfValue) return repeater.urlIconHalf;
45 else if (index < styledItem.effectiveValue) return repeater.urlIconFull;
46 else return repeater.urlIconEmpty;
47 }
48 }
49 }
50}