Add spellchecking suggestions
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Layouts 1.15
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Templates 2.15 as T
|
||||
import Qt.labs.platform 1.1 as Platform
|
||||
import QtQuick.Window 2.15
|
||||
|
||||
import org.kde.kirigami 2.15 as Kirigami
|
||||
|
||||
@@ -66,7 +68,8 @@ ToolBar {
|
||||
id: fontMetrics
|
||||
font: inputField.font
|
||||
}
|
||||
TextArea {
|
||||
|
||||
T.TextArea {
|
||||
id: inputField
|
||||
focus: true
|
||||
/* Some QQC2 styles will have their own predefined backgrounds for TextAreas.
|
||||
@@ -81,6 +84,7 @@ ToolBar {
|
||||
cursorShape: Qt.IBeamCursor
|
||||
z: 1
|
||||
}
|
||||
|
||||
leftPadding: mirrored ? 0 : Kirigami.Units.largeSpacing
|
||||
rightPadding: !mirrored ? 0 : Kirigami.Units.largeSpacing
|
||||
topPadding: 0
|
||||
@@ -97,6 +101,86 @@ ToolBar {
|
||||
wrapMode: Text.Wrap
|
||||
readOnly: currentRoom.usesEncryption
|
||||
|
||||
palette: Kirigami.Theme.palette
|
||||
Kirigami.Theme.colorSet: Kirigami.Theme.View
|
||||
Kirigami.Theme.inherit: false
|
||||
|
||||
implicitWidth: Math.max(contentWidth + leftPadding + rightPadding,
|
||||
implicitBackgroundWidth + leftInset + rightInset,
|
||||
placeholder.implicitWidth + leftPadding + rightPadding)
|
||||
implicitHeight: Math.max(contentHeight + topPadding + bottomPadding,
|
||||
implicitBackgroundHeight + topInset + bottomInset,
|
||||
placeholder.implicitHeight + topPadding + bottomPadding)
|
||||
|
||||
color: Kirigami.Theme.textColor
|
||||
selectionColor: Kirigami.Theme.highlightColor
|
||||
selectedTextColor: Kirigami.Theme.highlightedTextColor
|
||||
hoverEnabled: !Kirigami.Settings.tabletMode
|
||||
|
||||
// Work around Qt bug where NativeRendering breaks for non-integer scale factors
|
||||
// https://bugreports.qt.io/browse/QTBUG-67007
|
||||
renderType: Screen.devicePixelRatio % 1 !== 0 ? Text.QtRendering : Text.NativeRendering
|
||||
|
||||
selectByMouse: !Kirigami.Settings.tabletMode
|
||||
|
||||
cursorDelegate: Loader {
|
||||
visible: inputField.activeFocus && !inputField.readOnly && inputField.selectionStart === inputField.selectionEnd
|
||||
active: visible
|
||||
sourceComponent: CursorDelegate { target: inputField }
|
||||
}
|
||||
|
||||
CursorHandle {
|
||||
id: selectionStartHandle
|
||||
target: inputField
|
||||
}
|
||||
|
||||
CursorHandle {
|
||||
id: selectionEndHandle
|
||||
target: inputField
|
||||
isSelectionEnd: true
|
||||
}
|
||||
|
||||
TapHandler {
|
||||
acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
|
||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||
|
||||
// unfortunately, taphandler's pressed event only triggers when the press is lifted
|
||||
// we need to use the longpress signal since it triggers when the button is first pressed
|
||||
longPressThreshold: 0
|
||||
onLongPressed: TextFieldContextMenu.targetClick(point, inputField, spellcheckhighlighter, inputField.positionAt(point.position.x, point.position.y));
|
||||
}
|
||||
|
||||
onPressAndHold: {
|
||||
if (!Kirigami.Settings.tabletMode) {
|
||||
return;
|
||||
}
|
||||
forceActiveFocus();
|
||||
cursorPosition = positionAt(event.x, event.y);
|
||||
selectWord();
|
||||
}
|
||||
|
||||
onFocusChanged: {
|
||||
if (focus) {
|
||||
MobileTextActionsToolBar.controlRoot = inputField;
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
id: placeholder
|
||||
x: inputField.leftPadding
|
||||
y: inputField.topPadding
|
||||
width: inputField.width - (inputField.leftPadding + inputField.rightPadding)
|
||||
height: inputField.height - (inputField.topPadding + inputField.bottomPadding)
|
||||
|
||||
text: inputField.placeholderText
|
||||
font: inputField.font
|
||||
color: Kirigami.Theme.disabledTextColor
|
||||
horizontalAlignment: inputField.horizontalAlignment
|
||||
verticalAlignment: inputField.verticalAlignment
|
||||
visible: !inputField.length && !inputField.preeditText && (!inputField.activeFocus || inputField.horizontalAlignment !== Qt.AlignHCenter)
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
|
||||
ChatDocumentHandler {
|
||||
id: documentHandler
|
||||
@@ -107,6 +191,18 @@ ToolBar {
|
||||
room: currentRoom ?? null
|
||||
}
|
||||
|
||||
SpellcheckHighlighter {
|
||||
id: spellcheckhighlighter
|
||||
document: inputField.textDocument
|
||||
cursorPosition: inputField.cursorPosition
|
||||
selectionStart: inputField.selectionStart
|
||||
selectionEnd: inputField.selectionEnd
|
||||
onChangeCursorPosition: {
|
||||
inputField.cursorPosition = start;
|
||||
inputField.moveCursorSelection(end, TextEdit.SelectCharacters);
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: timeoutTimer
|
||||
repeat: false
|
||||
@@ -147,6 +243,9 @@ ToolBar {
|
||||
}
|
||||
|
||||
Keys.onPressed: {
|
||||
// trigger if context menu button is pressed
|
||||
TextFieldContextMenu.targetKeyPressed(event, inputField)
|
||||
|
||||
if (event.key === Qt.Key_PageDown) {
|
||||
switchRoomDown();
|
||||
} else if (event.key === Qt.Key_PageUp) {
|
||||
@@ -211,7 +310,10 @@ ToolBar {
|
||||
chatBar.complete();
|
||||
}
|
||||
|
||||
onPressed: MobileTextActionsToolBar.shouldBeVisible = true;
|
||||
|
||||
onTextChanged: {
|
||||
MobileTextActionsToolBar.shouldBeVisible = false;
|
||||
timeoutTimer.restart()
|
||||
repeatTimer.start()
|
||||
currentRoom.cachedInput = text
|
||||
|
||||
Reference in New Issue
Block a user