nheko/resources/qml/MatrixTextField.qml

183 lines
4.2 KiB
QML
Raw Normal View History

2021-03-14 02:45:20 +01:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
2021-03-14 02:45:20 +01:00
//
// SPDX-License-Identifier: GPL-3.0-or-later
2021-03-26 01:20:13 +01:00
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
2021-05-13 10:57:04 +02:00
import im.nheko 1.0
2021-02-23 17:06:21 +01:00
2022-01-24 00:41:55 +01:00
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
2022-01-28 15:24:56 +01:00
Timer {
id: timer
interval: 350
onTriggered: editingFinished()
}
onTextChanged: timer.restart()
2022-01-24 00:41:55 +01:00
signal textEdited
signal accepted
signal editingFinished
function forceActiveFocus() {
input.forceActiveFocus();
}
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
}
}
}
}
2021-07-17 22:17:05 +02:00
2022-01-24 00:41:55 +01:00
TextField {
id: input
Layout.fillWidth: true
palette: Nheko.colors
color: labelC.color
opacity: labelC.text ? 0 : 1
onTextEdited: c.textEdited()
onAccepted: c.accepted()
onEditingFinished: c.editingFinished()
background: Rectangle {
id: backgroundRect
color: labelC.text ? "transparent" : backgroundColor
}
}
2021-02-23 17:06:21 +01:00
Rectangle {
id: blueBar
2022-01-24 00:41:55 +01:00
Layout.fillWidth: true
2021-05-13 08:23:56 +02:00
color: Nheko.colors.highlight
2021-02-23 17:06:21 +01:00
height: 1
2021-02-23 17:06:21 +01:00
Rectangle {
id: blackBar
2022-01-24 00:41:55 +01:00
anchors.top: parent.top
2021-02-23 17:06:21 +01:00
anchors.horizontalCenter: parent.horizontalCenter
2022-01-24 00:41:55 +01:00
height: parent.height*2
2021-02-23 17:06:21 +01:00
width: 0
2021-05-13 08:23:56 +02:00
color: Nheko.colors.text
2021-02-23 17:06:21 +01:00
states: State {
name: "focused"
when: input.activeFocus == true
2021-02-23 17:06:21 +01:00
PropertyChanges {
target: blackBar
width: blueBar.width
}
2021-02-23 17:06:21 +01:00
}
2021-02-23 17:06:21 +01:00
transitions: Transition {
from: ""
to: "focused"
reversible: true
2022-01-24 00:41:55 +01:00
NumberAnimation {
2021-02-23 17:06:21 +01:00
target: blackBar
properties: "width"
2022-01-24 00:41:55 +01:00
duration: 310
easing.type: Easing.InCubic
alwaysRunToEnd: true
2021-02-23 17:06:21 +01:00
}
2021-02-23 17:06:21 +01:00
}
2021-02-23 17:06:21 +01:00
}
2021-02-23 17:06:21 +01:00
}
2022-01-24 00:41:55 +01:00
HoverHandler {
id: hover
enabled: c.ToolTip.text
}
}