Implement HLabeledItem loading mode

This commit is contained in:
miruka 2020-06-25 09:46:26 -04:00
parent da4a5ab5cd
commit 470b0f0de2
3 changed files with 53 additions and 14 deletions

View File

@ -9,6 +9,8 @@ HColumnLayout {
default property alias insideData: itemHolder.data default property alias insideData: itemHolder.data
property bool loading: false
readonly property Item item: itemHolder.children[0] readonly property Item item: itemHolder.children[0]
readonly property alias label: label readonly property alias label: label
readonly property alias errorLabel: errorLabel readonly property alias errorLabel: errorLabel
@ -16,7 +18,7 @@ HColumnLayout {
HRowLayout { HRowLayout {
spacing: parent.spacing spacing: theme.spacing
HLabel { HLabel {
id: label id: label
@ -51,6 +53,17 @@ HColumnLayout {
id: toolTip id: toolTip
visible: toolTip.text && hoverHandler.hovered visible: toolTip.text && hoverHandler.hovered
} }
HLoader {
source: "HBusyIndicator.qml"
active: loading
visible: height > 0
Layout.preferredWidth: height
Layout.preferredHeight: active ? label.height : 0
Behavior on Layout.preferredHeight { HNumberAnimation {} }
}
} }
Item { Item {

View File

@ -25,6 +25,8 @@ TextArea {
property color errorBorder: theme.controls.textArea.errorBorder property color errorBorder: theme.controls.textArea.errorBorder
property color focusedBorderColor: theme.controls.textArea.focusedBorder property color focusedBorderColor: theme.controls.textArea.focusedBorder
property string previousDefaultText: "" // private
function reset() { clear(); text = Qt.binding(() => defaultText) } function reset() { clear(); text = Qt.binding(() => defaultText) }
function insertAtCursor(text) { insert(cursorPosition, text) } function insertAtCursor(text) { insert(cursorPosition, text) }
@ -62,17 +64,28 @@ TextArea {
} }
} }
Component.onCompleted: {
// Break binding
previousDefaultText = previousDefaultText
// Set it only on component creation to avoid binding loops // Set it only on component creation to avoid binding loops
Component.onCompleted: if (! text) { if (! text) {
text = window.getState(this, "text", "") text = window.getState(this, "text", "")
textArea.cursorPosition = text.length cursorPosition = text.length
}
} }
onActiveFocusChanged:
text = activeFocus || changed ? text : Qt.binding(() => defaultText)
onTextChanged: window.saveState(this) onTextChanged: window.saveState(this)
onActiveFocusChanged: text = text // Break binding
onDefaultTextChanged: {
if (text === previousDefaultText)
text = Qt.binding(() => defaultText)
previousDefaultText = defaultText
}
// Prevent alt/super+any key from typing text // Prevent alt/super+any key from typing text
Keys.onPressed: if ( Keys.onPressed: if (
event.modifiers & Qt.AltModifier || event.modifiers & Qt.AltModifier ||

View File

@ -37,16 +37,27 @@ TextField {
} }
} }
Component.onCompleted: {
// Break binding
previousDefaultText = previousDefaultText
// Set it only on component creation to avoid binding loops // Set it only on component creation to avoid binding loops
Component.onCompleted: if (! text) { if (! text) {
text = window.getState(this, "text", "") text = window.getState(this, "text", "")
cursorPosition = text.length cursorPosition = text.length
} }
}
onTextChanged: window.saveState(this) onTextChanged: window.saveState(this)
onActiveFocusChanged: onActiveFocusChanged: text = text // Break binding
text = activeFocus || changed ? text : Qt.binding(() => defaultText)
onDefaultTextChanged: {
if (text === previousDefaultText)
text = Qt.binding(() => defaultText)
previousDefaultText = defaultText
}
// Prevent alt/super+any key from typing text // Prevent alt/super+any key from typing text
Keys.onPressed: if ( Keys.onPressed: if (
@ -81,6 +92,8 @@ TextField {
property string defaultText: "" property string defaultText: ""
readonly property bool changed: text !== defaultText readonly property bool changed: text !== defaultText
property string previousDefaultText: "" // private
function reset() { clear(); text = Qt.binding(() => defaultText)} function reset() { clear(); text = Qt.binding(() => defaultText)}