From c3c46ff1b12a30a65abfdf97e57dea2649ea001e Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Tue, 25 Oct 2016 10:23:05 +0300 Subject: [PATCH] improve tag completion allow to select item from tooltip by mouse and insert it to text edtior --- sources/qml/AWTextEditor.qml | 31 +++++++++++++++++++++++-------- sources/qml/BugReport.qml | 4 ++-- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/sources/qml/AWTextEditor.qml b/sources/qml/AWTextEditor.qml index 03a1104..ac0de23 100644 --- a/sources/qml/AWTextEditor.qml +++ b/sources/qml/AWTextEditor.qml @@ -33,6 +33,22 @@ Item { QtControls.ToolTip { id: tooltip + + property string substring + property var tags: [] + text: tags.join('\n') + + bottomPadding: 0 + topPadding: 0 + + MouseArea { + anchors.fill: parent + onClicked: { + var tagHeight = tooltip.height / tooltip.tags.length + var pos = Math.round(mouse.y / tagHeight, 0) + appendTag(tooltip.tags[pos], tooltip.substring) + } + } } onTextChanged: { @@ -42,19 +58,18 @@ Item { tooltip.visible = false return } - var tags = backend.dictKeys(true, "^" + currentTag).join('\n') - // exit if no suggestion found - if (tags.length == 0) { - tooltip.visible = false - return - } // update tooltip and show it - tooltip.text = tags + tooltip.substring = currentTag + tooltip.tags = backend.dictKeys(true, "^" + tooltip.substring) changeTooltipPosition() - tooltip.visible = true + tooltip.visible = (tooltip.tags.length != 0) } } + function appendTag(tag, substring) { + textArea.insert(textArea.cursorPosition, tag.substring(substring.length)) + } + function changeTooltipPosition() { tooltip.x = textArea. cursorRectangle.x tooltip.y = textArea. cursorRectangle.y diff --git a/sources/qml/BugReport.qml b/sources/qml/BugReport.qml index 10f27b6..44080a7 100644 --- a/sources/qml/BugReport.qml +++ b/sources/qml/BugReport.qml @@ -49,7 +49,7 @@ QtDialogs.Dialog { width: parent.width anchors.top: title.bottom anchors.bottom: parent.bottom - + QtControls.GroupBox { width: parent.width height: parent.height / 5 @@ -122,7 +122,7 @@ QtDialogs.Dialog { QtDialogs.FileDialog { id: logPath title: i18n("Open log file") - onAccepted: + onAccepted: logBody.text = awActions.getFileContent(logPath.fileUrl.toString().replace("file://", "")) } }