From 01bcdf10ee5afcf2a5919ec2f43b3b2a4365c934 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 15 Jun 2022 19:31:13 +0400 Subject: [PATCH] Add arrows to move in premium previews box. --- .../SourceFiles/boxes/premium_preview_box.cpp | 85 ++++++++++++------- Telegram/SourceFiles/info/info.style | 2 +- Telegram/SourceFiles/settings/settings.style | 13 ++- 3 files changed, 67 insertions(+), 33 deletions(-) diff --git a/Telegram/SourceFiles/boxes/premium_preview_box.cpp b/Telegram/SourceFiles/boxes/premium_preview_box.cpp index bcbb6cabb..200eb6b3c 100644 --- a/Telegram/SourceFiles/boxes/premium_preview_box.cpp +++ b/Telegram/SourceFiles/boxes/premium_preview_box.cpp @@ -1088,6 +1088,24 @@ void ReactionPreview::paintEffect(QPainter &p) { } return -1; }; + const auto select = [=](int index) { + const auto wasInside = (state->selected >= 0); + const auto nowInside = (index >= 0); + if (state->selected != index) { + if (wasInside) { + state->entries[state->selected]->setOver(false); + } + if (nowInside) { + state->entries[index]->setOver(true); + } + state->selected = index; + } + if (wasInside != nowInside) { + result->setCursor(nowInside + ? style::cur_pointer + : style::cur_default); + } + }; result->events( ) | rpl::start_with_next([=](not_null event) { if (event->type() == QEvent::MouseButtonPress) { @@ -1101,22 +1119,9 @@ void ReactionPreview::paintEffect(QPainter &p) { } else if (event->type() == QEvent::MouseMove) { const auto point = static_cast(event.get())->pos(); const auto index = lookup(point); - const auto wasInside = (state->selected >= 0); - const auto nowInside = (index >= 0); - if (state->selected != index) { - if (wasInside) { - state->entries[state->selected]->setOver(false); - } - if (nowInside) { - state->entries[index]->setOver(true); - } - state->selected = index; - } - if (wasInside != nowInside) { - result->setCursor(nowInside - ? style::cur_pointer - : style::cur_default); - } + select(lookup(point)); + } else if (event->type() == QEvent::Leave) { + select(-1); } }, lifetime); @@ -1230,14 +1235,6 @@ void PreviewBox( const auto outer = box->addRow( ChatBackPreview(box, size.height(), back), {}); - const auto close = Ui::CreateChild( - box->verticalLayout().get(), - st::settingsPremiumTopBarClose); - box->verticalLayout()->widthValue( - ) | rpl::start_with_next([=](int width) { - close->moveToRight(0, 0, width); - }, close->lifetime()); - close->setClickedCallback([=] { box->closeBox(); }); struct Hiding { not_null widget; @@ -1261,6 +1258,37 @@ void PreviewBox( const auto state = outer->lifetime().make_state(); state->selected = descriptor.section; + const auto move = [=](int delta) { + using Type = PremiumPreview; + const auto count = int(Type::kCount); + const auto now = state->selected.current(); + state->selected = Type((int(now) + count + delta) % count); + }; + + const auto buttonsParent = box->verticalLayout().get(); + const auto close = Ui::CreateChild( + buttonsParent, + st::settingsPremiumTopBarClose); + close->setClickedCallback([=] { box->closeBox(); }); + + const auto left = Ui::CreateChild( + buttonsParent, + st::settingsPremiumMoveLeft); + left->setClickedCallback([=] { move(-1); }); + + const auto right = Ui::CreateChild( + buttonsParent, + st::settingsPremiumMoveRight); + right->setClickedCallback([=] { move(1); }); + + buttonsParent->widthValue( + ) | rpl::start_with_next([=](int width) { + const auto outerHeight = st::premiumPreviewHeight; + close->moveToRight(0, 0, width); + left->moveToLeft(0, (outerHeight - left->height()) / 2, width); + right->moveToRight(0, (outerHeight - right->height()) / 2, width); + }, close->lifetime()); + state->preload = [=] { if (!state->showFinished) { state->preloadScheduled = true; @@ -1480,15 +1508,10 @@ void PreviewBox( ) | rpl::start_with_next([=](not_null e) { if (e->type() == QEvent::KeyPress) { const auto key = static_cast(e.get())->key(); - using Type = PremiumPreview; if (key == Qt::Key_Left) { - const auto count = int(Type::kCount); - const auto now = state->selected.current(); - state->selected = Type((int(now) + count - 1) % count); + move(-1); } else if (key == Qt::Key_Right) { - const auto count = int(Type::kCount); - const auto now = state->selected.current(); - state->selected = Type((int(now) + 1) % count); + move(1); } } }, box->lifetime()); diff --git a/Telegram/SourceFiles/info/info.style b/Telegram/SourceFiles/info/info.style index f4eb3b852..d5d8b0a9b 100644 --- a/Telegram/SourceFiles/info/info.style +++ b/Telegram/SourceFiles/info/info.style @@ -299,7 +299,7 @@ infoProfileNameLabel: FlatLabel(infoProfileStatusLabel) { linkFontOver: font(16px semibold underline); } } -infoVerifiedCheckPosition: point(10px, 2px); +infoVerifiedCheckPosition: point(2px, 2px); infoVerifiedCheck: icon { { "profile_verified_star", profileVerifiedCheckBg }, { "profile_verified_check", profileVerifiedCheckFg } diff --git a/Telegram/SourceFiles/settings/settings.style b/Telegram/SourceFiles/settings/settings.style index f9e69c96c..8e9b7c1b6 100644 --- a/Telegram/SourceFiles/settings/settings.style +++ b/Telegram/SourceFiles/settings/settings.style @@ -435,7 +435,7 @@ settingsPremiumTopBarBack: IconButton(infoTopBarBack) { } settingsPremiumLayerTopBarBack: IconButton(infoLayerTopBarBack) { icon: settingsPremiumTopBarBackIcon; - iconOver: settingsPremiumTopBarBackIcon; + iconOver: settingsPremiumTopBarBackIconOver; ripple: RippleAnimation(defaultRippleAnimation) { color: shadowFg; } @@ -447,6 +447,17 @@ settingsPremiumTopBarClose: IconButton(infoTopBarClose) { color: shadowFg; } } +settingsPremiumMoveLeft: IconButton(settingsPremiumLayerTopBarBack) { + width: 52px; + height: 56px; + iconPosition: point(-1px, -1px); +} +settingsPremiumMoveRightIcon: icon {{ "info/info_back-flip_horizontal", premiumButtonFg }}; +settingsPremiumMoveRightIconOver: icon {{ "info/info_back-flip_horizontal", premiumButtonFg }}; +settingsPremiumMoveRight: IconButton(settingsPremiumMoveLeft) { + icon: settingsPremiumMoveRightIcon; + iconOver: settingsPremiumMoveRightIconOver; +} settingsPremiumRowTitlePadding: margins(60px, 5px, 46px, 3px); settingsPremiumRowAboutPadding: margins(60px, 0px, 46px, 6px); settingsPremiumPreviewTitlePadding: margins(24px, 13px, 24px, 3px);