blob: 74cacf3382a8cb4d29b0ced18cdaa44b0c876624 (
plain) (
blame)
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import im.nheko 1.0
ColumnLayout {
id: c
property color backgroundColor: Nheko.colors.base
property alias color: labelC.color
property alias textPadding: input.padding
property alias text: input.text
property alias label: labelC.text
property alias placeholderText: input.placeholderText
property alias font: input.font
property alias echoMode: input.echoMode
property alias selectByMouse: input.selectByMouse
property var hasClear: false
Timer {
id: timer
interval: 350
onTriggered: editingFinished()
}
onTextChanged: timer.restart()
signal textEdited
signal accepted
signal editingFinished
function forceActiveFocus() {
input.forceActiveFocus();
}
function clear() {
input.clear();
}
ToolTip.delay: Nheko.tooltipDelay
ToolTip.visible: hover.hovered
spacing: 0
Item {
Layout.fillWidth: true
Layout.preferredHeight: labelC.contentHeight
Layout.margins: input.padding
Layout.bottomMargin: Nheko.paddingSmall
visible: labelC.text
z: 1
Label {
id: labelC
y: contentHeight + input.padding + Nheko.paddingSmall
enabled: false
palette: Nheko.colors
color: Nheko.colors.text
font.pixelSize: input.font.pixelSize
font.weight: Font.DemiBold
font.letterSpacing: input.font.pixelSize * 0.02
width: parent.width
state: labelC.text && (input.activeFocus == true || input.text) ? "focused" : ""
states: State {
name: "focused"
PropertyChanges {
target: labelC
y: 0
}
PropertyChanges {
target: input
opacity: 1
}
}
transitions: Transition {
from: ""
to: "focused"
reversible: true
NumberAnimation {
target: labelC
properties: "y"
duration: 210
easing.type: Easing.InCubic
alwaysRunToEnd: true
}
NumberAnimation {
target: input
properties: "opacity"
duration: 210
easing.type: Easing.InCubic
alwaysRunToEnd: true
}
}
}
}
TextField {
id: input
Layout.fillWidth: true
palette: Nheko.colors
color: labelC.color
opacity: labelC.text ? 0 : 1
focus: true
onTextEdited: c.textEdited()
onAccepted: c.accepted()
onEditingFinished: c.editingFinished()
background: Rectangle {
id: backgroundRect
color: labelC.text ? "transparent" : backgroundColor
}
ImageButton {
id: clearText
visible: c.hasClear && searchField.text !== ''
image: ":/icons/icons/ui/round-remove-button.svg"
focusPolicy: Qt.NoFocus
onClicked: {
searchField.clear()
topBar.searchString = "";
}
hoverEnabled: true
anchors {
top: parent.top
bottom: parent.bottom
right: parent.right
rightMargin: Nheko.paddingSmall
}
}
}
Rectangle {
id: blueBar
Layout.fillWidth: true
color: Nheko.colors.highlight
height: 1
Rectangle {
id: blackBar
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
height: parent.height*2
width: 0
color: Nheko.colors.text
states: State {
name: "focused"
when: input.activeFocus == true
PropertyChanges {
target: blackBar
width: blueBar.width
}
}
transitions: Transition {
from: ""
to: "focused"
reversible: true
NumberAnimation {
target: blackBar
properties: "width"
duration: 310
easing.type: Easing.InCubic
alwaysRunToEnd: true
}
}
}
}
HoverHandler {
id: hover
enabled: c.ToolTip.text
}
}
|