KNewStuff

Rating.qml
1 /*
2  SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 import QtQuick 2.11
8 import QtQuick.Layouts 1.11
9 
10 import org.kde.kirigami 2.0 as Kirigami
11 
12 RowLayout
13 {
14  id: view
15  property bool editable: false
16  property int max: 10
17  property int rating: 0
18  property real starSize: Kirigami.Units.gridUnit
19 
20  clip: true
21  spacing: 0
22 
23  readonly property var ratingIndex: (theRepeater.count/view.max)*view.rating
24 
25  Repeater {
26  id: theRepeater
27  model: 5
28  delegate: Kirigami.Icon {
29  Layout.minimumWidth: view.starSize
30  Layout.minimumHeight: view.starSize
31  Layout.preferredWidth: view.starSize
32  Layout.preferredHeight: view.starSize
33 
34  width: height
35  source: "rating"
36  opacity: (view.editable && mouse.item.containsMouse ? 0.7
37  : index>=view.ratingIndex ? 0.2
38  : 1)
39 
40  ConditionalLoader {
41  id: mouse
42 
43  anchors.fill: parent
44  condition: view.editable
45  componentTrue: MouseArea {
46  hoverEnabled: true
47  onClicked: rating = (max/theRepeater.model*(index+1))
48  }
49  componentFalse: null
50  }
51  }
52  }
53 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 18 2021 22:43:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.