Warning, /frameworks/qqc2-desktop-style/org.kde.desktop/ScrollView.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 2.9
0011 import QtQuick.Controls 2.15
0012 import QtQuick.Templates 2.15 as T
0013 import org.kde.kirigami 2.9 as Kirigami
0014 import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate
0015 
0016 T.ScrollView {
0017     id: controlRoot
0018 
0019     clip: true
0020 
0021     implicitWidth: Math.max(background ? background.implicitWidth : 0, contentWidth + leftPadding + rightPadding)
0022     implicitHeight: Math.max(background ? background.implicitHeight : 0, contentHeight + topPadding + bottomPadding)
0023 
0024     Kirigami.Theme.colorSet: Kirigami.Theme.View
0025     Kirigami.Theme.inherit: !background || !background.visible
0026 
0027     //size in pixel to accommodate the border drawn by qstyle
0028     topPadding: internal.backgroundVisible() && background.hasOwnProperty("topPadding") ? background.topPadding : 0
0029     leftPadding: (internal.backgroundVisible() && background.hasOwnProperty("leftPadding") ? background.leftPadding : 0)
0030                     + (mirrored ? internal.verticalScrollBarWidth : 0)
0031     rightPadding: (internal.backgroundVisible() && background.hasOwnProperty("rightPadding") ? background.rightPadding : 0)
0032                     + (!mirrored ? internal.verticalScrollBarWidth : 0)
0033     bottomPadding: (internal.backgroundVisible() && background.hasOwnProperty("bottomPadding") ? background.bottomPadding : 0)
0034                     + internal.horizontalScrollBarHeight
0035 
0036     //create a background only after Component.onCompleted, see on the component creation below for explanation
0037     Component.onCompleted: {
0038         if (!controlRoot.background) {
0039             controlRoot.background = backgroundComponent.createObject(controlRoot);
0040         }
0041     }
0042 
0043     data: [
0044         Kirigami.WheelHandler {
0045             target: controlRoot.contentItem
0046         },
0047         // create a background only after Component.onCompleted because:
0048         // implementations can set their own background in a declarative way.
0049         // ScrollView {background.visible: true} must *not* work, because all
0050         // upstream styles don't have a background so applications using this
0051         // would break with other styles.
0052         Component {
0053             id: backgroundComponent
0054             StylePrivate.StyleItem {
0055                 id: styled
0056                 control: controlRoot.contentItem
0057                 elementType: "frame"
0058                 visible: false
0059                 sunken: true
0060                 raised: false
0061                 enabled: controlRoot.contentItem.enabled
0062                 hasFocus: controlRoot.activeFocus || controlRoot.contentItem.activeFocus
0063                 hover: controlRoot.hovered
0064             }
0065         },
0066 
0067         QtObject {
0068             id: internal
0069 
0070             // Unlike bindings with non-deterministic order of propagation,
0071             // calling function will ensure that values are fresh (fetched at
0072             // the time of call) and also QML Engine will still subscribe to
0073             // the accessed properties regardless, making it safe & correct
0074             // way to factor out sub-expressions.
0075             function backgroundVisible() {
0076                 return controlRoot.background && controlRoot.background.visible;
0077             }
0078             readonly property real verticalScrollBarWidth: controlRoot.ScrollBar.vertical.visible && controlRoot.ScrollBar.vertical.interactive ? controlRoot.ScrollBar.vertical.width : 0
0079             readonly property real horizontalScrollBarHeight: controlRoot.ScrollBar.horizontal.visible && controlRoot.ScrollBar.vertical.interactive ? controlRoot.ScrollBar.horizontal.height : 0
0080         }
0081     ]
0082 
0083     ScrollBar.vertical: ScrollBar {
0084         parent: controlRoot
0085         z: 1
0086         x: controlRoot.mirrored
0087             ? (internal.backgroundVisible() && controlRoot.background.hasOwnProperty("leftPadding") ? controlRoot.background.leftPadding : 0)
0088             : controlRoot.width - width - (internal.backgroundVisible() && controlRoot.background.hasOwnProperty("rightPadding") ? controlRoot.background.rightPadding : 0)
0089         y: controlRoot.topPadding
0090         height: controlRoot.availableHeight
0091         active: controlRoot.ScrollBar.horizontal.active
0092     }
0093 
0094     ScrollBar.horizontal: ScrollBar {
0095         parent: controlRoot
0096         z: 1
0097         x: controlRoot.leftPadding
0098         y: controlRoot.height - height - (internal.backgroundVisible() && controlRoot.background.hasOwnProperty("bottomPadding") ? controlRoot.background.bottomPadding : 0)
0099         width: controlRoot.availableWidth
0100         active: controlRoot.ScrollBar.vertical.active
0101     }
0102 }