forked from papyros/qml-material
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathView.qml
More file actions
170 lines (141 loc) · 4.6 KB
/
Copy pathView.qml
File metadata and controls
170 lines (141 loc) · 4.6 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* QML Material - An application framework implementing Material Design.
*
* Copyright (C) 2014-2016 Michael Spencer <sonrisesoftware@gmail.com>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import QtQuick 2.4
import QtGraphicalEffects 1.0
import Material 0.3
/*!
\qmltype View
\inqmlmodule Material
\brief Provides a base view component, with support for Material Design elevation,
background colors, and tinting.
*/
Item {
id: item
width: 100
height: 62
property int elevation: 0
property real radius: 0
property string style: "default"
property color backgroundColor: elevation > 0 ? "white" : "transparent"
property color tintColor: "transparent"
property alias border: rect.border
property bool fullWidth
property bool fullHeight
property alias clipContent: rect.clip
default property alias data: rect.data
property bool elevationInverted: false
property var topShadow: [
{
"opacity": 0,
"offset": 0,
"blur": 0
},
{
"opacity": 0.12,
"offset": 1 * Units.dp,
"blur": 1.5 * Units.dp
},
{
"opacity": 0.16,
"offset": 3 * Units.dp,
"blur": 3 * Units.dp
},
{
"opacity": 0.19,
"offset": 10 * Units.dp,
"blur": 10 * Units.dp
},
{
"opacity": 0.25,
"offset": 14 * Units.dp,
"blur": 14 * Units.dp
},
{
"opacity": 0.30,
"offset": 19 * Units.dp,
"blur": 19 * Units.dp
}
]
property var bottomShadow: [
{
"opacity": 0,
"offset": 0 * Units.dp,
"blur": 0 * Units.dp
},
{
"opacity": 0.24,
"offset": 1 * Units.dp,
"blur": 1 * Units.dp
},
{
"opacity": 0.23,
"offset": 3 * Units.dp,
"blur": 3 * Units.dp
},
{
"opacity": 0.23,
"offset": 6 * Units.dp,
"blur": 3 * Units.dp
},
{
"opacity": 0.22,
"offset": 10 * Units.dp,
"blur": 5 * Units.dp
},
{
"opacity": 0.22,
"offset": 15 * Units.dp,
"blur": 6 * Units.dp
}
]
RectangularGlow {
property var elevationInfo: bottomShadow[Math.min(elevation, 5)]
property real horizontalShadowOffset: elevationInfo.offset * Math.sin((2 * Math.PI) * (parent.rotation / 360.0))
property real verticalShadowOffset: elevationInfo.offset * Math.cos((2 * Math.PI) * (parent.rotation / 360.0))
anchors.centerIn: parent
width: parent.width + (fullWidth ? 10 * Units.dp : 0)
height: parent.height + (fullHeight ? 20 * Units.dp : 0)
anchors.horizontalCenterOffset: horizontalShadowOffset * (elevationInverted ? -1 : 1)
anchors.verticalCenterOffset: verticalShadowOffset * (elevationInverted ? -1 : 1)
glowRadius: elevationInfo.blur
opacity: elevationInfo.opacity
spread: 0.05
color: "black"
cornerRadius: item.radius + glowRadius * 2.5
//visible: parent.opacity == 1
}
RectangularGlow {
property var elevationInfo: topShadow[Math.min(elevation, 5)]
property real horizontalShadowOffset: elevationInfo.offset * Math.sin((2 * Math.PI) * (parent.rotation / 360.0))
property real verticalShadowOffset: elevationInfo.offset * Math.cos((2 * Math.PI) * (parent.rotation / 360.0))
anchors.centerIn: parent
width: parent.width + (fullWidth ? 10 * Units.dp : 0)
height: parent.height + (fullHeight ? 20 * Units.dp : 0)
anchors.horizontalCenterOffset: horizontalShadowOffset * (elevationInverted ? -1 : 1)
anchors.verticalCenterOffset: verticalShadowOffset * (elevationInverted ? -1 : 1)
glowRadius: elevationInfo.blur
opacity: elevationInfo.opacity
spread: 0.05
color: "black"
cornerRadius: item.radius + glowRadius * 2.5
//visible: parent.opacity == 1
}
Rectangle {
id: rect
anchors.fill: parent
color: Qt.tint(backgroundColor, tintColor)
radius: item.radius
antialiasing: parent.rotation || radius > 0 ? true : false
clip: true
Behavior on color {
ColorAnimation { duration: 200 }
}
}
}