Warning, /frameworks/qqc2-desktop-style/org.kde.desktop/private/DefaultListItemBackground.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2017 Marco Martin <mart@kde.org>
0003     SPDX-FileCopyrightText: 2017 The Qt Company Ltd.
0004     SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
0005 
0006     SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-or-later
0007 */
0008 
0009 
0010 import QtQuick
0011 import QtQuick.Templates as T
0012 import org.kde.kirigami as Kirigami
0013 
0014 Rectangle {
0015     id: background
0016 
0017     property T.ItemDelegate control
0018 
0019     readonly property bool highlight: control.highlighted || control.down
0020     readonly property bool useAlternatingColors: {
0021         if (control.TableView.view?.alternatingRows && row % 2) {
0022             return true
0023         } else if (control.Kirigami.Theme.useAlternateBackgroundColor && index % 2) {
0024             return true
0025         }
0026         return false
0027     }
0028 
0029     readonly property color hoverColor: Qt.alpha(Kirigami.Theme.hoverColor, 0.3)
0030     readonly property color highlightColor: Kirigami.Theme.highlightColor
0031     readonly property color normalColor: useAlternatingColors ? Kirigami.Theme.alternateBackgroundColor : "transparent"
0032     // Workaround for QTBUG-113304
0033     readonly property bool reallyFocus: control.visualFocus || (control.activeFocus && control.focusReason === Qt.OtherFocusReason)
0034 
0035     property real horizontalPadding: control.TableView.view ? 0 : Kirigami.Units.smallSpacing
0036     property real verticalPadding: control.TableView.view ? 0 : Kirigami.Units.smallSpacing
0037     property real cornerRadius: control.TableView.view ? 0 : 3
0038 
0039     color: normalColor
0040 
0041     Rectangle {
0042         anchors {
0043             fill: parent
0044             leftMargin: background.horizontalPadding
0045             rightMargin: background.horizontalPadding
0046             // We want total spacing between consecutive list items to be
0047             // verticalPadding. So use half that as top/bottom margin, separately
0048             // ceiling/flooring them so that the total spacing is preserved.
0049             topMargin: Math.ceil(background.verticalPadding / 2)
0050             bottomMargin: Math.floor(background.verticalPadding / 2)
0051         }
0052 
0053         radius: background.cornerRadius
0054 
0055         color: {
0056             if (background.highlight) {
0057                 return background.highlightColor
0058             } else {
0059                 return (background.control.hovered || background.reallyFocus) ? background.hoverColor : background.normalColor
0060             }
0061         }
0062 
0063         border.width: 1
0064         border.color: {
0065             if (background.highlight) {
0066                 return background.highlightColor
0067             } else {
0068                 return (background.control.hovered || background.reallyFocus) ? Kirigami.Theme.hoverColor : "transparent"
0069             }
0070         }
0071     }
0072 }