From a8cd4be5a5bbd36035c6ec208d85b023d7cfc287 Mon Sep 17 00:00:00 2001 From: "B.Melnik" Date: Wed, 25 Aug 2021 15:18:04 +0300 Subject: [PATCH] fix(StatusBaseInput): fix click to focus Closes: #325 --- .../src/StatusQ/Controls/StatusBaseInput.qml | 245 +++++++++--------- 1 file changed, 123 insertions(+), 122 deletions(-) diff --git a/ui/StatusQ/src/StatusQ/Controls/StatusBaseInput.qml b/ui/StatusQ/src/StatusQ/Controls/StatusBaseInput.qml index a4b8ade1c0..31ba8e5a5a 100644 --- a/ui/StatusQ/src/StatusQ/Controls/StatusBaseInput.qml +++ b/ui/StatusQ/src/StatusQ/Controls/StatusBaseInput.qml @@ -58,10 +58,10 @@ Item { Rectangle { width: parent.width height: maximumHeight != 0 ? Math.min( - minimumHeight != 0 ? Math.max(statusBaseInput.implicitHeight, minimumHeight) - : implicitHeight, + minimumHeight != 0 ? Math.max(statusBaseInput.implicitHeight, minimumHeight) + : implicitHeight, maximumHeight) - : parent.height + : parent.height color: Theme.palette.baseColor2 radius: 8 @@ -78,137 +78,138 @@ Item { return sensor.containsMouse ? Theme.palette.primaryColor2 : "transparent" } + StatusIcon { + id: statusIcon + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + anchors.leftMargin: 10 + anchors.topMargin: 10 + + icon: statusBaseInput.icon.name + width: statusBaseInput.icon.width + height: statusBaseInput.icon.height + color: Theme.palette.baseColor1 + visible: !!statusBaseInput.icon.name + } + + Flickable { + id: flick + + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.left: statusIcon.visible ? statusIcon.right : parent.left + anchors.right: parent.right + anchors.leftMargin: statusIcon.visible ? 8 : statusBaseInput.leftPadding + anchors.rightMargin: statusBaseInput.rightPadding + clearable ? clearButtton.width : 0 + anchors.topMargin: statusBaseInput.topPadding + anchors.bottomMargin: statusBaseInput.bottomPadding + contentWidth: edit.paintedWidth + contentHeight: edit.paintedHeight + clip: true + + QC.ScrollBar.vertical: QC.ScrollBar { interactive: multiline } + + + function ensureVisible(r) { + if (contentX >= r.x) + contentX = r.x; + else if (contentX+width <= r.x+r.width) + contentX = r.x+r.width-width; + if (contentY >= r.y) + contentY = r.y; + else if (contentY+height <= r.y+r.height) + contentY = r.y+r.height-height; + } + + + + TextEdit { + id: edit + property string previousText: text + + width: flick.width + selectByMouse: true + selectionColor: Theme.palette.primaryColor2 + selectedTextColor: color + anchors.verticalCenter: parent.verticalCenter + focus: true + font.pixelSize: 15 + font.family: Theme.palette.baseFont.name + color: Theme.palette.directColor1 + onCursorRectangleChanged: flick.ensureVisible(cursorRectangle) + wrapMode: statusBaseInput.multiline ? Text.WrapAtWordBoundaryOrAnywhere : TextEdit.NoWrap + + onActiveFocusChanged: { + if (statusBaseInput.pristine) { + statusBaseInput.pristine = false + } + } + + Keys.onReturnPressed: { + if (multiline) { + event.accepted = false + } else { + event.accepted = true + } + } + + Keys.onEnterPressed: { + if (multiline) { + event.accepted = false + } else { + event.accepted = true + } + } + + onTextChanged: { + statusBaseInput.dirty = true + if (statusBaseInput.maximumLength > 0) { + if (text.length > statusBaseInput.maximumLength) { + var cursor = cursorPosition; + text = previousText; + if (cursor > text.length) { + cursorPosition = text.length; + } else { + cursorPosition = cursor-1; + } + } + previousText = text + } + } + + StatusBaseText { + id: placeholder + visible: edit.text.length === 0 + anchors.left: parent.left + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + font.pixelSize: 15 + + elide: StatusBaseText.ElideRight + font.family: Theme.palette.baseFont.name + color: statusBaseInput.enabled ? Theme.palette.baseColor1 : + Theme.palette.directColor6 + } + } + + } // Flickable MouseArea { id: sensor + enabled: !edit.activeFocus hoverEnabled: true anchors.fill: parent cursorShape: Qt.IBeamCursor onClicked: edit.forceActiveFocus() - - StatusIcon { - id: statusIcon - anchors.verticalCenter: parent.verticalCenter - anchors.left: parent.left - anchors.leftMargin: 10 - anchors.topMargin: 10 - - icon: statusBaseInput.icon.name - width: statusBaseInput.icon.width - height: statusBaseInput.icon.height - color: Theme.palette.baseColor1 - visible: !!statusBaseInput.icon.name - } - - Flickable { - id: flick - - anchors.top: parent.top - anchors.bottom: parent.bottom - anchors.left: statusIcon.visible ? statusIcon.right : parent.left - anchors.right: parent.right - anchors.leftMargin: statusIcon.visible ? 8 : statusBaseInput.leftPadding - anchors.rightMargin: statusBaseInput.rightPadding + clearable ? clearButtton.width : 0 - anchors.topMargin: statusBaseInput.topPadding - anchors.bottomMargin: statusBaseInput.bottomPadding - contentWidth: edit.paintedWidth - contentHeight: edit.paintedHeight - clip: true - - QC.ScrollBar.vertical: QC.ScrollBar { interactive: multiline } - - - function ensureVisible(r) { - if (contentX >= r.x) - contentX = r.x; - else if (contentX+width <= r.x+r.width) - contentX = r.x+r.width-width; - if (contentY >= r.y) - contentY = r.y; - else if (contentY+height <= r.y+r.height) - contentY = r.y+r.height-height; - } - - - - TextEdit { - id: edit - property string previousText: text - - width: flick.width - selectByMouse: true - selectionColor: Theme.palette.primaryColor2 - selectedTextColor: color - anchors.verticalCenter: parent.verticalCenter - focus: true - font.pixelSize: 15 - font.family: Theme.palette.baseFont.name - color: Theme.palette.directColor1 - onCursorRectangleChanged: flick.ensureVisible(cursorRectangle) - wrapMode: statusBaseInput.multiline ? Text.WrapAtWordBoundaryOrAnywhere : TextEdit.NoWrap - - onActiveFocusChanged: { - if (statusBaseInput.pristine) { - statusBaseInput.pristine = false - } - } - - Keys.onReturnPressed: { - if (multiline) { - event.accepted = false - } else { - event.accepted = true - } - } - - Keys.onEnterPressed: { - if (multiline) { - event.accepted = false - } else { - event.accepted = true - } - } - - onTextChanged: { - statusBaseInput.dirty = true - if (statusBaseInput.maximumLength > 0) { - if (text.length > statusBaseInput.maximumLength) { - var cursor = cursorPosition; - text = previousText; - if (cursor > text.length) { - cursorPosition = text.length; - } else { - cursorPosition = cursor-1; - } - } - previousText = text - } - } - - StatusBaseText { - id: placeholder - visible: edit.text.length === 0 - anchors.left: parent.left - anchors.right: parent.right - anchors.verticalCenter: parent.verticalCenter - font.pixelSize: 15 - - elide: StatusBaseText.ElideRight - font.family: Theme.palette.baseFont.name - color: statusBaseInput.enabled ? Theme.palette.baseColor1 : - Theme.palette.directColor6 - } - } - } - } // Flickable + } } // Rectangle StatusFlatRoundButton { id: clearButtton visible: edit.text.length != 0 && - statusBaseInput.clearable && - !statusBaseInput.multiline && - edit.activeFocus + statusBaseInput.clearable && + !statusBaseInput.multiline && + edit.activeFocus anchors.right: parent.right anchors.rightMargin: 11 anchors.verticalCenter: parent.verticalCenter