remove references to FlickableType in TextFieldWithHeaderType

This commit is contained in:
Cyril Anisimov
2025-07-26 17:33:03 +02:00
parent 9e805635c3
commit 810756eda8
@@ -1,233 +1,220 @@
import QtQuick import QtQuick
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Layouts import QtQuick.Layouts
import Style 1.0 import Style 1.0
import "TextTypes" import "TextTypes"
Item { Item {
id: root id: root
property string headerText property string headerText
property string headerTextDisabledColor: AmneziaStyle.color.charcoalGray property string headerTextDisabledColor: AmneziaStyle.color.charcoalGray
property string headerTextColor: AmneziaStyle.color.mutedGray property string headerTextColor: AmneziaStyle.color.mutedGray
property alias errorText: errorField.text property alias errorText: errorField.text
property bool checkEmptyText: false property bool checkEmptyText: false
property bool rightButtonClickedOnEnter: false property bool rightButtonClickedOnEnter: false
property string buttonText property string buttonText
property string buttonImageSource property string buttonImageSource
property var clickedFunc property var clickedFunc
property alias textField: textField property alias textField: textField
property string textFieldTextColor: AmneziaStyle.color.paleGray property string textFieldTextColor: AmneziaStyle.color.paleGray
property string textFieldTextDisabledColor: AmneziaStyle.color.mutedGray property string textFieldTextDisabledColor: AmneziaStyle.color.mutedGray
property bool textFieldEditable: true property bool textFieldEditable: true
property string borderColor: AmneziaStyle.color.slateGray property string borderColor: AmneziaStyle.color.slateGray
property string borderFocusedColor: AmneziaStyle.color.paleGray property string borderFocusedColor: AmneziaStyle.color.paleGray
property string backgroundColor: AmneziaStyle.color.onyxBlack property string backgroundColor: AmneziaStyle.color.onyxBlack
property string backgroundDisabledColor: AmneziaStyle.color.transparent property string backgroundDisabledColor: AmneziaStyle.color.transparent
property string bgBorderHoveredColor: AmneziaStyle.color.charcoalGray property string bgBorderHoveredColor: AmneziaStyle.color.charcoalGray
implicitWidth: content.implicitWidth implicitWidth: content.implicitWidth
implicitHeight: content.implicitHeight implicitHeight: content.implicitHeight
property FlickableType parentFlickable ColumnLayout {
id: content
Connections { anchors.fill: parent
target: textField
function onFocusChanged() { Rectangle {
if (textField.activeFocus) { id: backgroud
if (root.parentFlickable) { Layout.fillWidth: true
root.parentFlickable.ensureVisible(root) Layout.preferredHeight: input.implicitHeight
} color: root.enabled ? root.backgroundColor : root.backgroundDisabledColor
} radius: 16
} border.color: getBackgroundBorderColor(root.borderColor)
} border.width: 1
ColumnLayout { Behavior on border.color {
id: content PropertyAnimation { duration: 200 }
anchors.fill: parent }
Rectangle { RowLayout {
id: backgroud id: input
Layout.fillWidth: true anchors.fill: backgroud
Layout.preferredHeight: input.implicitHeight ColumnLayout {
color: root.enabled ? root.backgroundColor : root.backgroundDisabledColor Layout.margins: 16
radius: 16 LabelTextType {
border.color: getBackgroundBorderColor(root.borderColor) text: root.headerText
border.width: 1 color: root.enabled ? root.headerTextColor : root.headerTextDisabledColor
Behavior on border.color { visible: text !== ""
PropertyAnimation { duration: 200 }
} Layout.fillWidth: true
}
RowLayout {
id: input TextField {
anchors.fill: backgroud id: textField
ColumnLayout {
Layout.margins: 16 property bool isFocusable: true
LabelTextType {
text: root.headerText Keys.onTabPressed: {
color: root.enabled ? root.headerTextColor : root.headerTextDisabledColor FocusController.nextKeyTabItem()
}
visible: text !== ""
Keys.onBacktabPressed: {
Layout.fillWidth: true FocusController.previousKeyTabItem()
} }
TextField { enabled: root.textFieldEditable
id: textField color: root.enabled ? root.textFieldTextColor : root.textFieldTextDisabledColor
property bool isFocusable: true inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhSensitiveData | Qt.ImhNoPredictiveText
Keys.onTabPressed: { placeholderTextColor: AmneziaStyle.color.charcoalGray
FocusController.nextKeyTabItem()
} selectionColor: AmneziaStyle.color.richBrown
selectedTextColor: AmneziaStyle.color.paleGray
Keys.onBacktabPressed: {
FocusController.previousKeyTabItem() font.pixelSize: 16
} font.weight: 400
font.family: "PT Root UI VF"
enabled: root.textFieldEditable
color: root.enabled ? root.textFieldTextColor : root.textFieldTextDisabledColor height: 24
Layout.fillWidth: true
inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhSensitiveData | Qt.ImhNoPredictiveText
topPadding: 0
placeholderTextColor: AmneziaStyle.color.charcoalGray rightPadding: 0
leftPadding: 0
selectionColor: AmneziaStyle.color.richBrown bottomPadding: 0
selectedTextColor: AmneziaStyle.color.paleGray
background: Rectangle {
font.pixelSize: 16 anchors.fill: parent
font.weight: 400 color: root.enabled ? root.backgroundColor : root.backgroundDisabledColor
font.family: "PT Root UI VF" }
height: 24 onTextChanged: {
Layout.fillWidth: true root.errorText = ""
}
topPadding: 0
rightPadding: 0 onActiveFocusChanged: {
leftPadding: 0 if (root.checkEmptyText && text === "") {
bottomPadding: 0 root.errorText = qsTr("The field can't be empty")
}
background: Rectangle { }
anchors.fill: parent
color: root.enabled ? root.backgroundColor : root.backgroundDisabledColor MouseArea {
} anchors.fill: parent
acceptedButtons: Qt.RightButton
onTextChanged: { onClicked: contextMenu.open()
root.errorText = "" enabled: true
} }
onActiveFocusChanged: { ContextMenuType {
if (root.checkEmptyText && text === "") { id: contextMenu
root.errorText = qsTr("The field can't be empty") textObj: textField
} }
}
onFocusChanged: {
MouseArea { backgroud.border.color = getBackgroundBorderColor(root.borderColor)
anchors.fill: parent }
acceptedButtons: Qt.RightButton }
onClicked: contextMenu.open() }
enabled: true }
} }
ContextMenuType { SmallTextType {
id: contextMenu id: errorField
textObj: textField
} text: root.errorText
visible: root.errorText !== ""
onFocusChanged: { color: AmneziaStyle.color.vibrantRed
backgroud.border.color = getBackgroundBorderColor(root.borderColor)
} Layout.fillWidth: true
} }
} }
}
} MouseArea {
anchors.fill: root
SmallTextType { cursorShape: Qt.IBeamCursor
id: errorField
hoverEnabled: true
text: root.errorText
visible: root.errorText !== "" onPressed: function(mouse) {
color: AmneziaStyle.color.vibrantRed textField.forceActiveFocus()
mouse.accepted = false
Layout.fillWidth: true
} backgroud.border.color = getBackgroundBorderColor(root.borderColor)
} }
MouseArea { onEntered: {
anchors.fill: root backgroud.border.color = getBackgroundBorderColor(bgBorderHoveredColor)
cursorShape: Qt.IBeamCursor }
hoverEnabled: true
onExited: {
onPressed: function(mouse) { backgroud.border.color = getBackgroundBorderColor(root.borderColor)
textField.forceActiveFocus() }
mouse.accepted = false }
backgroud.border.color = getBackgroundBorderColor(root.borderColor) BasicButtonType {
} visible: (root.buttonText !== "") || (root.buttonImageSource !== "")
onEntered: { focusPolicy: Qt.NoFocus
backgroud.border.color = getBackgroundBorderColor(bgBorderHoveredColor) text: root.buttonText
} leftImageSource: root.buttonImageSource
anchors.top: content.top
onExited: { anchors.bottom: content.bottom
backgroud.border.color = getBackgroundBorderColor(root.borderColor) anchors.right: content.right
}
} height: content.implicitHeight
width: content.implicitHeight
BasicButtonType { squareLeftSide: true
visible: (root.buttonText !== "") || (root.buttonImageSource !== "")
clickedFunc: function() {
focusPolicy: Qt.NoFocus if (root.clickedFunc && typeof root.clickedFunc === "function") {
text: root.buttonText root.clickedFunc()
leftImageSource: root.buttonImageSource }
}
anchors.top: content.top }
anchors.bottom: content.bottom
anchors.right: content.right function getBackgroundBorderColor(noneFocusedColor) {
return textField.focus ? root.borderFocusedColor : noneFocusedColor
height: content.implicitHeight }
width: content.implicitHeight
squareLeftSide: true Keys.onEnterPressed: {
if (root.rightButtonClickedOnEnter && root.clickedFunc && typeof root.clickedFunc === "function") {
clickedFunc: function() { clickedFunc()
if (root.clickedFunc && typeof root.clickedFunc === "function") { }
root.clickedFunc()
} // if (KeyNavigation.tab) {
} // KeyNavigation.tab.forceActiveFocus();
} // }
}
function getBackgroundBorderColor(noneFocusedColor) {
return textField.focus ? root.borderFocusedColor : noneFocusedColor Keys.onReturnPressed: {
} if (root.rightButtonClickedOnEnter &&root.clickedFunc && typeof root.clickedFunc === "function") {
clickedFunc()
Keys.onEnterPressed: { }
if (root.rightButtonClickedOnEnter && root.clickedFunc && typeof root.clickedFunc === "function") {
clickedFunc() // if (KeyNavigation.tab) {
} // KeyNavigation.tab.forceActiveFocus();
// }
// if (KeyNavigation.tab) { }
// KeyNavigation.tab.forceActiveFocus(); }
// }
}
Keys.onReturnPressed: {
if (root.rightButtonClickedOnEnter &&root.clickedFunc && typeof root.clickedFunc === "function") {
clickedFunc()
}
// if (KeyNavigation.tab) {
// KeyNavigation.tab.forceActiveFocus();
// }
}
}