Debian Codegraph @

resources/qml/MatrixTextField.qml

raw
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 import QtQuick 2.12
6 import QtQuick.Controls 2.12
7 import QtQuick.Layouts 1.12
8 import im.nheko 1.0
9
10 ColumnLayout {
11 id: c
12
13 property color backgroundColor: palette.base
14 property alias color: labelC.color
15 property alias echoMode: input.echoMode
16 property alias font: input.font
17 property var hasClear: false
18 property alias label: labelC.text
19 property alias placeholderText: input.placeholderText
20 property alias selectByMouse: input.selectByMouse
21 property alias text: input.text
22 property alias textPadding: input.padding
23
24 signal accepted
25 signal editingFinished
26 signal textEdited
27
28 function clear() {
29 input.clear();
30 }
31 function forceActiveFocus() {
32 input.forceActiveFocus();
33 }
34
35 ToolTip.delay: Nheko.tooltipDelay
36 ToolTip.visible: hover.hovered
37 spacing: 0
38
39 onTextChanged: timer.restart()
40
41 Timer {
42 id: timer
43
44 interval: 350
45
46 onTriggered: editingFinished()
47 }
48 Item {
49 Layout.bottomMargin: Nheko.paddingSmall
50 Layout.fillWidth: true
51 Layout.margins: input.padding
52 Layout.preferredHeight: labelC.contentHeight
53 visible: labelC.text
54 z: 1
55
56 Label {
57 id: labelC
58
59 color: palette.text
60 enabled: false
61 font.letterSpacing: input.font.pixelSize * 0.02
62 font.pixelSize: input.font.pixelSize
63 font.weight: Font.DemiBold
64 state: labelC.text && (input.activeFocus == true || input.text) ? "focused" : ""
65 width: parent.width
66 y: contentHeight + input.padding + Nheko.paddingSmall
67
68 states: State {
69 name: "focused"
70
71 PropertyChanges {
72 labelC.y: 0
73 }
74 PropertyChanges {
75 input.opacity: 1
76 }
77 }
78 transitions: Transition {
79 from: ""
80 reversible: true
81 to: "focused"
82
83 NumberAnimation {
84 alwaysRunToEnd: true
85 duration: 210
86 easing.type: Easing.InCubic
87 properties: "y"
88 target: labelC
89 }
90 NumberAnimation {
91 alwaysRunToEnd: true
92 duration: 210
93 easing.type: Easing.InCubic
94 properties: "opacity"
95 target: input
96 }
97 }
98 }
99 }
100 TextField {
101 id: input
102
103 Layout.fillWidth: true
104 color: labelC.color
105 focus: true
106 opacity: labelC.text ? 0 : 1
107
108 background: Rectangle {
109 id: backgroundRect
110
111 color: labelC.text ? "transparent" : backgroundColor
112 }
113
114 onAccepted: c.accepted()
115 onEditingFinished: c.editingFinished()
116 onTextEdited: c.textEdited()
117
118 ImageButton {
119 id: clearText
120
121 focusPolicy: Qt.NoFocus
122 hoverEnabled: true
123 image: ":/icons/icons/ui/round-remove-button.svg"
124 visible: c.hasClear && searchField.text !== ''
125
126 onClicked: {
127 searchField.clear();
128 topBar.searchString = "";
129 }
130
131 anchors {
132 bottom: parent.bottom
133 right: parent.right
134 rightMargin: Nheko.paddingSmall
135 top: parent.top
136 }
137 }
138 }
139 Rectangle {
140 id: blueBar
141
142 Layout.fillWidth: true
143 color: palette.highlight
144 Layout.preferredHeight: 1
145
146 Rectangle {
147 id: blackBar
148
149 anchors.horizontalCenter: parent.horizontalCenter
150 anchors.top: parent.top
151 color: palette.text
152 height: parent.height * 2
153 width: 0
154
155 states: State {
156 name: "focused"
157 when: input.activeFocus == true
158
159 PropertyChanges {
160 blackBar.width: blueBar.width
161 }
162 }
163 transitions: Transition {
164 from: ""
165 reversible: true
166 to: "focused"
167
168 NumberAnimation {
169 alwaysRunToEnd: true
170 duration: 310
171 easing.type: Easing.InCubic
172 properties: "width"
173 target: blackBar
174 }
175 }
176 }
177 }
178 HoverHandler {
179 id: hover
180
181 enabled: c.ToolTip.text
182 }
183 }