DatePicker: minimum and maximum dates; "First transaction" and "Today" links

This commit is contained in:
rating89us 2021-06-10 19:26:31 +02:00 committed by rating89us
parent 7c379e2cda
commit 6b37abc577
2 changed files with 84 additions and 5 deletions

View file

@ -33,6 +33,7 @@ import QtQuick.Layouts 1.2
import QtGraphicalEffects 1.0
import QtQuick.Controls.Styles 1.2
import FontAwesome 1.0
import moneroComponents.TransactionHistoryModel 1.0
import "." as MoneroComponents
import "effects/" as MoneroEffects
@ -45,6 +46,11 @@ Item {
property color backgroundColor : MoneroComponents.Style.appWindowBorderColor
property color errorColor : "red"
property bool error: false
property bool isFromDatePicker: false
property bool isCalendarDisplayingMinimumDate: calendar.visibleMonth == calendar.minimumDate.getMonth() && calendar.visibleYear == calendar.minimumDate.getFullYear()
property bool isCalendarDisplayingMaximumDate: calendar.visibleMonth == calendar.maximumDate.getMonth() && calendar.visibleYear == calendar.maximumDate.getFullYear()
property alias minimumDate: calendar.minimumDate
property alias maximumDate: calendar.maximumDate
property alias inputLabel: inputLabel
signal dateChanged();
@ -264,7 +270,7 @@ Item {
color: MoneroComponents.Style.middlePanelBackgroundColor
border.width: 1
border.color: MoneroComponents.Style.appWindowBorderColor
height: datePicker.expanded ? calendar.height + 2 : 0
height: datePicker.expanded ? calendar.height + todayLabel.height + 2 : 0
clip: true
Behavior on height {
@ -275,8 +281,8 @@ Item {
anchors.fill: parent
scrollGestureEnabled: false
onWheel: {
if (wheel.angleDelta.y > 0) return calendar.showPreviousMonth();
if (wheel.angleDelta.y < 0) return calendar.showNextMonth();
if (wheel.angleDelta.y > 0 && !isCalendarDisplayingMinimumDate) return calendar.showPreviousMonth();
if (wheel.angleDelta.y < 0 && !isCalendarDisplayingMaximumDate) return calendar.showNextMonth();
}
}
@ -299,6 +305,7 @@ Item {
anchors.bottomMargin: 10
height: 220
frameVisible: false
selectedDate: currentDate
style: CalendarStyle {
gridVisible: false
@ -416,6 +423,7 @@ Item {
id: prevMonthIcon
anchors.centerIn: parent
image: "qrc:///images/prevMonth.png"
visible: !isCalendarDisplayingMinimumDate
height: 8
width: 12
fontAwesomeFallbackIcon: FontAwesome.arrowLeft
@ -424,6 +432,7 @@ Item {
}
MouseArea {
visible: !isCalendarDisplayingMinimumDate
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
@ -442,6 +451,7 @@ Item {
id: nextMonthIcon
anchors.centerIn: parent
image: "qrc:///images/prevMonth.png"
visible: !isCalendarDisplayingMaximumDate
height: 8
width: 12
rotation: 180
@ -451,6 +461,7 @@ Item {
}
MouseArea {
visible: !isCalendarDisplayingMaximumDate
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
@ -460,6 +471,57 @@ Item {
}
}
}
MoneroComponents.TextPlain {
anchors.top: calendar.bottom
anchors.topMargin: -4
anchors.left: calendar.left
anchors.leftMargin: 5
font.family: MoneroComponents.Style.fontMonoRegular.name
font.pixelSize: 13
color: firstTransactionMouseArea.containsMouse ? MoneroComponents.Style.buttonBackgroundColorHover : MoneroComponents.Style.buttonBackgroundColor
themeTransition: false
visible: isFromDatePicker && typeof root.model !== 'undefined' && root.model != null && root.model.rowCount() > 0
text: qsTr("First transaction") + translationManager.emptyString
MouseArea {
id: firstTransactionMouseArea
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
onClicked: {
if (appWindow.currentWallet != null && typeof root.model !== 'undefined' && root.model != null) {
datePicker.currentDate = root.model.data(root.model.index((root.model.rowCount() - 1), 0), TransactionHistoryModel.TransactionDateRole);
}
popup.close()
}
}
}
MoneroComponents.TextPlain {
id: todayLabel
anchors.top: calendar.bottom
anchors.topMargin: -4
anchors.right: calendar.right
anchors.rightMargin: 5
font.family: MoneroComponents.Style.fontMonoRegular.name
font.pixelSize: 13
color: todayLabelMouseArea.containsMouse ? MoneroComponents.Style.buttonBackgroundColorHover : MoneroComponents.Style.buttonBackgroundColor
themeTransition: false
visible: !isFromDatePicker
text: qsTr("Today") + translationManager.emptyString
MouseArea {
id: todayLabelMouseArea
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
onClicked: {
datePicker.currentDate = new Date();
popup.close()
}
}
}
}
}
}

View file

@ -203,6 +203,21 @@ Rectangle {
width: 100
inputLabel.text: qsTr("Date from") + translationManager.emptyString
inputLabel.font.pixelSize: 14
minimumDate: {
if (appWindow.currentWallet != null && typeof root.model !== 'undefined' && root.model != null) {
var count = root.model.rowCount()
if (count > 0) {
//date of the first transaction
return root.model.data(root.model.index((count - 1), 0), TransactionHistoryModel.TransactionDateRole);
} else {
//date of monero birth
return new Date("2014-04-18");
}
}
}
maximumDate: toDatePicker.currentDate
isFromDatePicker: true
onCurrentDateChanged: {
if(root.initialized){
root.reset();
@ -216,6 +231,8 @@ Rectangle {
Layout.fillWidth: true
width: 100
inputLabel.text: qsTr("Date to") + translationManager.emptyString
minimumDate: fromDatePicker.currentDate
maximumDate: new Date() //today
onCurrentDateChanged: {
if(root.initialized){
@ -1784,8 +1801,8 @@ Rectangle {
//date of the first transaction
fromDatePicker.currentDate = root.model.data(root.model.index((count - 1), 0), TransactionHistoryModel.TransactionDateRole);
} else {
//date of monero birth (2014-04-18)
fromDatePicker.currentDate = model.transactionHistory.firstDateTime
//date of monero birth
fromDatePicker.currentDate = new Date("2014-04-18");
}
}