Added ability to provide some style color to calendar box.

This commit is contained in:
23rd 2022-03-06 14:34:33 +03:00
parent fa1c2e9dbc
commit 239c617818
3 changed files with 85 additions and 20 deletions

View file

@ -503,6 +503,41 @@ calendarScroll: ScrollArea(defaultSolidScroll) {
deltax: 3px; deltax: 3px;
hiding: 1000; hiding: 1000;
} }
CalendarColors {
dayTextColor: color;
dayTextGrayedOutColor: color;
iconButtonNext: IconButton;
iconButtonNextDisabled: icon;
iconButtonPrevious: IconButton;
iconButtonPreviousDisabled: icon;
iconButtonRippleColorDisabled: color;
rippleColor: color;
rippleColorHighlighted: color;
rippleGrayedOutColor: color;
titleTextColor: color;
}
defaultCalendarColors: CalendarColors {
dayTextColor: boxTextFg;
dayTextGrayedOutColor: windowSubTextFg;
iconButtonNext: calendarNext;
iconButtonNextDisabled: calendarNextDisabled;
iconButtonPrevious: calendarPrevious;
iconButtonPreviousDisabled: calendarPreviousDisabled;
iconButtonRippleColorDisabled: boxBg;
rippleColor: windowBgOver;
rippleColorHighlighted: dialogsRippleBgActive;
rippleGrayedOutColor: windowBgRipple;
titleTextColor: boxTitleFg;
}
passcodeTextStyle: TextStyle(defaultTextStyle) { passcodeTextStyle: TextStyle(defaultTextStyle) {
lineHeight: 20px; lineHeight: 20px;

View file

@ -344,7 +344,8 @@ public:
Inner( Inner(
QWidget *parent, QWidget *parent,
not_null<Context*> context, not_null<Context*> context,
const style::CalendarSizes &st); const style::CalendarSizes &st,
const style::CalendarColors &styleColors);
[[nodiscard]] int countMaxHeight() const; [[nodiscard]] int countMaxHeight() const;
void setDateChosenCallback(Fn<void(QDate)> callback); void setDateChosenCallback(Fn<void(QDate)> callback);
@ -368,6 +369,7 @@ private:
void paintRows(Painter &p, QRect clip); void paintRows(Painter &p, QRect clip);
const style::CalendarSizes &_st; const style::CalendarSizes &_st;
const style::CalendarColors &_styleColors;
const not_null<Context*> _context; const not_null<Context*> _context;
bool _twoPressSelectionStarted = false; bool _twoPressSelectionStarted = false;
@ -461,9 +463,11 @@ void CalendarBox::FloatingDate::paint() {
CalendarBox::Inner::Inner( CalendarBox::Inner::Inner(
QWidget *parent, QWidget *parent,
not_null<Context*> context, not_null<Context*> context,
const style::CalendarSizes &st) const style::CalendarSizes &st,
const style::CalendarColors &styleColors)
: RpWidget(parent) : RpWidget(parent)
, _st(st) , _st(st)
, _styleColors(styleColors)
, _context(context) { , _context(context) {
setMouseTracking(true); setMouseTracking(true);
@ -572,10 +576,10 @@ void CalendarBox::Inner::paintRows(Painter &p, QRect clip) {
const auto it = _ripples.find(index); const auto it = _ripples.find(index);
if (it != _ripples.cend() && !selectionMode) { if (it != _ripples.cend() && !selectionMode) {
const auto colorOverride = (!highlighted const auto colorOverride = (!highlighted
? st::windowBgOver ? _styleColors.rippleColor
: grayedOut : grayedOut
? st::windowBgRipple ? _styleColors.rippleGrayedOutColor
: st::dialogsRippleBgActive)->c; : _styleColors.rippleColorHighlighted)->c;
it->second->paint(p, innerLeft, innerTop, width(), &colorOverride); it->second->paint(p, innerLeft, innerTop, width(), &colorOverride);
if (it->second->empty()) { if (it->second->empty()) {
_ripples.erase(it); _ripples.erase(it);
@ -584,9 +588,13 @@ void CalendarBox::Inner::paintRows(Painter &p, QRect clip) {
p.setPen(selected p.setPen(selected
? st::activeButtonFg ? st::activeButtonFg
: highlighted : highlighted
? (grayedOut ? st::windowSubTextFg : st::dialogsNameFgActive) ? (grayedOut
? _styleColors.dayTextGrayedOutColor
: st::dialogsNameFgActive)
: enabled : enabled
? (grayedOut ? st::windowSubTextFg : st::boxTextFg) ? (grayedOut
? _styleColors.dayTextGrayedOutColor
: _styleColors.dayTextColor)
: st::windowSubTextFg); : st::windowSubTextFg);
p.drawText(rect, _context->labelFromIndex(index), style::al_center); p.drawText(rect, _context->labelFromIndex(index), style::al_center);
} }
@ -727,7 +735,8 @@ public:
Title( Title(
QWidget *parent, QWidget *parent,
not_null<Context*> context, not_null<Context*> context,
const style::CalendarSizes &st); const style::CalendarSizes &st,
const style::CalendarColors &styleColors);
protected: protected:
void paintEvent(QPaintEvent *e); void paintEvent(QPaintEvent *e);
@ -738,6 +747,7 @@ private:
void paintDayNames(Painter &p, QRect clip); void paintDayNames(Painter &p, QRect clip);
const style::CalendarSizes &_st; const style::CalendarSizes &_st;
const style::CalendarColors &_styleColors;
const not_null<Context*> _context; const not_null<Context*> _context;
QString _text; QString _text;
@ -749,9 +759,11 @@ private:
CalendarBox::Title::Title( CalendarBox::Title::Title(
QWidget *parent, QWidget *parent,
not_null<Context*> context, not_null<Context*> context,
const style::CalendarSizes &st) const style::CalendarSizes &st,
const style::CalendarColors &styleColors)
: RpWidget(parent) : RpWidget(parent)
, _st(st) , _st(st)
, _styleColors(styleColors)
, _context(context) { , _context(context) {
const auto dayWidth = st::calendarDaysFont->width(langDayOfWeek(1)); const auto dayWidth = st::calendarDaysFont->width(langDayOfWeek(1));
_textLeft = _st.padding.left() + (_st.cellSize.width() - dayWidth) / 2; _textLeft = _st.padding.left() + (_st.cellSize.width() - dayWidth) / 2;
@ -794,7 +806,7 @@ void CalendarBox::Title::paintEvent(QPaintEvent *e) {
const auto clip = e->rect(); const auto clip = e->rect();
p.setFont(st::calendarTitleFont); p.setFont(st::calendarTitleFont);
p.setPen(st::boxTitleFg); p.setPen(_styleColors.titleTextColor);
p.drawTextLeft( p.drawTextLeft(
_textLeft, _textLeft,
(st::calendarTitleHeight - st::calendarTitleFont->height) / 2, (st::calendarTitleHeight - st::calendarTitleFont->height) / 2,
@ -824,14 +836,18 @@ void CalendarBox::Title::paintDayNames(Painter &p, QRect clip) {
CalendarBox::CalendarBox(QWidget*, CalendarBoxArgs &&args) CalendarBox::CalendarBox(QWidget*, CalendarBoxArgs &&args)
: _st(args.st) : _st(args.st)
, _styleColors(args.stColors)
, _context( , _context(
std::make_unique<Context>(args.month.value(), args.highlighted.value())) std::make_unique<Context>(args.month.value(), args.highlighted.value()))
, _scroll(std::make_unique<ScrollArea>(this, st::calendarScroll)) , _scroll(std::make_unique<ScrollArea>(this, st::calendarScroll))
, _inner( , _inner(_scroll->setOwnedWidget(object_ptr<Inner>(
_scroll->setOwnedWidget(object_ptr<Inner>(this, _context.get(), _st))) this,
, _title(this, _context.get(), _st) _context.get(),
, _previous(this, st::calendarPrevious) _st,
, _next(this, st::calendarNext) _styleColors)))
, _title(this, _context.get(), _st, _styleColors)
, _previous(this, _styleColors.iconButtonPrevious)
, _next(this, _styleColors.iconButtonNext)
, _callback(std::move(args.callback.value())) , _callback(std::move(args.callback.value()))
, _finalize(std::move(args.finalize)) , _finalize(std::move(args.finalize))
, _jumpTimer([=] { jump(_jumpButton); }) , _jumpTimer([=] { jump(_jumpButton); })
@ -1062,18 +1078,28 @@ bool CalendarBox::tooltipWindowActive() const {
} }
void CalendarBox::monthChanged(QDate month) { void CalendarBox::monthChanged(QDate month) {
setDimensions(_st.width, st::calendarTitleHeight + _st.daysHeight + _inner->countMaxHeight()); setDimensions(
_st.width,
st::calendarTitleHeight + _st.daysHeight + _inner->countMaxHeight());
_previousEnabled = isPreviousEnabled(); _previousEnabled = isPreviousEnabled();
_previous->setIconOverride(_previousEnabled ? nullptr : &st::calendarPreviousDisabled); _previous->setIconOverride(_previousEnabled
_previous->setRippleColorOverride(_previousEnabled ? nullptr : &st::boxBg); ? nullptr
: &_styleColors.iconButtonPreviousDisabled);
_previous->setRippleColorOverride(_previousEnabled
? nullptr
: &_styleColors.iconButtonRippleColorDisabled);
_previous->setPointerCursor(_previousEnabled); _previous->setPointerCursor(_previousEnabled);
if (!_previousEnabled) { if (!_previousEnabled) {
_previous->clearState(); _previous->clearState();
} }
_nextEnabled = isNextEnabled(); _nextEnabled = isNextEnabled();
_next->setIconOverride(_nextEnabled ? nullptr : &st::calendarNextDisabled); _next->setIconOverride(_nextEnabled
_next->setRippleColorOverride(_nextEnabled ? nullptr : &st::boxBg); ? nullptr
: &_styleColors.iconButtonNextDisabled);
_next->setRippleColorOverride(_nextEnabled
? nullptr
: &_styleColors.iconButtonRippleColorDisabled);
_next->setPointerCursor(_nextEnabled); _next->setPointerCursor(_nextEnabled);
if (!_nextEnabled) { if (!_nextEnabled) {
_next->clearState(); _next->clearState();

View file

@ -16,10 +16,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace style { namespace style {
struct CalendarSizes; struct CalendarSizes;
struct CalendarColors;
} // namespace style } // namespace style
namespace st { namespace st {
extern const style::CalendarSizes &defaultCalendarSizes; extern const style::CalendarSizes &defaultCalendarSizes;
extern const style::CalendarColors &defaultCalendarColors;
} // namespace st } // namespace st
namespace Ui { namespace Ui {
@ -43,6 +45,7 @@ struct CalendarBoxArgs {
Fn<void( Fn<void(
not_null<Ui::CalendarBox*>, not_null<Ui::CalendarBox*>,
std::optional<int>)> selectionChanged; std::optional<int>)> selectionChanged;
const style::CalendarColors &stColors = st::defaultCalendarColors;
}; };
class CalendarBox final : public BoxContent, private AbstractTooltipShower { class CalendarBox final : public BoxContent, private AbstractTooltipShower {
@ -82,6 +85,7 @@ private:
bool tooltipWindowActive() const override; bool tooltipWindowActive() const override;
const style::CalendarSizes &_st; const style::CalendarSizes &_st;
const style::CalendarColors &_styleColors;
class Context; class Context;
std::unique_ptr<Context> _context; std::unique_ptr<Context> _context;