You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nheko/resources/qml/MatrixTextField.qml

184 lines
4.6 KiB

// 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
1 year ago
property color backgroundColor: palette.base
property alias color: labelC.color
1 year ago
property alias echoMode: input.echoMode
property alias font: input.font
property var hasClear: false
property alias label: labelC.text
property alias placeholderText: input.placeholderText
property alias selectByMouse: input.selectByMouse
1 year ago
property alias text: input.text
property alias textPadding: input.padding
signal accepted
signal editingFinished
1 year ago
signal textEdited
function clear() {
input.clear();
}
1 year ago
function forceActiveFocus() {
input.forceActiveFocus();
}
ToolTip.delay: Nheko.tooltipDelay
ToolTip.visible: hover.hovered
spacing: 0
1 year ago
onTextChanged: timer.restart()
Timer {
id: timer
interval: 350
onTriggered: editingFinished()
}
Item {
1 year ago
Layout.bottomMargin: Nheko.paddingSmall
Layout.fillWidth: true
Layout.margins: input.padding
1 year ago
Layout.preferredHeight: labelC.contentHeight
visible: labelC.text
z: 1
Label {
id: labelC
color: palette.text
1 year ago
enabled: false
font.letterSpacing: input.font.pixelSize * 0.02
font.pixelSize: input.font.pixelSize
font.weight: Font.DemiBold
state: labelC.text && (input.activeFocus == true || input.text) ? "focused" : ""
1 year ago
width: parent.width
y: contentHeight + input.padding + Nheko.paddingSmall
states: State {
name: "focused"
PropertyChanges {
labelC.y: 0
}
PropertyChanges {
input.opacity: 1
}
}
transitions: Transition {
from: ""
reversible: true
1 year ago
to: "focused"
NumberAnimation {
1 year ago
alwaysRunToEnd: true
duration: 210
easing.type: Easing.InCubic
1 year ago
properties: "y"
target: labelC
}
NumberAnimation {
1 year ago
alwaysRunToEnd: true
duration: 210
easing.type: Easing.InCubic
1 year ago
properties: "opacity"
target: input
}
}
}
}
TextField {
id: input
1 year ago
Layout.fillWidth: true
color: labelC.color
focus: true
1 year ago
opacity: labelC.text ? 0 : 1
background: Rectangle {
id: backgroundRect
color: labelC.text ? "transparent" : backgroundColor
}
1 year ago
onAccepted: c.accepted()
onEditingFinished: c.editingFinished()
onTextEdited: c.textEdited()
ImageButton {
id: clearText
1 year ago
focusPolicy: Qt.NoFocus
hoverEnabled: true
image: ":/icons/icons/ui/round-remove-button.svg"
visible: c.hasClear && searchField.text !== ''
onClicked: {
1 year ago
searchField.clear();
topBar.searchString = "";
}
1 year ago
anchors {
bottom: parent.bottom
right: parent.right
rightMargin: Nheko.paddingSmall
1 year ago
top: parent.top
}
}
}
Rectangle {
id: blueBar
Layout.fillWidth: true
color: palette.highlight
Layout.preferredHeight: 1
Rectangle {
id: blackBar
anchors.horizontalCenter: parent.horizontalCenter
1 year ago
anchors.top: parent.top
color: palette.text
1 year ago
height: parent.height * 2
width: 0
states: State {
name: "focused"
when: input.activeFocus == true
PropertyChanges {
blackBar.width: blueBar.width
}
}
transitions: Transition {
from: ""
reversible: true
1 year ago
to: "focused"
NumberAnimation {
1 year ago
alwaysRunToEnd: true
duration: 310
easing.type: Easing.InCubic
1 year ago
properties: "width"
target: blackBar
}
}
}
}
HoverHandler {
id: hover
1 year ago
enabled: c.ToolTip.text
}
}