Warning, /frameworks/qqc2-desktop-style/org.kde.desktop/TextField.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 
0005     SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-or-later
0006 */
0007 
0008 
0009 import QtQuick
0010 import QtQuick.Window
0011 import QtQuick.Controls as Controls
0012 import QtQuick.Templates as T
0013 import org.kde.kirigami as Kirigami
0014 import org.kde.desktop.private as Private
0015 import org.kde.qqc2desktopstyle.private as StylePrivate
0016 
0017 T.TextField {
0018     id: controlRoot
0019 
0020     Kirigami.Theme.colorSet: Kirigami.Theme.View
0021     Kirigami.Theme.inherit: false
0022 
0023     implicitWidth: Math.max(200,
0024                             placeholderText ? placeholder.implicitWidth + leftPadding + rightPadding : 0)
0025                             || contentWidth + leftPadding + rightPadding
0026     implicitHeight: Math.max(contentHeight + topPadding + bottomPadding,
0027                              background ? background.implicitHeight : 0,
0028                              placeholder.implicitHeight + topPadding + bottomPadding)
0029 
0030     padding: 6
0031 
0032     placeholderTextColor: Kirigami.Theme.disabledTextColor
0033     color: enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
0034     selectionColor: Kirigami.Theme.highlightColor
0035     selectedTextColor: Kirigami.Theme.highlightedTextColor
0036     verticalAlignment: TextInput.AlignVCenter
0037     hoverEnabled: !Kirigami.Settings.tabletMode
0038 
0039     selectByMouse: !Kirigami.Settings.tabletMode
0040 
0041     cursorDelegate: Kirigami.Settings.tabletMode ? mobileCursor : null
0042 
0043     Component {
0044         id: mobileCursor
0045         Private.MobileCursor {
0046             target: controlRoot
0047         }
0048     }
0049 
0050     onFocusChanged: {
0051         if (focus) {
0052             Private.MobileTextActionsToolBar.controlRoot = controlRoot;
0053         }
0054     }
0055 
0056     onTextChanged: Private.MobileTextActionsToolBar.shouldBeVisible = false;
0057 
0058     onPressed: event => Private.MobileTextActionsToolBar.shouldBeVisible = true;
0059 
0060     TapHandler {
0061         acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad | PointerDevice.Stylus
0062         acceptedButtons: Qt.LeftButton | Qt.RightButton
0063 
0064         // unfortunately, taphandler's pressed event only triggers when the press is lifted
0065         // we need to use the longpress signal since it triggers when the button is first pressed
0066         longPressThreshold: 0
0067         onLongPressed: {
0068             Private.TextFieldContextMenu.targetClick(
0069                 point,
0070                 controlRoot,
0071                 /*spellcheckHighlighterInstantiator*/ null,
0072                 /*mousePosition*/ null,
0073             );
0074         }
0075     }
0076 
0077     Keys.onPressed: event => {
0078         // trigger if context menu button is pressed
0079         Private.TextFieldContextMenu.targetKeyPressed(event, controlRoot)
0080 
0081         // Disable undo action for security reasons
0082         // See QTBUG-103934
0083         if ((echoMode === TextInput.PasswordEchoOnEdit || echoMode === TextInput.Password) && event.matches(StandardKey.Undo)) {
0084             event.accepted = true
0085         }
0086     }
0087 
0088     onPressAndHold: event => {
0089         if (!Kirigami.Settings.tabletMode) {
0090             return;
0091         }
0092         forceActiveFocus();
0093         cursorPosition = positionAt(event.x, event.y);
0094         selectWord();
0095     }
0096 
0097     Private.MobileCursor {
0098         target: controlRoot
0099         selectionStartHandle: true
0100         readonly property rect rect: controlRoot.positionToRectangle(controlRoot.selectionStart)
0101         x: rect.x + target.padding
0102         y: rect.y + target.padding
0103     }
0104 
0105     Text {
0106         id: placeholder
0107         x: controlRoot.leftPadding
0108         y: controlRoot.topPadding
0109         width: controlRoot.width - controlRoot.leftPadding - controlRoot.rightPadding
0110         height: controlRoot.height - controlRoot.topPadding - controlRoot.bottomPadding
0111 
0112         text: controlRoot.placeholderText
0113         font: controlRoot.font
0114         color: controlRoot.placeholderTextColor
0115         LayoutMirroring.enabled: false
0116         horizontalAlignment: controlRoot.effectiveHorizontalAlignment
0117         verticalAlignment: controlRoot.verticalAlignment
0118         visible: !controlRoot.length && !controlRoot.preeditText && (!controlRoot.activeFocus || controlRoot.horizontalAlignment !== Qt.AlignHCenter)
0119         elide: Text.ElideRight
0120     }
0121 
0122     background: StylePrivate.StyleItem {
0123         control: controlRoot
0124         elementType: "edit"
0125 
0126         sunken: true
0127         hasFocus: controlRoot.activeFocus
0128         hover: controlRoot.hovered
0129     }
0130 }