From bda29efb58c853de611ce43d708d7884b2386ea2 Mon Sep 17 00:00:00 2001 From: uncor3 Date: Fri, 22 May 2026 11:50:59 +0000 Subject: [PATCH] implement StateView --- src/ui/base/StateView.qml | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/ui/base/StateView.qml diff --git a/src/ui/base/StateView.qml b/src/ui/base/StateView.qml new file mode 100644 index 0000000..18407bb --- /dev/null +++ b/src/ui/base/StateView.qml @@ -0,0 +1,63 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +Item { + id: root + + enum State { + Loading, + Error, + Content + } + + property int viewState: StateView.State.Loading + property string errorText: "Something went wrong." + property bool retryable: true + property alias contentItem: contentSlot.data + + signal retryRequested() + + StackLayout { + anchors.fill: parent + currentIndex: root.viewState + + /* 0 — Loading */ + Item { + BusyIndicator { + anchors.centerIn: parent + running: root.viewState === StateView.State.Loading + } + } + + /* 1 — Error */ + Item { + ColumnLayout { + anchors.centerIn: parent + spacing: 12 + + Text { + Layout.alignment: Qt.AlignHCenter + Layout.maximumWidth: 300 + text: root.errorText + wrapMode: Text.WordWrap + horizontalAlignment: Text.AlignHCenter + color: "#cc3333" + font.pixelSize: 14 + } + + Button { + Layout.alignment: Qt.AlignHCenter + visible: root.retryable + text: "Retry" + onClicked: root.retryRequested() + } + } + } + + /* 2- Content */ + Item { + id: contentSlot + } + } +} \ No newline at end of file