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 | // the separator line doesn't work yet with the plasmoids design | ||||
48 | visible: typeof plasmoid === "undefined" | ||||
49 | width: units.devicePixelRatio | ||||
50 | color: PlasmaCore.ColorScope.textColor | ||||
51 | opacity: 0.1 | ||||
52 | } | ||||
53 | PlasmaCore.FrameSvgItem { | ||||
54 | anchors.fill: parent | ||||
55 | imagePath:"widgets/scrollbar" | ||||
39 | colorGroup: PlasmaCore.ColorScope.colorGroup | 56 | colorGroup: PlasmaCore.ColorScope.colorGroup | ||
40 | visible: control.size < 1.0 | | |||
41 | 57 | | |||
42 | prefix: control.horizontal ? "background-horizontal" : "background-vertical" | 58 | prefix: controlRoot.horizontal ? "background-horizontal" : "background-vertical" | ||
43 | opacity: Kirigami.Settings.isMobile ? (control.active ? 1 : 0) : (control.hovered ? 1 : 0) | 59 | opacity: controlRoot.hovered | ||
44 | Behavior on opacity { | 60 | Behavior on opacity { | ||
45 | OpacityAnimator { | 61 | OpacityAnimator { | ||
46 | duration: units.longDuration | 62 | duration: units.longDuration | ||
47 | } | 63 | } | ||
48 | } | 64 | } | ||
49 | } | 65 | } | ||
66 | } | ||||
67 | | ||||
68 | onPositionChanged: { | ||||
69 | disappearTimer.restart(); | ||||
70 | handleGraphics.handleState = Math.min(1, handleGraphics.handleState + 0.1) | ||||
71 | } | ||||
50 | 72 | | |||
51 | contentItem: PlasmaCore.FrameSvgItem { | 73 | contentItem: Item { | ||
74 | PlasmaCore.FrameSvgItem { | ||||
75 | anchors.fill: parent | ||||
52 | imagePath:"widgets/scrollbar" | 76 | imagePath:"widgets/scrollbar" | ||
77 | | ||||
53 | implicitWidth: scrollbarSvg.elementSize("hint-scrollbar-size").width | 78 | implicitWidth: scrollbarSvg.elementSize("hint-scrollbar-size").width | ||
79 | visible: controlRoot.interactive && controlRoot.size < 1.0 | ||||
54 | implicitHeight: implicitWidth | 80 | implicitHeight: implicitWidth | ||
55 | colorGroup: PlasmaCore.ColorScope.colorGroup | 81 | colorGroup: PlasmaCore.ColorScope.colorGroup | ||
56 | visible: control.size < 1.0 | | |||
57 | 82 | | |||
58 | prefix: control.hovered ? "mouseover-slider" : "slider" | 83 | prefix: controlRoot.hovered ? "mouseover-slider" : "slider" | ||
59 | opacity: Kirigami.Settings.isMobile ? (control.active ? 1 : 0) : 1 | 84 | } | ||
60 | Behavior on opacity { | 85 | Rectangle { | ||
61 | OpacityAnimator { | 86 | id: handleGraphics | ||
62 | duration: units.longDuration | 87 | | ||
88 | property real handleState: 0 | ||||
89 | | ||||
90 | visible: !controlRoot.interactive | ||||
91 | x: Math.round(controlRoot.orientation == Qt.Vertical | ||||
davidedmundson: Math.round? | |||||
92 | ? (parent.width - width) - (parent.width/2 - width/2) * handleState | ||||
93 | : 0) | ||||
94 | | ||||
95 | y: Math.round(controlRoot.orientation == Qt.Horizontal | ||||
davidedmundson: Math.round | |||||
96 | ? (parent.height - height) - (parent.height/2 - height/2) * handleState | ||||
97 | : 0) | ||||
98 | | ||||
99 | NumberAnimation { | ||||
100 | id: resetAnim | ||||
101 | target: handleGraphics | ||||
102 | property: "handleState" | ||||
103 | from: handleGraphics.handleState | ||||
104 | to: 0 | ||||
105 | duration: Kirigami.Units.longDuration | ||||
106 | easing.type: Easing.InOutQuad | ||||
107 | } | ||||
108 | | ||||
109 | width: Math.round(controlRoot.orientation == Qt.Vertical | ||||
110 | ? Math.max(2, Kirigami.Units.smallSpacing * handleState) | ||||
111 | : parent.width) | ||||
112 | height: Math.round(controlRoot.orientation == Qt.Horizontal | ||||
113 | ? Math.max(2, Kirigami.Units.smallSpacing * handleState) | ||||
114 | : parent.height) | ||||
115 | radius: Math.min(width, height) | ||||
116 | color: PlasmaCore.ColorScope.textColor | ||||
117 | opacity: 0.3 | ||||
118 | Timer { | ||||
119 | id: disappearTimer | ||||
120 | interval: 1000 | ||||
121 | onTriggered: { | ||||
122 | resetAnim.restart(); | ||||
123 | handleGraphics.handleState = 0; | ||||
124 | } | ||||
63 | } | 125 | } | ||
64 | } | 126 | } | ||
65 | } | 127 | } | ||
66 | 128 | | |||
67 | PlasmaCore.Svg { | 129 | PlasmaCore.Svg { | ||
68 | id: scrollbarSvg | 130 | id: scrollbarSvg | ||
69 | imagePath: "widgets/scrollbar" | 131 | imagePath: "widgets/scrollbar" | ||
70 | //TODO: support arrows? | 132 | //TODO: support arrows? | ||
71 | property bool arrowPresent: scrollbarSvg.hasElement("arrow-up") | 133 | property bool arrowPresent: scrollbarSvg.hasElement("arrow-up") | ||
72 | //new theme may be different | 134 | //new theme may be different | ||
73 | onRepaintNeeded: arrowPresent = scrollbarSvg.hasElement("arrow-up") | 135 | onRepaintNeeded: arrowPresent = scrollbarSvg.hasElement("arrow-up") | ||
74 | } | 136 | } | ||
75 | } | 137 | } |
Math.round?