2021-03-14 04:45:20 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
2022-01-01 06:57:53 +03:00
|
|
|
// 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
|
|
|
|
2021-03-06 21:48:24 +03:00
|
|
|
|
2022-01-24 02:41:55 +03: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-12-21 00:34:55 +03:00
|
|
|
property var hasClear: false
|
2022-01-24 02:41:55 +03:00
|
|
|
|
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
|
|
|
|
|
|
|
|
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 23:17:05 +03:00
|
|
|
|
2022-01-24 02:41:55 +03:00
|
|
|
TextField {
|
|
|
|
id: input
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
palette: Nheko.colors
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-12-21 00:34:55 +03:00
|
|
|
ToolButton {
|
|
|
|
id: clearText
|
|
|
|
Layout.fillWidth: true
|
|
|
|
visible: c.hasClear && searchField.text !== ''
|
|
|
|
icon.source: "image://colorimage/:/icons/icons/ui/round-remove-button.svg?" + (clearText.hovered ? Nheko.colors.highlight : Nheko.colors.buttonText)
|
|
|
|
focusPolicy: Qt.NoFocus
|
|
|
|
onClicked: {
|
|
|
|
searchField.clear()
|
|
|
|
topBar.searchString = "";
|
|
|
|
}
|
|
|
|
hoverEnabled: true
|
|
|
|
background: null
|
|
|
|
anchors {
|
|
|
|
verticalCenter: parent.verticalCenter
|
|
|
|
right: parent.right
|
|
|
|
}
|
|
|
|
// clear the default hover effects.
|
|
|
|
|
|
|
|
Image {
|
|
|
|
height: parent.height - 2 * Nheko.paddingSmall
|
|
|
|
width: height
|
|
|
|
source: "image://colorimage/:/icons/icons/ui/round-remove-button.svg?" + (clearText.hovered ? Nheko.colors.highlight : Nheko.colors.buttonText)
|
|
|
|
|
|
|
|
anchors {
|
|
|
|
verticalCenter: parent.verticalCenter
|
|
|
|
right: parent.right
|
|
|
|
margins: Nheko.paddingSmall
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2021-05-13 09:23:56 +03:00
|
|
|
color: Nheko.colors.highlight
|
2021-02-23 19:06:21 +03:00
|
|
|
height: 1
|
2021-03-14 03:24:26 +03:00
|
|
|
|
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
|
2021-05-13 09:23:56 +03:00
|
|
|
color: Nheko.colors.text
|
2021-03-14 03:24:26 +03:00
|
|
|
|
2021-02-23 19:06:21 +03:00
|
|
|
states: State {
|
2021-03-14 03:24:26 +03:00
|
|
|
name: "focused"
|
|
|
|
when: input.activeFocus == true
|
|
|
|
|
2021-02-23 19:06:21 +03:00
|
|
|
PropertyChanges {
|
|
|
|
target: blackBar
|
|
|
|
width: blueBar.width
|
|
|
|
}
|
2021-03-14 03:24:26 +03:00
|
|
|
|
2021-02-23 19:06:21 +03:00
|
|
|
}
|
2021-03-14 03:24:26 +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
|
|
|
|
2021-03-14 03:24:26 +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
|
2021-03-14 03:24:26 +03:00
|
|
|
alwaysRunToEnd: true
|
2021-02-23 19:06:21 +03:00
|
|
|
}
|
2021-03-14 03:24:26 +03:00
|
|
|
|
2021-02-23 19:06:21 +03:00
|
|
|
}
|
2021-03-14 03:24:26 +03:00
|
|
|
|
2021-02-23 19:06:21 +03:00
|
|
|
}
|
2021-03-14 03:24:26 +03:00
|
|
|
|
2021-02-23 19:06:21 +03:00
|
|
|
}
|
2021-03-14 03:24:26 +03:00
|
|
|
|
2022-01-24 02:41:55 +03:00
|
|
|
HoverHandler {
|
|
|
|
id: hover
|
|
|
|
enabled: c.ToolTip.text
|
2021-03-14 03:24:26 +03:00
|
|
|
}
|
|
|
|
}
|