diff --git a/src/contents/ui/AddRecord.qml b/src/contents/ui/AddRecord.qml new file mode 100644 index 0000000000000000000000000000000000000000..fdbb91a9a43785616c8e57e78218d0aa21b1700a --- /dev/null +++ b/src/contents/ui/AddRecord.qml @@ -0,0 +1,138 @@ +import QtQuick 2.14 +import org.kde.kirigami 2.12 as Kirigami +import QtQuick.Controls 2.14 as Controls +import QtQuick.Layouts 1.14 as Layouts +import QtQuick.Controls 1.4 as Old +import QtQuick.Dialogs 1.3 as Dialogs + +Kirigami.PageRoute { + name: "addrecord" + Component { + Kirigami.Page { + id: recordAddPage + title: qsTr("Add Service Record") + Layouts.ColumnLayout { + anchors.fill: parent + Kirigami.InlineMessage { + Layouts.Layout.fillWidth: true + Layouts.Layout.leftMargin: 10 + Layouts.Layout.rightMargin: 10 + z: 9997 + type: Kirigami.MessageType.Error + showCloseButton: true + id: formError + } + Kirigami.FormLayout { + Layouts.Layout.alignment: Qt.AlignHCenter + Layouts.Layout.fillWidth: true + width: recordAddPage.width + + Item { + Kirigami.FormData.isSection: true + Kirigami.FormData.label: "Service Information" + } + + Controls.TextField { + id: providerField + selectByMouse: true + Kirigami.FormData.label: qsTr("Service Provider")+":" + } + + Controls.ComboBox { + id: typeField + model: serviceTypeModel + textRole: "text" + valueRole: "value" + onActivated: { + if(currentValue == -1) { + customTypeField.visible = true; + } else { + customTypeField.visible = false; + } + } + Kirigami.FormData.label: qsTr("Service Type")+":" + } + + Controls.TextField { + id: customTypeField + visible: false + Kirigami.FormData.label: qsTr("Custom Service Type")+":" + } + + Layouts.RowLayout { + Kirigami.FormData.label: qsTr("Date")+":" + Controls.TextField { + id: dateField + text: new Date().toLocaleDateString(Qt.locale()) + readOnly: true + } + Controls.Button { + icon.name: "office-calendar" + text: qsTr("Select Date") + display: Controls.AbstractButton.IconOnly + onClicked: { + calendarPopup.open(); + } + } + } + + Controls.TextField { + id: milesField + selectByMouse: true + Kirigami.FormData.label: qsTr("Miles")+":" + inputMethodHints: Qt.ImhDigitsOnly + validator: IntValidator { + bottom: 0 + top: 500000 + } + } + + Controls.TextArea { + id: notesField + placeholderText: qsTr("Notes about service") + selectByMouse: true + Kirigami.FormData.label: qsTr("Notes")+":" + } + + Layouts.RowLayout { + + Controls.Button { + text: qsTr("Add") + highlighted: true + onClicked: { + var dateObj = Date.fromLocaleDateString(Qt.locale(), dateField.text); + var typeText = typeField.currentText; + if(typeField.currentValue == -1) { + typeText = customTypeField.text; + } + if(milesField.acceptableInput) { + recordModel.addNewRecord(providerField.text, typeField.currentValue, typeText, dateObj.toISOString(), parseInt(milesField.text), notesField.text); + router.popRoute(); + } else { + formError.text = qsTr("Invalid number of miles."); + formError.visible = true; + } + } + } + Controls.Button { + text: qsTr("Cancel") + onClicked: { + router.popRoute(); + } + } + } + } + } + + Kirigami.OverlaySheet { + id: calendarPopup + Old.Calendar { + selectedDate: Date.fromLocaleDateString(Qt.locale(), dateField.text) + onClicked: { + dateField.text = date.toLocaleDateString(Qt.locale()); + } + } + } + } + } +} diff --git a/src/contents/ui/AddVehicle.qml b/src/contents/ui/AddVehicle.qml new file mode 100644 index 0000000000000000000000000000000000000000..cfa24baedb3e34c486eccd3e7705671b7536b550 --- /dev/null +++ b/src/contents/ui/AddVehicle.qml @@ -0,0 +1,95 @@ +import QtQuick 2.14 +import org.kde.kirigami 2.12 as Kirigami +import QtQuick.Controls 2.14 as Controls +import QtQuick.Layouts 1.14 as Layouts + +Kirigami.PageRoute { + name: "addvehicle" + Component { + Kirigami.Page { + id: vehicleAddPage + title: qsTr("Add Vehicle") + Layouts.ColumnLayout { + anchors.fill: parent + Kirigami.InlineMessage { + Layouts.Layout.fillWidth: true + Layouts.Layout.leftMargin: 10 + Layouts.Layout.rightMargin: 10 + z: 9997 + type: Kirigami.MessageType.Error + showCloseButton: true + id: formError + } + Kirigami.FormLayout { + Layouts.Layout.alignment: Qt.AlignHCenter + Layouts.Layout.fillWidth: true + width: vehicleAddPage.width + + Item { + Kirigami.FormData.isSection: true + Kirigami.FormData.label: "Vehicle Information" + } + + Controls.TextField { + id: nameField + selectByMouse: true + Kirigami.FormData.label: qsTr("Vehicle Name")+":" + } + + Controls.TextField { + id: makeField + selectByMouse: true + Kirigami.FormData.label: qsTr("Make")+":" + } + + Controls.TextField { + id: modelField + selectByMouse: true + Kirigami.FormData.label: qsTr("Model")+":" + } + + Controls.TextField { + id: yearField + selectByMouse: true + Kirigami.FormData.label: qsTr("Year")+":" + inputMethodHints: Qt.ImhDigitsOnly + validator: IntValidator { + bottom: 1900 + top: 4000 + } + } + + Controls.TextField { + id: vinField + selectByMouse: true + Kirigami.FormData.label: qsTr("VIN")+":" + } + + Layouts.RowLayout { + + Controls.Button { + text: qsTr("Add") + highlighted: true + onClicked: { + if(yearField.acceptableInput) { + vehicleModel.addNewVehicle(nameField.text, makeField.text, modelField.text, parseInt(yearField.text), "", vinField.text); + router.popRoute(); + } else { + formError.text = qsTr("Year is invalid!"); + formError.visible = true; + } + } + } + + Controls.Button { + text: qsTr("Cancel") + onClicked: { + router.popRoute(); + } + } + } + } + } + } + } +} diff --git a/src/contents/ui/MainPage.qml b/src/contents/ui/MainPage.qml new file mode 100644 index 0000000000000000000000000000000000000000..465687ec9d2413a871cdbca021d22929555d8bff --- /dev/null +++ b/src/contents/ui/MainPage.qml @@ -0,0 +1,123 @@ +import QtQuick 2.14 +import org.kde.kirigami 2.12 as Kirigami +import QtQuick.Controls 2.14 as Controls +import QtQuick.Layouts 1.14 as Layouts +import QtQuick.Controls 1.4 as Old +import QtQuick.Dialogs 1.3 as Dialogs + +Kirigami.PageRoute { + name: "main" + Component { + Kirigami.Page { + id: mainPage + mainAction: Kirigami.Action { + text: qsTr("Add Vehicle") + iconName: "list-add" + onTriggered: { + router.navigateToRoute(["main","addvehicle"]); + } + } + contextualActions: [ + Kirigami.Action { + iconName: "application-javascript" + text: qsTr("Import From Carfax JSON") + onTriggered: { + importDialog.visible = true; + } + }, + Kirigami.Action { + iconName: "help-about" + text: qsTr("About") + onTriggered: { + router.navigateToRoute("about"); + } + } + ] + title: "Vehicles" + Dialogs.FileDialog { + id: importDialog + title: qsTr("Select Carfax Json file to import...") + nameFilters: ["Carfax Vehicle Json (*.json)"] + onAccepted: { + if(jsonConverter.importCarfaxJsonToDB(importDialog.fileUrl)) { + // + } else { + root.showPassiveNotification(qsTr("Failed to parse file."),"short"); + } + } + } + Kirigami.CardsListView { + anchors.fill: parent + id: vehicleView + model: vehicleModel + delegate: Kirigami.Card { + id: card + banner { + title: name + } + header: Row{ + topPadding: 10.0 + rightPadding: 10.0 + leftPadding: 10.0 + layoutDirection: Qt.RightToLeft + spacing: 5 + Controls.Label { + text: vin + visible: root.wideScreen && mainPage.width > 550 + anchors.verticalCenter: parent.verticalCenter + } + Image { + id: vinIcon + source: "qrc:/license.svg" + sourceSize.width: 32 + sourceSize.height: 32 + anchors.verticalCenter: parent.verticalCenter + MouseArea { + id: vinMouse + hoverEnabled: true + anchors.fill: vinIcon + } + Controls.ToolTip { + id: vinTip + text: vin + visible: vinMouse.containsMouse + } + } + } + contentItem: Item{ + implicitHeight: Kirigami.Units.gridUnit * 4 + Layouts.ColumnLayout { + Kirigami.Heading { + text: maker + " " + vmodel + level: 2 + } + Kirigami.Heading { + text: year + level: 4 + } + } + } + actions: [ + Kirigami.Action { + text: qsTr("Examine Logs") + iconName: "edit-find" + onTriggered: { + router.navigateToRoute(["main", {"route": "servicerecords", "data": {"id": id, "name": name}}]); + } + } + ] + hiddenActions: [ + Kirigami.Action { + text: qsTr("Delete") + iconName: "edit-delete" + onTriggered: { + vehicleModel.removeVehicle(index); + } + } + ] + } + Controls.ScrollBar.vertical: Controls.ScrollBar {} + } + } + } +} diff --git a/src/contents/ui/ServiceRecords.qml b/src/contents/ui/ServiceRecords.qml new file mode 100644 index 0000000000000000000000000000000000000000..d1b72b77fbd008fbc30254e67ddee61ddd214212 --- /dev/null +++ b/src/contents/ui/ServiceRecords.qml @@ -0,0 +1,99 @@ +import QtQuick 2.14 +import org.kde.kirigami 2.12 as Kirigami +import QtQuick.Controls 2.14 as Controls +import QtQuick.Layouts 1.14 as Layouts + +Kirigami.PageRoute { + name: "servicerecords" + + Component { + Kirigami.ScrollablePage { + property var serviceId: Kirigami.PageRouter.data.id + Component.onCompleted: { + recordModel.changeVehicleFilter(serviceId); + //Check vehicle warnings + dbAnalytics.checkOilChangeNeededForVehicle(serviceId, appAnalyticsSettings.value("milesForOilChange",5000), appAnalyticsSettings.value("monthsForOilChange",6)); + } + Connections { + target: recordModel + function onVehicleUpdated(vehicleId) { + //Check vehicle warnings + if(vehicleId == serviceId) { + dbAnalytics.checkOilChangeNeededForVehicle(vehicleId, appAnalyticsSettings.value("milesForOilChange",5000), appAnalyticsSettings.value("monthsForOilChange",6)); + } + } + } + id: serviceRecordPage + title: qsTr("Service Records for ") + Kirigami.PageRouter.data.name + mainAction: Kirigami.Action { + text: qsTr("Add Service Record") + iconName: "list-add" + onTriggered: { + router.pushRoute({"route": "addrecord", "data": serviceId}); + } + } + ListView { + id: serviceView + Layouts.Layout.fillHeight: true + Layouts.Layout.fillWidth: true + model: recordModel + headerPositioning: ListView.OverlayHeader + header: Kirigami.ListSectionHeader { + z: 9997 + contentItem: Layouts.ColumnLayout { + Kirigami.InlineMessage { + Layouts.Layout.fillWidth: true + type: Kirigami.MessageType.Information + id: oilMessage + showCloseButton: false + text: qsTr("You are due for an oil change!") + Connections { + target: dbAnalytics + function onIsOilChangeNeeded(changeNeeded) { + oilMessage.visible = changeNeeded; + } + } + } + } + } + delegate: Kirigami.SwipeListItem { + contentItem: Layouts.ColumnLayout { + Kirigami.Heading { + text: serviceprovider + level: 2 + } + Kirigami.Heading { + text: servicetypename + level: 2 + } + Controls.Label { + text: new Date(servicedate).toLocaleDateString(Qt.locale()) + } + Row { + Image { + source: "qrc:/speed.svg" + sourceSize.width: 16 + sourceSize.height: 16 + } + Controls.Label { + text: miles + } + } + Controls.Label { + text: notes + } + } + actions: [ + Kirigami.Action { + text: qsTr("Remove") + iconName: "edit-delete" + onTriggered: { + recordModel.removeRecord(index); + } + } + ] + } + } + } + } +} diff --git a/src/contents/ui/main.qml b/src/contents/ui/main.qml index 5bc19cd7c4027d3dd0bf04e23de74de84dd3f7f2..5f46ac535f7b7eba53b38ee09a1bb79994a9fcb8 100644 --- a/src/contents/ui/main.qml +++ b/src/contents/ui/main.qml @@ -36,122 +36,7 @@ Kirigami.ApplicationWindow { initialRoute: "main" pageStack: root.pageStack.columnView - Kirigami.PageRoute { - name: "main" - Component { - Kirigami.Page { - id: mainPage - mainAction: Kirigami.Action { - text: qsTr("Add Vehicle") - iconName: "list-add" - onTriggered: { - router.navigateToRoute(["main","addvehicle"]); - } - } - contextualActions: [ - Kirigami.Action { - iconName: "application-javascript" - text: qsTr("Import From Carfax JSON") - onTriggered: { - importDialog.visible = true; - } - }, - Kirigami.Action { - iconName: "help-about" - text: qsTr("About") - onTriggered: { - router.navigateToRoute("about"); - } - } - ] - title: "Vehicles" - Dialogs.FileDialog { - id: importDialog - title: qsTr("Select Carfax Json file to import...") - nameFilters: ["Carfax Vehicle Json (*.json)"] - onAccepted: { - if(jsonConverter.importCarfaxJsonToDB(importDialog.fileUrl)) { - // - } else { - root.showPassiveNotification(qsTr("Failed to parse file."),"short"); - } - } - } - Kirigami.CardsListView { - anchors.fill: parent - id: vehicleView - model: vehicleModel - delegate: Kirigami.Card { - id: card - banner { - title: name - } - header: Row{ - topPadding: 10.0 - rightPadding: 10.0 - leftPadding: 10.0 - layoutDirection: Qt.RightToLeft - spacing: 5 - Controls.Label { - text: vin - visible: root.wideScreen && mainPage.width > 550 - anchors.verticalCenter: parent.verticalCenter - } - Image { - id: vinIcon - source: "qrc:/license.svg" - sourceSize.width: 32 - sourceSize.height: 32 - anchors.verticalCenter: parent.verticalCenter - MouseArea { - id: vinMouse - hoverEnabled: true - anchors.fill: vinIcon - } - Controls.ToolTip { - id: vinTip - text: vin - visible: vinMouse.containsMouse - } - } - } - contentItem: Item{ - implicitHeight: Kirigami.Units.gridUnit * 4 - Layouts.ColumnLayout { - Kirigami.Heading { - text: maker + " " + vmodel - level: 2 - } - Kirigami.Heading { - text: year - level: 4 - } - } - } - actions: [ - Kirigami.Action { - text: qsTr("Examine Logs") - iconName: "edit-find" - onTriggered: { - router.navigateToRoute(["main", {"route": "servicerecords", "data": {"id": id, "name": name}}]); - } - } - ] - hiddenActions: [ - Kirigami.Action { - text: qsTr("Delete") - iconName: "edit-delete" - onTriggered: { - vehicleModel.removeVehicle(index); - } - } - ] - } - Controls.ScrollBar.vertical: Controls.ScrollBar {} - } - } - } - } + MainPage{} Kirigami.PageRoute { name: "about" @@ -170,322 +55,10 @@ Kirigami.ApplicationWindow { } } - Kirigami.PageRoute { - name: "addvehicle" - Component { - Kirigami.Page { - id: vehicleAddPage - title: qsTr("Add Vehicle") - Layouts.ColumnLayout { - anchors.fill: parent - Kirigami.InlineMessage { - Layouts.Layout.fillWidth: true - Layouts.Layout.leftMargin: 10 - Layouts.Layout.rightMargin: 10 - z: 9997 - type: Kirigami.MessageType.Error - showCloseButton: true - id: formError - } - Kirigami.FormLayout { - Layouts.Layout.alignment: Qt.AlignHCenter - Layouts.Layout.fillWidth: true - width: vehicleAddPage.width - - Item { - Kirigami.FormData.isSection: true - Kirigami.FormData.label: "Vehicle Information" - } - - Controls.TextField { - id: nameField - selectByMouse: true - Kirigami.FormData.label: qsTr("Vehicle Name")+":" - } - - Controls.TextField { - id: makeField - selectByMouse: true - Kirigami.FormData.label: qsTr("Make")+":" - } - - Controls.TextField { - id: modelField - selectByMouse: true - Kirigami.FormData.label: qsTr("Model")+":" - } - - Controls.TextField { - id: yearField - selectByMouse: true - Kirigami.FormData.label: qsTr("Year")+":" - inputMethodHints: Qt.ImhDigitsOnly - validator: IntValidator { - bottom: 1900 - top: 4000 - } - } - - Controls.TextField { - id: vinField - selectByMouse: true - Kirigami.FormData.label: qsTr("VIN")+":" - } - - Layouts.RowLayout { - - Controls.Button { - text: qsTr("Add") - highlighted: true - onClicked: { - if(yearField.acceptableInput) { - vehicleModel.addNewVehicle(nameField.text, makeField.text, modelField.text, parseInt(yearField.text), "", vinField.text); - router.popRoute(); - } else { - formError.text = qsTr("Year is invalid!"); - formError.visible = true; - } - } - } - - Controls.Button { - text: qsTr("Cancel") - onClicked: { - router.popRoute(); - } - } - } - } - } - } - } - } + AddVehicle{} - Kirigami.PageRoute { - name: "servicerecords" - - Component { - Kirigami.ScrollablePage { - property var serviceId: Kirigami.PageRouter.data.id - Component.onCompleted: { - recordModel.changeVehicleFilter(serviceId); - //Check vehicle warnings - dbAnalytics.checkOilChangeNeededForVehicle(serviceId, appAnalyticsSettings.value("milesForOilChange",5000), appAnalyticsSettings.value("monthsForOilChange",6)); - } - Connections { - target: recordModel - function onVehicleUpdated(vehicleId) { - //Check vehicle warnings - if(vehicleId == serviceId) { - dbAnalytics.checkOilChangeNeededForVehicle(vehicleId, appAnalyticsSettings.value("milesForOilChange",5000), appAnalyticsSettings.value("monthsForOilChange",6)); - } - } - } - id: serviceRecordPage - title: qsTr("Service Records for ") + Kirigami.PageRouter.data.name - mainAction: Kirigami.Action { - text: qsTr("Add Service Record") - iconName: "list-add" - onTriggered: { - router.pushRoute({"route": "addrecord", "data": serviceId}); - } - } - ListView { - id: serviceView - Layouts.Layout.fillHeight: true - Layouts.Layout.fillWidth: true - model: recordModel - headerPositioning: ListView.OverlayHeader - header: Kirigami.ListSectionHeader { - z: 9997 - contentItem: Layouts.ColumnLayout { - Kirigami.InlineMessage { - Layouts.Layout.fillWidth: true - type: Kirigami.MessageType.Information - id: oilMessage - showCloseButton: false - text: qsTr("You are due for an oil change!") - Connections { - target: dbAnalytics - function onIsOilChangeNeeded(changeNeeded) { - oilMessage.visible = changeNeeded; - } - } - } - } - } - delegate: Kirigami.SwipeListItem { - contentItem: Layouts.ColumnLayout { - Kirigami.Heading { - text: serviceprovider - level: 2 - } - Kirigami.Heading { - text: servicetypename - level: 2 - } - Controls.Label { - text: new Date(servicedate).toLocaleDateString(Qt.locale()) - } - Row { - Image { - source: "qrc:/speed.svg" - sourceSize.width: 16 - sourceSize.height: 16 - } - Controls.Label { - text: miles - } - } - Controls.Label { - text: notes - } - } - actions: [ - Kirigami.Action { - text: qsTr("Remove") - iconName: "edit-delete" - onTriggered: { - recordModel.removeRecord(index); - } - } - ] - } - } - } - } - } + ServiceRecords{} - Kirigami.PageRoute { - name: "addrecord" - Component { - Kirigami.Page { - id: recordAddPage - title: qsTr("Add Service Record") - Layouts.ColumnLayout { - anchors.fill: parent - Kirigami.InlineMessage { - Layouts.Layout.fillWidth: true - Layouts.Layout.leftMargin: 10 - Layouts.Layout.rightMargin: 10 - z: 9997 - type: Kirigami.MessageType.Error - showCloseButton: true - id: formError - } - Kirigami.FormLayout { - Layouts.Layout.alignment: Qt.AlignHCenter - Layouts.Layout.fillWidth: true - width: recordAddPage.width - - Item { - Kirigami.FormData.isSection: true - Kirigami.FormData.label: "Service Information" - } - - Controls.TextField { - id: providerField - selectByMouse: true - Kirigami.FormData.label: qsTr("Service Provider")+":" - } - - Controls.ComboBox { - id: typeField - model: serviceTypeModel - textRole: "text" - valueRole: "value" - onActivated: { - if(currentValue == -1) { - customTypeField.visible = true; - } else { - customTypeField.visible = false; - } - } - Kirigami.FormData.label: qsTr("Service Type")+":" - } - - Controls.TextField { - id: customTypeField - visible: false - Kirigami.FormData.label: qsTr("Custom Service Type")+":" - } - - Layouts.RowLayout { - Kirigami.FormData.label: qsTr("Date")+":" - Controls.TextField { - id: dateField - text: new Date().toLocaleDateString(Qt.locale()) - readOnly: true - } - Controls.Button { - icon.name: "office-calendar" - text: qsTr("Select Date") - display: Controls.AbstractButton.IconOnly - onClicked: { - calendarPopup.open(); - } - } - } - - Controls.TextField { - id: milesField - selectByMouse: true - Kirigami.FormData.label: qsTr("Miles")+":" - inputMethodHints: Qt.ImhDigitsOnly - validator: IntValidator { - bottom: 0 - top: 500000 - } - } - - Controls.TextArea { - id: notesField - placeholderText: qsTr("Notes about service") - selectByMouse: true - Kirigami.FormData.label: qsTr("Notes")+":" - } - - Layouts.RowLayout { - - Controls.Button { - text: qsTr("Add") - highlighted: true - onClicked: { - var dateObj = Date.fromLocaleDateString(Qt.locale(), dateField.text); - var typeText = typeField.currentText; - if(typeField.currentValue == -1) { - typeText = customTypeField.text; - } - if(milesField.acceptableInput) { - recordModel.addNewRecord(providerField.text, typeField.currentValue, typeText, dateObj.toISOString(), parseInt(milesField.text), notesField.text); - router.popRoute(); - } else { - formError.text = qsTr("Invalid number of miles."); - formError.visible = true; - } - } - } - Controls.Button { - text: qsTr("Cancel") - onClicked: { - router.popRoute(); - } - } - } - } - } - - Kirigami.OverlaySheet { - id: calendarPopup - Old.Calendar { - selectedDate: Date.fromLocaleDateString(Qt.locale(), dateField.text) - onClicked: { - dateField.text = date.toLocaleDateString(Qt.locale()); - } - } - } - } - } - } + AddRecord{} } } diff --git a/src/resources.qrc b/src/resources.qrc index 720af0fbc6b26c6205050c4d30eb5b98661d141f..69578300d6834307a706ef56b8340232746553b8 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -1,6 +1,10 @@ contents/ui/main.qml + contents/ui/MainPage.qml + contents/ui/AddVehicle.qml + contents/ui/ServiceRecords.qml + contents/ui/AddRecord.qml contents/speed.svg contents/license.svg ../packaging/org.eyecreate.vehiclevoyage.svg