Browse Source

added date edit (unpolished)

pull/2/head
Skycoder42 7 years ago
parent
commit
2e03b31720
No known key found for this signature in database GPG Key ID: 8E01AD9EF0578D2B
  1. 2
      src/imports/mvvmquick/ContrastToolBar.qml
  2. 169
      src/imports/mvvmquick/DateEdit.qml
  3. 4
      src/imports/mvvmquick/icons/ic_navigate_before_white_24px.svg
  4. 4
      src/imports/mvvmquick/icons/ic_navigate_next_white_24px.svg
  5. 3
      src/imports/mvvmquick/mvvmquick.pro
  6. 1
      src/imports/mvvmquick/qmldir
  7. 2
      src/imports/mvvmquick/qtmvvmquick_plugin.qrc
  8. 20
      src/mvvmquick/DateEdit.qml
  9. 3
      src/mvvmquick/TimeEdit.qml
  10. 2
      src/mvvmquick/inputviewfactory.cpp
  11. 1
      src/mvvmquick/qtmvvmquick_module.qrc

2
src/imports/mvvmquick/ContrastToolBar.qml

@ -28,7 +28,7 @@ ToolBar {
* the color value is checked, too. If baseColor is easily readable, it is simply returned
* as result. Otherwise the method proceeds as usual.
*/
function accentTextColor(accentColor, baseColor) {
function accentTextColor(accentColor, baseColor) { //TODO move to global
var a = (0.299 * accentColor.r + 0.587 * accentColor.g + 0.144 * accentColor.b);
if(typeof baseColor !== "undefined") {
var b = (0.299 * baseColor.r + 0.587 * baseColor.g + 0.144 * baseColor.b);

169
src/imports/mvvmquick/DateEdit.qml

@ -0,0 +1,169 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Controls.Material 2.3
import QtQuick.Layouts 1.3
import Qt.labs.calendar 1.0
ListView {
id: _calenderList
property date firstDate: new Date(1970, 0, 1)
property date lastDate: new Date(9999, 11, 31)
property date currentDate: today();
function today() {
var cDate = new Date();
cDate.setHours(0, 0, 0, 0, 0);
return cDate;
}
QtObject {
id: _p
property bool _skipNextFocus: false
function focusDate() {
if(_skipNextFocus)
_skipNextFocus = false;
else {
_calenderList.currentIndex = calendarModel.indexOf(_calenderList.currentDate);
_calenderList.positionViewAtIndex(_calenderList.currentIndex, ListView.SnapPosition);
}
}
}
Component.onCompleted: _p.focusDate()
onCurrentDateChanged: _p.focusDate()
implicitWidth: 300
implicitHeight: 200
interactive: true
keyNavigationWraps: true
snapMode: ListView.SnapOneItem
orientation: ListView.Horizontal
highlightRangeMode: ListView.StrictlyEnforceRange
clip: true
model: CalendarModel {
id: calendarModel
from: _calenderList.firstDate
to: _calenderList.lastDate
}
delegate: GridLayout {
width: _calenderList.width
height: _calenderList.height
columns: 4
Button {
Layout.rowSpan: 3
Layout.fillHeight: true
Layout.preferredWidth: 36
flat: true
icon.name: "go-previous"
icon.source: "qrc:/de/skycoder42/qtmvvm/quick/icons/ic_navigate_before.svg"
icon.width: 24
icon.height: 24
onClicked: _calenderList.decrementCurrentIndex()
}
Label {
Layout.columnSpan: 2
Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
font.bold: true
text: grid.title
}
Button {
Layout.rowSpan: 3
Layout.fillHeight: true
Layout.preferredWidth: 36
flat: true
icon.name: "go-next"
icon.source: "qrc:/de/skycoder42/qtmvvm/quick/icons/ic_navigate_next.svg"
icon.width: 24
icon.height: 24
onClicked: _calenderList.incrementCurrentIndex()
}
Item {
Layout.fillWidth: true
} // spacer
DayOfWeekRow {
Layout.fillWidth: true
}
WeekNumberColumn {
month: model.month
year: model.year
Layout.fillHeight: true
}
MonthGrid {
id: grid
month: model.month
year: model.year
Layout.fillWidth: true
Layout.fillHeight: true
delegate: Label {
id: dayDelegate
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
opacity: model.month === grid.month ? 1 : 0.5
text: model.day
font: grid.font
//TODO accent text color
background: Rectangle {
readonly property double size: Math.max(dayDelegate.width, dayDelegate.height) * 1.2
anchors.centerIn: parent
height: size
width: size
color: Material.accentColor //TODO highlight color from globally
opacity: model.day === _calenderList.currentDate.getDate() && model.month === _calenderList.currentDate.getMonth() ? 1 : 0
radius: size / 2
Behavior on opacity {
NumberAnimation {
duration: 750
easing.type: Easing.OutBack
}
}
}
MouseArea {
anchors.fill: parent
onClicked: {
if(model.month < grid.month) {
_calenderList.decrementCurrentIndex();
_p._skipNextFocus = true;
} else if(model.month > grid.month) {
_calenderList.incrementCurrentIndex();
_p._skipNextFocus = true;
}
_calenderList.currentDate = model.date;
}
}
}
}
Item {
Layout.fillWidth: true
Layout.columnSpan: 4
Layout.minimumHeight: 0
Layout.maximumHeight: 0
} // spacer, only needed for the additional padding below the month grid
}
}

4
src/imports/mvvmquick/icons/ic_navigate_before_white_24px.svg

@ -0,0 +1,4 @@
<svg fill="#FFFFFF" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>

After

Width:  |  Height:  |  Size: 209 B

4
src/imports/mvvmquick/icons/ic_navigate_next_white_24px.svg

@ -0,0 +1,4 @@
<svg fill="#FFFFFF" height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"/>
<path d="M0 0h24v24H0z" fill="none"/>
</svg>

After

Width:  |  Height:  |  Size: 210 B

3
src/imports/mvvmquick/mvvmquick.pro

@ -54,8 +54,9 @@ QML_FILES += \
RoundMenuButton.qml \
DecorLabel.qml \
MsgDelegate.qml \
TimeTumbler.qml \
TimeEdit.qml \
TimeTumbler.qml
DateEdit.qml
RESOURCES += \
qtmvvmquick_plugin.qrc

1
src/imports/mvvmquick/qmldir

@ -30,6 +30,7 @@ RoundMenuButton 1.1 RoundMenuButton.qml
DecorLabel 1.1 DecorLabel.qml
MsgDelegate 1.1 MsgDelegate.qml
TimeEdit 1.1 TimeEdit.qml
DateEdit 1.1 DateEdit.qml
PresenterProgress 1.0 PresenterProgress.qml
PresentingStackView 1.0 PresentingStackView.qml

2
src/imports/mvvmquick/qtmvvmquick_plugin.qrc

@ -9,6 +9,8 @@
<file alias="ic_settings_backup_restore.svg">icons/ic_settings_backup_restore_white_24px.svg</file>
<file alias="ic_chevron_right.svg">icons/ic_chevron_right_white_24px.svg</file>
<file alias="ic_more_vert.svg">icons/ic_more_vert_white_24px.svg</file>
<file alias="ic_navigate_before.svg">icons/ic_navigate_before_white_24px.svg</file>
<file alias="ic_navigate_next.svg">icons/ic_navigate_next_white_24px.svg</file>
</qresource>
<qresource prefix="/de/skycoder42/qtmvvm/quick/qml">
<file>FileDialog.qml</file>

20
src/mvvmquick/DateEdit.qml

@ -0,0 +1,20 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import de.skycoder42.QtMvvm.Quick 1.1 as QtMvvm
QtMvvm.DateEdit {
id: _edit
property var inputValue: new Date()
onInputValueChanged: {
var realDate = typeof inputValue == "string" ? new Date(inputValue + "T00:00:00") : inputValue
if(realDate.getDate() !== currentDate.getDate() ||
realDate.getMonth() !== currentDate.getMonth() ||
realDate.getYear() !== currentDate.getYear()) {
currentDate = realDate
}
}
onCurrentDateChanged: inputValue = currentDate
}

3
src/mvvmquick/TimeEdit.qml

@ -11,7 +11,8 @@ QtMvvm.TimeEdit {
onInputValueChanged: {
var realTime = typeof inputValue == "string" ? new Date("2000-01-01T" + inputValue) : inputValue
if(realTime.getHours() !== time.getHours() ||
realTime.getMinutes() !== time.getMinutes()) {
realTime.getMinutes() !== time.getMinutes() ||
realTime.getSeconds() !== time.getSeconds()) {
time = realTime
}
}

2
src/mvvmquick/inputviewfactory.cpp

@ -115,8 +115,8 @@ InputViewFactoryPrivate::InputViewFactoryPrivate() :
{QMetaType::typeName(QMetaType::Double), QStringLiteral("qrc:/qtmvvm/inputs/DoubleSpinBox.qml")},
{"number", QStringLiteral("qrc:/qtmvvm/inputs/DoubleSpinBox.qml")},
{"range", QStringLiteral("qrc:/qtmvvm/inputs/Slider.qml")},
// {QMetaType::typeName(QMetaType::QDate), QStringLiteral("qrc:/qtmvvm/inputs/")},
{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::QFont), QStringLiteral("qrc:/qtmvvm/inputs/FontEdit.qml")},

1
src/mvvmquick/qtmvvmquick_module.qrc

@ -11,6 +11,7 @@
<file>RadioListEdit.qml</file>
<file>Slider.qml</file>
<file>TimeEdit.qml</file>
<file>DateEdit.qml</file>
</qresource>
<qresource prefix="/qtmvvm/delegates">
<file>BoolDelegate.qml</file>

Loading…
Cancel
Save