mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-01-14 03:01:15 +00:00
Added shortcuts to skip months in CalendarBox.
This commit is contained in:
parent
299aa69058
commit
27528d084f
@ -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<Inner>(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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user