Warning, /multimedia/elisa/src/qml/SortMenu.qml is written in an unsupported language. File is not indexed.

0001 /*
0002    SPDX-FileCopyrightText: 2020 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>
0003 
0004    SPDX-License-Identifier: LGPL-3.0-or-later
0005  */
0006 
0007 import QtQuick 2.15
0008 import QtQuick.Controls 2.15 as QQC2
0009 
0010 QQC2.Menu {
0011     id: root
0012 
0013     property int sortRole
0014     property string sortRoleName
0015     property var sortRoles
0016     property var sortRoleNames
0017     property /*Qt::SortOrder*/int sortOrder
0018     property var sortOrderNames
0019 
0020     title: i18nc("@title:menu", "Sort By")
0021 
0022     function refreshSortOrderNames() {
0023         if (!sortOrderNames) {
0024             return
0025         }
0026 
0027         for (let i = 0; i < sortRoleNames.length; ++i) {
0028             if (sortRoles[i] === sortRole && sortOrderNames.length >= (i * 2 + 1)) {
0029                 ascendingSortOrder.text = sortOrderNames[i * 2]
0030                 descendingSortOrder.text = sortOrderNames[i * 2 + 1]
0031                 sortRoleName = sortRoleNames[i]
0032             }
0033         }
0034     }
0035 
0036     QQC2.ButtonGroup {
0037         id: rolesButtonGroup
0038     }
0039 
0040     Repeater {
0041         id: rolesRepeater
0042 
0043         model: root.sortRoleNames.length > 1 ? root.sortRoleNames.length : 0
0044 
0045         delegate: QQC2.MenuItem {
0046             required property int index
0047 
0048             text: root.sortRoleNames[index]
0049 
0050             checkable: true
0051 
0052             checked: root.sortRoles[index] === root.sortRole
0053 
0054             onToggled: {
0055                 root.sortRole = root.sortRoles[index]
0056                 checked = (root.sortRoles[index] === root.sortRole)
0057             }
0058 
0059             QQC2.ButtonGroup.group: rolesButtonGroup
0060         }
0061     }
0062 
0063     QQC2.MenuSeparator {
0064         visible: root.sortRoleNames.length > 1
0065     }
0066 
0067     QQC2.ButtonGroup {
0068         id: orderButtonGroup
0069     }
0070 
0071     QQC2.MenuItem {
0072         id: ascendingSortOrder
0073 
0074         checkable: true
0075         checked: root.sortOrder === Qt.AscendingOrder
0076 
0077         onToggled: root.sortOrder = Qt.AscendingOrder
0078 
0079         QQC2.ButtonGroup.group: orderButtonGroup
0080     }
0081 
0082     QQC2.MenuItem {
0083         id: descendingSortOrder
0084 
0085         checkable: true
0086         checked: root.sortOrder === Qt.DescendingOrder
0087 
0088         onToggled: root.sortOrder = Qt.DescendingOrder
0089 
0090         QQC2.ButtonGroup.group: orderButtonGroup
0091     }
0092 
0093     onSortRoleChanged: refreshSortOrderNames()
0094 
0095     onSortOrderNamesChanged: refreshSortOrderNames()
0096 }