From 2461e00c737c9600087add2d6983e70a1bb7a258 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Sun, 19 Feb 2023 21:22:45 +0100 Subject: [PATCH] Better restructuring of QML files --- AnimatedInputPanel.qml | 41 +++++++++ AnimatedStackView.qml | 37 ++++++++ CMakeLists.txt | 3 + DevicesSettingsPage.qml | 9 +- LampRegistersPanel.qml | 73 ++++++++++++++++ LightControlWindow.qml | 151 ++------------------------------- RegisterGroupsSettingsPage.qml | 34 ++++++++ RegistersSettingsItem.qml | 10 +-- registergroupsmodel.cpp | 83 ++++++++++++++++++ registergroupsmodel.h | 2 + 10 files changed, 290 insertions(+), 153 deletions(-) create mode 100644 AnimatedInputPanel.qml create mode 100644 AnimatedStackView.qml create mode 100644 LampRegistersPanel.qml diff --git a/AnimatedInputPanel.qml b/AnimatedInputPanel.qml new file mode 100644 index 0000000..daf126c --- /dev/null +++ b/AnimatedInputPanel.qml @@ -0,0 +1,41 @@ +import QtQuick +import QtQuick.VirtualKeyboard + +InputPanel { + id: inputPanel + + states: State { + name: "visible" + when: inputPanel.active + PropertyChanges { + target: inputPanel + y: window.height - inputPanel.height + } + } + transitions: [ + Transition { + from: "visible" + to: "" + reversible: false + ParallelAnimation { + NumberAnimation { + properties: "y" + duration: 1000 + easing.type: Easing.OutBounce + } + } + }, + Transition { + from: "" + to: "visible" + reversible: false + ParallelAnimation { + NumberAnimation { + properties: "y" + duration: 1000 + easing.type: Easing.OutBounce + } + } + } + ] +} diff --git a/AnimatedStackView.qml b/AnimatedStackView.qml new file mode 100644 index 0000000..62c4e78 --- /dev/null +++ b/AnimatedStackView.qml @@ -0,0 +1,37 @@ +import QtQuick +import QtQuick.Controls.Material + +StackView { + pushEnter: Transition { + PropertyAnimation { + property: "opacity" + from: 0 + to:1 + duration: 200 + } + } + pushExit: Transition { + PropertyAnimation { + property: "opacity" + from: 1 + to:0 + duration: 200 + } + } + popEnter: Transition { + PropertyAnimation { + property: "opacity" + from: 0 + to:1 + duration: 200 + } + } + popExit: Transition { + PropertyAnimation { + property: "opacity" + from: 1 + to:0 + duration: 200 + } + } +} diff --git a/CMakeLists.txt b/CMakeLists.txt index 82401fa..dcfcf40 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,9 @@ qt_add_qml_module(applightcontrol IconComboBox.qml IconsModel.qml DeviceTypeRegisterTypesModel.qml + LampRegistersPanel.qml + AnimatedInputPanel.qml + AnimatedStackView.qml ) set_target_properties(applightcontrol PROPERTIES diff --git a/DevicesSettingsPage.qml b/DevicesSettingsPage.qml index 9423fce..072775f 100644 --- a/DevicesSettingsPage.qml +++ b/DevicesSettingsPage.qml @@ -21,9 +21,12 @@ ColumnLayout { Layout.maximumWidth: 300 Layout.fillHeight: true - model: devicesModel + model: DevicesModel { + id: model + controller: __controller + } - onAddClicked: (index) => { const newIndex = index < 0 ? 0 : index + 1; if (devicesModel.insertRow(newIndex)) currentIndex = newIndex; else console.warn('failed'); } + onAddClicked: (index) => { const newIndex = index < 0 ? 0 : index + 1; if (model.insertRow(newIndex)) currentIndex = newIndex; else console.warn('failed'); } onRemoveClicked: (index) => { const dialog = dialogComponent.createObject(Overlay.overlay); dialog.index = index; @@ -43,7 +46,7 @@ ColumnLayout { modal: true title: qsTr('Confirmation') - onAccepted: devicesModel.removeRow(index) + onAccepted: model.removeRow(index) Label { id: textContainer diff --git a/LampRegistersPanel.qml b/LampRegistersPanel.qml new file mode 100644 index 0000000..39c3b17 --- /dev/null +++ b/LampRegistersPanel.qml @@ -0,0 +1,73 @@ +import QtQuick +import QtQuick.Controls.Material +import QtQuick.Layouts + +import lightcontrol + +Flickable { + id: lampRegistersPanel + + property bool active + + states: State { + name: "invisible" + when: !lampRegistersPanel.active + PropertyChanges { + target: lampRegistersPanel + y: window.height + } + } + transitions: [ + Transition { + from: "invisible" + to: "" + reversible: false + ParallelAnimation { + NumberAnimation { + properties: "y" + duration: 1000 + easing.type: Easing.OutBounce + } + } + }, + Transition { + from: "" + to: "invisible" + reversible: false + ParallelAnimation { + NumberAnimation { + properties: "y" + duration: 1000 + easing.type: Easing.OutBounce + } + } + } + ] + + contentWidth: theFlow.width + contentHeight: theFlow.height + + flickableDirection: Flickable.HorizontalFlick + + RowLayout { + id: theFlow + + height: parent.height + + spacing: 5 + + Repeater { + model: DevicesModel { + controller: __controller + } + + delegate: LightSliderPane { + light: model + + //Layout.fillHeight: true + + height: theFlow.height + } + } + } +} diff --git a/LightControlWindow.qml b/LightControlWindow.qml index 271fbeb..7873c68 100644 --- a/LightControlWindow.qml +++ b/LightControlWindow.qml @@ -2,9 +2,6 @@ import QtQuick import QtQuick.Controls.Material import QtQuick.Layouts import QtQuick.Window -import QtQuick.VirtualKeyboard - -import lightcontrol ApplicationWindow { id: window @@ -22,11 +19,6 @@ ApplicationWindow { property int masterWhite property int masterStrobo - DevicesModel { - id: devicesModel - controller: __controller - } - ColumnLayout { anchors.left: parent.left anchors.top: parent.top @@ -38,124 +30,27 @@ ApplicationWindow { Layout.preferredHeight: 75 } - StackView { + AnimatedStackView { id: stackview Layout.fillWidth: true Layout.fillHeight: true - initialItem: homePage - - Component { - id: homePage - + initialItem: Component { HomePage { } } - - pushEnter: Transition { - PropertyAnimation { - property: "opacity" - from: 0 - to:1 - duration: 200 - } - } - pushExit: Transition { - PropertyAnimation { - property: "opacity" - from: 1 - to:0 - duration: 200 - } - } - popEnter: Transition { - PropertyAnimation { - property: "opacity" - from: 0 - to:1 - duration: 200 - } - } - popExit: Transition { - PropertyAnimation { - property: "opacity" - from: 1 - to:0 - duration: 200 - } - } } } - Flickable { + LampRegistersPanel { id: lampRegistersPanel - z: 98 x: 0 height: 300 y: window.height - height width: window.width - property bool active: typeof stackview.currentItem.needsRegler == 'boolean' ? stackview.currentItem.needsRegler : false - states: State { - name: "invisible" - when: !lampRegistersPanel.active - PropertyChanges { - target: lampRegistersPanel - y: window.height - } - } - transitions: [ - Transition { - from: "invisible" - to: "" - reversible: false - ParallelAnimation { - NumberAnimation { - properties: "y" - duration: 1000 - easing.type: Easing.OutBounce - } - } - }, - Transition { - from: "" - to: "invisible" - reversible: false - ParallelAnimation { - NumberAnimation { - properties: "y" - duration: 1000 - easing.type: Easing.OutBounce - } - } - } - ] - - contentWidth: theFlow.width - contentHeight: theFlow.height - - flickableDirection: Flickable.HorizontalFlick - - RowLayout { - id: theFlow - - height: parent.height - - spacing: 5 - - Repeater { - model: devicesModel - - delegate: LightSliderPane { - light: model - - //Layout.fillHeight: true - - height: theFlow.height - } - } - } + active: typeof stackview.currentItem.needsRegler == 'boolean' ? stackview.currentItem.needsRegler : false } Button { @@ -175,46 +70,12 @@ ApplicationWindow { focus: false } - InputPanel { + AnimatedInputPanel { id: inputPanel + z: 99 x: 0 y: window.height width: window.width - - states: State { - name: "visible" - when: inputPanel.active - PropertyChanges { - target: inputPanel - y: window.height - inputPanel.height - } - } - transitions: [ - Transition { - from: "visible" - to: "" - reversible: false - ParallelAnimation { - NumberAnimation { - properties: "y" - duration: 1000 - easing.type: Easing.OutBounce - } - } - }, - Transition { - from: "" - to: "visible" - reversible: false - ParallelAnimation { - NumberAnimation { - properties: "y" - duration: 1000 - easing.type: Easing.OutBounce - } - } - } - ] } } diff --git a/RegisterGroupsSettingsPage.qml b/RegisterGroupsSettingsPage.qml index e1a1c08..eeb6096 100644 --- a/RegisterGroupsSettingsPage.qml +++ b/RegisterGroupsSettingsPage.qml @@ -23,8 +23,42 @@ ColumnLayout { Layout.fillHeight: true model: RegisterGroupsModel { + id: model controller: __controller } + + onAddClicked: (index) => { const newIndex = index < 0 ? 0 : index + 1; if (model.insertRow(newIndex)) currentIndex = newIndex; else console.warn('failed'); } + onRemoveClicked: (index) => { + const dialog = dialogComponent.createObject(Overlay.overlay); + dialog.index = index; + dialog.open(); + } + + Component { + id: dialogComponent + + Dialog { + property int index + + anchors.centerIn: parent + standardButtons: DialogButtonBox.Yes | DialogButtonBox.Cancel + modal: true + title: qsTr('Confirmation') + + onAccepted: model.removeRow(index) + + Label { + id: textContainer + + anchors.fill: parent + + horizontalAlignment: Qt.AlignLeft + verticalAlignment: Qt.AlignTop + + text: qsTr('Are you sure you want to remove row %0').arg(index) + } + } + } } ColumnLayout { diff --git a/RegistersSettingsItem.qml b/RegistersSettingsItem.qml index 12ae731..c98f6ec 100644 --- a/RegistersSettingsItem.qml +++ b/RegistersSettingsItem.qml @@ -5,12 +5,12 @@ import QtQuick.Layouts import lightcontrol Pane { - property alias deviceTypeId: deviceTypeRegistersModel.deviceTypeId + property alias deviceTypeId: model.deviceTypeId Material.elevation: 6 DeviceTypeRegistersModel { - id: deviceTypeRegistersModel + id: model controller: __controller } @@ -29,10 +29,10 @@ Pane { textRole: 'registerTypeName' - model: deviceTypeRegistersModel + model: model - onAddClicked: (index) => { const newIndex = index < 0 ? 0 : index + 1; if (deviceTypeRegistersModel.insertRow(newIndex)) currentIndex = newIndex; else console.warn('failed'); } - onRemoveClicked: (index) => deviceTypeRegistersModel.removeRow(index) + onAddClicked: (index) => { const newIndex = index < 0 ? 0 : index + 1; if (model.insertRow(newIndex)) currentIndex = newIndex; else console.warn('failed'); } + onRemoveClicked: (index) => model.removeRow(index) } } diff --git a/registergroupsmodel.cpp b/registergroupsmodel.cpp index a919c74..6c1cdae 100644 --- a/registergroupsmodel.cpp +++ b/registergroupsmodel.cpp @@ -173,6 +173,89 @@ bool RegisterGroupsModel::setData(const QModelIndex &index, const QVariant &valu } } +bool RegisterGroupsModel::insertRows(int row, int count, const QModelIndex &parent) +{ + if (parent.isValid()) + { + qWarning() << "hilfe" << __LINE__; + return false; + } + + if (!m_controller) + { + qWarning() << "hilfe" << __LINE__; + return false; + } + + auto &devices = m_controller->lightProject().devices; + + if (row < 0) + { + qWarning() << "hilfe" << __LINE__; + return false; + } + + if (row > devices.size()) + { + qWarning() << "hilfe" << __LINE__; + return false; + } + + auto max_iter = std::max_element(std::cbegin(devices), std::cend(devices), [](const auto &l, const auto &r){ return l.id < r.id; }); + auto id = max_iter != std::cend(devices) ? max_iter->id + 1 : 0; + + beginInsertRows({}, row, row+count-1); + auto iter = std::begin(devices) + row; + for (auto i = 0; i < count; i++) + iter = devices.insert(iter, LightConfig{ .id=id++, .name="", .deviceTypeId=0, .address=0, .position={} }) + 1; + endInsertRows(); + + return true; +} + +bool RegisterGroupsModel::removeRows(int row, int count, const QModelIndex &parent) +{ + if (parent.isValid()) + { + qWarning() << "hilfe" << __LINE__; + return false; + } + + if (!m_controller) + { + qWarning() << "hilfe" << __LINE__; + return false; + } + + auto &devices = m_controller->lightProject().devices; + + if (row < 0) + { + qWarning() << "hilfe" << __LINE__; + return false; + } + + if (row >= devices.size()) + { + qWarning() << "hilfe" << __LINE__; + return false; + } + + if (row + count > devices.size()) + { + qWarning() << "hilfe" << __LINE__; + return false; + } + + beginRemoveRows({}, row, row+count-1); + auto begin = std::begin(devices) + row; + auto end = begin + count; + devices.erase(begin, end); + endRemoveRows(); + + return true; +} + namespace { void registrierDenShit() { diff --git a/registergroupsmodel.h b/registergroupsmodel.h index eca9f2c..cd10097 100644 --- a/registergroupsmodel.h +++ b/registergroupsmodel.h @@ -22,6 +22,8 @@ public: QHash roleNames() const override; bool setData(const QModelIndex &index, const QVariant &value, int role) override; + bool insertRows(int row, int count, const QModelIndex &parent) override; + bool removeRows(int row, int count, const QModelIndex &parent) override; signals: void controllerChanged(DmxController *controller);