@@ -147,6 +147,9 @@ Item {
147
147
onTextMainChanged: {
148
148
resultsModel .setProperty (index, " resText" , textMain) // 文字改变时写入列表
149
149
}
150
+ copy: tableMouseArea .selectCopy
151
+ copyAll: tableMouseArea .selectAllCopy
152
+ selectAll: tableMouseArea .selectAll
150
153
}
151
154
// 滚动条
152
155
ScrollBar .vertical : ScrollBar { id: scrollBar }
@@ -203,7 +206,7 @@ Item {
203
206
}
204
207
return [li, lt, ri, rt]
205
208
}
206
- // 根据 Index 的参数,选择对应文本。返回选取类型:
209
+ // 根据 Index 的参数,选择对应文本。
207
210
function selectIndex () {
208
211
const lr = getIndexes ()
209
212
const li = lr[0 ], lt= lr[1 ], ri= lr[2 ], rt= lr[3 ]
@@ -235,6 +238,40 @@ Item {
235
238
}
236
239
selectUpdate++
237
240
}
241
+ // 全选
242
+ function selectAll () {
243
+ if (resultsModel .count === 0 ) return
244
+ startIndex = startTextIndex = 0
245
+ endIndex = resultsModel .count - 1
246
+ endTextIndex = resultsModel .get (endIndex).resText .length
247
+ selectIndex ()
248
+ }
249
+ // 复制已选中的内容
250
+ function selectCopy () {
251
+ const lr = getIndexes ()
252
+ const li = lr[0 ], lt= lr[1 ], ri= lr[2 ], rt= lr[3 ]
253
+ if (li < 0 || ri < 0 ) return
254
+ let copyText = " "
255
+ for (let i = li; i <= ri; i++ ) {
256
+ let item = resultsModel .get (i)
257
+ if (i === li && i === ri) // 单个块
258
+ copyText = item .resText .substring (lt, rt)
259
+ else if (i === li) // 多个块的起始
260
+ copyText = item .resText .substring (lt)+ " \n "
261
+ else if (i === ri) // 多个块的结束
262
+ copyText += item .resText .substring (0 , rt)
263
+ else // 多个块的中间
264
+ copyText += item .resText + " \n "
265
+ }
266
+ if (copyText && copyText .length > 0 ) {
267
+ qmlapp .utilsConnector .copyText (copyText)
268
+ }
269
+ }
270
+ // 复制所有
271
+ function selectAllCopy () {
272
+ selectAll ()
273
+ selectCopy ()
274
+ }
238
275
// 按下
239
276
onPressed: {
240
277
const info = getWhere ()
@@ -270,48 +307,17 @@ Item {
270
307
onReleased: {
271
308
const info = getWhere ()
272
309
if (info=== undefined || info .where < 0 ) {
273
- startIndex = startTextIndex = endIndex = endTextIndex - 1
310
+ selectIndex ()
274
311
return
275
312
}
276
313
endIndex = info .index
277
314
endTextIndex = info .where
278
- if (startIndex!== endIndex) { // 多块选中,预先激活本元素焦点,准备接收键盘事件
279
- tableMouseArea .forceActiveFocus ()
280
- }
281
315
selectIndex () // 选中
282
316
if (startIndex=== endIndex && startTextIndex=== endTextIndex) {
283
317
info .obj .focus (info .where ) // 单击移动光标
284
318
}
285
- else if (startIndex=== endIndex) {
286
- info .obj .focus (- 1 ) // 单块选中,激活焦点
287
- }
288
- }
289
- // 按键事件
290
- Keys .onPressed : {
291
- if (event .modifiers & Qt .ControlModifier ) {
292
- // 复制
293
- if (event .key === Qt .Key_C ) {
294
- console .log (" == copy: " )
295
- const lr = getIndexes ()
296
- const li = lr[0 ], lt= lr[1 ], ri= lr[2 ], rt= lr[3 ]
297
- if (li < 0 || ri < 0 ) return
298
- let copyText = " "
299
- for (let i = li; i <= ri; i++ ) {
300
- let item = resultsModel .get (i)
301
- if (i === li && i === ri) // 单个块
302
- copyText = item .resText .substring (lt, rt)
303
- else if (i === li) // 多个块的起始
304
- copyText = item .resText .substring (lt)+ " \n "
305
- else if (i === ri) // 多个块的结束
306
- copyText += item .resText .substring (0 , rt)
307
- else // 多个块的中间
308
- copyText += item .resText + " \n "
309
- }
310
- if (copyText && copyText .length > 0 ) {
311
- console .log (" == copy" , copyText)
312
- qmlapp .utilsConnector .copyText (copyText)
313
- }
314
- }
319
+ else {
320
+ info .obj .focus (- 1 ) // 激活焦点
315
321
}
316
322
}
317
323
}
@@ -334,10 +340,21 @@ Item {
334
340
resultsModel .clear ()
335
341
}
336
342
}
337
- CheckButton {
343
+ Button_ {
344
+ id: ctrlBtn2
338
345
anchors .top : parent .top
339
346
anchors .bottom : parent .bottom
340
347
anchors .right : ctrlBtn1 .left
348
+ text_: qsTr (" 操作" )
349
+ toolTip: qsTr (" 鼠标拖拽:可选中多个文本框的内容\n Ctrl+A单击:全选单个文本框的内容\n Ctrl+A双击:全选所有文本框的内容\n Ctrl+C单击:复制选中的内容\n Ctrl+C双击:全选所有文本框并复制" )
350
+ onClicked: {
351
+ tableMouseArea .selectAllCopy ()
352
+ }
353
+ }
354
+ CheckButton {
355
+ anchors .top : parent .top
356
+ anchors .bottom : parent .bottom
357
+ anchors .right : ctrlBtn2 .left
341
358
text_: qsTr (" 滚动" )
342
359
toolTip: qsTr (" 自动滚动到底部" )
343
360
textColor_: autoToBottom ? theme .textColor : theme .subTextColor
0 commit comments