-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCodeTips.x
More file actions
173 lines (158 loc) · 6.55 KB
/
CodeTips.x
File metadata and controls
173 lines (158 loc) · 6.55 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//xlang Source, Name:CodeTips.x
//Date: Tue Apr 11:35:04 2021
class CodeTips : QWidget{
QLabel lbltitle, lblcontent, lbllink, pushpin, lblcopy;
String pushpin_qss_unpush = "background-image: url(res/toolbar/unpush.png);";
String pushpin_qss_push = "background-image: url(res/toolbar/push.png);";
String defaultPath ;
bool pushed = false;
public void onAttach()override{
lbltitle = (QLabel)attachByName(new QLabel(), "lbltitle");
lblcontent = (QLabel)attachByName(new QLabel(), "lblcontent");
lbllink = (QLabel)attachByName(new QLabel(), "lbllink");
lblcopy = (QLabel)attachByName(new QLabel(), "lblcopy");
pushpin = (QLabel)attachByName(new QLabel(), "pushpin");
lbltitle.setOnMouseEventListener(new onMouseEventListener(){
bool bpressed = false;
int _ox, _oy, _wx , _wy;
public void onMouseButtonPress(QObject obj, int Button, int x, int y, int flags, int source) {
if (bpressed == false){
bpressed = true;
QPoint qpt = lbltitle.mapToGlobal(x,y);
_ox = qpt.x;_oy = qpt.y;
_wx = CodeTips.this.x(); _wy = CodeTips.this.y();
}
}
public void onMouseButtonRelease(QObject obj, int Button, int x, int y, int flags, int source) {
bpressed = false;
}
public void onMouseMove(QObject obj, int Button, int x, int y, int flags, int source) {
if (bpressed){
QPoint qpt = lbltitle.mapToGlobal(x,y);
x = qpt.x;y = qpt.y;
CodeTips.this.move(_wx + (x - _ox), _wy + (y - _oy));
}
}
});
pushpin.setOnMouseEventListener(new onMouseEventListener(){
void onMouseButtonRelease(QObject obj, int Button, int x, int y, int flags, int source) {
pushed = !pushed;
pushpin.setStyleSheetString(pushed? pushpin_qss_push : pushpin_qss_unpush);
setFocus();
}
});
lbllink.setOnMouseEventListener(new onMouseEventListener(){
void onMouseButtonPress(QObject obj,int Button,int x,int y,int flags,int source)override{
//TODO
lbllink.setText("<b><u style=\"color:#fb8416\">跟踪链接</u> </b>");
}
void onMouseButtonRelease(QObject obj, int Button, int x, int y, int flags, int source) {
onLink();
lbllink.setText("<b><u style=\"color:#1684fb\">跟踪链接</u> </b>");
}
});
lblcopy.setOnMouseEventListener(new onMouseEventListener(){
void onMouseButtonPress(QObject obj,int Button,int x,int y,int flags,int source)override{
lblcopy.setText("<b><u style=\"color:#fb8416\">复制到剪贴板</u> </b>");
}
void onMouseButtonRelease(QObject obj, int Button, int x, int y, int flags, int source) {
setClipboardText(lbltitle.getText() + "\n" + lblcontent.getText());
lblcopy.setText("<b><u style=\"color:#1684fb\">复制到剪贴板</u> </b>");
}
});
setOnKeyEventListener(new onKeyEventListener(){
bool onKeyPress(QObject obj,int key,bool repeat,int count,String text,int scanCode,int virtualKey,int modifier)override{
if (key == Constant.Key_Escape){
hide();
}
return false;
}
});
}
public void onLink(){
String szContent = lblcontent.getText();
String [] strs = szContent.split('\n');
for (int i = 0; i < strs.length; i++){
String item = strs[i].trim(true);
if (analyze_link(item)){
return;
}
}
QPoint cpt = lbllink.mapToGlobal(0,0);
lbllink.showToolTips(cpt.x,cpt.y,"无可用链接",-1);
}
public bool analyze_link(String lineText){
String file = nilptr;
int line , row;
if (lineText.length() < 3){
return false;
}
try{
int lp = lineText.indexOf(':', 3);
if (lp != -1 && (lp + 1) < lineText.length()) {
file = lineText.substring(0, lp).trim(true);
int le = lineText.indexOf(':', lp + 1);
if (le != -1 && (le + 1) < lineText.length()){
line = lineText.substring(lp + 1, le).parseInt();
int rp = lineText.indexOf(':', le + 1);
if (rp != -1 && le != -1) {
row = lineText.substring(le + 1, rp).parseInt();
}else{
row = 0;
}
}else{
return false;
}
}else{
return false;
}
}catch(Exception e){
return false;
}
if (false == DocumentView.locateForLineRow(XWorkspace.workspace, file, line > 0 ? (line - 1) : line , row, 1)){
if (defaultPath != nilptr && defaultPath.length() > 0){
file = defaultPath.findVolumePath().appendPath(file);
return DocumentView.locateForLineRow(XWorkspace.workspace, file, line > 0 ? (line - 1) : line , row, 1);
}
}else{
return true;
}
return false;
}
public static CodeTips createTips(QWidget w){
QDialog newDlg = new QDialog();
if (newDlg.load(UIManager.getUIData(__xPackageResource("ui/tips.ui")), w) == false){
return nilptr;
}
CodeTips wizard = new CodeTips();
wizard.attach(newDlg);
return wizard;
}
public void hide(bool bForce){
if (!pushed){
hide();
}
}
void onFocusOut(bool focus,int reson)override{
hide(false);
}
public void showTips(String _defaultPath, QPoint pt, String title, String content){
setWindowFlags(Constant.WindowStaysOnTopHint);
pushed = false;
pushpin.setStyleSheetString(pushed? pushpin_qss_push : pushpin_qss_unpush);
if (title != nilptr){
lbltitle.setText(title);
}else{
lbltitle.setText("提示:");
}
defaultPath = _defaultPath;
lblcontent.setText(content);
lblcontent.adjustSize();
//setContentsMargins(2,4,4,2);
move(pt.x, pt.y);
adjustSize();
show();
raise();
//setFocus();
}
};