@@ -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: true
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,18 @@ T.TextField {
116121 }
117122 }
118123
124+ Keys .enabled : control .activeFocus && (! copyAllowed || ! cutAllowed)
125+ Keys .onPressed : function (event ) {
126+ if (event .matches (StandardKey .Copy )) {
127+ if (! copyAllowed) {
128+ event .accepted = true
129+ return
130+ }
131+ } else if (event .matches (StandardKey .Cut )) {
132+ if (! cutAllowed) {
133+ event .accepted = true
134+ return
135+ }
136+ }
137+ }
119138}
0 commit comments