Unified API to save/restore state properties
This commit is contained in:
@@ -4,7 +4,6 @@ import "../utils.js" as Utils
|
||||
|
||||
Drawer {
|
||||
id: drawer
|
||||
objectName: "" // Set one to allow storing the user size to a file
|
||||
implicitWidth: horizontal ? calculatedSize : parent.width
|
||||
implicitHeight: vertical ? calculatedSize : parent.height
|
||||
|
||||
@@ -25,14 +24,18 @@ Drawer {
|
||||
background: Rectangle { id: bg; color: theme.colors.strongBackground }
|
||||
|
||||
|
||||
property string saveName: ""
|
||||
property string saveId: ""
|
||||
property var saveProperties: ["preferredSize"]
|
||||
|
||||
//
|
||||
|
||||
property alias color: bg.color
|
||||
|
||||
property int defaultSize: 300
|
||||
|
||||
property int preferredSize:
|
||||
window.uiState[objectName] ?
|
||||
(window.uiState[objectName].size || defaultSize) :
|
||||
defaultSize
|
||||
window.getState(this, "preferredSize", defaultSize)
|
||||
|
||||
property int minimumSize: resizeAreaSize
|
||||
property int maximumSize:
|
||||
@@ -109,17 +112,7 @@ Drawer {
|
||||
(drawer.edge === Qt.BottomEdge ? -mouseY : mouseY)
|
||||
}
|
||||
|
||||
onReleased: {
|
||||
if (! drawer.objectName) {
|
||||
console.warn("Can't save pane size, no objectName set")
|
||||
return
|
||||
}
|
||||
|
||||
window.uiState[drawer.objectName] = {
|
||||
size: drawer.preferredSize,
|
||||
}
|
||||
window.uiStateChanged()
|
||||
}
|
||||
onReleased: window.saveState(drawer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ import QtQuick.Controls 2.12
|
||||
|
||||
TextField {
|
||||
id: field
|
||||
objectName: "" // Set one to allow remembering the text using a file
|
||||
selectByMouse: true
|
||||
leftPadding: theme.spacing
|
||||
rightPadding: leftPadding
|
||||
@@ -32,13 +31,9 @@ TextField {
|
||||
|
||||
// Set it only on component creation to avoid binding loops
|
||||
Component.onCompleted:
|
||||
if (! text && uiState[objectName]) text = uiState[objectName].text
|
||||
if (! text) text = window.getState(this, "text", "")
|
||||
|
||||
onTextChanged: {
|
||||
if (! objectName) return
|
||||
window.uiState[objectName] = {text}
|
||||
window.uiStateChanged()
|
||||
}
|
||||
onTextChanged: window.saveState(this)
|
||||
|
||||
Keys.onPressed: if (
|
||||
event.modifiers & Qt.AltModifier ||
|
||||
@@ -46,6 +41,10 @@ TextField {
|
||||
) event.accepted = true // XXX Still needed?
|
||||
|
||||
|
||||
property string saveName: ""
|
||||
property string saveId: ""
|
||||
property var saveProperties: ["text"]
|
||||
|
||||
property bool error: false
|
||||
|
||||
property alias radius: textFieldBackground.radius
|
||||
|
Reference in New Issue
Block a user