2017-03-07 14:03:07 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-03-07 14:03:07 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-03-07 14:03:07 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2021-01-19 07:14:50 +00:00
|
|
|
#include "ui/layers/box_content.h"
|
2021-11-15 09:09:44 +00:00
|
|
|
#include "ui/widgets/tooltip.h"
|
2021-11-11 11:44:12 +00:00
|
|
|
#include "base/required.h"
|
2021-11-15 09:09:44 +00:00
|
|
|
#include "base/timer.h"
|
2017-03-07 14:03:07 +00:00
|
|
|
|
2022-01-24 16:33:30 +00:00
|
|
|
#include <QtCore/QDate>
|
|
|
|
|
2018-10-06 18:51:07 +00:00
|
|
|
namespace style {
|
|
|
|
struct CalendarSizes;
|
2022-03-06 11:34:33 +00:00
|
|
|
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;
|
2022-03-06 11:34:33 +00:00
|
|
|
extern const style::CalendarColors &defaultCalendarColors;
|
2021-11-11 11:44:12 +00:00
|
|
|
} // namespace st
|
|
|
|
|
2017-03-07 14:03:07 +00:00
|
|
|
namespace Ui {
|
2021-01-19 07:14:50 +00:00
|
|
|
|
2017-03-07 14:03:07 +00:00
|
|
|
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;
|
2021-11-15 09:09:44 +00:00
|
|
|
bool allowsSelection = false;
|
2021-11-16 05:52:13 +00:00
|
|
|
Fn<void(
|
|
|
|
not_null<Ui::CalendarBox*>,
|
|
|
|
std::optional<int>)> selectionChanged;
|
2022-03-06 11:34:33 +00:00
|
|
|
const style::CalendarColors &stColors = st::defaultCalendarColors;
|
2021-11-11 11:44:12 +00:00
|
|
|
};
|
2017-03-07 14:03:07 +00:00
|
|
|
|
2021-11-15 09:09:44 +00:00
|
|
|
class CalendarBox final : public BoxContent, private AbstractTooltipShower {
|
2017-03-07 14:03:07 +00:00
|
|
|
public:
|
2021-11-11 11:44:12 +00:00
|
|
|
CalendarBox(QWidget*, CalendarBoxArgs &&args);
|
2017-03-07 14:03:07 +00:00
|
|
|
~CalendarBox();
|
|
|
|
|
2021-11-16 05:52:13 +00:00
|
|
|
void toggleSelectionMode(bool enabled);
|
|
|
|
|
2021-11-16 07:26:35 +00:00
|
|
|
[[nodiscard]] QDate selectedFirstDate() const;
|
|
|
|
[[nodiscard]] QDate selectedLastDate() const;
|
|
|
|
|
2017-03-07 14:03:07 +00:00
|
|
|
protected:
|
|
|
|
void prepare() override;
|
|
|
|
|
2018-12-30 20:14:25 +00:00
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
2017-03-07 14:03:07 +00:00
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void monthChanged(QDate month);
|
|
|
|
|
2017-03-07 16:40:17 +00:00
|
|
|
bool isPreviousEnabled() const;
|
|
|
|
bool isNextEnabled() const;
|
|
|
|
|
2018-12-30 20:14:25 +00:00
|
|
|
void goPreviousMonth();
|
|
|
|
void goNextMonth();
|
2021-11-11 13:03:06 +00:00
|
|
|
void setExactScroll();
|
|
|
|
void processScroll();
|
2021-11-16 05:52:13 +00:00
|
|
|
void createButtons();
|
2018-12-30 20:14:25 +00:00
|
|
|
|
2021-11-15 09:09:44 +00:00
|
|
|
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;
|
2022-03-06 11:34:33 +00:00
|
|
|
const style::CalendarColors &_styleColors;
|
2018-10-06 18:51:07 +00:00
|
|
|
|
2017-03-07 14:03:07 +00:00
|
|
|
class Context;
|
|
|
|
std::unique_ptr<Context> _context;
|
|
|
|
|
2021-11-11 11:44:12 +00:00
|
|
|
std::unique_ptr<ScrollArea> _scroll;
|
|
|
|
|
2017-03-07 14:03:07 +00:00
|
|
|
class Inner;
|
2021-11-11 11:44:12 +00:00
|
|
|
not_null<Inner*> _inner;
|
2017-03-07 14:03:07 +00:00
|
|
|
|
2021-11-30 13:36:37 +00:00
|
|
|
class FloatingDate;
|
|
|
|
std::unique_ptr<FloatingDate> _floatingDate;
|
|
|
|
|
2017-03-07 14:03:07 +00:00
|
|
|
class Title;
|
|
|
|
object_ptr<Title> _title;
|
2021-01-19 07:14:50 +00:00
|
|
|
object_ptr<IconButton> _previous;
|
|
|
|
object_ptr<IconButton> _next;
|
2021-11-15 09:09:44 +00:00
|
|
|
bool _previousEnabled = false;
|
|
|
|
bool _nextEnabled = false;
|
2017-03-07 14:03:07 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(QDate date)> _callback;
|
2018-10-06 11:06:07 +00:00
|
|
|
FnMut<void(not_null<CalendarBox*>)> _finalize;
|
2021-11-11 13:03:06 +00:00
|
|
|
bool _watchScroll = false;
|
2017-03-07 14:03:07 +00:00
|
|
|
|
2021-11-15 09:09:44 +00:00
|
|
|
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;
|
|
|
|
|
2017-03-07 14:03:07 +00:00
|
|
|
};
|
2021-01-19 07:14:50 +00:00
|
|
|
|
|
|
|
} // namespace Ui
|