Warning, /frameworks/knewstuff/src/qtquick/qml/private/Rating.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.11 0008 import QtQuick.Layouts 1.11 0009 import QtQuick.Controls 2.11 as QtControls 0010 0011 import org.kde.kirigami 2.0 as Kirigami 0012 0013 RowLayout 0014 { 0015 id: view 0016 property bool editable: false 0017 property int max: 100 0018 property int rating: 0 0019 property real starSize: Kirigami.Units.gridUnit 0020 property bool reverseLayout: false 0021 0022 clip: true 0023 spacing: 0 0024 0025 readonly property var ratingIndex: Math.floor((theRepeater.count*view.rating)/view.max) 0026 readonly property var ratingHalf: (theRepeater.count*view.rating)%view.max >= view.max / 2 0027 0028 QtControls.Label { 0029 Layout.minimumWidth: view.starSize 0030 Layout.minimumHeight: view.starSize 0031 visible: view.reverseLayout 0032 text: ratingAsText.text 0033 } 0034 Item { 0035 visible: view.reverseLayout 0036 Layout.minimumHeight: view.starSize; 0037 Layout.minimumWidth: Kirigami.Units.smallSpacing; 0038 Layout.maximumWidth: Kirigami.Units.smallSpacing; 0039 } 0040 Repeater { 0041 id: theRepeater 0042 model: 5 0043 delegate: Kirigami.Icon { 0044 Layout.minimumWidth: view.starSize 0045 Layout.minimumHeight: view.starSize 0046 Layout.preferredWidth: view.starSize 0047 Layout.preferredHeight: view.starSize 0048 0049 source: index < view.ratingIndex 0050 ? "rating" 0051 : (view.ratingHalf && index == view.ratingIndex 0052 ? (view.LayoutMirroring.enabled ? "rating-half-rtl" : "rating-half") 0053 : "rating-unrated") 0054 opacity: (view.editable && mouse.item.containsMouse) ? 0.7 : 1 0055 0056 ConditionalLoader { 0057 id: mouse 0058 0059 anchors.fill: parent 0060 condition: view.editable 0061 componentTrue: MouseArea { 0062 hoverEnabled: true 0063 onClicked: rating = (max/theRepeater.model*(index+1)) 0064 } 0065 componentFalse: null 0066 } 0067 } 0068 } 0069 Item { 0070 visible: !view.reverseLayout 0071 Layout.minimumHeight: view.starSize; 0072 Layout.minimumWidth: Kirigami.Units.smallSpacing; 0073 Layout.maximumWidth: Kirigami.Units.smallSpacing; 0074 } 0075 QtControls.Label { 0076 id: ratingAsText 0077 Layout.minimumWidth: view.starSize 0078 Layout.minimumHeight: view.starSize 0079 visible: !view.reverseLayout 0080 text: i18ndc("knewstuff6", "A text representation of the rating, shown as a fraction of the max value", "(%1/%2)", view.rating / 10, view.max / 10) 0081 } 0082 }