2024-10-15 19:26:12 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.5
|
|
|
|
import QtQuick.Layouts 1.15
|
2022-05-07 11:45:15 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2022-06-22 12:16:21 +00:00
|
|
|
import shared.popups 1.0
|
2022-05-07 11:45:15 +00:00
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
|
2023-11-17 14:08:43 +00:00
|
|
|
FocusScope {
|
2022-05-07 11:45:15 +00:00
|
|
|
id: root
|
|
|
|
|
|
|
|
property string sectionTitle
|
|
|
|
property int contentWidth
|
2024-10-15 19:26:12 +00:00
|
|
|
readonly property int contentHeight: root.height - titleRow.height - Theme.padding
|
2022-05-07 11:45:15 +00:00
|
|
|
|
2023-07-11 15:10:26 +00:00
|
|
|
property alias titleRowLeftComponentLoader: leftLoader
|
2022-05-07 11:45:15 +00:00
|
|
|
property alias titleRowComponentLoader: loader
|
|
|
|
property list<Item> headerComponents
|
2022-10-20 13:41:18 +00:00
|
|
|
property alias bottomHeaderComponents: secondHeaderRow.contentItem
|
2024-01-24 12:02:03 +00:00
|
|
|
default property alias content: contentWrapper.children
|
2023-07-11 15:10:26 +00:00
|
|
|
property alias titleLayout: titleLayout
|
2022-05-07 11:45:15 +00:00
|
|
|
|
2024-07-18 20:10:24 +00:00
|
|
|
property bool stickTitleRowComponentLoader: false
|
|
|
|
|
2022-06-22 12:16:21 +00:00
|
|
|
property bool dirty: false
|
2024-03-04 12:41:54 +00:00
|
|
|
|
|
|
|
// Used to configure the dirty behaviour of the settings page as a must blocker notification when
|
|
|
|
// user wants to leave the current page or just, ignore the changes done. Default: blocker
|
|
|
|
property bool ignoreDirty: false
|
|
|
|
|
2022-06-22 12:16:21 +00:00
|
|
|
property bool saveChangesButtonEnabled: false
|
2023-11-17 14:08:43 +00:00
|
|
|
readonly property alias toast: settingsDirtyToastMessage
|
2022-06-22 12:16:21 +00:00
|
|
|
|
2024-03-04 12:41:54 +00:00
|
|
|
// Used to configure the dirty toast behaviour (by default overlay on top of content)
|
|
|
|
property bool autoscrollWhenDirty: false
|
|
|
|
|
2024-01-26 15:39:42 +00:00
|
|
|
readonly property real availableHeight:
|
|
|
|
scrollView.availableHeight - settingsDirtyToastMessagePlaceholder.height
|
2024-10-15 19:26:12 +00:00
|
|
|
- Theme.bigPadding
|
2024-01-26 15:39:42 +00:00
|
|
|
|
2022-04-01 10:30:55 +00:00
|
|
|
signal baseAreaClicked()
|
2022-06-22 12:16:21 +00:00
|
|
|
signal saveChangesClicked()
|
2023-11-17 14:08:43 +00:00
|
|
|
signal saveForLaterClicked()
|
2022-06-22 12:16:21 +00:00
|
|
|
signal resetChangesClicked()
|
|
|
|
|
|
|
|
function notifyDirty() {
|
|
|
|
settingsDirtyToastMessage.notifyDirty();
|
|
|
|
}
|
2022-05-07 11:45:15 +00:00
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
readonly property int titleRowHeight: 56
|
2024-03-04 12:41:54 +00:00
|
|
|
readonly property int bottomDirtyToastMargin: 36
|
2022-05-07 11:45:15 +00:00
|
|
|
}
|
|
|
|
|
2022-06-03 15:32:03 +00:00
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: { root.baseAreaClicked() }
|
|
|
|
}
|
2022-04-01 10:30:55 +00:00
|
|
|
|
2022-05-07 11:45:15 +00:00
|
|
|
Component.onCompleted: {
|
|
|
|
if (headerComponents.length) {
|
|
|
|
for (let i in headerComponents) {
|
|
|
|
headerComponents[i].parent = titleRow
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-20 13:41:18 +00:00
|
|
|
ColumnLayout {
|
2022-05-07 11:45:15 +00:00
|
|
|
id: titleRow
|
2022-10-20 13:41:18 +00:00
|
|
|
width: root.contentWidth
|
|
|
|
spacing: 0
|
2023-03-21 05:10:06 +00:00
|
|
|
|
2022-10-20 13:41:18 +00:00
|
|
|
RowLayout {
|
2023-07-11 15:10:26 +00:00
|
|
|
id: titleLayout
|
2023-09-22 09:58:02 +00:00
|
|
|
Layout.fillWidth: true
|
2022-10-20 13:41:18 +00:00
|
|
|
Layout.preferredHeight: visible ? d.titleRowHeight : 0
|
|
|
|
visible: (root.sectionTitle !== "")
|
|
|
|
|
2023-07-11 15:10:26 +00:00
|
|
|
Loader {
|
|
|
|
id: leftLoader
|
|
|
|
}
|
|
|
|
|
2022-10-20 13:41:18 +00:00
|
|
|
StatusBaseText {
|
2024-07-18 20:10:24 +00:00
|
|
|
Layout.fillWidth: !root.stickTitleRowComponentLoader
|
2022-10-20 13:41:18 +00:00
|
|
|
text: root.sectionTitle
|
|
|
|
font.weight: Font.Bold
|
|
|
|
font.pixelSize: Constants.settingsSection.mainHeaderFontSize
|
|
|
|
color: Theme.palette.directColor1
|
|
|
|
}
|
2022-05-07 11:45:15 +00:00
|
|
|
|
2022-10-20 13:41:18 +00:00
|
|
|
Loader {
|
|
|
|
id: loader
|
2024-07-18 20:10:24 +00:00
|
|
|
Layout.leftMargin: root.stickTitleRowComponentLoader ? 8 : 0
|
2022-10-20 13:41:18 +00:00
|
|
|
}
|
2022-05-07 11:45:15 +00:00
|
|
|
}
|
2022-10-20 13:41:18 +00:00
|
|
|
Control {
|
|
|
|
id: secondHeaderRow
|
|
|
|
Layout.fillWidth: true
|
|
|
|
visible: !!contentItem
|
2022-05-07 11:45:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-13 12:29:38 +00:00
|
|
|
StatusScrollView {
|
2022-06-22 12:16:21 +00:00
|
|
|
id: scrollView
|
2022-08-12 12:11:57 +00:00
|
|
|
objectName: "settingsContentBaseScrollView"
|
2022-10-20 13:41:18 +00:00
|
|
|
anchors.top: titleRow.bottom
|
2022-05-07 11:45:15 +00:00
|
|
|
anchors.bottom: parent.bottom
|
2024-10-15 19:26:12 +00:00
|
|
|
anchors.topMargin: titleLayout.visible ? Theme.padding: 0
|
2022-07-14 11:03:36 +00:00
|
|
|
padding: 0
|
2023-03-20 12:29:05 +00:00
|
|
|
width: root.width
|
|
|
|
contentWidth: root.contentWidth
|
2024-10-15 19:26:12 +00:00
|
|
|
contentHeight: contentLayout.implicitHeight + Theme.bigPadding
|
2022-06-22 12:16:21 +00:00
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
Column {
|
|
|
|
id: contentLayout
|
|
|
|
width: scrollView.availableWidth
|
2022-04-01 10:30:55 +00:00
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
MouseArea {
|
|
|
|
onClicked: root.baseAreaClicked()
|
|
|
|
width: contentWrapper.implicitWidth
|
|
|
|
height: contentWrapper.implicitHeight
|
2022-12-07 15:29:37 +00:00
|
|
|
hoverEnabled: true
|
2022-06-22 12:16:21 +00:00
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
Column {
|
|
|
|
id: contentWrapper
|
2023-11-17 14:08:43 +00:00
|
|
|
onVisibleChanged: if (visible) forceActiveFocus()
|
2022-06-22 12:16:21 +00:00
|
|
|
}
|
2022-07-14 11:03:36 +00:00
|
|
|
}
|
2022-06-22 12:16:21 +00:00
|
|
|
|
2024-03-04 12:41:54 +00:00
|
|
|
// Used only when dirty toast visible and in case of autoscrolling configuration
|
2022-07-14 11:03:36 +00:00
|
|
|
Item {
|
2024-01-26 15:39:42 +00:00
|
|
|
id: settingsDirtyToastMessagePlaceholder
|
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
width: settingsDirtyToastMessage.implicitWidth
|
2024-03-04 12:41:54 +00:00
|
|
|
height: settingsDirtyToastMessage.active && root.autoscrollWhenDirty ?
|
|
|
|
(settingsDirtyToastMessage.implicitHeight + d.bottomDirtyToastMargin) : 0 /*Overlay on top of content*/
|
2022-06-22 12:16:21 +00:00
|
|
|
|
2022-07-14 11:03:36 +00:00
|
|
|
Behavior on implicitHeight {
|
2024-03-04 12:41:54 +00:00
|
|
|
enabled: root.autoscrollWhenDirty
|
2022-07-14 11:03:36 +00:00
|
|
|
NumberAnimation {
|
|
|
|
duration: 150
|
|
|
|
easing.type: Easing.InOutQuad
|
2022-06-22 12:16:21 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-01 10:30:55 +00:00
|
|
|
}
|
2022-05-07 11:45:15 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-22 12:16:21 +00:00
|
|
|
|
|
|
|
SettingsDirtyToastMessage {
|
|
|
|
id: settingsDirtyToastMessage
|
|
|
|
anchors.bottom: scrollView.bottom
|
2024-03-04 12:41:54 +00:00
|
|
|
anchors.bottomMargin: d.bottomDirtyToastMargin
|
2024-03-04 15:57:27 +00:00
|
|
|
|
|
|
|
// Left anchors and margin added bc of the implementation of the `SettingsContentBase` parent margin and to avoid
|
|
|
|
// this toast to be wrongly centered
|
2024-03-08 17:03:44 +00:00
|
|
|
// Constants.settingsSection.leftMargin is the margin set up to the parent when using `SettingsContentBase` inside central
|
|
|
|
// panel property of `StatusSectionLayout` and needs to be taken into account to counteract it
|
|
|
|
// when trying to align horizontally the save toast component
|
2024-03-04 15:57:27 +00:00
|
|
|
anchors.left: root.left
|
2024-03-08 17:03:44 +00:00
|
|
|
anchors.leftMargin: -Constants.settingsSection.leftMargin / 2 + (root.width / 2 - width / 2)
|
2024-03-04 15:57:27 +00:00
|
|
|
|
2022-06-22 12:16:21 +00:00
|
|
|
active: root.dirty
|
2024-03-04 12:41:54 +00:00
|
|
|
flickable: root.autoscrollWhenDirty ? scrollView.flickable : null
|
2022-06-22 12:16:21 +00:00
|
|
|
saveChangesButtonEnabled: root.saveChangesButtonEnabled
|
|
|
|
onResetChangesClicked: root.resetChangesClicked()
|
|
|
|
onSaveChangesClicked: root.saveChangesClicked()
|
2023-11-17 14:08:43 +00:00
|
|
|
onSaveForLaterClicked: root.saveForLaterClicked()
|
2022-06-22 12:16:21 +00:00
|
|
|
}
|
2022-05-07 11:45:15 +00:00
|
|
|
}
|