blob: 0458c3bbbd74c1407cdc8fc5a31de43a4647f5a4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
import QtQuick
import QtQuick.Templates as T
import QtQuick.Controls.impl
import QtQuick.Controls.Material
import QtQuick.Controls.Material.impl
T.TextArea {
id: control
implicitWidth: Math.max(contentWidth + leftPadding + rightPadding,
implicitBackgroundWidth + leftInset + rightInset,
placeholder.implicitWidth + leftPadding + rightPadding)
implicitHeight: Math.max(contentHeight + topPadding + bottomPadding,
implicitBackgroundHeight + topInset + bottomInset)
// 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: enabled && activeFocus ? Material.accentColor : Material.hintTextColor
Material.containerStyle: Material.Outlined
ContextMenu.menu: TextEditingContextMenu {
control: control
}
cursorDelegate: CursorDelegate { }
FloatingPlaceholderText {
id: placeholder
width: control.width - (control.leftPadding + control.rightPadding)
text: control.placeholderText
font: control.font
color: control.placeholderTextColor
elide: Text.ElideRight
renderType: control.renderType
// 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
leftPadding: control.leftPadding
floatingLeftPadding: control.Material.textFieldHorizontalPadding
}
background: MaterialTextContainer {
implicitWidth: 120
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
}
}
|