From 15dc6064ef9c77b2a63a7e3f288a9e2e10f42541 Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 11 Nov 2021 18:24:45 +0400 Subject: [PATCH] Improve CalendarBox title design for vertical layout. --- Telegram/Resources/icons/calendar_down.png | Bin 0 -> 188 bytes Telegram/Resources/icons/calendar_down@2x.png | Bin 0 -> 291 bytes Telegram/Resources/icons/calendar_down@3x.png | Bin 0 -> 867 bytes Telegram/SourceFiles/boxes/boxes.style | 10 ++--- .../SourceFiles/ui/boxes/calendar_box.cpp | 36 +++++++++++------- Telegram/SourceFiles/ui/boxes/calendar_box.h | 1 - 6 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 Telegram/Resources/icons/calendar_down.png create mode 100644 Telegram/Resources/icons/calendar_down@2x.png create mode 100644 Telegram/Resources/icons/calendar_down@3x.png diff --git a/Telegram/Resources/icons/calendar_down.png b/Telegram/Resources/icons/calendar_down.png new file mode 100644 index 0000000000000000000000000000000000000000..e7213ec3665dfded99b94bb5e3a036b5e98c62ac GIT binary patch literal 188 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wkP%zKa z#WBR9_w3|@oCgeen5XhRWZd%KB+8?<#Yyvq;n~HePbRyh7b`M1Yz#c^_d~s*qd{dt zPP>PbkP_2`l-tu%CLNnHOK;M?^bdDdD4e|eWr6U#2GNv@3*KFtu}*I5!{yViPKcI{ j-+N|B!jTm64T3RVB` zYucyRH|Ynf_{2HIbDm6G@#gjv8>xR{5}Frp91nfdI-NQ&=)P8m;&hhLdYh2}c1*1X9O;kB}1`IM^TWyOw)4;#L7rgTayJ}MC_ nzeY7WM)dz@e+$+;?GG$XHvbshY?@1f9%S%z^>bP0l+XkK1rKtb literal 0 HcmV?d00001 diff --git a/Telegram/Resources/icons/calendar_down@3x.png b/Telegram/Resources/icons/calendar_down@3x.png new file mode 100644 index 0000000000000000000000000000000000000000..f48c3def0d04fdce670e64999a56b995da532e6f GIT binary patch literal 867 zcmV-p1DyPcP)ClY5F>la#h-M`04drZ~7*k+VB0Iw{Xt+Qh^Wx z@{1+%23S>b0N#oN@Kzjvx8eZ2^(BC&X{6a~l1wJUizif>OolX@O`>Vq%smi7pzAt% zy&eEyG#Vk7%fY|L`^x2V7>z~%fL^bMwY9a+_X##OHegv6KFe_&gtMFRIOGa2*O_j z7X$&-YL&@xeSM8YBH`ElDZaS4U=|yOfn+inIeapigkc!W{+E}R-(TWaqqDO!rip2q zkYzbCcv+TVnkKXF`T2QJ{j6cJSPWhLz8Z}N6h&DXUQrY@8VzbM*L6`W7Q;M(jgOCy zXZGLkYPDKWRds22RaMbywWvKD$HB?T3C$pr+dV0z{Qyv~3 zRyk9aDuOJ_sMqUMFwgUt6J@<#U-eX9x)72i%{9M-$uJCmqT~~R5CTyYQLEJ!hOgCX z5JhoS_|*gWSEW*!8@^JhMA9?T0E7^9Ivpl_r_+fNKH31Ao0}Mq$D#1!@fg``_TLRa z$YfL)4u>=F!{HFAR4Qut=mQWk89Vy@{uJJ_tc8X>?g0pyj2-QE8|`*`sd0PWOYl?t tR{dWecYmYe0K63k;H@|SZ^Z$4>jQXfOWEie75M-F002ovPDHLkV1l}0mn;AP literal 0 HcmV?d00001 diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index e868a3bea..3e519d40f 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -492,8 +492,8 @@ calendarPrevious: IconButton { width: calendarTitleHeight; height: calendarTitleHeight; - icon: icon {{ "title_back", boxTitleFg }}; - iconPosition: point(20px, 20px); + icon: icon {{ "calendar_down-flip_vertical", boxTitleFg }}; + iconPosition: point(-1px, -1px); rippleAreaPosition: point(6px, 6px); rippleAreaSize: 44px; @@ -501,9 +501,9 @@ calendarPrevious: IconButton { color: windowBgOver; } } -calendarPreviousDisabled: icon {{ "title_back", menuIconFg }}; +calendarPreviousDisabled: icon {{ "calendar_down-flip_vertical", menuIconFg }}; calendarNext: IconButton(calendarPrevious) { - icon: icon {{ "title_back-flip_horizontal", boxTitleFg }}; + icon: icon {{ "calendar_down", boxTitleFg }}; } CalendarSizes { width: pixels; @@ -512,7 +512,7 @@ CalendarSizes { cellInner: pixels; padding: margins; } -calendarNextDisabled: icon {{ "title_back-flip_horizontal", menuIconFg }}; +calendarNextDisabled: icon {{ "calendar_down", menuIconFg }}; calendarTitleFont: boxTitleFont; defaultCalendarSizes: CalendarSizes { width: boxWideWidth; diff --git a/Telegram/SourceFiles/ui/boxes/calendar_box.cpp b/Telegram/SourceFiles/ui/boxes/calendar_box.cpp index 485f62f0e..8e96b29c1 100644 --- a/Telegram/SourceFiles/ui/boxes/calendar_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/calendar_box.cpp @@ -504,6 +504,7 @@ private: QString _text; int _textWidth = 0; + int _textLeft = 0; }; @@ -514,6 +515,9 @@ CalendarBox::Title::Title( : RpWidget(parent) , _st(st) , _context(context) { + const auto dayWidth = st::calendarDaysFont->width(langDayOfWeek(1)); + _textLeft = _st.padding.left() + (_st.cellSize.width() - dayWidth) / 2; + _context->monthValue( ) | rpl::start_with_next([=](QDate date) { monthChanged(date); @@ -533,7 +537,12 @@ void CalendarBox::Title::paintEvent(QPaintEvent *e) { p.setFont(st::calendarTitleFont); p.setPen(st::boxTitleFg); - p.drawTextLeft((width() - _textWidth) / 2, (st::calendarTitleHeight - st::calendarTitleFont->height) / 2, width(), _text, _textWidth); + p.drawTextLeft( + _textLeft, + (st::calendarTitleHeight - st::calendarTitleFont->height) / 2, + width(), + _text, + _textWidth); paintDayNames(p, clip); } @@ -614,6 +623,7 @@ bool CalendarBox::isNextEnabled() const { void CalendarBox::goPreviousMonth() { if (isPreviousEnabled()) { + _watchScroll = false; _context->skipMonth(-1); setExactScroll(); } @@ -621,6 +631,7 @@ void CalendarBox::goPreviousMonth() { void CalendarBox::goNextMonth() { if (isNextEnabled()) { + _watchScroll = false; _context->skipMonth(1); setExactScroll(); } @@ -668,8 +679,17 @@ void CalendarBox::monthChanged(QDate month) { } void CalendarBox::resizeEvent(QResizeEvent *e) { - _previous->moveToLeft(0, 0); - _next->moveToRight(0, 0); + const auto dayWidth = st::calendarDaysFont->width(langDayOfWeek(7)); + const auto skip = _st.padding.left() + + _st.cellSize.width() * (kDaysInWeek - 1) + + (_st.cellSize.width() - dayWidth) / 2 + + dayWidth; + const auto right = width() - skip; + const auto shift = _next->width() + - (_next->width() - st::calendarPrevious.icon.width()) / 2 + - st::calendarPrevious.icon.width(); + _next->moveToRight(right - shift, 0); + _previous->moveToRight(right - shift + _next->width(), 0); const auto title = st::calendarTitleHeight + _st.daysHeight; _title->setGeometryToLeft(0, 0, width(), title); _scroll->setGeometryToLeft(0, title, width(), height() - title); @@ -688,16 +708,6 @@ void CalendarBox::keyPressEvent(QKeyEvent *e) { } } -void CalendarBox::wheelEvent(QWheelEvent *e) { - const auto direction = Ui::WheelDirection(e); - - if (direction < 0) { - goPreviousMonth(); - } else if (direction > 0) { - goNextMonth(); - } -} - CalendarBox::~CalendarBox() = default; } // namespace Ui diff --git a/Telegram/SourceFiles/ui/boxes/calendar_box.h b/Telegram/SourceFiles/ui/boxes/calendar_box.h index b3952dc87..a5115ffce 100644 --- a/Telegram/SourceFiles/ui/boxes/calendar_box.h +++ b/Telegram/SourceFiles/ui/boxes/calendar_box.h @@ -48,7 +48,6 @@ protected: void keyPressEvent(QKeyEvent *e) override; void resizeEvent(QResizeEvent *e) override; - void wheelEvent(QWheelEvent *e) override; private: void monthChanged(QDate month);