Changeset View
Changeset View
Standalone View
Standalone View
src/declarativeimports/plasmacomponents3/ScrollBar.qml
Show All 14 Lines | |||||
15 | * License along with this program; if not, write to the | 15 | * License along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | 16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | import QtQuick 2.6 | 20 | import QtQuick 2.6 | ||
21 | import QtQuick.Templates @QQC2_VERSION@ as T | 21 | import QtQuick.Templates @QQC2_VERSION@ as T | ||
22 | import org.kde.plasma.core 2.0 as PlasmaCore | 22 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
23 | import org.kde.kirigami 2.2 as Kirigami | 23 | import org.kde.kirigami 2.10 as Kirigami | ||
24 | 24 | | |||
25 | T.ScrollBar { | 25 | T.ScrollBar { | ||
26 | id: control | 26 | id: controlRoot | ||
27 | 27 | | |||
28 | implicitWidth: background.implicitWidth | 28 | implicitWidth: background.implicitWidth | ||
29 | implicitHeight: background.implicitHeight | 29 | implicitHeight: background.implicitHeight | ||
30 | 30 | | |||
31 | hoverEnabled: !Kirigami.Settings.isMobile | 31 | hoverEnabled: !Kirigami.Settings.isMobile | ||
32 | 32 | | |||
33 | visible: control.size < 1.0 | 33 | visible: controlRoot.size < 1.0 | ||
34 | 34 | | |||
35 | background: PlasmaCore.FrameSvgItem { | 35 | interactive: !Kirigami.Settings.tabletMode | ||
36 | imagePath:"widgets/scrollbar" | 36 | | ||
37 | background: Item { | ||||
38 | visible: controlRoot.size < 1.0 && controlRoot.interactive | ||||
37 | implicitWidth: scrollbarSvg.elementSize("hint-scrollbar-size").width | 39 | implicitWidth: scrollbarSvg.elementSize("hint-scrollbar-size").width | ||
38 | implicitHeight: implicitWidth | 40 | implicitHeight: implicitWidth | ||
41 | Rectangle { | ||||
42 | anchors { | ||||
43 | top: parent.top | ||||
44 | bottom: parent.bottom | ||||
45 | left: parent.left | ||||
46 | } | ||||
47 | visible: typeof plasmoid === "undefined" | ||||
48 | width: units.devicePixelRatio | ||||
49 | color: PlasmaCore.ColorScope.textColor | ||||
50 | opacity: 0.1 | ||||
51 | } | ||||
52 | PlasmaCore.FrameSvgItem { | ||||
53 | anchors.fill: parent | ||||
54 | imagePath:"widgets/scrollbar" | ||||
39 | colorGroup: PlasmaCore.ColorScope.colorGroup | 55 | colorGroup: PlasmaCore.ColorScope.colorGroup | ||
40 | visible: control.size < 1.0 | | |||
41 | 56 | | |||
42 | prefix: control.horizontal ? "background-horizontal" : "background-vertical" | 57 | prefix: controlRoot.horizontal ? "background-horizontal" : "background-vertical" | ||
43 | opacity: Kirigami.Settings.isMobile ? (control.active ? 1 : 0) : (control.hovered ? 1 : 0) | 58 | opacity: controlRoot.hovered | ||
44 | Behavior on opacity { | 59 | Behavior on opacity { | ||
45 | OpacityAnimator { | 60 | OpacityAnimator { | ||
46 | duration: units.longDuration | 61 | duration: units.longDuration | ||
47 | } | 62 | } | ||
48 | } | 63 | } | ||
49 | } | 64 | } | ||
65 | } | ||||
66 | | ||||
67 | onPositionChanged: { | ||||
68 | disappearTimer.restart(); | ||||
69 | handleGraphics.handleState = Math.min(1, handleGraphics.handleState + 0.1) | ||||
70 | } | ||||
50 | 71 | | |||
51 | contentItem: PlasmaCore.FrameSvgItem { | 72 | contentItem: Item { | ||
73 | PlasmaCore.FrameSvgItem { | ||||
74 | anchors.fill: parent | ||||
52 | imagePath:"widgets/scrollbar" | 75 | imagePath:"widgets/scrollbar" | ||
76 | | ||||
53 | implicitWidth: scrollbarSvg.elementSize("hint-scrollbar-size").width | 77 | implicitWidth: scrollbarSvg.elementSize("hint-scrollbar-size").width | ||
78 | visible: controlRoot.interactive && controlRoot.size < 1.0 | ||||
54 | implicitHeight: implicitWidth | 79 | implicitHeight: implicitWidth | ||
55 | colorGroup: PlasmaCore.ColorScope.colorGroup | 80 | colorGroup: PlasmaCore.ColorScope.colorGroup | ||
56 | visible: control.size < 1.0 | | |||
57 | 81 | | |||
58 | prefix: control.hovered ? "mouseover-slider" : "slider" | 82 | prefix: controlRoot.hovered ? "mouseover-slider" : "slider" | ||
59 | opacity: Kirigami.Settings.isMobile ? (control.active ? 1 : 0) : 1 | 83 | } | ||
60 | Behavior on opacity { | 84 | Rectangle { | ||
61 | OpacityAnimator { | 85 | id: handleGraphics | ||
62 | duration: units.longDuration | 86 | | ||
87 | property real handleState: 0 | ||||
88 | | ||||
89 | visible: !controlRoot.interactive | ||||
90 | x: controlRoot.orientation == Qt.Vertical | ||||
davidedmundson: Math.round? | |||||
91 | ? (parent.width - width) - (parent.width/2 - width/2) * handleState | ||||
92 | : 0 | ||||
93 | | ||||
94 | y: controlRoot.orientation == Qt.Horizontal | ||||
davidedmundson: Math.round | |||||
95 | ? (parent.height - height) - (parent.height/2 - height/2) * handleState | ||||
96 | : 0 | ||||
97 | | ||||
98 | NumberAnimation { | ||||
99 | id: resetAnim | ||||
100 | target: handleGraphics | ||||
101 | property: "handleState" | ||||
102 | from: handleGraphics.handleState | ||||
103 | to: 0 | ||||
104 | duration: Kirigami.Units.longDuration | ||||
105 | easing.type: Easing.InOutQuad | ||||
106 | } | ||||
107 | | ||||
108 | width: Math.round(controlRoot.orientation == Qt.Vertical | ||||
109 | ? Math.max(2, Kirigami.Units.smallSpacing * handleState) | ||||
110 | : parent.width) | ||||
111 | height: Math.round(controlRoot.orientation == Qt.Horizontal | ||||
112 | ? Math.max(2, Kirigami.Units.smallSpacing * handleState) | ||||
113 | : parent.height) | ||||
114 | radius: Math.min(width, height) | ||||
115 | color: PlasmaCore.ColorScope.textColor | ||||
116 | opacity: 0.3 | ||||
117 | Timer { | ||||
118 | id: disappearTimer | ||||
119 | interval: 1000 | ||||
120 | onTriggered: { | ||||
121 | resetAnim.restart(); | ||||
122 | handleGraphics.handleState = 0; | ||||
123 | } | ||||
63 | } | 124 | } | ||
64 | } | 125 | } | ||
65 | } | 126 | } | ||
66 | 127 | | |||
67 | PlasmaCore.Svg { | 128 | PlasmaCore.Svg { | ||
68 | id: scrollbarSvg | 129 | id: scrollbarSvg | ||
69 | imagePath: "widgets/scrollbar" | 130 | imagePath: "widgets/scrollbar" | ||
70 | //TODO: support arrows? | 131 | //TODO: support arrows? | ||
71 | property bool arrowPresent: scrollbarSvg.hasElement("arrow-up") | 132 | property bool arrowPresent: scrollbarSvg.hasElement("arrow-up") | ||
72 | //new theme may be different | 133 | //new theme may be different | ||
73 | onRepaintNeeded: arrowPresent = scrollbarSvg.hasElement("arrow-up") | 134 | onRepaintNeeded: arrowPresent = scrollbarSvg.hasElement("arrow-up") | ||
74 | } | 135 | } | ||
75 | } | 136 | } |
Math.round?