Debian Codegraph @

src/app/qml/components/ResizeableSidebar.qml

raw
1 /*
2 * Copyright (C) 2015, 2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18 import Lomiri.Components 1.3
19
20 Item {
21 id: resizeableSidebar
22
23 /* Remember to set left or right anchor */
24 anchors { top: parent.top; bottom: parent.bottom }
25
26 property int minimumWidth: units.gu(20)
27 property int maximumWidth: units.gu(40)
28
29 readonly property bool resizing: resizerSensing.pressed
30
31 width: units.gu(20)
32
33 Rectangle {
34 id: verticalDivider
35 anchors {
36 top: parent.top
37 bottom: parent.bottom
38 right: resizeableSidebar.anchors.left ? parent.right : undefined
39 left: resizeableSidebar.anchors.left ? undefined : parent.left
40 }
41 width: units.dp(1)
42 color: theme.palette.normal.base
43
44 // Stay above the sidebar content
45 z: 10
46
47 MouseArea {
48 id: resizerSensing
49 objectName: "Divider"
50 enabled: verticalDivider.width > 0
51 anchors {
52 fill: parent
53 leftMargin: enabled ? -units.gu(1) : 0
54 rightMargin: enabled ? -units.gu(1) : 0
55 }
56 cursorShape: Qt.SizeHorCursor
57 drag {
58 axis: Drag.XAxis
59 target: resizer
60 smoothed: false
61 minimumX: resizeableSidebar.minimumWidth
62 maximumX: resizeableSidebar.maximumWidth
63 }
64 onPressed: resizer.x = resizeableSidebar.width
65 }
66 states: State {
67 name: "active"
68 when: resizerSensing.pressed || resizerSensing.containsMouse
69 PropertyChanges {
70 target: verticalDivider
71 color: Qt.darker(theme.palette.normal.background, 1.5)
72 }
73 }
74 transitions: Transition {
75 from: ""
76 to: "*"
77 reversible: true
78 ColorAnimation {
79 target: verticalDivider
80 property: "color"
81 duration: LomiriAnimation.SlowDuration
82 }
83 }
84 }
85 Item {
86 id: resizer
87 height: parent.height
88 onXChanged: resizeableSidebar.width = x
89 }
90
91 VerticalDivider {
92 anchors {
93 top: parent.top
94 bottom: parent.bottom
95 right: parent.right
96 }
97 }
98 }