2023-09-04 16:45:54 +02:00
|
|
|
// Copyright (C) 2023 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
|
|
|
|
|
|
|
|
|
import QtQuick
|
|
|
|
|
import StudioControls as StudioControls
|
|
|
|
|
import StudioTheme as StudioTheme
|
2023-09-19 13:46:53 +02:00
|
|
|
import HelperWidgets as HelperWidgets
|
2023-09-04 16:45:54 +02:00
|
|
|
|
|
|
|
|
FocusScope {
|
|
|
|
|
id: root
|
|
|
|
|
|
|
|
|
|
required property int index
|
|
|
|
|
required property string value
|
|
|
|
|
required property int type
|
|
|
|
|
|
|
|
|
|
function setCursorBegin() { textInput.cursorPosition = 0 }
|
|
|
|
|
function setCursorEnd() { textInput.cursorPosition = textInput.text.length }
|
|
|
|
|
|
|
|
|
|
function isEditable() { return root.type === ConditionListModel.Intermediate
|
|
|
|
|
|| root.type === ConditionListModel.Literal
|
|
|
|
|
|| root.type === ConditionListModel.Invalid }
|
|
|
|
|
|
|
|
|
|
function isIntermediate() { return root.type === ConditionListModel.Intermediate }
|
|
|
|
|
function isLiteral() { return root.type === ConditionListModel.Literal }
|
|
|
|
|
function isOperator() { return root.type === ConditionListModel.Operator }
|
|
|
|
|
function isProperty() { return root.type === ConditionListModel.Variable }
|
|
|
|
|
function isShadow() { return root.type === ConditionListModel.Shadow }
|
2023-09-11 11:47:34 +02:00
|
|
|
function isInvalid() { return root.type === ConditionListModel.Invalid }
|
2023-09-04 16:45:54 +02:00
|
|
|
|
|
|
|
|
signal remove()
|
|
|
|
|
signal update(var value)
|
2023-09-11 11:47:34 +02:00
|
|
|
signal submit(int cursorPosition)
|
2023-09-04 16:45:54 +02:00
|
|
|
|
|
|
|
|
readonly property int margin: StudioTheme.Values.flowPillMargin
|
2023-09-12 11:14:58 +02:00
|
|
|
property var operatorModel
|
2023-09-04 16:45:54 +02:00
|
|
|
|
2023-09-15 14:47:28 +02:00
|
|
|
property bool hovered: rootMouseArea.containsMouse
|
|
|
|
|
property bool selected: root.focus
|
|
|
|
|
|
2023-09-18 15:41:54 +02:00
|
|
|
property int maxTextWidth: 600
|
|
|
|
|
|
2023-09-15 14:47:28 +02:00
|
|
|
width: row.width
|
2023-09-04 16:45:54 +02:00
|
|
|
height: StudioTheme.Values.flowPillHeight
|
|
|
|
|
|
|
|
|
|
onActiveFocusChanged: {
|
|
|
|
|
if (root.activeFocus && root.isEditable())
|
|
|
|
|
textInput.forceActiveFocus()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Keys.onPressed: function (event) {
|
|
|
|
|
if (root.isEditable())
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if (event.key === Qt.Key_Backspace || event.key === Qt.Key_Delete)
|
|
|
|
|
root.remove()
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-19 13:46:53 +02:00
|
|
|
HelperWidgets.ToolTipArea {
|
2023-09-04 16:45:54 +02:00
|
|
|
id: rootMouseArea
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
hoverEnabled: true
|
|
|
|
|
cursorShape: root.isEditable() ? Qt.IBeamCursor : Qt.ArrowCursor
|
|
|
|
|
onClicked: root.forceActiveFocus()
|
2023-09-19 13:46:53 +02:00
|
|
|
tooltip: {
|
|
|
|
|
if (textItem.visible) {
|
|
|
|
|
if (textItem.truncated)
|
|
|
|
|
return textItem.text
|
|
|
|
|
else
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (textMetrics.width > textInput.width)
|
|
|
|
|
return textInput.text
|
|
|
|
|
|
|
|
|
|
return ""
|
|
|
|
|
}
|
2023-09-04 16:45:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: pill
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
color: {
|
2023-09-15 14:47:28 +02:00
|
|
|
if (root.isIntermediate())
|
2023-09-04 16:45:54 +02:00
|
|
|
return "transparent"
|
|
|
|
|
|
2023-09-15 14:47:28 +02:00
|
|
|
if (root.isShadow())
|
|
|
|
|
return StudioTheme.Values.themePillShadowBackground
|
|
|
|
|
|
|
|
|
|
if (root.isInvalid() && root.selected)
|
|
|
|
|
return StudioTheme.Values.themeWarning
|
|
|
|
|
|
|
|
|
|
if (root.hovered) {
|
|
|
|
|
if (root.isOperator())
|
|
|
|
|
return StudioTheme.Values.themePillOperatorBackgroundHover
|
|
|
|
|
if (root.isLiteral())
|
|
|
|
|
return StudioTheme.Values.themePillLiteralBackgroundHover
|
|
|
|
|
|
|
|
|
|
return StudioTheme.Values.themePillDefaultBackgroundHover
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (root.isLiteral())
|
|
|
|
|
return StudioTheme.Values.themePillLiteralBackgroundIdle
|
|
|
|
|
|
|
|
|
|
if (root.isOperator())
|
|
|
|
|
return StudioTheme.Values.themePillOperatorBackgroundIdle
|
|
|
|
|
|
|
|
|
|
return StudioTheme.Values.themePillDefaultBackgroundIdle
|
2023-09-04 16:45:54 +02:00
|
|
|
}
|
2023-09-15 14:47:28 +02:00
|
|
|
border.color: root.isInvalid() ? StudioTheme.Values.themeWarning
|
|
|
|
|
: StudioTheme.Values.themePillOutline
|
2023-09-04 16:45:54 +02:00
|
|
|
border.width: {
|
|
|
|
|
if (root.isShadow())
|
|
|
|
|
return 0
|
|
|
|
|
if (root.isInvalid())
|
|
|
|
|
return 1
|
|
|
|
|
if (root.isEditable())
|
|
|
|
|
return 0
|
2023-09-15 14:47:28 +02:00
|
|
|
if (root.selected)
|
2023-09-04 16:45:54 +02:00
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
}
|
2023-09-12 11:14:58 +02:00
|
|
|
radius: StudioTheme.Values.flowPillRadius
|
2023-09-04 16:45:54 +02:00
|
|
|
|
|
|
|
|
Row {
|
|
|
|
|
id: row
|
2023-09-15 14:47:28 +02:00
|
|
|
leftPadding: root.margin
|
|
|
|
|
rightPadding: icon.visible ? 0 : root.margin
|
2023-09-04 16:45:54 +02:00
|
|
|
|
2023-09-19 11:57:38 +02:00
|
|
|
property int textWidth: Math.min(textMetrics.advanceWidth + 2,
|
2023-09-18 15:41:54 +02:00
|
|
|
root.maxTextWidth - row.leftPadding
|
|
|
|
|
- (icon.visible ? icon.width : root.margin))
|
|
|
|
|
|
|
|
|
|
TextMetrics {
|
|
|
|
|
id: textMetrics
|
|
|
|
|
text: textItem.visible ? textItem.text : textInput.text
|
|
|
|
|
font: textItem.font
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-04 16:45:54 +02:00
|
|
|
Text {
|
|
|
|
|
id: textItem
|
2023-09-18 15:41:54 +02:00
|
|
|
width: row.textWidth
|
2023-09-15 14:47:28 +02:00
|
|
|
height: StudioTheme.Values.flowPillHeight
|
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2023-09-18 15:41:54 +02:00
|
|
|
textFormat: Text.PlainText
|
|
|
|
|
elide: Text.ElideMiddle
|
2023-09-04 16:45:54 +02:00
|
|
|
font.pixelSize: StudioTheme.Values.baseFontSize
|
2023-09-15 13:28:28 +02:00
|
|
|
color: root.isShadow() ? StudioTheme.Values.themePillTextSelected
|
|
|
|
|
: StudioTheme.Values.themePillText
|
2023-09-12 11:14:58 +02:00
|
|
|
text: root.isOperator() ? root.operatorModel.convertValueToName(root.value)
|
|
|
|
|
: root.value
|
2023-09-15 14:47:28 +02:00
|
|
|
visible: root.isOperator() || root.isProperty() || root.isShadow()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextInput {
|
|
|
|
|
id: textInput
|
|
|
|
|
x: root.isInvalid() ? root.margin : 0
|
2023-09-18 15:41:54 +02:00
|
|
|
width: row.textWidth
|
2023-09-15 14:47:28 +02:00
|
|
|
height: StudioTheme.Values.flowPillHeight
|
|
|
|
|
topPadding: 1
|
2023-09-18 15:41:54 +02:00
|
|
|
clip: true
|
2023-09-15 14:47:28 +02:00
|
|
|
font.pixelSize: StudioTheme.Values.baseFontSize
|
2023-09-15 13:28:28 +02:00
|
|
|
color: {
|
|
|
|
|
if (root.isIntermediate())
|
|
|
|
|
return StudioTheme.Values.themePillTextEdit
|
|
|
|
|
if (root.isInvalid() && root.selected)
|
|
|
|
|
return StudioTheme.Values.themePillTextSelected
|
|
|
|
|
return StudioTheme.Values.themePillText
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
selectedTextColor:StudioTheme.Values.themePillTextSelected
|
|
|
|
|
selectionColor: StudioTheme.Values.themeInteraction
|
|
|
|
|
|
2023-09-15 14:47:28 +02:00
|
|
|
text: root.value
|
|
|
|
|
visible: !textItem.visible
|
|
|
|
|
enabled: root.isEditable()
|
|
|
|
|
|
|
|
|
|
onEditingFinished: {
|
|
|
|
|
root.update(textInput.text) // emit
|
|
|
|
|
root.submit(textInput.cursorPosition) // emit
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-15 17:34:38 +02:00
|
|
|
Keys.onReleased: function (event) {
|
2023-09-15 14:47:28 +02:00
|
|
|
if (event.key === Qt.Key_Backspace) {
|
|
|
|
|
if (textInput.text !== "")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
root.remove() // emit
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-04 16:45:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
id: icon
|
2023-09-15 14:47:28 +02:00
|
|
|
width: StudioTheme.Values.flowPillHeight
|
2023-09-04 16:45:54 +02:00
|
|
|
height: StudioTheme.Values.flowPillHeight
|
2023-09-15 14:47:28 +02:00
|
|
|
visible: !root.isShadow() && !root.isIntermediate()
|
2023-09-04 16:45:54 +02:00
|
|
|
|
|
|
|
|
Text {
|
|
|
|
|
font.family: StudioTheme.Constants.iconFont.family
|
|
|
|
|
font.pixelSize: StudioTheme.Values.smallIconFontSize
|
2023-09-15 13:28:28 +02:00
|
|
|
color: root.isInvalid() && root.selected ? StudioTheme.Values.themePillTextSelected
|
|
|
|
|
: StudioTheme.Values.themePillText
|
2023-09-04 16:45:54 +02:00
|
|
|
text: StudioTheme.Constants.close_small
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
id: mouseArea
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
onClicked: root.remove()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|