Warning, /frameworks/qqc2-desktop-style/org.kde.desktop/TextArea.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2017 Marco Martin <mart@kde.org> 0003 SPDX-FileCopyrightText: 2017 The Qt Company Ltd. 0004 SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org> 0005 SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk> 0006 0007 SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-or-later 0008 */ 0009 0010 0011 import QtQml.Models 0012 import QtQuick 0013 import QtQuick.Window 0014 import QtQuick.Templates as T 0015 import org.kde.kirigami as Kirigami 0016 import org.kde.sonnet as Sonnet 0017 import org.kde.desktop.private as Private 0018 import org.kde.qqc2desktopstyle.private as StylePrivate 0019 0020 T.TextArea { 0021 id: controlRoot 0022 Kirigami.Theme.colorSet: Kirigami.Theme.View 0023 Kirigami.Theme.inherit: false 0024 0025 implicitWidth: Math.max(contentWidth + leftPadding + rightPadding, 0026 implicitBackgroundWidth + leftInset + rightInset, 0027 placeholder.implicitWidth + leftPadding + rightPadding) 0028 implicitHeight: Math.max(contentHeight + topPadding + bottomPadding, 0029 implicitBackgroundHeight + topInset + bottomInset, 0030 placeholder.implicitHeight + topPadding + bottomPadding) 0031 0032 padding: 6 0033 0034 color: Kirigami.Theme.textColor 0035 selectionColor: Kirigami.Theme.highlightColor 0036 selectedTextColor: Kirigami.Theme.highlightedTextColor 0037 hoverEnabled: !Kirigami.Settings.tabletMode || !Kirigami.Settings.hasTransientTouchInput 0038 verticalAlignment: TextEdit.AlignTop 0039 0040 selectByMouse: hoverEnabled 0041 0042 cursorDelegate: !hoverEnabled ? mobileCursor : null 0043 Component { 0044 id: mobileCursor 0045 Private.MobileCursor { 0046 target: controlRoot 0047 } 0048 } 0049 0050 onTextChanged: Private.MobileTextActionsToolBar.shouldBeVisible = false; 0051 onPressed: event => { 0052 Private.MobileTextActionsToolBar.shouldBeVisible = true; 0053 } 0054 0055 TapHandler { 0056 enabled: controlRoot.selectByMouse 0057 0058 acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad | PointerDevice.Stylus 0059 acceptedButtons: Qt.LeftButton | Qt.RightButton 0060 0061 // unfortunately, taphandler's pressed event only triggers when the press is lifted 0062 // we need to use the longpress signal since it triggers when the button is first pressed 0063 longPressThreshold: 0 0064 0065 onLongPressed: { 0066 Private.TextFieldContextMenu.targetClick( 0067 point, 0068 controlRoot, 0069 spellcheckHighlighterInstantiator, 0070 controlRoot.positionAt(point.position.x, point.position.y), 0071 ); 0072 } 0073 } 0074 0075 Kirigami.SpellCheck.enabled: !controlRoot.readOnly 0076 && Private.GlobalSonnetSettings.checkerEnabledByDefault 0077 0078 Instantiator { 0079 id: spellcheckHighlighterInstantiator 0080 0081 active: controlRoot.Kirigami.SpellCheck.enabled 0082 asynchronous: true 0083 0084 Sonnet.SpellcheckHighlighter { 0085 active: true 0086 document: controlRoot.textDocument 0087 cursorPosition: controlRoot.cursorPosition 0088 selectionStart: controlRoot.selectionStart 0089 selectionEnd: controlRoot.selectionEnd 0090 misspelledColor: Kirigami.Theme.negativeTextColor 0091 0092 onChangeCursorPosition: (start, end) => { 0093 controlRoot.cursorPosition = start; 0094 controlRoot.moveCursorSelection(end, TextEdit.SelectCharacters); 0095 } 0096 } 0097 } 0098 0099 Keys.onPressed: event => { 0100 // trigger if context menu button is pressed 0101 if (controlRoot.selectByMouse) { 0102 Private.TextFieldContextMenu.targetKeyPressed(event, controlRoot) 0103 } 0104 } 0105 0106 onPressAndHold: event => { 0107 if (hoverEnabled) { 0108 return; 0109 } 0110 forceActiveFocus(); 0111 cursorPosition = positionAt(event.x, event.y); 0112 selectWord(); 0113 } 0114 0115 Private.MobileCursor { 0116 target: controlRoot 0117 selectionStartHandle: true 0118 readonly property rect rect: target.positionToRectangle(target.selectionStart) 0119 x: rect.x 0120 y: rect.y 0121 } 0122 0123 onFocusChanged: { 0124 if (focus) { 0125 Private.MobileTextActionsToolBar.controlRoot = controlRoot; 0126 } 0127 } 0128 0129 Label { 0130 id: placeholder 0131 x: controlRoot.leftPadding 0132 y: controlRoot.topPadding 0133 width: controlRoot.width - (controlRoot.leftPadding + controlRoot.rightPadding) 0134 height: controlRoot.height - (controlRoot.topPadding + controlRoot.bottomPadding) 0135 0136 text: controlRoot.placeholderText 0137 font: controlRoot.font 0138 color: Kirigami.Theme.disabledTextColor 0139 horizontalAlignment: controlRoot.horizontalAlignment 0140 verticalAlignment: controlRoot.verticalAlignment 0141 visible: !controlRoot.length && !controlRoot.preeditText && (!controlRoot.activeFocus || controlRoot.horizontalAlignment !== Qt.AlignHCenter) 0142 elide: Text.ElideRight 0143 } 0144 0145 background: StylePrivate.StyleItem { 0146 control: controlRoot 0147 elementType: "edit" 0148 implicitWidth: 200 0149 implicitHeight: 22 0150 0151 sunken: true 0152 hasFocus: controlRoot.activeFocus 0153 hover: controlRoot.hovered 0154 } 0155 }