Warning, /plasma/plasma-workspace/applets/clipboard/contents/ui/ClipboardItemDelegate.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> 0003 SPDX-FileCopyrightText: 2014 Sebastian Kügler <sebas@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 import QtQuick 0009 import QtQuick.Layouts 1.1 0010 import Qt5Compat.GraphicalEffects 0011 0012 import org.kde.plasma.plasmoid 2.0 0013 import org.kde.plasma.components 3.0 as PlasmaComponents 0014 import org.kde.kirigami 2.20 as Kirigami 0015 0016 PlasmaComponents.ItemDelegate { 0017 id: menuItem 0018 0019 property bool supportsBarcodes 0020 property int maximumNumberOfPreviews: Math.floor(width / (Kirigami.Units.gridUnit * 4 + Kirigami.Units.smallSpacing)) 0021 readonly property real gradientThreshold: (label.width - toolButtonsLoader.width) / label.width 0022 // Consider tall to be > about 1.5x the default height for purposes of top-aligning 0023 // the buttons to preserve Fitts' Law when deleting multiple items in a row, 0024 // or else the top-alignment doesn't look deliberate enough and people will think 0025 // it's a bug 0026 readonly property bool isTall: height > Math.round(Kirigami.Units.gridUnit * 2.5) 0027 0028 signal itemSelected(string uuid) 0029 signal remove(string uuid) 0030 signal edit(string uuid) 0031 signal barcode(string text) 0032 signal triggerAction(string uuid) 0033 0034 // the 1.6 comes from ToolButton's default height 0035 height: Math.max(label.height, Math.round(Kirigami.Units.gridUnit * 1.6)) + 2 * Kirigami.Units.smallSpacing 0036 0037 enabled: true 0038 0039 onClicked: { 0040 menuItem.itemSelected(UuidRole); 0041 if (main.hideOnWindowDeactivate) { 0042 main.expanded = false; 0043 } else { 0044 forceActiveFocus(); // Or activeFocus will always be false after clicking buttons in the heading 0045 } 0046 } 0047 0048 Keys.onEnterPressed: event => Keys.returnPressed(event) 0049 Keys.onReturnPressed: menuItem.clicked() 0050 Keys.onDeletePressed: { 0051 remove(UuidRole); 0052 } 0053 0054 ListView.onIsCurrentItemChanged: { 0055 if (ListView.isCurrentItem) { 0056 labelMask.source = label // calculate on demand 0057 } 0058 } 0059 0060 // this stuff here is used so we can fade out the text behind the tool buttons 0061 Item { 0062 id: labelMaskSource 0063 anchors.fill: label 0064 visible: false 0065 0066 Rectangle { 0067 anchors.centerIn: parent 0068 rotation: LayoutMirroring.enabled ? 90 : -90 // you cannot even rotate gradients without Qt5Compat.GraphicalEffects 0069 width: parent.height 0070 height: parent.width 0071 0072 gradient: Gradient { 0073 GradientStop { position: 0.0; color: "white" } 0074 GradientStop { position: gradientThreshold - 0.25; color: "white"} 0075 GradientStop { position: gradientThreshold; color: "transparent"} 0076 GradientStop { position: 1; color: "transparent"} 0077 } 0078 } 0079 } 0080 0081 OpacityMask { 0082 id: labelMask 0083 anchors.fill: label 0084 cached: true 0085 maskSource: labelMaskSource 0086 visible: !!source && menuItem.ListView.isCurrentItem 0087 0088 TapHandler { 0089 enabled: !toolButtonsLoader.item?.hovered // https://bugreports.qt.io/browse/QTBUG-108821 0090 onTapped: { 0091 menuItem.clicked() // https://bugreports.qt.io/browse/QTBUG-63395 0092 } 0093 } 0094 0095 DragHandler { 0096 id: dragHandler 0097 enabled: !toolButtonsLoader.item?.hovered 0098 } 0099 } 0100 0101 Item { 0102 id: label 0103 height: childrenRect.height 0104 visible: !menuItem.ListView.isCurrentItem 0105 anchors { 0106 left: parent.left 0107 leftMargin: Math.ceil(Kirigami.Units.gridUnit / 2) - listMargins.left 0108 right: parent.right 0109 rightMargin: Math.ceil(Kirigami.Units.gridUnit / 2) - listMargins.right 0110 verticalCenter: parent.verticalCenter 0111 } 0112 0113 Loader { 0114 width: parent.width 0115 source: ["Text", "Image", "Url"][TypeRole] + "ItemDelegate.qml" 0116 } 0117 } 0118 0119 Loader { 0120 id: toolButtonsLoader 0121 0122 anchors { 0123 right: label.right 0124 verticalCenter: parent.verticalCenter 0125 // This is here because you can't assign to it in AnchorChanges below 0126 topMargin: Math.ceil(Kirigami.Units.gridUnit / 2) - listMargins.top 0127 } 0128 source: "DelegateToolButtons.qml" 0129 active: menuItem.ListView.isCurrentItem 0130 0131 // It's not recommended to change anchors via conditional bindings, use AnchorChanges instead. 0132 // See https://doc.qt.io/qt-5/qtquick-positioning-anchors.html#changing-anchors 0133 states: [ 0134 State { 0135 when: menuItem.isTall 0136 0137 AnchorChanges { 0138 target: toolButtonsLoader 0139 anchors.top: parent.top 0140 anchors.verticalCenter: undefined 0141 } 0142 } 0143 ] 0144 0145 onActiveChanged: { 0146 if (active) { 0147 menuItem.KeyNavigation.tab = toolButtonsLoader.item.children[0] 0148 menuItem.KeyNavigation.right = toolButtonsLoader.item.children[0] 0149 // break binding, once it was loaded, never unload 0150 active = true; 0151 } 0152 } 0153 } 0154 }