tdesktop/Telegram/SourceFiles/ui/boxes/calendar_box.h

124 lines
2.8 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "ui/layers/box_content.h"
#include "ui/widgets/tooltip.h"
2021-11-11 11:44:12 +00:00
#include "base/required.h"
#include "base/timer.h"
2022-01-24 16:33:30 +00:00
#include <QtCore/QDate>
2018-10-06 18:51:07 +00:00
namespace style {
struct CalendarSizes;
struct CalendarColors;
2018-10-06 18:51:07 +00:00
} // namespace style
2021-11-11 11:44:12 +00:00
namespace st {
extern const style::CalendarSizes &defaultCalendarSizes;
extern const style::CalendarColors &defaultCalendarColors;
2021-11-11 11:44:12 +00:00
} // namespace st
namespace Ui {
class IconButton;
2021-11-11 11:44:12 +00:00
class ScrollArea;
class CalendarBox;
struct CalendarBoxArgs {
template <typename T>
using required = base::required<T>;
required<QDate> month;
required<QDate> highlighted;
required<Fn<void(QDate date)>> callback;
FnMut<void(not_null<CalendarBox*>)> finalize;
const style::CalendarSizes &st = st::defaultCalendarSizes;
QDate minDate;
QDate maxDate;
bool allowsSelection = false;
2021-11-16 05:52:13 +00:00
Fn<void(
not_null<Ui::CalendarBox*>,
std::optional<int>)> selectionChanged;
const style::CalendarColors &stColors = st::defaultCalendarColors;
2021-11-11 11:44:12 +00:00
};
class CalendarBox final : public BoxContent, private AbstractTooltipShower {
public:
2021-11-11 11:44:12 +00:00
CalendarBox(QWidget*, CalendarBoxArgs &&args);
~CalendarBox();
2021-11-16 05:52:13 +00:00
void toggleSelectionMode(bool enabled);
[[nodiscard]] QDate selectedFirstDate() const;
[[nodiscard]] QDate selectedLastDate() const;
protected:
void prepare() override;
void keyPressEvent(QKeyEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
private:
void monthChanged(QDate month);
bool isPreviousEnabled() const;
bool isNextEnabled() const;
void goPreviousMonth();
void goNextMonth();
void setExactScroll();
void processScroll();
2021-11-16 05:52:13 +00:00
void createButtons();
void showJumpTooltip(not_null<IconButton*> button);
void jumpAfterDelay(not_null<IconButton*> button);
void jump(QPointer<IconButton> button);
QString tooltipText() const override;
QPoint tooltipPos() const override;
bool tooltipWindowActive() const override;
2018-10-06 18:51:07 +00:00
const style::CalendarSizes &_st;
const style::CalendarColors &_styleColors;
2018-10-06 18:51:07 +00:00
class Context;
std::unique_ptr<Context> _context;
2021-11-11 11:44:12 +00:00
std::unique_ptr<ScrollArea> _scroll;
class Inner;
2021-11-11 11:44:12 +00:00
not_null<Inner*> _inner;
class FloatingDate;
std::unique_ptr<FloatingDate> _floatingDate;
class Title;
object_ptr<Title> _title;
object_ptr<IconButton> _previous;
object_ptr<IconButton> _next;
bool _previousEnabled = false;
bool _nextEnabled = false;
Fn<void(QDate date)> _callback;
2018-10-06 11:06:07 +00:00
FnMut<void(not_null<CalendarBox*>)> _finalize;
bool _watchScroll = false;
QPointer<IconButton> _tooltipButton;
QPointer<IconButton> _jumpButton;
base::Timer _jumpTimer;
2021-11-16 05:52:13 +00:00
bool _selectionMode = false;
Fn<void(
not_null<Ui::CalendarBox*>,
std::optional<int>)> _selectionChanged;
};
} // namespace Ui