Warning, /maui/nomad-style/ScrollBar.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * Copyright 2017 Marco Martin <mart@kde.org>
0003  * Copyright 2017 The Qt Company Ltd.
0004  *
0005  * GNU Lesser General Public License Usage
0006  * Alternatively, this file may be used under the terms of the GNU Lesser
0007  * General Public License version 3 as published by the Free Software
0008  * Foundation and appearing in the file LICENSE.LGPLv3 included in the
0009  * packaging of this file. Please review the following information to
0010  * ensure the GNU Lesser General Public License version 3 requirements
0011  * will be met: https://www.gnu.org/licenses/lgpl.html.
0012  *
0013  * GNU General Public License Usage
0014  * Alternatively, this file may be used under the terms of the GNU
0015  * General Public License version 2.0 or later as published by the Free
0016  * Software Foundation and appearing in the file LICENSE.GPL included in
0017  * the packaging of this file. Please review the following information to
0018  * ensure the GNU General Public License version 2.0 requirements will be
0019  * met: http://www.gnu.org/licenses/gpl-2.0.html.
0020  */
0021 
0022 
0023 import QtQuick 2.6
0024 import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate
0025 import QtQuick.Templates 2.3 as T
0026 import org.kde.kirigami 2.2 as Kirigami
0027 
0028 T.ScrollBar {
0029     id: controlRoot
0030 
0031     implicitWidth: background.implicitWidth
0032     implicitHeight: background.implicitHeight
0033 
0034     hoverEnabled: true
0035 
0036     visible: controlRoot.size < 1.0
0037 
0038     background: MouseArea {
0039         id: mouseArea
0040         anchors.fill: parent
0041         visible: controlRoot.size < 1.0
0042         hoverEnabled: true
0043         state: "inactive"
0044         onPositionChanged: style.activeControl = style.hitTest(mouse.x, mouse.y)
0045         onExited: style.activeControl = "groove";
0046         onPressed: {
0047             if (style.activeControl == "down") {
0048                 buttonTimer.increment = 0.02;
0049                 buttonTimer.running = true;
0050                 mouse.accepted = true
0051             } else if (style.activeControl == "up") {
0052                 buttonTimer.increment = -0.02;
0053                 buttonTimer.running = true;
0054                 mouse.accepted = true
0055             } else {
0056                 mouse.accepted = false
0057             }
0058         }
0059         onReleased: {
0060             buttonTimer.running = false;
0061             mouse.accepted = false
0062         }
0063         onCanceled: buttonTimer.running = false;
0064 
0065         implicitWidth: style.horizontal ? 200 : style.pixelMetric("scrollbarExtent")
0066         implicitHeight: style.horizontal ? style.pixelMetric("scrollbarExtent") : 200
0067 
0068         StylePrivate.StyleItem {
0069             id: style
0070             control: controlRoot
0071             anchors.fill: parent
0072             elementType: "scrollbar"
0073             hover: activeControl != "none"
0074             activeControl: "none"
0075             sunken: controlRoot.pressed
0076             minimum: 0
0077             maximum: (controlRoot.height/controlRoot.size - controlRoot.height)
0078             value: controlRoot.position * (controlRoot.height/controlRoot.size)
0079             horizontal: controlRoot.orientation == Qt.Horizontal
0080             enabled: controlRoot.enabled
0081 
0082             visible: controlRoot.size < 1.0
0083             opacity: 1
0084 
0085             Timer {
0086                 id: buttonTimer
0087                 property real increment
0088                 repeat: true
0089                 interval: 150
0090                 onTriggered: {
0091                     controlRoot.position += increment;
0092                 }
0093             }
0094         }
0095         StylePrivate.StyleItem {
0096             id: inactiveStyle
0097             anchors.fill: parent
0098             control: controlRoot
0099             elementType: "scrollbar"
0100             activeControl: "none"
0101             sunken: false
0102             minimum: 0
0103             maximum: style.maximum
0104             value: style.value
0105             horizontal: style.horizontal
0106             enabled: controlRoot.enabled
0107 
0108             visible: controlRoot.size < 1.0
0109             opacity: 1
0110         }
0111         states: [
0112             State {
0113                 name: "hover"
0114                 when: mouseArea.containsMouse
0115                 PropertyChanges {
0116                     target: style
0117                     opacity: 1
0118                 }
0119                 PropertyChanges {
0120                     target: inactiveStyle
0121                     opacity: 0
0122                 }
0123             },
0124             State {
0125                 name: "inactive"
0126                 when: !mouseArea.containsMouse
0127                 PropertyChanges {
0128                     target: style
0129                     opacity: 0
0130                 }
0131                 PropertyChanges {
0132                     target: inactiveStyle
0133                     opacity: 1
0134                 }
0135             }
0136         ]
0137         transitions: [
0138             Transition {
0139                 ParallelAnimation {
0140                     NumberAnimation {
0141                         target: style
0142                         property: "opacity"
0143                         duration: Kirigami.Units.shortDuration
0144                         easing.type: Easing.InOutQuad
0145                     }
0146                     NumberAnimation {
0147                         target: inactiveStyle
0148                         property: "opacity"
0149                         duration: Kirigami.Units.shortDuration
0150                         easing.type: Easing.InOutQuad
0151                     }
0152                 }
0153             }
0154         ]
0155     }
0156 
0157     contentItem: Item {}
0158 }