fix calendar key naviagtion

This commit is contained in:
Gaelle Braud 2024-08-12 16:00:43 +02:00
parent 8cffd73df5
commit fda2f0557b
4 changed files with 16 additions and 21 deletions

View file

@ -30,6 +30,8 @@
#include "model/tool/ToolModel.hpp"
#include "tool/providers/AvatarProvider.hpp"
#include <limits.h>
#include <QClipboard>
#include <QDesktopServices>
#include <QHostAddress>
@ -1250,12 +1252,6 @@ bool Utils::isCurrentMonth(QDate date) {
return date.month() == currentDate.month() && date.year() == currentDate.year();
}
bool Utils::isBeforeToday(QDate date) {
auto currentDate = QDate::currentDate();
auto res = date.daysTo(currentDate) > 0;
return res;
}
bool Utils::datesAreEqual(const QDate &a, const QDate &b) {
return a.month() == b.month() && a.year() == b.year() && a.day() == b.day();
}
@ -1295,8 +1291,13 @@ QDateTime Utils::addYears(QDateTime date, int years) {
}
int Utils::timeOffset(QDateTime start, QDateTime end) {
qDebug() << "offset between times" << start.msecsTo(end);
return start.msecsTo(end);
int offset = start.secsTo(end);
return std::min(offset, INT_MAX);
}
int Utils::daysOffset(QDateTime start, QDateTime end) {
int offset = start.daysTo(end);
return std::min(offset, INT_MAX);
}
int Utils::getYear(const QDate &date) {

View file

@ -102,7 +102,6 @@ public:
Q_INVOKABLE static bool isCurrentDay(QDateTime date);
Q_INVOKABLE static bool isCurrentDay(QDate date);
Q_INVOKABLE static bool isCurrentMonth(QDate date);
Q_INVOKABLE static bool isBeforeToday(QDate date);
Q_INVOKABLE static bool datesAreEqual(const QDate &a, const QDate &b);
Q_INVOKABLE static bool dateisInMonth(const QDate &a, int month, int year);
Q_INVOKABLE static QDateTime createDateTime(const QDate &date, int hour, int min);
@ -113,6 +112,7 @@ public:
Q_INVOKABLE static QDateTime addSecs(QDateTime date, int secs);
Q_INVOKABLE static QDateTime addYears(QDateTime date, int years);
Q_INVOKABLE static int timeOffset(QDateTime start, QDateTime end);
Q_INVOKABLE static int daysOffset(QDateTime start, QDateTime end);
Q_INVOKABLE static QString interpretUrl(const QString &uri);
Q_INVOKABLE static bool isValidSIPAddress(const QString &uri);
Q_INVOKABLE static bool isValidIPAddress(const QString &host);

View file

@ -101,19 +101,14 @@ ListView {
year: model.year
month: model.month
property var curDate: model.date
onMonthChanged: {
console.log("cur date changed", month)
}
locale: Qt.locale(ConstantsCpp.DefaultLocale)
delegate: FocusScope {
id: focusDay
property bool isSelectedDay: mainItem.selectedDate ? UtilsCpp.datesAreEqual(mainItem.selectedDate, model.date) : false
property var d: model.date
objectName: 'focusDay'
// width: 30 * DefaultStyle.dp
// height: 30 * DefaultStyle.dp
activeFocusOnTab: true
focus: index == 0
focus: UtilsCpp.isCurrentMonth(model.date) && UtilsCpp.isCurrentDay(model.date) || index == 0
Keys.onPressed: (event)=> {
if (event.key == Qt.Key_Space || event.key == Qt.Key_Enter || event.key == Qt.Key_Return) {
monthGrid.clicked(model.date)
@ -123,16 +118,14 @@ ListView {
if( previous.objectName != 'focusDay'){
previousButton.clicked(undefined)
}else{
previous.forceActiveFocus()
if (UtilsCpp.daysOffset(new Date(), model.date) >= 0) previous.forceActiveFocus()
}
}else if(event.key == Qt.Key_Right){
var next = nextItemInFocusChain()
console.log(next.objectName)
if( next.objectName != 'focusDay'){
nextButton.clicked(undefined)
} else {
next.forceActiveFocus()
}
}
}
@ -143,6 +136,7 @@ ListView {
hoverEnabled: true
cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
acceptedButtons: Qt.LeftButton
// onEntered: focusDay.forceActiveFocus()
onPressed: (event) =>{
focusDay.forceActiveFocus()
event.accepted = false
@ -176,8 +170,7 @@ ListView {
}
}
onClicked: (date) => {
if (UtilsCpp.isBeforeToday(date)) return;
mainItem.selectedDate = date
if (UtilsCpp.daysOffset(new Date(), date) >= 0) mainItem.selectedDate = date
}
}
}

View file

@ -23,7 +23,8 @@ ComboBox {
property var maxTime
popup.width: 73 * DefaultStyle.dp
listView.model: 48
listView.height: Math.min(204 * DefaultStyle.dp, listView.implicitHeight)
listView.height: Math.min(204 * DefaultStyle.dp, listView.contentHeight)
popup.height: Math.min(204 * DefaultStyle.dp, listView.contentHeight)
editable: true
popup.closePolicy: Popup.PressOutsideParent | Popup.CloseOnPressOutside
onCurrentTextChanged: input.text = currentText