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
0011 import QtQuick.Controls
0012 import QtQuick.Templates as T
0013 import org.kde.kirigami as Kirigami
0014 import org.kde.qqc2desktopstyle.private as StylePrivate
0015 
0016 T.ScrollView {
0017     id: controlRoot
0018 
0019     implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
0020                             contentWidth + leftPadding + rightPadding)
0021     implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
0022                              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: controlRoot.background?.visible ? (background.topPadding ?? 0) : 0
0029     leftPadding: (controlRoot.background?.visible ? (background.leftPadding ?? 0) : 0)
0030                     + (mirrored ? internal.verticalScrollBarWidth : 0)
0031     rightPadding: (controlRoot.background?.visible ? (background.rightPadding ?? 0) : 0)
0032                     + (!mirrored ? internal.verticalScrollBarWidth : 0)
0033     bottomPadding: (controlRoot.background?.visible ? (background.bottomPadding ?? 0) : 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
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             readonly property real verticalScrollBarWidth: controlRoot.ScrollBar.vertical.visible && controlRoot.ScrollBar.vertical.interactive ? controlRoot.ScrollBar.vertical.width : 0
0071             readonly property real horizontalScrollBarHeight: controlRoot.ScrollBar.horizontal.visible && controlRoot.ScrollBar.vertical.interactive ? controlRoot.ScrollBar.horizontal.height : 0
0072         }
0073     ]
0074 
0075     ScrollBar.vertical: ScrollBar {
0076         parent: controlRoot
0077         z: 1
0078         x: controlRoot.mirrored
0079             ? (controlRoot.background?.visible ? (controlRoot.background.leftPadding ?? 0) : 0)
0080             : controlRoot.width - width - (controlRoot.background?.visible ? (controlRoot.background.rightPadding ?? 0) : 0)
0081         y: controlRoot.topPadding
0082         height: controlRoot.availableHeight
0083         active: controlRoot.ScrollBar.horizontal.active
0084     }
0085 
0086     ScrollBar.horizontal: ScrollBar {
0087         parent: controlRoot
0088         z: 1
0089         x: controlRoot.leftPadding
0090         y: controlRoot.height - height - (controlRoot.background?.visible ? (controlRoot.background.bottomPadding ?? 0) : 0)
0091         width: controlRoot.availableWidth
0092         active: controlRoot.ScrollBar.vertical.active
0093     }
0094 }