@@ -12,11 +12,16 @@ T.TextField {
1212 property D .Palette placeholderTextPalette: DS .Style .edit .placeholderText
1313 placeholderTextColor: D .ColorSelector .placeholderTextPalette
1414 property alias backgroundColor: panel .backgroundColor
15+ property bool canCopy: true
16+ property bool canCut: ! control .readonly
1517 // alert control properties
1618 property alias alertText: panel .alertText
1719 property alias alertDuration: panel .alertDuration
1820 property alias showAlert: panel .showAlert
1921
22+ readonly property bool copyAllowed: control .selectedText .length && control .echoMode === TextInput .Normal && control .canCopy
23+ readonly property bool cutAllowed: ! control .readonly && control .selectedText .length && control .echoMode === TextInput .Normal && control .canCut
24+
2025 implicitWidth: Math .max (DS .Style .control .implicitWidth (control),
2126 placeholderText ? placeholder .implicitWidth + leftPadding + rightPadding
2227 : 0 ) || contentWidth + leftPadding + rightPadding
@@ -77,14 +82,14 @@ T.TextField {
7782 {
7883 text: qsTr (" Copy" )
7984 onTriggered: control .copy ()
80- enabled: control . selectedText . length && control . echoMode === TextInput . Normal
85+ enabled: copyAllowed
8186 }
8287
8388 MenuItem
8489 {
8590 text: qsTr (" Cut" )
8691 onTriggered: control .cut ()
87- enabled: ! control . readonly && control . selectedText . length && control . echoMode === TextInput . Normal
92+ enabled: cutAllowed
8893 }
8994
9095 MenuItem
@@ -116,4 +121,25 @@ T.TextField {
116121 }
117122 }
118123
124+ function handleKeyEvent (event ) {
125+ if (event .matches (StandardKey .Copy )) {
126+ if (! copyAllowed) {
127+ event .accepted = true
128+ return true
129+ }
130+ } else if (event .matches (StandardKey .Cut )) {
131+ if (! cutAllowed) {
132+ event .accepted = true
133+ return true
134+ }
135+ }
136+ return false
137+ }
138+
139+ Keys .enabled : control .activeFocus && (! copyAllowed || ! cutAllowed)
140+ Keys .onPressed : function (event ) {
141+ if (handleKeyEvent (event )) {
142+ return
143+ }
144+ }
119145}
0 commit comments