fix calendar key naviagtion
This commit is contained in:
parent
8cffd73df5
commit
fda2f0557b
4 changed files with 16 additions and 21 deletions
|
|
@ -30,6 +30,8 @@
|
||||||
#include "model/tool/ToolModel.hpp"
|
#include "model/tool/ToolModel.hpp"
|
||||||
#include "tool/providers/AvatarProvider.hpp"
|
#include "tool/providers/AvatarProvider.hpp"
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
|
|
@ -1250,12 +1252,6 @@ bool Utils::isCurrentMonth(QDate date) {
|
||||||
return date.month() == currentDate.month() && date.year() == currentDate.year();
|
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) {
|
bool Utils::datesAreEqual(const QDate &a, const QDate &b) {
|
||||||
return a.month() == b.month() && a.year() == b.year() && a.day() == b.day();
|
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) {
|
int Utils::timeOffset(QDateTime start, QDateTime end) {
|
||||||
qDebug() << "offset between times" << start.msecsTo(end);
|
int offset = start.secsTo(end);
|
||||||
return start.msecsTo(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) {
|
int Utils::getYear(const QDate &date) {
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,6 @@ public:
|
||||||
Q_INVOKABLE static bool isCurrentDay(QDateTime date);
|
Q_INVOKABLE static bool isCurrentDay(QDateTime date);
|
||||||
Q_INVOKABLE static bool isCurrentDay(QDate date);
|
Q_INVOKABLE static bool isCurrentDay(QDate date);
|
||||||
Q_INVOKABLE static bool isCurrentMonth(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 datesAreEqual(const QDate &a, const QDate &b);
|
||||||
Q_INVOKABLE static bool dateisInMonth(const QDate &a, int month, int year);
|
Q_INVOKABLE static bool dateisInMonth(const QDate &a, int month, int year);
|
||||||
Q_INVOKABLE static QDateTime createDateTime(const QDate &date, int hour, int min);
|
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 addSecs(QDateTime date, int secs);
|
||||||
Q_INVOKABLE static QDateTime addYears(QDateTime date, int years);
|
Q_INVOKABLE static QDateTime addYears(QDateTime date, int years);
|
||||||
Q_INVOKABLE static int timeOffset(QDateTime start, QDateTime end);
|
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 QString interpretUrl(const QString &uri);
|
||||||
Q_INVOKABLE static bool isValidSIPAddress(const QString &uri);
|
Q_INVOKABLE static bool isValidSIPAddress(const QString &uri);
|
||||||
Q_INVOKABLE static bool isValidIPAddress(const QString &host);
|
Q_INVOKABLE static bool isValidIPAddress(const QString &host);
|
||||||
|
|
|
||||||
|
|
@ -101,19 +101,14 @@ ListView {
|
||||||
year: model.year
|
year: model.year
|
||||||
month: model.month
|
month: model.month
|
||||||
property var curDate: model.date
|
property var curDate: model.date
|
||||||
onMonthChanged: {
|
|
||||||
console.log("cur date changed", month)
|
|
||||||
}
|
|
||||||
locale: Qt.locale(ConstantsCpp.DefaultLocale)
|
locale: Qt.locale(ConstantsCpp.DefaultLocale)
|
||||||
delegate: FocusScope {
|
delegate: FocusScope {
|
||||||
id: focusDay
|
id: focusDay
|
||||||
property bool isSelectedDay: mainItem.selectedDate ? UtilsCpp.datesAreEqual(mainItem.selectedDate, model.date) : false
|
property bool isSelectedDay: mainItem.selectedDate ? UtilsCpp.datesAreEqual(mainItem.selectedDate, model.date) : false
|
||||||
property var d: model.date
|
property var d: model.date
|
||||||
objectName: 'focusDay'
|
objectName: 'focusDay'
|
||||||
// width: 30 * DefaultStyle.dp
|
|
||||||
// height: 30 * DefaultStyle.dp
|
|
||||||
activeFocusOnTab: true
|
activeFocusOnTab: true
|
||||||
focus: index == 0
|
focus: UtilsCpp.isCurrentMonth(model.date) && UtilsCpp.isCurrentDay(model.date) || index == 0
|
||||||
Keys.onPressed: (event)=> {
|
Keys.onPressed: (event)=> {
|
||||||
if (event.key == Qt.Key_Space || event.key == Qt.Key_Enter || event.key == Qt.Key_Return) {
|
if (event.key == Qt.Key_Space || event.key == Qt.Key_Enter || event.key == Qt.Key_Return) {
|
||||||
monthGrid.clicked(model.date)
|
monthGrid.clicked(model.date)
|
||||||
|
|
@ -123,16 +118,14 @@ ListView {
|
||||||
if( previous.objectName != 'focusDay'){
|
if( previous.objectName != 'focusDay'){
|
||||||
previousButton.clicked(undefined)
|
previousButton.clicked(undefined)
|
||||||
}else{
|
}else{
|
||||||
previous.forceActiveFocus()
|
if (UtilsCpp.daysOffset(new Date(), model.date) >= 0) previous.forceActiveFocus()
|
||||||
}
|
}
|
||||||
}else if(event.key == Qt.Key_Right){
|
}else if(event.key == Qt.Key_Right){
|
||||||
var next = nextItemInFocusChain()
|
var next = nextItemInFocusChain()
|
||||||
console.log(next.objectName)
|
|
||||||
if( next.objectName != 'focusDay'){
|
if( next.objectName != 'focusDay'){
|
||||||
nextButton.clicked(undefined)
|
nextButton.clicked(undefined)
|
||||||
} else {
|
} else {
|
||||||
next.forceActiveFocus()
|
next.forceActiveFocus()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -143,6 +136,7 @@ ListView {
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
|
cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||||
acceptedButtons: Qt.LeftButton
|
acceptedButtons: Qt.LeftButton
|
||||||
|
// onEntered: focusDay.forceActiveFocus()
|
||||||
onPressed: (event) =>{
|
onPressed: (event) =>{
|
||||||
focusDay.forceActiveFocus()
|
focusDay.forceActiveFocus()
|
||||||
event.accepted = false
|
event.accepted = false
|
||||||
|
|
@ -176,8 +170,7 @@ ListView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onClicked: (date) => {
|
onClicked: (date) => {
|
||||||
if (UtilsCpp.isBeforeToday(date)) return;
|
if (UtilsCpp.daysOffset(new Date(), date) >= 0) mainItem.selectedDate = date
|
||||||
mainItem.selectedDate = date
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ ComboBox {
|
||||||
property var maxTime
|
property var maxTime
|
||||||
popup.width: 73 * DefaultStyle.dp
|
popup.width: 73 * DefaultStyle.dp
|
||||||
listView.model: 48
|
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
|
editable: true
|
||||||
popup.closePolicy: Popup.PressOutsideParent | Popup.CloseOnPressOutside
|
popup.closePolicy: Popup.PressOutsideParent | Popup.CloseOnPressOutside
|
||||||
onCurrentTextChanged: input.text = currentText
|
onCurrentTextChanged: input.text = currentText
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue