diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.cpp b/Telegram/SourceFiles/boxes/edit_caption_box.cpp index b1f82ff1b..d78787bfc 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.cpp +++ b/Telegram/SourceFiles/boxes/edit_caption_box.cpp @@ -37,13 +37,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/chat/attach/attach_single_file_preview.h" #include "ui/chat/attach/attach_single_media_preview.h" #include "ui/controls/emoji_button.h" +#include "ui/effects/scroll_content_shadow.h" #include "ui/image/image.h" #include "ui/toast/toast.h" #include "ui/ui_utility.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/input_fields.h" #include "ui/widgets/scroll_area.h" -#include "ui/wrap/fade_wrap.h" #include "ui/wrap/slide_wrap.h" #include "ui/wrap/vertical_layout.h" #include "window/window_session_controller.h" @@ -125,9 +125,7 @@ EditCaptionBox::EditCaptionBox( PrepareEditText(item))) , _emojiToggle(base::make_unique_q( this, - st::boxAttachEmoji)) -, _topShadow(base::make_unique_q(this)) -, _bottomShadow(base::make_unique_q(this)) { + st::boxAttachEmoji)) { Expects(item->media() != nullptr); Expects(item->media()->allowsEditCaption()); @@ -151,7 +149,7 @@ void EditCaptionBox::prepare() { rebuildPreview(); setupEditEventHandler(); - setupShadows(); + SetupShadowsToScrollContent(this, _scroll, _contentHeight.events()); setupControls(); setupPhotoEditorEventHandler(); @@ -282,31 +280,6 @@ void EditCaptionBox::setupField() { _field->setTextCursor(cursor); } -void EditCaptionBox::setupShadows() { - using namespace rpl::mappers; - - const auto _topShadow = Ui::CreateChild(this); - const auto _bottomShadow = Ui::CreateChild(this); - _scroll->geometryValue( - ) | rpl::start_with_next([=](const QRect &geometry) { - _topShadow->resizeToWidth(geometry.width()); - _topShadow->move( - geometry.x(), - geometry.y()); - _bottomShadow->resizeToWidth(geometry.width()); - _bottomShadow->move( - geometry.x(), - geometry.y() + geometry.height() - st::lineWidth); - }, _topShadow->lifetime()); - - _topShadow->toggleOn(_scroll->scrollTopValue() | rpl::map(_1 > 0)); - _bottomShadow->toggleOn(rpl::combine( - _scroll->scrollTopValue(), - _scroll->heightValue(), - _contentHeight.events(), - _1 + _2 < _3)); -} - void EditCaptionBox::setupControls() { auto hintLabelToggleOn = _previewRebuilds.events_starting_with( {} diff --git a/Telegram/SourceFiles/boxes/edit_caption_box.h b/Telegram/SourceFiles/boxes/edit_caption_box.h index 02b364881..ce9b68acc 100644 --- a/Telegram/SourceFiles/boxes/edit_caption_box.h +++ b/Telegram/SourceFiles/boxes/edit_caption_box.h @@ -27,7 +27,6 @@ class AbstractSinglePreview; class InputField; class EmojiButton; class VerticalLayout; -class FadeShadow; enum class AlbumType; } // namespace Ui @@ -51,7 +50,6 @@ private: void rebuildPreview(); void setupEditEventHandler(); void setupPhotoEditorEventHandler(); - void setupShadows(); void setupField(); void setupControls(); @@ -81,7 +79,6 @@ private: const base::unique_qptr _scroll; const base::unique_qptr _field; const base::unique_qptr _emojiToggle; - const base::unique_qptr _topShadow, _bottomShadow; base::unique_qptr _content; base::unique_qptr _emojiPanel; diff --git a/Telegram/SourceFiles/boxes/reactions_settings_box.cpp b/Telegram/SourceFiles/boxes/reactions_settings_box.cpp index eeec04020..410ee8a92 100644 --- a/Telegram/SourceFiles/boxes/reactions_settings_box.cpp +++ b/Telegram/SourceFiles/boxes/reactions_settings_box.cpp @@ -23,11 +23,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_common.h" #include "ui/chat/chat_style.h" #include "ui/chat/chat_theme.h" +#include "ui/effects/scroll_content_shadow.h" #include "ui/layers/generic_box.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" #include "ui/widgets/scroll_area.h" -#include "ui/wrap/fade_wrap.h" #include "ui/wrap/vertical_layout.h" #include "window/section_widget.h" #include "window/window_session_controller.h" @@ -373,37 +373,6 @@ void AddMessage( }, widget->lifetime()); } -void SetupShadows( - not_null parent, - not_null scroll, - not_null inner) { - using namespace rpl::mappers; - - const auto topShadow = Ui::CreateChild(parent.get()); - const auto bottomShadow = Ui::CreateChild(parent.get()); - scroll->geometryValue( - ) | rpl::start_with_next_done([=](const QRect &geometry) { - topShadow->resizeToWidth(geometry.width()); - topShadow->move( - geometry.x(), - geometry.y()); - bottomShadow->resizeToWidth(geometry.width()); - bottomShadow->move( - geometry.x(), - geometry.y() + geometry.height() - st::lineWidth); - }, [t = Ui::MakeWeak(topShadow), b = Ui::MakeWeak(bottomShadow)] { - Ui::DestroyChild(t.data()); - Ui::DestroyChild(b.data()); - }, topShadow->lifetime()); - - topShadow->toggleOn(scroll->scrollTopValue() | rpl::map(_1 > 0)); - bottomShadow->toggleOn(rpl::combine( - scroll->scrollTopValue(), - scroll->heightValue(), - inner->heightValue(), - _1 + _2 < _3)); -} - } // namespace void ReactionsSettingsBox( @@ -503,7 +472,10 @@ void ReactionsSettingsBox( } check->raise(); - SetupShadows(scrollContainer, scroll, buttonsContainer); + Ui::SetupShadowsToScrollContent( + scrollContainer, + scroll, + buttonsContainer->heightValue()); box->setTitle(tr::lng_settings_chat_reactions_title()); box->setWidth(st::boxWideWidth); diff --git a/Telegram/SourceFiles/boxes/send_files_box.cpp b/Telegram/SourceFiles/boxes/send_files_box.cpp index d548102c6..34853fa13 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.cpp +++ b/Telegram/SourceFiles/boxes/send_files_box.cpp @@ -26,11 +26,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/mime_type.h" #include "base/event_filter.h" #include "ui/effects/animations.h" +#include "ui/effects/scroll_content_shadow.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" #include "ui/widgets/scroll_area.h" -#include "ui/wrap/fade_wrap.h" #include "ui/wrap/vertical_layout.h" #include "ui/chat/attach/attach_prepare.h" #include "ui/chat/attach/attach_send_files_way.h" @@ -312,34 +312,6 @@ void SendFilesBox::enqueueNextPrepare() { }); } -void SendFilesBox::setupShadows() { - using namespace rpl::mappers; - - const auto topShadow = Ui::CreateChild(this); - const auto bottomShadow = Ui::CreateChild(this); - _scroll->geometryValue( - ) | rpl::start_with_next_done([=](const QRect &geometry) { - topShadow->resizeToWidth(geometry.width()); - topShadow->move( - geometry.x(), - geometry.y()); - bottomShadow->resizeToWidth(geometry.width()); - bottomShadow->move( - geometry.x(), - geometry.y() + geometry.height() - st::lineWidth); - }, [t = Ui::MakeWeak(topShadow), b = Ui::MakeWeak(bottomShadow)] { - Ui::DestroyChild(t.data()); - Ui::DestroyChild(b.data()); - }, topShadow->lifetime()); - - topShadow->toggleOn(_scroll->scrollTopValue() | rpl::map(_1 > 0)); - bottomShadow->toggleOn(rpl::combine( - _scroll->scrollTopValue(), - _scroll->heightValue(), - _inner->heightValue(), - _1 + _2 < _3)); -} - void SendFilesBox::prepare() { _send = addButton( (_sendType == Api::SendType::Normal @@ -359,7 +331,7 @@ void SendFilesBox::prepare() { setupSendWayControls(); preparePreview(); initPreview(); - setupShadows(); + SetupShadowsToScrollContent(this, _scroll, _inner->heightValue()); boxClosing() | rpl::start_with_next([=] { if (!_confirmed && _cancelledCallback) { diff --git a/Telegram/SourceFiles/boxes/send_files_box.h b/Telegram/SourceFiles/boxes/send_files_box.h index 207456cff..e2089fb14 100644 --- a/Telegram/SourceFiles/boxes/send_files_box.h +++ b/Telegram/SourceFiles/boxes/send_files_box.h @@ -123,7 +123,6 @@ private: void refreshControls(); void setupSendWayControls(); void setupCaption(); - void setupShadows(); void setupEmojiPanel(); void updateSendWayControlsVisibility(); diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp index a813bccfe..f9779cab6 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_document.cpp @@ -10,11 +10,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "passport/passport_panel_controller.h" #include "passport/passport_panel_edit_scans.h" #include "passport/ui/passport_details_row.h" +#include "ui/effects/scroll_content_shadow.h" #include "ui/widgets/input_fields.h" #include "ui/widgets/scroll_area.h" #include "ui/widgets/labels.h" #include "ui/widgets/buttons.h" -#include "ui/widgets/shadow.h" #include "ui/widgets/checkbox.h" #include "ui/wrap/vertical_layout.h" #include "ui/wrap/fade_wrap.h" @@ -219,8 +219,6 @@ PanelEditDocument::PanelEditDocument( : _controller(controller) , _scheme(std::move(scheme)) , _scroll(this, st::passportPanelScroll) -, _topShadow(this) -, _bottomShadow(this) , _done( this, tr::lng_passport_save_value(), @@ -247,8 +245,6 @@ PanelEditDocument::PanelEditDocument( : _controller(controller) , _scheme(std::move(scheme)) , _scroll(this, st::passportPanelScroll) -, _topShadow(this) -, _bottomShadow(this) , _done( this, tr::lng_passport_save_value(), @@ -272,8 +268,6 @@ PanelEditDocument::PanelEditDocument( : _controller(controller) , _scheme(std::move(scheme)) , _scroll(this, st::passportPanelScroll) -, _topShadow(this) -, _bottomShadow(this) , _done( this, tr::lng_passport_save_value(), @@ -289,7 +283,7 @@ void PanelEditDocument::setupControls( ScanListData &&scans, std::optional &&translations, std::map &&specialFiles) { - setupContent( + const auto inner = setupContent( error, data, scansError, @@ -298,10 +292,8 @@ void PanelEditDocument::setupControls( std::move(translations), std::move(specialFiles)); - using namespace rpl::mappers; + Ui::SetupShadowsToScrollContent(this, _scroll, inner->heightValue()); - _topShadow->toggleOn( - _scroll->scrollTopValue() | rpl::map(_1 > 0)); _done->addClickHandler([=] { crl::on_main(this, [=] { save(); @@ -604,10 +596,6 @@ bool PanelEditDocument::hasUnsavedChanges() const { void PanelEditDocument::updateControlsGeometry() { const auto submitTop = height() - _done->height(); _scroll->setGeometry(0, 0, width(), submitTop); - _topShadow->resizeToWidth(width()); - _topShadow->moveToLeft(0, 0); - _bottomShadow->resizeToWidth(width()); - _bottomShadow->moveToLeft(0, submitTop - st::lineWidth); _done->resizeToWidth(width()); _done->moveToLeft(0, submitTop); diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_document.h b/Telegram/SourceFiles/passport/passport_panel_edit_document.h index 0ab72f0aa..40415d65e 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_document.h +++ b/Telegram/SourceFiles/passport/passport_panel_edit_document.h @@ -13,8 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Ui { class InputField; class ScrollArea; -class FadeShadow; -class PlainShadow; class FlatLabel; class RoundButton; class VerticalLayout; @@ -157,8 +155,6 @@ private: Scheme _scheme; object_ptr _scroll; - object_ptr _topShadow; - object_ptr _bottomShadow; QPointer _editScans; QPointer> _commonError; diff --git a/Telegram/SourceFiles/passport/passport_panel_form.cpp b/Telegram/SourceFiles/passport/passport_panel_form.cpp index 5802e6c3a..364b74171 100644 --- a/Telegram/SourceFiles/passport/passport_panel_form.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_form.cpp @@ -14,13 +14,12 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/click_handler_types.h" #include "data/data_user.h" #include "ui/effects/animations.h" -#include "ui/widgets/shadow.h" +#include "ui/effects/scroll_content_shadow.h" #include "ui/widgets/buttons.h" #include "ui/widgets/scroll_area.h" #include "ui/widgets/labels.h" #include "ui/widgets/box_content_divider.h" #include "ui/wrap/vertical_layout.h" -#include "ui/wrap/fade_wrap.h" #include "ui/wrap/padding_wrap.h" #include "ui/text/text_utilities.h" #include "ui/text/text_options.h" @@ -37,8 +36,6 @@ PanelForm::PanelForm( : RpWidget(parent) , _controller(controller) , _scroll(this, st::passportPanelScroll) -, _topShadow(this) -, _bottomShadow(this) , _submit( this, tr::lng_passport_authorize(), @@ -53,15 +50,7 @@ void PanelForm::setupControls() { _controller->submitForm(); }); - using namespace rpl::mappers; - - _topShadow->toggleOn( - _scroll->scrollTopValue() | rpl::map(_1 > 0)); - _bottomShadow->toggleOn(rpl::combine( - _scroll->scrollTopValue(), - _scroll->heightValue(), - inner->heightValue(), - _1 + _2 < _3)); + SetupShadowsToScrollContent(this, _scroll, inner->heightValue()); } not_null PanelForm::setupContent() { @@ -188,10 +177,6 @@ void PanelForm::resizeEvent(QResizeEvent *e) { void PanelForm::updateControlsGeometry() { const auto submitTop = height() - _submit->height(); _scroll->setGeometry(0, 0, width(), submitTop); - _topShadow->resizeToWidth(width()); - _topShadow->moveToLeft(0, 0); - _bottomShadow->resizeToWidth(width()); - _bottomShadow->moveToLeft(0, submitTop - st::lineWidth); _submit->setFullWidth(width()); _submit->moveToLeft(0, submitTop); diff --git a/Telegram/SourceFiles/passport/passport_panel_form.h b/Telegram/SourceFiles/passport/passport_panel_form.h index 26b2dfa3b..83ea1b2da 100644 --- a/Telegram/SourceFiles/passport/passport_panel_form.h +++ b/Telegram/SourceFiles/passport/passport_panel_form.h @@ -13,7 +13,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Ui { class BoxContentDivider; class ScrollArea; -class FadeShadow; class RoundButton; class FlatLabel; class UserpicButton; @@ -47,8 +46,6 @@ private: not_null _controller; object_ptr _scroll; - object_ptr _topShadow; - object_ptr _bottomShadow; object_ptr _submit; QPointer _userpic; diff --git a/Telegram/SourceFiles/ui/effects/scroll_content_shadow.cpp b/Telegram/SourceFiles/ui/effects/scroll_content_shadow.cpp new file mode 100644 index 000000000..0acd5bf60 --- /dev/null +++ b/Telegram/SourceFiles/ui/effects/scroll_content_shadow.cpp @@ -0,0 +1,47 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "ui/effects/scroll_content_shadow.h" + +#include "ui/rp_widget.h" +#include "ui/widgets/scroll_area.h" +#include "ui/wrap/fade_wrap.h" + +namespace Ui { + +void SetupShadowsToScrollContent( + not_null parent, + not_null scroll, + rpl::producer &&innerHeightValue) { + using namespace rpl::mappers; + + const auto topShadow = Ui::CreateChild(parent.get()); + const auto bottomShadow = Ui::CreateChild(parent.get()); + scroll->geometryValue( + ) | rpl::start_with_next_done([=](const QRect &geometry) { + topShadow->resizeToWidth(geometry.width()); + topShadow->move( + geometry.x(), + geometry.y()); + bottomShadow->resizeToWidth(geometry.width()); + bottomShadow->move( + geometry.x(), + geometry.y() + geometry.height() - st::lineWidth); + }, [t = Ui::MakeWeak(topShadow), b = Ui::MakeWeak(bottomShadow)] { + Ui::DestroyChild(t.data()); + Ui::DestroyChild(b.data()); + }, topShadow->lifetime()); + + topShadow->toggleOn(scroll->scrollTopValue() | rpl::map(_1 > 0)); + bottomShadow->toggleOn(rpl::combine( + scroll->scrollTopValue(), + scroll->heightValue(), + std::move(innerHeightValue), + _1 + _2 < _3)); +} + +} // namespace Ui diff --git a/Telegram/SourceFiles/ui/effects/scroll_content_shadow.h b/Telegram/SourceFiles/ui/effects/scroll_content_shadow.h new file mode 100644 index 000000000..ca02dc5cb --- /dev/null +++ b/Telegram/SourceFiles/ui/effects/scroll_content_shadow.h @@ -0,0 +1,20 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +namespace Ui { + +class RpWidget; +class ScrollArea; + +void SetupShadowsToScrollContent( + not_null parent, + not_null scroll, + rpl::producer &&innerHeightValue); + +} // namespace Ui diff --git a/Telegram/cmake/td_ui.cmake b/Telegram/cmake/td_ui.cmake index b8195cb31..ab15739d5 100644 --- a/Telegram/cmake/td_ui.cmake +++ b/Telegram/cmake/td_ui.cmake @@ -223,6 +223,8 @@ PRIVATE ui/controls/who_reacted_context_action.h ui/controls/window_outdated_bar.cpp ui/controls/window_outdated_bar.h + ui/effects/scroll_content_shadow.cpp + ui/effects/scroll_content_shadow.h ui/text/format_song_name.cpp ui/text/format_song_name.h ui/text/format_values.cpp