matrixion/resources/qml/MatrixTextField.qml

184 lines
4.6 KiB
QML
Raw Normal View History

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