-
Notifications
You must be signed in to change notification settings - Fork 363
/
IpItem.qml
81 lines (76 loc) · 2.17 KB
/
IpItem.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import QtQuick 2.12
import QtQuick.Controls 2.12
//每一段的编辑框
TextInput {
id: control
//向前移动,如删除时
//checkAll=true全选,cursorLeft=true光标在左侧
signal gotoPrev(bool checkAll, bool cursorLeft)
//向后移动,如已输入三个数字
signal gotoNext(bool checkAll, bool cursorLeft)
//复制
signal doCopy(bool copyOne)
//粘贴
signal doPaste()
selectByMouse: true
//inputMask: "999"
validator: RegExpValidator{
regExp: /^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])$/
}
verticalAlignment: TextInput.AlignVCenter
horizontalAlignment: TextInput.AlignHCenter
onTextChanged: {
if(text.length>=3){
control.gotoNext(false,true);
}
}
Keys.enabled: true
Keys.onPressed: {
event.accepted=false;
switch(event.key){
case Qt.Key_Tab:
case Qt.Key_Period:
control.gotoNext(true,false);
break;
case Qt.Key_Left:
if(cursorPosition==0){
control.gotoPrev(false,false);
}
break;
case Qt.Key_Right:
if(cursorPosition==text.length){
control.gotoNext(false,true);
}
break;
case Qt.Key_Backspace:
if(cursorPosition==0 && text.length<=0){
control.gotoPrev(false,false);
}
break;
case Qt.Key_C:
//选中文本的话就用edit在带的复制操作
if(event.modifiers===Qt.ControlModifier){
event.accepted=true;
//console.log('do copy')
control.doCopy(selectedText.length>0);
}
break;
case Qt.Key_V:
if(event.modifiers===Qt.ControlModifier){
event.accepted=true;
//console.log('do paste')
control.doPaste();
}
break;
}
}
Keys.onReleased: {
event.accepted=false;
switch(event.key){
case Qt.Key_C:
case Qt.Key_V:
event.accepted=(event.modifiers===Qt.ControlModifier);
break;
}
}
}