KNewStuff

Rating.qml
1 /*
2  * Copyright (C) 2012 Aleix Pol Gonzalez <[email protected]>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Library/Lesser General Public License
6  * version 2, or (at your option) any later version, as published by the
7  * Free Software Foundation
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details
13  *
14  * You should have received a copy of the GNU Library/Lesser General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 import QtQuick 2.11
21 import QtQuick.Layouts 1.11
22 
23 import org.kde.kirigami 2.0 as Kirigami
24 
25 RowLayout
26 {
27  id: view
28  property bool editable: false
29  property int max: 10
30  property int rating: 0
31  property real starSize: Kirigami.Units.gridUnit
32 
33  clip: true
34  spacing: 0
35 
36  readonly property var ratingIndex: (theRepeater.count/view.max)*view.rating
37 
38  Repeater {
39  id: theRepeater
40  model: 5
41  delegate: Kirigami.Icon {
42  Layout.minimumWidth: view.starSize
43  Layout.minimumHeight: view.starSize
44  Layout.preferredWidth: view.starSize
45  Layout.preferredHeight: view.starSize
46 
47  width: height
48  source: "rating"
49  opacity: (view.editable && mouse.item.containsMouse ? 0.7
50  : index>=view.ratingIndex ? 0.2
51  : 1)
52 
53  ConditionalLoader {
54  id: mouse
55 
56  anchors.fill: parent
57  condition: view.editable
58  componentTrue: MouseArea {
59  hoverEnabled: true
60  onClicked: rating = (max/theRepeater.model*(index+1))
61  }
62  componentFalse: null
63  }
64  }
65  }
66 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Aug 9 2020 22:43:40 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.