diff --git a/Telegram/SourceFiles/boxes/calendar_box.cpp b/Telegram/SourceFiles/boxes/calendar_box.cpp index 4b1e7febb..e5831be39 100644 --- a/Telegram/SourceFiles/boxes/calendar_box.cpp +++ b/Telegram/SourceFiles/boxes/calendar_box.cpp @@ -495,16 +495,8 @@ void CalendarBox::setMaxDate(QDate date) { } void CalendarBox::prepare() { - _previous->setClickedCallback([this] { - if (isPreviousEnabled()) { - _context->skipMonth(-1); - } - }); - _next->setClickedCallback([this] { - if (isNextEnabled()) { - _context->skipMonth(1); - } - }); + _previous->setClickedCallback([this] { goPreviousMonth(); }); + _next->setClickedCallback([this] { goNextMonth(); }); // _inner = setInnerWidget(object_ptr(this, _context.get()), st::calendarScroll, st::calendarTitleHeight); _inner->setDateChosenCallback(std::move(_callback)); @@ -528,6 +520,18 @@ bool CalendarBox::isNextEnabled() const { return (_context->maxDayIndex() >= _context->daysCount()); } +void CalendarBox::goPreviousMonth() { + if (isPreviousEnabled()) { + _context->skipMonth(-1); + } +} + +void CalendarBox::goNextMonth() { + if (isNextEnabled()) { + _context->skipMonth(1); + } +} + void CalendarBox::monthChanged(QDate month) { setDimensions(_st.width, st::calendarTitleHeight + _inner->countHeight()); auto previousEnabled = isPreviousEnabled(); @@ -548,4 +552,14 @@ void CalendarBox::resizeEvent(QResizeEvent *e) { BoxContent::resizeEvent(e); } +void CalendarBox::keyPressEvent(QKeyEvent *e) { + if (e->key() == Qt::Key_Escape) { + e->ignore(); + } else if (e->key() == Qt::Key_Left) { + goPreviousMonth(); + } else if (e->key() == Qt::Key_Right) { + goNextMonth(); + } +} + CalendarBox::~CalendarBox() = default; diff --git a/Telegram/SourceFiles/boxes/calendar_box.h b/Telegram/SourceFiles/boxes/calendar_box.h index 2f8b65004..8a582de01 100644 --- a/Telegram/SourceFiles/boxes/calendar_box.h +++ b/Telegram/SourceFiles/boxes/calendar_box.h @@ -42,6 +42,7 @@ public: protected: void prepare() override; + void keyPressEvent(QKeyEvent *e) override; void resizeEvent(QResizeEvent *e) override; private: @@ -50,6 +51,9 @@ private: bool isPreviousEnabled() const; bool isNextEnabled() const; + void goPreviousMonth(); + void goNextMonth(); + const style::CalendarSizes &_st; class Context;