forked from papyros/qml-material
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTextFieldStyle.qml
More file actions
167 lines (143 loc) · 5.72 KB
/
Copy pathTextFieldStyle.qml
File metadata and controls
167 lines (143 loc) · 5.72 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
/*
* QML Material - An application framework implementing Material Design.
*
* Copyright (C) 2015-2016 Michael Spencer <sonrisesoftware@gmail.com>
* 2015 Ricardo Vieira <ricardo.vieira@tecnico.ulisboa.pt>
*
* 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 QtQuick.Controls.Styles 1.3
import QtQuick.Layouts 1.1
import Material 0.3
TextFieldStyle {
id: style
padding {
left: 0
right: 0
top: 0
bottom: 0
}
font {
family: echoMode == TextInput.Password ? "Default" : "Roboto"
pixelSize: 16 * Units.dp
}
renderType: Text.QtRendering
placeholderTextColor: "transparent"
selectedTextColor: "white"
selectionColor: control.hasOwnProperty("color") ? control.color : Theme.accentColor
textColor: Theme.light.textColor
background : Item {
id: background
property color color: control.hasOwnProperty("color") ? control.color : Theme.accentColor
property color errorColor: control.hasOwnProperty("errorColor")
? control.errorColor : Palette.colors["red"]["500"]
property string helperText: control.hasOwnProperty("helperText") ? control.helperText : ""
property bool floatingLabel: control.hasOwnProperty("floatingLabel") ? control.floatingLabel : ""
property bool hasError: control.hasOwnProperty("hasError")
? control.hasError : characterLimit && control.length > characterLimit
property int characterLimit: control.hasOwnProperty("characterLimit") ? control.characterLimit : 0
property bool showBorder: control.hasOwnProperty("showBorder") ? control.showBorder : true
Rectangle {
id: underline
color: background.hasError ? background.errorColor
: control.activeFocus ? background.color
: Theme.light.hintColor
height: control.activeFocus ? 2 * Units.dp : 1 * Units.dp
visible: background.showBorder
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
}
Behavior on height {
NumberAnimation { duration: 200 }
}
Behavior on color {
ColorAnimation { duration: 200 }
}
}
Label {
id: fieldPlaceholder
anchors.verticalCenter: parent.verticalCenter
text: control.placeholderText
font.pixelSize: 16 * Units.dp
anchors.margins: -12 * Units.dp
color: background.hasError ? background.errorColor
: control.activeFocus && control.text !== ""
? background.color : Theme.light.hintColor
states: [
State {
name: "floating"
when: control.displayText.length > 0 && background.floatingLabel
AnchorChanges {
target: fieldPlaceholder
anchors.verticalCenter: undefined
anchors.top: parent.top
}
PropertyChanges {
target: fieldPlaceholder
font.pixelSize: 12 * Units.dp
}
},
State {
name: "hidden"
when: control.displayText.length > 0 && !background.floatingLabel
PropertyChanges {
target: fieldPlaceholder
visible: false
}
}
]
transitions: [
Transition {
id: floatingTransition
enabled: false
AnchorAnimation {
duration: 200
}
NumberAnimation {
duration: 200
property: "font.pixelSize"
}
}
]
Component.onCompleted: floatingTransition.enabled = true
}
RowLayout {
anchors {
left: parent.left
right: parent.right
top: underline.top
topMargin: 4 * Units.dp
}
Label {
id: helperTextLabel
visible: background.helperText && background.showBorder
text: background.helperText
font.pixelSize: 12 * Units.dp
color: background.hasError ? background.errorColor
: Qt.darker(Theme.light.hintColor)
Behavior on color {
ColorAnimation { duration: 200 }
}
property string helperText: control.hasOwnProperty("helperText")
? control.helperText : ""
}
Label {
id: charLimitLabel
Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
visible: background.characterLimit && background.showBorder
text: control.length + " / " + background.characterLimit
font.pixelSize: 12 * Units.dp
color: background.hasError ? background.errorColor : Theme.light.hintColor
horizontalAlignment: Text.AlignLeft
Behavior on color {
ColorAnimation { duration: 200 }
}
}
}
}
}