diff --git a/Telegram/SourceFiles/chat_helpers/chat_helpers.style b/Telegram/SourceFiles/chat_helpers/chat_helpers.style index 21f1ad3c3..14af86253 100644 --- a/Telegram/SourceFiles/chat_helpers/chat_helpers.style +++ b/Telegram/SourceFiles/chat_helpers/chat_helpers.style @@ -968,6 +968,7 @@ historyComposeField: InputField(defaultInputField) { duration: 100; } historyComposeFieldMaxHeight: 224px; +historyComposeFieldFadeHeight: 8px; // historyMinHeight: 56px; historyAttach: IconButton(defaultIconButton) { diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index ee3418394..77ca3bdd3 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/qthelp_url.h" #include "base/event_filter.h" #include "ui/layers/generic_box.h" +#include "ui/rect.h" #include "core/shortcuts.h" #include "core/application.h" #include "core/core_settings.h" @@ -442,6 +443,74 @@ bool HasSendText(not_null field) { return false; } +void InitMessageFieldFade(not_null field) { + class Fade final : public Ui::RpWidget { + public: + using Ui::RpWidget::RpWidget; + + void setFade(QPixmap &&fade) { + _fade = std::move(fade); + } + + int resizeGetHeight(int newWidth) override { + return st::historyComposeFieldFadeHeight; + } + + private: + void paintEvent(QPaintEvent *event) override { + auto p = QPainter(this); + p.drawTiledPixmap(rect(), _fade); + } + + QPixmap _fade; + + }; + + const auto topFade = Ui::CreateChild(field.get()); + const auto bottomFade = Ui::CreateChild(field.get()); + + const auto generateFade = [=] { + const auto size = QSize(1, st::historyComposeFieldFadeHeight); + auto fade = QPixmap(size * style::DevicePixelRatio()); + fade.setDevicePixelRatio(style::DevicePixelRatio()); + fade.fill(Qt::transparent); + { + auto p = QPainter(&fade); + + auto gradient = QLinearGradient(0, 1, 0, size.height()); + gradient.setStops({ + { 0., st::historyComposeField.textBg->c }, + { .9, Qt::transparent }, + }); + p.setPen(Qt::NoPen); + p.setBrush(gradient); + p.drawRect(Rect(size)); + } + bottomFade->setFade(fade.transformed(QTransform().scale(1, -1))); + topFade->setFade(std::move(fade)); + }; + generateFade(); + style::PaletteChanged( + ) | rpl::start_with_next([=] { + generateFade(); + }, topFade->lifetime()); + + field->sizeValue( + ) | rpl::start_with_next_done([=](const QSize &size) { + topFade->resizeToWidth(size.width()); + bottomFade->resizeToWidth(size.width()); + bottomFade->move( + 0, + size.height() - st::historyComposeFieldFadeHeight); + }, [t = Ui::MakeWeak(topFade), b = Ui::MakeWeak(bottomFade)] { + Ui::DestroyChild(t.data()); + Ui::DestroyChild(b.data()); + }, topFade->lifetime()); + + topFade->show(); + bottomFade->show(); +} + InlineBotQuery ParseInlineBotQuery( not_null session, not_null field) { diff --git a/Telegram/SourceFiles/chat_helpers/message_field.h b/Telegram/SourceFiles/chat_helpers/message_field.h index 7bce7facf..18ad42c09 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.h +++ b/Telegram/SourceFiles/chat_helpers/message_field.h @@ -79,6 +79,8 @@ void InitSpellchecker( bool HasSendText(not_null field); +void InitMessageFieldFade(not_null field); + struct InlineBotQuery { QString query; QString username; diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index 4921e6307..5fa7a5a19 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -398,6 +398,7 @@ HistoryWidget::HistoryWidget( showPremiumToast(document); return false; }); + InitMessageFieldFade(_field); _keyboard->sendCommandRequests( ) | rpl::start_with_next([=](Bot::SendCommandRequest r) { diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 05675a2fe..ada3c7295 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -1575,6 +1575,7 @@ void ComposeControls::initField() { } return false; }); + InitMessageFieldFade(_field); _field->setEditLinkCallback( DefaultEditLinkCallback(_show, _field, &_st.boxField)); initAutocomplete();