diff --git a/src/mvvmquick/DateTimeEdit.qml b/src/mvvmquick/DateTimeEdit.qml new file mode 100644 index 0000000..9879150 --- /dev/null +++ b/src/mvvmquick/DateTimeEdit.qml @@ -0,0 +1,70 @@ +import QtQuick 2.10 +import QtQuick.Controls 2.3 +import QtQuick.Controls.Material 2.3 +import QtQuick.Controls.Universal 2.3 +import QtQuick.Layouts 1.3 +import de.skycoder42.QtMvvm.Quick 1.1 as QtMvvm + +ColumnLayout { + id: _edit + + property var inputValue: new Date() + + readonly property date combinedDate: new Date(_dateEdit.currentDate.getFullYear(), + _dateEdit.currentDate.getMonth(), + _dateEdit.currentDate.getDate(), + _timeEdit.time.getHours(), + _timeEdit.time.getMinutes(), + _timeEdit.time.getSeconds()) + + onInputValueChanged: { + var realDate = typeof inputValue == "string" ? new Date(inputValue) : inputValue + if(realDate.getYear() !== combinedDate.getYear() || + realDate.getMonth() !== combinedDate.getMonth() || + realDate.getDate() !== combinedDate.getDate() || + realDate.getHours() !== combinedDate.getHours() || + realDate.getMinutes() !== combinedDate.getMinutes() || + realDate.getSeconds() !== combinedDate.getSeconds()) { + _dateEdit.currentDate = realDate; + _timeEdit.time = realDate; + } + } + onCombinedDateChanged: { + inputValue = combinedDate + } + + TabBar { + id: _tabBar + position: TabBar.Header + currentIndex: _swipeView.currentIndex + Layout.fillWidth: true + + Material.background: "transparent" + Universal.background: "transparent" + + TabButton { + text: qsTr("Date") + } + + TabButton { + text: qsTr("Time") + } + } + + SwipeView { + id: _swipeView + currentIndex: _tabBar.currentIndex + Layout.fillWidth: true + Layout.fillHeight: true + Layout.preferredHeight: Math.max(_dateEdit.implicitHeight, _timeEdit.implicitHeight) + Layout.preferredWidth: Math.max(_dateEdit. implicitWidth, _timeEdit. implicitWidth) + + QtMvvm.DateEdit { + id: _dateEdit + } + + QtMvvm.TimeEdit { + id: _timeEdit + } + } +} diff --git a/src/mvvmquick/inputviewfactory.cpp b/src/mvvmquick/inputviewfactory.cpp index 0c3517d..015516e 100644 --- a/src/mvvmquick/inputviewfactory.cpp +++ b/src/mvvmquick/inputviewfactory.cpp @@ -117,8 +117,8 @@ InputViewFactoryPrivate::InputViewFactoryPrivate() : {"range", QStringLiteral("qrc:/qtmvvm/inputs/Slider.qml")}, {QMetaType::typeName(QMetaType::QTime), QStringLiteral("qrc:/qtmvvm/inputs/TimeEdit.qml")}, {QMetaType::typeName(QMetaType::QDate), QStringLiteral("qrc:/qtmvvm/inputs/DateEdit.qml")}, -// {QMetaType::typeName(QMetaType::QDateTime), QStringLiteral("qrc:/qtmvvm/inputs/")}, -// {"date", QStringLiteral("qrc:/qtmvvm/inputs/.qml")}, + {QMetaType::typeName(QMetaType::QDateTime), QStringLiteral("qrc:/qtmvvm/inputs/DateTimeEdit.qml")}, + {"date", QStringLiteral("qrc:/qtmvvm/inputs/DateTimeEdit.qml")}, {QMetaType::typeName(QMetaType::QFont), QStringLiteral("qrc:/qtmvvm/inputs/FontEdit.qml")}, {QMetaType::typeName(QMetaType::QUrl), QStringLiteral("qrc:/qtmvvm/inputs/UrlField.qml")}, {"selection", QStringLiteral("qrc:/qtmvvm/inputs/ListEdit.qml")}, diff --git a/src/mvvmquick/qtmvvmquick_module.qrc b/src/mvvmquick/qtmvvmquick_module.qrc index 9c8ebd2..eb986eb 100644 --- a/src/mvvmquick/qtmvvmquick_module.qrc +++ b/src/mvvmquick/qtmvvmquick_module.qrc @@ -12,6 +12,7 @@ Slider.qml TimeEdit.qml DateEdit.qml + DateTimeEdit.qml BoolDelegate.qml