From 07013d0ed4b48022aacb06f09b1499c0862a4926 Mon Sep 17 00:00:00 2001 From: miruka Date: Tue, 23 Jun 2020 08:44:58 -0400 Subject: [PATCH] Unify text field/area focus line into a component --- src/gui/Base/HBottomFocusLine.qml | 22 ++++++++++++++++++++++ src/gui/Base/HTextArea.qml | 14 ++------------ src/gui/Base/HTextField.qml | 14 ++------------ 3 files changed, 26 insertions(+), 24 deletions(-) create mode 100644 src/gui/Base/HBottomFocusLine.qml diff --git a/src/gui/Base/HBottomFocusLine.qml b/src/gui/Base/HBottomFocusLine.qml new file mode 100644 index 00000000..1184d544 --- /dev/null +++ b/src/gui/Base/HBottomFocusLine.qml @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later + +import QtQuick 2.12 + + +HRectangleBottomBorder { + id: line + + + property bool show: false + + + transform: Scale { + origin.x: line.width / 2 + origin.y: line.height / 2 + xScale: line.show ? 1 : 0 + + Behavior on xScale { HNumberAnimation {} } + } + + Behavior on color { HColorAnimation {} } +} diff --git a/src/gui/Base/HTextArea.qml b/src/gui/Base/HTextArea.qml index 6b0c83a5..1ab98931 100644 --- a/src/gui/Base/HTextArea.qml +++ b/src/gui/Base/HTextArea.qml @@ -55,20 +55,10 @@ TextArea { border.width: bordered ? theme.controls.textArea.borderWidth : 0 border.color: borderColor - HRectangleBottomBorder { - id: bottomBorder + HBottomFocusLine { + show: textArea.activeFocus borderHeight: theme.controls.textArea.borderWidth color: error ? errorBorder : focusedBorderColor - - transform: Scale { - origin.x: bottomBorder.width / 2 - origin.y: bottomBorder.height / 2 - xScale: textArea.activeFocus ? 1 : 0 - - Behavior on xScale { HNumberAnimation {} } - } - - Behavior on color { HColorAnimation {} } } } diff --git a/src/gui/Base/HTextField.qml b/src/gui/Base/HTextField.qml index b07a3c47..fcb66e93 100644 --- a/src/gui/Base/HTextField.qml +++ b/src/gui/Base/HTextField.qml @@ -30,20 +30,10 @@ TextField { border.width: bordered ? theme.controls.textField.borderWidth : 0 border.color: borderColor - HRectangleBottomBorder { - id: bottomBorder + HBottomFocusLine { + show: field.activeFocus borderHeight: theme.controls.textField.borderWidth color: error ? errorBorder : focusedBorderColor - - transform: Scale { - origin.x: bottomBorder.width / 2 - origin.y: bottomBorder.height / 2 - xScale: field.activeFocus ? 1 : 0 - - Behavior on xScale { HNumberAnimation {} } - } - - Behavior on color { HColorAnimation {} } } }