matrixion/resources/qml/MatrixTextField.qml

187 lines
4.3 KiB
QML
Raw Normal View History

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