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 0006 SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-or-later 0007 */ 0008 0009 0010 import QtQuick 2.12 0011 import QtQuick.Window 2.1 0012 import QtQuick.Templates 2.15 as T 0013 import org.kde.kirigami 2.18 as Kirigami 0014 import org.kde.qqc2desktopstyle.private 1.0 as StylePrivate 0015 import org.kde.sonnet 1.0 as Sonnet 0016 import "private" as Private 0017 0018 T.TextArea { 0019 id: controlRoot 0020 palette: Kirigami.Theme.inherit ? Kirigami.Theme.palette : undefined 0021 Kirigami.Theme.colorSet: Kirigami.Theme.View 0022 Kirigami.Theme.inherit: false 0023 0024 implicitWidth: Math.max(contentWidth + leftPadding + rightPadding, 0025 background ? background.implicitWidth : 0, 0026 placeholder.implicitWidth + leftPadding + rightPadding) 0027 implicitHeight: Math.max(contentHeight + topPadding + bottomPadding, 0028 background ? background.implicitHeight : 0, 0029 placeholder.implicitHeight + topPadding + bottomPadding) 0030 0031 padding: 6 0032 0033 color: Kirigami.Theme.textColor 0034 selectionColor: Kirigami.Theme.highlightColor 0035 selectedTextColor: Kirigami.Theme.highlightedTextColor 0036 wrapMode: Text.WordWrap 0037 hoverEnabled: !Kirigami.Settings.tabletMode || !Kirigami.Settings.hasTransientTouchInput 0038 verticalAlignment: TextEdit.AlignTop 0039 0040 // Work around Qt bug where NativeRendering breaks for non-integer scale factors 0041 // https://bugreports.qt.io/browse/QTBUG-67007 0042 renderType: Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering 0043 0044 selectByMouse: hoverEnabled 0045 0046 cursorDelegate: !hoverEnabled ? mobileCursor : null 0047 Component { 0048 id: mobileCursor 0049 Private.MobileCursor { 0050 target: controlRoot 0051 } 0052 } 0053 0054 onTextChanged: Private.MobileTextActionsToolBar.shouldBeVisible = false; 0055 onPressed: Private.MobileTextActionsToolBar.shouldBeVisible = true; 0056 0057 TapHandler { 0058 enabled: controlRoot.selectByMouse 0059 0060 acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus 0061 acceptedButtons: Qt.LeftButton | Qt.RightButton 0062 0063 // unfortunately, taphandler's pressed event only triggers when the press is lifted 0064 // we need to use the longpress signal since it triggers when the button is first pressed 0065 longPressThreshold: 0 0066 onLongPressed: Private.TextFieldContextMenu.targetClick(point, controlRoot, spellcheckhighlighterLoader, controlRoot.positionAt(point.position.x, point.position.y)); 0067 } 0068 0069 Loader { 0070 id: sonnetSettings 0071 active: controlRoot.Kirigami.SpellChecking.enabled && !controlRoot.readOnly 0072 sourceComponent: Sonnet.Settings {} 0073 } 0074 0075 Loader { 0076 id: spellcheckhighlighterLoader 0077 0078 active: sonnetSettings.active && sonnetSettings.item.checkerEnabledByDefault 0079 onActiveChanged: if (active) { 0080 item.active = true; 0081 } 0082 sourceComponent: Sonnet.SpellcheckHighlighter { 0083 id: spellcheckhighlighter 0084 document: controlRoot.textDocument 0085 cursorPosition: controlRoot.cursorPosition 0086 selectionStart: controlRoot.selectionStart 0087 selectionEnd: controlRoot.selectionEnd 0088 misspelledColor: Kirigami.Theme.negativeTextColor 0089 active: spellcheckhighlighterLoader.activable && settings.checkerEnabledByDefault 0090 0091 onChangeCursorPosition: { 0092 controlRoot.cursorPosition = start; 0093 controlRoot.moveCursorSelection(end, TextEdit.SelectCharacters); 0094 } 0095 } 0096 } 0097 0098 Keys.onPressed: { 0099 // trigger if context menu button is pressed 0100 if (controlRoot.selectByMouse) { 0101 Private.TextFieldContextMenu.targetKeyPressed(event, controlRoot) 0102 } 0103 } 0104 0105 onPressAndHold: { 0106 if (hoverEnabled) { 0107 return; 0108 } 0109 forceActiveFocus(); 0110 cursorPosition = positionAt(event.x, event.y); 0111 selectWord(); 0112 } 0113 0114 Private.MobileCursor { 0115 target: controlRoot 0116 selectionStartHandle: true 0117 readonly property rect rect: target.positionToRectangle(target.selectionStart) 0118 x: rect.x 0119 y: rect.y 0120 } 0121 0122 onFocusChanged: { 0123 if (focus) { 0124 Private.MobileTextActionsToolBar.controlRoot = controlRoot; 0125 } 0126 } 0127 0128 Label { 0129 id: placeholder 0130 x: controlRoot.leftPadding 0131 y: controlRoot.topPadding 0132 width: controlRoot.width - (controlRoot.leftPadding + controlRoot.rightPadding) 0133 height: controlRoot.height - (controlRoot.topPadding + controlRoot.bottomPadding) 0134 0135 text: controlRoot.placeholderText 0136 font: controlRoot.font 0137 color: Kirigami.Theme.disabledTextColor 0138 horizontalAlignment: controlRoot.horizontalAlignment 0139 verticalAlignment: controlRoot.verticalAlignment 0140 visible: !controlRoot.length && !controlRoot.preeditText && (!controlRoot.activeFocus || controlRoot.horizontalAlignment !== Qt.AlignHCenter) 0141 elide: Text.ElideRight 0142 } 0143 0144 background: StylePrivate.StyleItem { 0145 control: controlRoot 0146 elementType: "edit" 0147 implicitWidth: 200 0148 implicitHeight: 22 0149 0150 sunken: true 0151 hasFocus: controlRoot.activeFocus 0152 hover: controlRoot.hovered 0153 } 0154 }