Warning, /plasma/qqc2-breeze-style/style/qtquickcontrols/TextArea.qml is written in an unsupported language. File is not indexed.

0001 // NOTE: check this
0002 /* SPDX-FileCopyrightText: 2020 Noah Davis <noahadvs@gmail.com>
0003  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0004  */
0005 
0006 import QtQuick
0007 import QtQuick.Controls as Controls
0008 import QtQuick.Templates as T
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.breeze.impl as Impl
0011 
0012 T.TextArea {
0013     id: control
0014 
0015     implicitWidth: Math.max(contentWidth + leftPadding + rightPadding,
0016                             implicitBackgroundWidth + leftInset + rightInset,
0017                             placeholder.implicitWidth + leftPadding + rightPadding)
0018     implicitHeight: Math.max(contentHeight + topPadding + bottomPadding,
0019                              implicitBackgroundHeight + topInset + bottomInset,
0020                              placeholder.implicitHeight + topPadding + bottomPadding)
0021     property bool visualFocus: control.activeFocus && (
0022         control.focusReason == Qt.TabFocusReason ||
0023         control.focusReason == Qt.BacktabFocusReason ||
0024         control.focusReason == Qt.ShortcutFocusReason
0025     )
0026 
0027 
0028     padding: Kirigami.Units.mediumSpacing
0029     property real horizontalPadding: Impl.Units.mediumHorizontalPadding
0030     property real verticalPadding: padding
0031     leftPadding: horizontalPadding
0032     rightPadding: horizontalPadding
0033     topPadding: verticalPadding
0034     bottomPadding: verticalPadding
0035 
0036     Kirigami.Theme.colorSet: Kirigami.Theme.View
0037     Kirigami.Theme.inherit: background == null
0038 
0039     color: Kirigami.Theme.textColor
0040     selectionColor: Kirigami.Theme.highlightColor
0041     selectedTextColor: Kirigami.Theme.highlightedTextColor
0042     placeholderTextColor: Kirigami.Theme.disabledTextColor
0043 
0044     selectByMouse: true
0045     mouseSelectionMode: Kirigami.Settings.tabletMode ?
0046         TextEdit.SelectWords : TextEdit.SelectCharacters
0047 
0048     cursorDelegate: Loader {
0049         visible: control.activeFocus && !control.readOnly && control.selectionStart === control.selectionEnd
0050         active: visible
0051         sourceComponent: Impl.CursorDelegate { target: control }
0052     }
0053 
0054     Controls.Label {
0055         id: placeholder
0056         anchors {
0057             fill: parent
0058             leftMargin: control.leftPadding
0059             rightMargin: control.rightPadding
0060             topMargin: control.topPadding
0061             bottomMargin: control.bottomPadding
0062         }
0063 
0064         text: control.placeholderText
0065         font: control.font
0066         color: control.placeholderTextColor
0067         horizontalAlignment: control.horizontalAlignment
0068         verticalAlignment: control.verticalAlignment
0069         visible: !control.length && !control.preeditText && (!control.activeFocus || control.horizontalAlignment !== Qt.AlignHCenter)
0070         elide: Text.ElideRight
0071         renderType: control.renderType
0072     }
0073 
0074     background:Impl.TextEditBackground {
0075         control: control
0076         implicitWidth: 200
0077         visualFocus: control.visualFocus
0078     }
0079 
0080     Impl.CursorHandle {
0081         id: selectionStartHandle
0082         target: control
0083     }
0084 
0085     Impl.CursorHandle {
0086         id: selectionEndHandle
0087         target: control
0088         isSelectionEnd: true
0089     }
0090 
0091     MobileTextActionsToolBar {
0092         id: mobileTextActionsToolBar
0093         target: control
0094     }
0095 
0096     onActiveFocusChanged: {
0097         if (!activeFocus) {
0098             mobileTextActionsToolBar.visible = false
0099         } else if (Kirigami.Settings.tabletMode) {
0100             mobileTextActionsToolBar.visible = true
0101         }
0102     }
0103 
0104     onSelectedTextChanged: {
0105         if (Kirigami.Settings.tabletMode && selectedText.length > 0) {
0106             mobileTextActionsToolBar.item.open()
0107         }
0108     }
0109 
0110     onPressAndHold: {
0111         if (Kirigami.Settings.tabletMode && selectByMouse) {
0112             forceActiveFocus();
0113             cursorPosition = positionAt(event.x, event.y);
0114             selectWord();
0115             mobileTextActionsToolBar.item.open()
0116         }
0117     }
0118 }