Merge pull request #348 from amnezia-vpn/bugfix/changed_textfield_border_hover_color

added border hover effect for textarea
This commit is contained in:
Nethius 2023-09-29 16:24:28 +03:00 committed by GitHub
commit ed1afa7549
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 100 additions and 49 deletions

View file

@ -9,12 +9,23 @@ Rectangle {
property alias textArea: textArea property alias textArea: textArea
property alias textAreaText: textArea.text property alias textAreaText: textArea.text
property string borderHoveredColor: "#494B50"
property string borderNormalColor: "#2C2D30"
property string borderFocusedColor: "#d7d8db"
height: 148 height: 148
color: "#1C1D21" color: "#1C1D21"
border.width: 1 border.width: 1
border.color: "#2C2D30" border.color: getBorderColor(borderNormalColor)
radius: 16 radius: 16
MouseArea {
id: parentMouse
anchors.fill: parent
cursorShape: Qt.IBeamCursor
onClicked: textArea.forceActiveFocus()
hoverEnabled: true
FlickableType { FlickableType {
id: fl id: fl
interactive: false interactive: false
@ -55,14 +66,20 @@ Rectangle {
wrapMode: Text.Wrap wrapMode: Text.Wrap
MouseArea { MouseArea {
id: textAreaMouse
anchors.fill: parent anchors.fill: parent
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
hoverEnabled: true
onClicked: { onClicked: {
fl.interactive = true fl.interactive = true
contextMenu.open() contextMenu.open()
} }
} }
onFocusChanged: {
root.border.color = getBorderColor(borderNormalColor)
}
ContextMenuType { ContextMenuType {
id: contextMenu id: contextMenu
textObj: textArea textObj: textArea
@ -70,10 +87,21 @@ Rectangle {
} }
} }
//todo make whole background clickable, with code below we lose ability to select text by mouse onPressed: {
// MouseArea { root.border.color = getBorderColor(borderFocusedColor)
// anchors.fill: parent }
// cursorShape: Qt.IBeamCursor
// onClicked: textArea.forceActiveFocus() onExited: {
// } root.border.color = getBorderColor(borderNormalColor)
}
onEntered: {
root.border.color = getBorderColor(borderHoveredColor)
}
}
function getBorderColor(noneFocusedColor) {
return textArea.focus ? root.borderFocusedColor : noneFocusedColor
}
} }

View file

@ -30,6 +30,7 @@ Item {
property string backgroundColor: "#1c1d21" property string backgroundColor: "#1c1d21"
property string backgroundDisabledColor: "transparent" property string backgroundDisabledColor: "transparent"
property string bgBorderHoveredColor: "#494B50"
implicitWidth: content.implicitWidth implicitWidth: content.implicitWidth
implicitHeight: content.implicitHeight implicitHeight: content.implicitHeight
@ -44,7 +45,7 @@ Item {
Layout.preferredHeight: input.implicitHeight Layout.preferredHeight: input.implicitHeight
color: root.enabled ? root.backgroundColor : root.backgroundDisabledColor color: root.enabled ? root.backgroundColor : root.backgroundDisabledColor
radius: 16 radius: 16
border.color: textField.focus ? root.borderFocusedColor : root.borderColor border.color: getBackgroundBorderColor(root.borderColor)
border.width: 1 border.width: 1
Behavior on border.color { Behavior on border.color {
@ -102,12 +103,17 @@ Item {
anchors.fill: parent anchors.fill: parent
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
onClicked: contextMenu.open() onClicked: contextMenu.open()
enabled: true
} }
ContextMenuType { ContextMenuType {
id: contextMenu id: contextMenu
textObj: textField textObj: textField
} }
onFocusChanged: {
backgroud.border.color = getBackgroundBorderColor(root.borderColor)
}
} }
} }
@ -149,11 +155,28 @@ Item {
MouseArea { MouseArea {
anchors.fill: root anchors.fill: root
cursorShape: Qt.PointingHandCursor cursorShape: Qt.IBeamCursor
hoverEnabled: true
onPressed: function(mouse) { onPressed: function(mouse) {
textField.forceActiveFocus() textField.forceActiveFocus()
mouse.accepted = false mouse.accepted = false
backgroud.border.color = getBackgroundBorderColor(root.borderColor)
} }
onEntered: {
backgroud.border.color = getBackgroundBorderColor(bgBorderHoveredColor)
}
onExited: {
backgroud.border.color = getBackgroundBorderColor(root.borderColor)
}
}
function getBackgroundBorderColor(noneFocusedColor) {
return textField.focus ? root.borderFocusedColor : noneFocusedColor
} }
} }