Warning, /plasma/plasma-desktop/applets/kicker/package/contents/ui/ItemListDialog.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2013-2014 Eike Hein <hein@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.15
0008 
0009 import org.kde.plasma.core as PlasmaCore
0010 import org.kde.plasma.plasmoid 2.0
0011 import org.kde.kirigami 2.20 as Kirigami
0012 
0013 import org.kde.plasma.private.kicker 0.1 as Kicker
0014 
0015 Kicker.SubMenu {
0016     id: itemDialog
0017 
0018     property alias focusParent: itemListView.focusParent
0019     property alias model: funnelModel.sourceModel
0020 
0021     property bool aboutToBeDestroyed: false
0022 
0023     visible: false
0024     flags: Qt.WindowStaysOnTopHint
0025     hideOnWindowDeactivate: kicker.hideOnWindowDeactivate
0026     location: PlasmaCore.Types.Floating
0027     offset: Kirigami.Units.smallSpacing
0028 
0029     onWindowDeactivated: {
0030         if (!aboutToBeDestroyed) {
0031             kicker.expanded = false;
0032         }
0033     }
0034 
0035     mainItem: ItemListView {
0036         id: itemListView
0037 
0038         height: {
0039             const m = funnelModel.sourceModel;
0040 
0041             if (m === null || m === undefined) {
0042                 // TODO: setting height to 0 triggers a warning in PlasmaQuick::Dialog
0043                 return 0;
0044             }
0045 
0046             return Math.min(
0047                 // either fit in screen boundaries (cut to the nearest item/separator boundary), ...
0048                 __subFloorMultipleOf(
0049                     itemDialog.availableScreenRectForItem(itemListView).height
0050                     - itemDialog.margins.top
0051                     - itemDialog.margins.bottom,
0052                     itemHeight
0053                 ) + m.separatorCount * (separatorHeight - itemHeight)
0054                 ,
0055                 // ...or fit the content itself -- whichever is shorter.
0056                 ((m.count - m.separatorCount) * itemHeight)
0057                 + (m.separatorCount * separatorHeight)
0058             );
0059         }
0060 
0061         // get x rounded down to the multiple of y, minus extra y.
0062         function __subFloorMultipleOf(x : real, y : real) : real {
0063             return (Math.floor(x / y) - 1) * y;
0064         }
0065 
0066         iconsEnabled: true
0067 
0068         dialog: itemDialog
0069 
0070         model: funnelModel
0071 
0072         Kicker.FunnelModel {
0073             id: funnelModel
0074 
0075             property bool sorted: sourceModel.hasOwnProperty("sorted") ? sourceModel.sorted : false
0076 
0077             Component.onCompleted: {
0078                 kicker.reset.connect(funnelModel.reset);
0079             }
0080 
0081             onCountChanged: {
0082                 if (sourceModel && count === 0) {
0083                     itemDialog.delayedDestroy();
0084                 }
0085             }
0086 
0087             onSourceModelChanged: {
0088                 itemListView.currentIndex = -1;
0089             }
0090         }
0091     }
0092 
0093     function delayedDestroy() {
0094         aboutToBeDestroyed = true;
0095         Plasmoid.hideOnWindowDeactivate = false;
0096         visible = false;
0097 
0098         Qt.callLater(() => itemDialog.destroy());
0099     }
0100 }