Warning, /plasma/discover/discover/qml/ReviewsStats.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  *   SPDX-FileCopyrightText: 2023 Marco Martin <mart@kde.org>
0003  *
0004  *   SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 pragma ComponentBehavior: Bound
0008 
0009 import QtQuick
0010 import QtQuick.Controls as QQC2
0011 import QtQuick.Layouts
0012 import org.kde.discover as Discover
0013 import org.kde.discover.app as DiscoverApp
0014 import org.kde.kirigami as Kirigami
0015 import org.kde.kitemmodels as KItemModels
0016 
0017 BasicAbstractCard {
0018     id: root
0019 
0020     required property Discover.AbstractResource application
0021     required property Discover.ReviewsModel reviewsModel
0022     required property KItemModels.KSortFilterProxyModel sortModel
0023     required property int visibleReviews
0024     required property bool compact
0025 
0026     content: GridLayout {
0027         rows: root.compact ? 6 : 5
0028         columns: root.compact ? 2 : 3
0029         flow: GridLayout.TopToBottom
0030         rowSpacing: 0
0031         columnSpacing: Kirigami.Units.largeSpacing
0032 
0033         Kirigami.Heading {
0034             Layout.fillWidth: true
0035             Layout.maximumWidth: globalRating.implicitWidth
0036             Layout.fillHeight: true
0037             Layout.rowSpan: 3
0038             horizontalAlignment: Text.AlignHCenter
0039             verticalAlignment: Text.AlignVCenter
0040             minimumPointSize: 10
0041             font.pointSize: 70
0042             fontSizeMode: Text.Fit
0043             text: (Math.min(10, root.application.rating.sortableRating) / 2.0).toFixed(1)
0044         }
0045         Rating {
0046             id: globalRating
0047             Layout.alignment: Qt.AlignCenter
0048             value: root.application.rating.sortableRating
0049             precision: Rating.Precision.HalfStar
0050         }
0051         QQC2.Label {
0052             Layout.alignment: Qt.AlignCenter
0053             text: i18nc("how many reviews", "%1 reviews", root.application.rating.ratingCount)
0054         }
0055         Repeater {
0056             model: ["five", "four", "three", "two", "one"]
0057             delegate: RowLayout {
0058                 id: delegate
0059 
0060                 required property int index
0061                 required property string modelData
0062 
0063                 Layout.fillWidth: true
0064                 Layout.preferredHeight: Math.ceil(Math.max(globalRating.height, implicitHeight))
0065                 Layout.row: index
0066                 Layout.column: 1
0067                 QQC2.Label {
0068                     id: numberLabel
0069                     text: 5 - delegate.index
0070                     Layout.preferredWidth: Math.ceil(Math.max(implicitWidth, numberMetrics.width))
0071                     Layout.alignment: Qt.AlignCenter
0072                     horizontalAlignment: Text.AlignHCenter
0073                     TextMetrics {
0074                         id: numberMetrics
0075                         font: numberLabel.font
0076                         text: i18nc("widest character in the language", "M")
0077                     }
0078                 }
0079                 QQC2.ProgressBar {
0080                     Layout.fillWidth: true
0081                     from: 0
0082                     to: 1
0083                     value: reviewsModel.starsCount[delegate.modelData] / reviewsModel.count
0084                     // This is to make the progressbar right margin from the card edge exactly the same as the top one
0085                     rightInset: topInset - Math.round((height - topInset - bottomInset) / 2) + Math.round((parent.height - height) / 2)
0086                 }
0087             }
0088         }
0089         ListView {
0090             id: reviewsPreview
0091             Layout.row: root.compact ? 5 : 0
0092             Layout.column: root.compact ? 0 : 2
0093             Layout.columnSpan: root.compact ? 2 : 1
0094             Layout.rowSpan: 5
0095             Layout.fillHeight: true
0096             Layout.fillWidth: true
0097             Layout.preferredWidth: Kirigami.Units.gridUnit * 18
0098             Layout.preferredHeight: Kirigami.Units.gridUnit * 8
0099             clip: true
0100             orientation: ListView.Horizontal
0101             currentIndex: 0
0102             pixelAligned: true
0103             snapMode: ListView.SnapToItem
0104             highlightRangeMode: ListView.StrictlyEnforceRange
0105 
0106             displayMarginBeginning: 0
0107             displayMarginEnd: 0
0108 
0109             preferredHighlightBegin: currentItem ? Math.round((width - currentItem.width) / 2) : 0
0110             preferredHighlightEnd: currentItem ? preferredHighlightBegin + currentItem.width : 0
0111 
0112             highlightMoveDuration: Kirigami.Units.longDuration
0113             highlightResizeDuration: Kirigami.Units.longDuration
0114 
0115             model: DiscoverApp.PaginateModel {
0116                 sourceModel: sortModel
0117                 pageSize: visibleReviews
0118             }
0119             delegate: Item {
0120                 id: delegate
0121 
0122                 required property string summary
0123                 required property string display
0124                 required property string reviewer
0125 
0126                 width: reviewsPreview.width
0127                 height: reviewsPreview.height
0128 
0129                 ColumnLayout {
0130                     anchors {
0131                         left: parent.left
0132                         right: parent.right
0133                         verticalCenter: parent.verticalCenter
0134                     }
0135                     Kirigami.Heading {
0136                         Layout.fillWidth: true
0137                         Layout.alignment: Qt.AlignCenter
0138                         horizontalAlignment: Text.AlignHCenter
0139                         elide: Text.ElideRight
0140                         text: delegate.summary
0141                     }
0142                     QQC2.Label {
0143                         Layout.fillWidth: true
0144                         Layout.alignment: Qt.AlignCenter
0145                         horizontalAlignment: Text.AlignHCenter
0146                         wrapMode: Text.WordWrap
0147                         elide: Text.ElideRight
0148                         maximumLineCount: 2
0149                         text: delegate.display
0150                     }
0151                     QQC2.Label {
0152                         Layout.alignment: Qt.AlignCenter
0153                         opacity: 0.8
0154                         text: delegate.reviewer || i18n("Unknown reviewer")
0155                     }
0156                 }
0157             }
0158 
0159             Timer {
0160                 running: true
0161                 repeat: true
0162                 interval: 10000
0163                 onTriggered: reviewsPreview.currentIndex = (reviewsPreview.currentIndex + 1) % reviewsPreview.count
0164             }
0165 
0166             QQC2.Label {
0167                 id: openingQuote
0168                 anchors {
0169                     left: parent.left
0170                     top: parent.top
0171                     topMargin: quoteMetrics.boundingRect.top - quoteMetrics.tightBoundingRect.top
0172                 }
0173                 parent: reviewsPreview
0174                 font.pointSize: Kirigami.Theme.defaultFont.pointSize * 4
0175                 text: i18nc("Opening upper air quote", "“")
0176                 opacity: 0.4
0177                 TextMetrics {
0178                     id: quoteMetrics
0179                     font: openingQuote.font
0180                     text: openingQuote.text
0181                 }
0182             }
0183             QQC2.Label {
0184                 anchors {
0185                     right: parent.right
0186                     bottom: parent.bottom
0187                 }
0188                 parent: reviewsPreview
0189                 font.pointSize: Kirigami.Theme.defaultFont.pointSize * 4
0190                 text: i18nc("Closing lower air quote", "„")
0191                 opacity: 0.4
0192             }
0193             RowLayout {
0194                 anchors {
0195                     left: parent.left
0196                     right: parent.right
0197                     bottom: parent.bottom
0198                 }
0199                 parent: reviewsPreview
0200                 MouseArea {
0201                     Layout.fillWidth: true
0202                     Layout.fillHeight: true
0203                     onClicked: reviewsPreview.currentIndex = Math.max(reviewsPreview.currentIndex - 1, 0)
0204                 }
0205                 QQC2.PageIndicator {
0206                     count: reviewsPreview.count
0207                     currentIndex: reviewsPreview.currentIndex
0208                     interactive: true
0209                     onCurrentIndexChanged: reviewsPreview.currentIndex = currentIndex
0210                 }
0211                 MouseArea {
0212                     Layout.fillWidth: true
0213                     Layout.fillHeight: true
0214                     onClicked: reviewsPreview.currentIndex = Math.min(reviewsPreview.currentIndex + 1, reviewsPreview.count - 1)
0215                 }
0216             }
0217         }
0218     }
0219 }