@@ -240,6 +240,9 @@ StickersListWidget::StickersListWidget(
240240, _megagroupSetAbout(st::columnMinimalWidthThird
241241 - st::emojiScroll.width
242242 - st().headerLeft)
243+ , _photoButtonBg(st::stickersPhotoButtonRadius, st().overBg)
244+ , _photoButtonText(tr::lng_attach_photo(tr::now).toUpper())
245+ , _photoButtonTextWidth(st::stickersPhotoButtonFont->width (_photoButtonText))
243246, _addText(tr::lng_stickers_featured_add(tr::now))
244247, _addWidth(st::stickersTrendingAdd.style.font->width (_addText))
245248, _installedText(tr::lng_stickers_featured_installed(tr::now))
@@ -317,6 +320,10 @@ rpl::producer<FileChosen> StickersListWidget::chosen() const {
317320 return _chosen.events ();
318321}
319322
323+ rpl::producer<> StickersListWidget::photoRequests () const {
324+ return _photoRequests.events ();
325+ }
326+
320327rpl::producer<> StickersListWidget::scrollUpdated () const {
321328 return _scrollUpdated.events ();
322329}
@@ -502,7 +509,7 @@ template <typename Callback>
502509bool StickersListWidget::enumerateSections (Callback callback) const {
503510 auto info = SectionInfo ();
504511 info.top = _search ? _search->height () : 0 ;
505- info.top += searchShortcutsHeight ();
512+ info.top += photoRowHeight () + searchShortcutsHeight ();
506513 const auto &sets = shownSets ();
507514 for (auto i = 0 ; i != sets.size (); ++i) {
508515 auto &set = sets[i];
@@ -969,7 +976,69 @@ void StickersListWidget::startSearchSwapAnimation(
969976}
970977
971978int StickersListWidget::searchShortcutsTop () const {
972- return _search ? _search->height () : 0 ;
979+ return (_search ? _search->height () : 0 ) + photoRowHeight ();
980+ }
981+
982+ int StickersListWidget::photoRowHeight () const {
983+ if (!_features.photoButton || _isMasks || _section == Section::Search) {
984+ return 0 ;
985+ }
986+ const auto &padding = st::stickersPhotoRowPadding;
987+ return padding.top () + st::stickersPhotoButtonHeight + padding.bottom ();
988+ }
989+
990+ QRect StickersListWidget::photoButtonRect () const {
991+ const auto &padding = st::stickersPhotoButtonPadding;
992+ const auto &icon = st ().photoButtonIcon ;
993+ const auto buttonWidth = padding.left ()
994+ + icon.width ()
995+ + st::stickersPhotoButtonIconSkip
996+ + _photoButtonTextWidth
997+ + padding.right ();
998+ const auto top = (_search ? _search->height () : 0 )
999+ + st::stickersPhotoRowPadding.top ();
1000+ return QRect (
1001+ (width () - buttonWidth) / 2 ,
1002+ top,
1003+ buttonWidth,
1004+ st::stickersPhotoButtonHeight);
1005+ }
1006+
1007+ void StickersListWidget::paintPhotoButton (Painter &p, QRect clip) {
1008+ if (!photoRowHeight ()) {
1009+ return ;
1010+ }
1011+ const auto rect = photoButtonRect ();
1012+ if (!rect.intersects (clip)) {
1013+ return ;
1014+ }
1015+ _photoButtonBg.paint (p, myrtlrect (rect));
1016+ if (_photoButtonRipple) {
1017+ _photoButtonRipple->paint (p, myrtlrect (rect).x (), rect.y (), width ());
1018+ if (_photoButtonRipple->empty ()) {
1019+ _photoButtonRipple.reset ();
1020+ }
1021+ }
1022+ const auto &padding = st::stickersPhotoButtonPadding;
1023+ const auto &icon = st ().photoButtonIcon ;
1024+ icon.paint (
1025+ p,
1026+ rect.x () + padding.left (),
1027+ rect.y () + (rect.height () - icon.height ()) / 2 ,
1028+ width ());
1029+ const auto &font = st::stickersPhotoButtonFont;
1030+ const auto textLeft = rect.x ()
1031+ + padding.left ()
1032+ + icon.width ()
1033+ + st::stickersPhotoButtonIconSkip;
1034+ p.setFont (font);
1035+ p.setPen (st ().textFg );
1036+ p.drawTextLeft (
1037+ textLeft,
1038+ rect.y () + (rect.height () - font->height ) / 2 ,
1039+ width (),
1040+ _photoButtonText,
1041+ _photoButtonTextWidth);
9731042}
9741043
9751044int StickersListWidget::searchShortcutsHeight () const {
@@ -1555,6 +1624,7 @@ void StickersListWidget::paintStickers(Painter &p, QRect clip) {
15551624 _paintAsPremium = session ().premium ();
15561625 _pathGradient->startFrame (0 , width (), width () / 2 );
15571626 paintSearchShortcuts (p, clip);
1627+ paintPhotoButton (p, clip);
15581628
15591629 auto &sets = shownSets ();
15601630 const auto selectedSticker = std::get_if<OverSticker>(&_selected);
@@ -2412,6 +2482,10 @@ void StickersListWidget::setPressed(OverState newPressed) {
24122482 if (_megagroupSetButtonRipple) {
24132483 _megagroupSetButtonRipple->lastStop ();
24142484 }
2485+ } else if (std::get_if<OverPhotoButton>(&_pressed)) {
2486+ if (_photoButtonRipple) {
2487+ _photoButtonRipple->lastStop ();
2488+ }
24152489 }
24162490 _pressed = newPressed;
24172491 if (auto button = std::get_if<OverButton>(&_pressed)) {
@@ -2445,6 +2519,18 @@ void StickersListWidget::setPressed(OverState newPressed) {
24452519 }
24462520 _megagroupSetButtonRipple->add (mapFromGlobal (QCursor::pos ())
24472521 - myrtlrect (megagroupSetButtonRectFinal ()).topLeft ());
2522+ } else if (std::get_if<OverPhotoButton>(&_pressed)) {
2523+ if (!_photoButtonRipple) {
2524+ auto mask = Ui::RippleAnimation::RoundRectMask (
2525+ photoButtonRect ().size (),
2526+ st::stickersPhotoButtonRadius);
2527+ _photoButtonRipple = std::make_unique<Ui::RippleAnimation>(
2528+ st ().searchPackRipple ,
2529+ std::move (mask),
2530+ [this ] { rtlupdate (photoButtonRect ()); });
2531+ }
2532+ _photoButtonRipple->add (mapFromGlobal (QCursor::pos ())
2533+ - myrtlrect (photoButtonRect ()).topLeft ());
24482534 }
24492535}
24502536
@@ -2779,6 +2865,9 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) {
27792865 if (std::get_if<OverSearchBack>(&pressed)) {
27802866 backToSearchResults ();
27812867 return ;
2868+ } else if (std::get_if<OverPhotoButton>(&pressed)) {
2869+ _photoRequests.fire ({});
2870+ return ;
27822871 } else if (auto shortcut = std::get_if<OverSearchShortcut>(&pressed)) {
27832872 toggleSearchShortcut (shortcut->index );
27842873 return ;
@@ -3556,6 +3645,9 @@ void StickersListWidget::updateSelected() {
35563645 }
35573646 setSelected (newSelected);
35583647 return ;
3648+ } else if (photoRowHeight () && myrtlrect (photoButtonRect ()).contains (p)) {
3649+ setSelected (OverPhotoButton{});
3650+ return ;
35593651 }
35603652 const auto &sets = shownSets ();
35613653 auto sx = (rtl () ? width () - p.x () : p.x ()) - stickersLeft ();
@@ -3667,6 +3759,8 @@ void StickersListWidget::setSelected(OverState newSelected) {
36673759 rtlupdate (searchBackRect ());
36683760 } else if (std::get_if<OverGroupAdd>(&_selected)) {
36693761 rtlupdate (megagroupSetButtonRectFinal ());
3762+ } else if (std::get_if<OverPhotoButton>(&_selected)) {
3763+ rtlupdate (photoButtonRect ());
36703764 }
36713765 };
36723766 updateSelected ();
0 commit comments