Warning, /plasma/qqc2-breeze-style/style/impl/MenuItemBackground.qml is written in an unsupported language. File is not indexed.

0001 /* SPDX-FileCopyrightText: 2020 Noah Davis <noahadvs@gmail.com>
0002  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003  */
0004 
0005 import QtQuick
0006 import QtQuick.Templates as T
0007 import org.kde.kirigami as Kirigami
0008 
0009 import "." as Impl
0010 
0011 Loader {
0012     id: root
0013     property T.MenuItem control: root.parent
0014     // God, this code is ugly. Somehow this works, but `control.ListView.view && control.ListView.view.highlight` doesn't.
0015     property bool isInListView: control.ListView.view ?? false
0016     property bool listViewHasHighlight: isInListView && (control.ListView.view.highlight ?? false)
0017 
0018     property color normalColor: control instanceof T.SwipeDelegate ? Kirigami.Theme.backgroundColor
0019         : Qt.rgba(
0020             Kirigami.Theme.backgroundColor.r,
0021             Kirigami.Theme.backgroundColor.g,
0022             Kirigami.Theme.backgroundColor.b,
0023             0
0024         )
0025     property bool highlightBackground: control.down || control.highlighted
0026 
0027     // Rectangle compatibility properties. 3rd party devs might assume that these properties are available.
0028     property color color: {
0029         if (highlightBackground) {
0030             return Kirigami.Theme.alternateBackgroundColor
0031         } else {
0032             return normalColor
0033         }
0034     }
0035     property real radius: Impl.Units.smallRadius
0036     property QtObject border: QtObject {
0037         property real width: highlightBackground ? Impl.Units.smallBorder : 0
0038         property color color: Kirigami.Theme.focusColor
0039     }
0040 
0041     property bool backgroundAnimationRunning: false
0042     property bool borderAnimationRunning: false
0043 
0044     visible: (highlightBackground || backgroundAnimationRunning || borderAnimationRunning) && !listViewHasHighlight
0045     active: visible
0046     sourceComponent: Component {
0047         Kirigami.ShadowedRectangle {
0048             id: mainBackground
0049             readonly property bool isCurrentItem: root.isInListView && control.ListView.isCurrentItem
0050             readonly property int currentIndex: root.isInListView ? control.ListView.view.currentIndex : 0
0051 //             readonly property int count: root.isInListView ? control.ListView.view.count : 0
0052             readonly property bool horizontalListView: root.isInListView && control.ListView.view.orientation === ListView.Horizontal
0053 
0054             implicitHeight: Impl.Units.mediumControlHeight
0055 
0056             radius: root.radius
0057             readonly property real topRadius: !root.isInListView || (isCurrentItem && currentIndex == 0) ? radius : 0
0058             readonly property real bottomRadius: !root.isInListView || (isCurrentItem && currentIndex == control.ListView.view.count-1) ? radius : 0
0059 
0060             corners {
0061                 topLeftRadius: topRadius
0062                 topRightRadius: topRadius
0063                 bottomLeftRadius: bottomRadius
0064                 bottomRightRadius: bottomRadius
0065             }
0066 
0067             color: root.color
0068 
0069             border {
0070                 width: root.border.width
0071                 color: root.border.color
0072             }
0073 
0074             Behavior on color {
0075                 enabled: highlightBackground
0076                 ColorAnimation {
0077                     duration: Kirigami.Units.shortDuration
0078                     easing.type: Easing.OutCubic
0079                     onRunningChanged: root.backgroundAnimationRunning = running
0080                 }
0081             }
0082             Behavior on border.color {
0083                 enabled: highlightBackground
0084                 ColorAnimation {
0085                     duration: Kirigami.Units.shortDuration
0086                     easing.type: Easing.OutCubic
0087                     onRunningChanged: root.borderAnimationRunning = running
0088                 }
0089             }
0090         }
0091     }
0092 }
0093