aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols/material/TextArea.qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/quickcontrols/material/TextArea.qml')
-rw-r--r--src/quickcontrols/material/TextArea.qml63
1 files changed, 48 insertions, 15 deletions
diff --git a/src/quickcontrols/material/TextArea.qml b/src/quickcontrols/material/TextArea.qml
index 242cbf691b..99efa222cf 100644
--- a/src/quickcontrols/material/TextArea.qml
+++ b/src/quickcontrols/material/TextArea.qml
@@ -14,37 +14,70 @@ T.TextArea {
implicitBackgroundWidth + leftInset + rightInset,
placeholder.implicitWidth + leftPadding + rightPadding)
implicitHeight: Math.max(contentHeight + topPadding + bottomPadding,
- implicitBackgroundHeight + topInset + bottomInset,
- placeholder.implicitHeight + 1 + topPadding + bottomPadding)
+ implicitBackgroundHeight + topInset + bottomInset)
- topPadding: 8
- bottomPadding: 16
+ // If we're clipped, or we're in a Flickable that's clipped, set our topInset
+ // to half the height of the placeholder text to avoid it being clipped.
+ topInset: clip || (parent?.parent as Flickable && parent?.parent.clip) ? placeholder.largestHeight / 2 : 0
+
+ leftPadding: Material.textFieldHorizontalPadding
+ rightPadding: Material.textFieldHorizontalPadding
+ // Need to account for the placeholder text when it's sitting on top.
+ topPadding: Material.containerStyle === Material.Filled && placeholderText.length > 0 && (activeFocus || length > 0)
+ ? Material.textFieldVerticalPadding + placeholder.largestHeight
+ // When the condition above is not met, the text should always sit in the middle
+ // of a default-height TextArea, which is just near the top for a higher-than-default one.
+ // Account for any topInset as well, otherwise the text will be too close to the background.
+ : ((implicitBackgroundHeight - placeholder.largestHeight) / 2) + topInset
+ bottomPadding: Material.textFieldVerticalPadding
color: enabled ? Material.foreground : Material.hintTextColor
selectionColor: Material.accentColor
selectedTextColor: Material.primaryHighlightedTextColor
- placeholderTextColor: Material.hintTextColor
+ placeholderTextColor: enabled && activeFocus ? Material.accentColor : Material.hintTextColor
+
+ Material.containerStyle: Material.Outlined
+
cursorDelegate: CursorDelegate { }
- PlaceholderText {
+ FloatingPlaceholderText {
id: placeholder
- x: control.leftPadding
- y: control.topPadding
+ // Don't set this to control.leftPadding, because we don't want it to change if the user changes leftPadding.
+ x: control.Material.textFieldHorizontalPadding
width: control.width - (control.leftPadding + control.rightPadding)
- height: control.height - (control.topPadding + control.bottomPadding)
text: control.placeholderText
font: control.font
color: control.placeholderTextColor
- verticalAlignment: control.verticalAlignment
elide: Text.ElideRight
renderType: control.renderType
- visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter)
+ // When the TextArea is in a Flickable, the background is reparented to it
+ // so that decorations don't move with the content. We need to do the same.
+ // Also allow the background to be set to null; in that case we're just not visible.
+ parent: control.background?.parent ?? null
+
+ filled: control.Material.containerStyle === Material.Filled
+ verticalPadding: control.Material.textFieldVerticalPadding
+ controlHasActiveFocus: control.activeFocus
+ controlHasText: control.length > 0
+ controlImplicitBackgroundHeight: control.implicitBackgroundHeight
+ controlHeight: control.height
}
- background: Rectangle {
- y: parent.height - height - control.bottomPadding / 2
+ background: MaterialTextContainer {
implicitWidth: 120
- height: control.activeFocus ? 2 : 1
- color: control.activeFocus ? control.Material.accentColor : control.Material.hintTextColor
+ implicitHeight: control.Material.textFieldHeight
+
+ filled: control.Material.containerStyle === Material.Filled
+ fillColor: control.Material.textFieldFilledContainerColor
+ outlineColor: (enabled && control.hovered) ? control.Material.primaryTextColor : control.Material.hintTextColor
+ focusedOutlineColor: control.Material.accentColor
+ // When the control's size is set larger than its implicit size, use whatever size is smaller
+ // so that the gap isn't too big.
+ placeholderTextWidth: Math.min(placeholder.width, placeholder.implicitWidth) * placeholder.scale
+ placeholderTextHAlign: control.effectiveHorizontalAlignment
+ controlHasActiveFocus: control.activeFocus
+ controlHasText: control.length > 0
+ placeholderHasText: placeholder.text.length > 0
+ horizontalPadding: control.Material.textFieldHorizontalPadding
}
}