aboutsummaryrefslogtreecommitdiffstats
path: root/src/labs/stylekit/ScrollView.qml
blob: 4c633059c42722821779e7a92895f45b753cb1ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Qt-Security score:significant reason:default

import QtQuick
import QtQuick.Templates as T
import Qt.labs.StyleKit
import Qt.labs.StyleKit.impl

T.ScrollView {
    id: control

    implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
                            implicitContentWidth + leftPadding + rightPadding)
    implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
                             implicitContentHeight + topPadding + bottomPadding)

    // rightPadding and bottomPadding are used to make space for the scrollBars
    // but because we're setting them explicitly here, there will be no effect
    // if the user assign a value to the padding property, so we accumulate it
    // with the scrollbar width and height
    rightPadding: effectiveScrollBarWidth + __styleReader.rightPadding
    bottomPadding: effectiveScrollBarHeight + __styleReader.bottomPadding
    topPadding: __styleReader.topPadding
    leftPadding: __styleReader.leftPadding

    StyleKitControl.controlType: __styleReader.type
    property StyleKitReader __styleReader: StyleKitReader {
        type: StyleKitReader.ScrollView
        enabled: control.enabled
        focused: control.activeFocus
        hovered: control.hovered
        palette: control.palette
    }

    // ScrollView has no styling, but we anyway need to subclass it
    // and attach the scrollbars, in order to use the ones defined
    // in the StyleKit module.
    ScrollBar.vertical: ScrollBar {
        parent: control
        x: control.mirrored ? 0 : control.width - width
        y: control.topPadding
        height: control.availableHeight
        active: control.ScrollBar.horizontal.active
    }

    ScrollBar.horizontal: ScrollBar {
        parent: control
        x: control.leftPadding
        y: control.height - height
        width: control.availableWidth
        active: control.ScrollBar.vertical.active
    }
}