From fda2f0557b11a2e1f6a428565e0655e985bf7d3b Mon Sep 17 00:00:00 2001 From: Gaelle Braud Date: Mon, 12 Aug 2024 16:00:43 +0200 Subject: [PATCH] fix calendar key naviagtion --- Linphone/tool/Utils.cpp | 17 +++++++++-------- Linphone/tool/Utils.hpp | 2 +- Linphone/view/Item/Calendar.qml | 15 ++++----------- Linphone/view/Item/TimeComboBox.qml | 3 ++- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Linphone/tool/Utils.cpp b/Linphone/tool/Utils.cpp index 7f2926393..fcb932aec 100644 --- a/Linphone/tool/Utils.cpp +++ b/Linphone/tool/Utils.cpp @@ -30,6 +30,8 @@ #include "model/tool/ToolModel.hpp" #include "tool/providers/AvatarProvider.hpp" +#include + #include #include #include @@ -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) { diff --git a/Linphone/tool/Utils.hpp b/Linphone/tool/Utils.hpp index 3f56c4a2c..9398649c3 100644 --- a/Linphone/tool/Utils.hpp +++ b/Linphone/tool/Utils.hpp @@ -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); diff --git a/Linphone/view/Item/Calendar.qml b/Linphone/view/Item/Calendar.qml index 4e2b2bda0..95db3a624 100644 --- a/Linphone/view/Item/Calendar.qml +++ b/Linphone/view/Item/Calendar.qml @@ -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 } } } diff --git a/Linphone/view/Item/TimeComboBox.qml b/Linphone/view/Item/TimeComboBox.qml index 13f84abc2..82a73e6df 100644 --- a/Linphone/view/Item/TimeComboBox.qml +++ b/Linphone/view/Item/TimeComboBox.qml @@ -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