Better restructuring of QML files

This commit is contained in:
2023-02-19 21:22:45 +01:00
parent 9edce9bee4
commit 2461e00c73
10 changed files with 290 additions and 153 deletions

41
AnimatedInputPanel.qml Normal file
View File

@ -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
}
}
}
]
}

37
AnimatedStackView.qml Normal file
View File

@ -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
}
}
}

View File

@ -46,6 +46,9 @@ qt_add_qml_module(applightcontrol
IconComboBox.qml IconComboBox.qml
IconsModel.qml IconsModel.qml
DeviceTypeRegisterTypesModel.qml DeviceTypeRegisterTypesModel.qml
LampRegistersPanel.qml
AnimatedInputPanel.qml
AnimatedStackView.qml
) )
set_target_properties(applightcontrol PROPERTIES set_target_properties(applightcontrol PROPERTIES

View File

@ -21,9 +21,12 @@ ColumnLayout {
Layout.maximumWidth: 300 Layout.maximumWidth: 300
Layout.fillHeight: true 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) => { onRemoveClicked: (index) => {
const dialog = dialogComponent.createObject(Overlay.overlay); const dialog = dialogComponent.createObject(Overlay.overlay);
dialog.index = index; dialog.index = index;
@ -43,7 +46,7 @@ ColumnLayout {
modal: true modal: true
title: qsTr('Confirmation') title: qsTr('Confirmation')
onAccepted: devicesModel.removeRow(index) onAccepted: model.removeRow(index)
Label { Label {
id: textContainer id: textContainer

73
LampRegistersPanel.qml Normal file
View File

@ -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
}
}
}
}

View File

@ -2,9 +2,6 @@ import QtQuick
import QtQuick.Controls.Material import QtQuick.Controls.Material
import QtQuick.Layouts import QtQuick.Layouts
import QtQuick.Window import QtQuick.Window
import QtQuick.VirtualKeyboard
import lightcontrol
ApplicationWindow { ApplicationWindow {
id: window id: window
@ -22,11 +19,6 @@ ApplicationWindow {
property int masterWhite property int masterWhite
property int masterStrobo property int masterStrobo
DevicesModel {
id: devicesModel
controller: __controller
}
ColumnLayout { ColumnLayout {
anchors.left: parent.left anchors.left: parent.left
anchors.top: parent.top anchors.top: parent.top
@ -38,124 +30,27 @@ ApplicationWindow {
Layout.preferredHeight: 75 Layout.preferredHeight: 75
} }
StackView { AnimatedStackView {
id: stackview id: stackview
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
initialItem: homePage initialItem: Component {
Component {
id: homePage
HomePage { 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 id: lampRegistersPanel
z: 98 z: 98
x: 0 x: 0
height: 300 height: 300
y: window.height - height y: window.height - height
width: window.width width: window.width
property bool active: typeof stackview.currentItem.needsRegler == 'boolean' ? stackview.currentItem.needsRegler : false
states: State { active: typeof stackview.currentItem.needsRegler == 'boolean' ? stackview.currentItem.needsRegler : false
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
}
}
}
} }
Button { Button {
@ -175,46 +70,12 @@ ApplicationWindow {
focus: false focus: false
} }
InputPanel { AnimatedInputPanel {
id: inputPanel id: inputPanel
z: 99 z: 99
x: 0 x: 0
y: window.height y: window.height
width: window.width 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
}
}
}
]
} }
} }

View File

@ -23,8 +23,42 @@ ColumnLayout {
Layout.fillHeight: true Layout.fillHeight: true
model: RegisterGroupsModel { model: RegisterGroupsModel {
id: model
controller: __controller 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 { ColumnLayout {

View File

@ -5,12 +5,12 @@ import QtQuick.Layouts
import lightcontrol import lightcontrol
Pane { Pane {
property alias deviceTypeId: deviceTypeRegistersModel.deviceTypeId property alias deviceTypeId: model.deviceTypeId
Material.elevation: 6 Material.elevation: 6
DeviceTypeRegistersModel { DeviceTypeRegistersModel {
id: deviceTypeRegistersModel id: model
controller: __controller controller: __controller
} }
@ -29,10 +29,10 @@ Pane {
textRole: 'registerTypeName' 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'); } onAddClicked: (index) => { const newIndex = index < 0 ? 0 : index + 1; if (model.insertRow(newIndex)) currentIndex = newIndex; else console.warn('failed'); }
onRemoveClicked: (index) => deviceTypeRegistersModel.removeRow(index) onRemoveClicked: (index) => model.removeRow(index)
} }
} }

View File

@ -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="<neu>", .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 { namespace {
void registrierDenShit() void registrierDenShit()
{ {

View File

@ -22,6 +22,8 @@ public:
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) 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: signals:
void controllerChanged(DmxController *controller); void controllerChanged(DmxController *controller);