Libplasma

TextArea.qml
1/*
2 SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7import QtQuick
8import QtQuick.Controls
9import QtQuick.Templates as T
10import org.kde.ksvg as KSvg
11//NOTE: importing PlasmaCore is necessary in order to make KSvg load the current Plasma Theme
12import org.kde.plasma.core as PlasmaCore
13import "private" as Private
14import org.kde.kirigami as Kirigami
15import "mobiletextselection" as MobileTextSelection
17T.TextArea {
18 id: control
19
20 implicitWidth: Math.max(contentWidth + leftPadding + rightPadding,
21 background ? background.implicitWidth : 0,
22 placeholder.implicitWidth + leftPadding + rightPadding)
23 implicitHeight: Math.max(contentHeight + topPadding + bottomPadding,
24 background ? background.implicitHeight : 0,
25 placeholder.implicitHeight + topPadding + bottomPadding)
26
27 padding: 6
28
29 Kirigami.Theme.colorSet: Kirigami.Theme.View
30 Kirigami.Theme.inherit: false
31 color: Kirigami.Theme.textColor
32 selectionColor: Kirigami.Theme.highlightColor
33 selectedTextColor: Kirigami.Theme.highlightedTextColor
34 opacity: control.enabled ? 1 : 0.6
35 verticalAlignment: TextEdit.AlignTop
36 hoverEnabled: !Kirigami.Settings.tabletMode || !Kirigami.Settings.hasTransientTouchInput
37
38 selectByMouse: hoverEnabled
39
40 cursorDelegate: !hoverEnabled ? mobileCursor : null
41 Component {
42 id: mobileCursor
43 MobileTextSelection.MobileCursor {
44 target: control
45 }
46 }
47
48 onTextChanged: MobileTextSelection.MobileTextActionsToolBar.shouldBeVisible = false;
49 onPressed: event => MobileTextSelection.MobileTextActionsToolBar.shouldBeVisible = true;
50
51 onPressAndHold: event => {
52 if (hoverEnabled) {
53 return;
54 }
55 forceActiveFocus();
56 cursorPosition = positionAt(event.x, event.y);
57 selectWord();
58 }
59
60 MobileTextSelection.MobileCursor {
61 target: control
62 selectionStartHandle: true
63 property var rect: target.positionToRectangle(target.selectionStart)
64 x: rect.x
65 y: rect.y
66 }
67
68 onFocusChanged: {
69 if (focus) {
70 MobileTextSelection.MobileTextActionsToolBar.controlRoot = control;
71 }
72 }
73
74 Label {
75 id: placeholder
76 x: control.leftPadding
77 y: control.topPadding
78 width: control.width - (control.leftPadding + control.rightPadding)
79 height: control.height - (control.topPadding + control.bottomPadding)
80
81 text: control.placeholderText
82 font: control.font
83 color: Kirigami.Theme.textColor
84 opacity: 0.5
85 enabled: false
86 horizontalAlignment: control.horizontalAlignment
87 verticalAlignment: control.verticalAlignment
88 visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter)
89 elide: Text.ElideRight
90 }
91
92 background: Item {
93 Private.TextFieldFocus {
94 state: control.activeFocus ? "focus" : (control.hovered ? "hover" : "hidden")
95 anchors.fill: parent
96 }
98 id: base
99 anchors.fill: parent
100 imagePath: "widgets/lineedit"
101 prefix: "base"
102 }
103 }
104}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:10:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.