From 3c3ce24675248dad4b3d26ea028da7cc20f54401 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 3 Jun 2020 14:24:00 +0300 Subject: [PATCH] Added ability to remove WebPage preview from scheduled messages section. --- .../view/history_view_compose_controls.cpp | 117 +++++++++++------- .../view/history_view_compose_controls.h | 1 + .../view/history_view_scheduled_section.cpp | 2 +- 3 files changed, 71 insertions(+), 49 deletions(-) diff --git a/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp index cba9f618e5..24e684cf93 100644 --- a/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/history_view_compose_controls.cpp @@ -74,16 +74,19 @@ public: bool isEditingMessage() const; rpl::producer editMsgId() const; MessageToEdit queryToEdit(); + WebPageId webPageId() const; rpl::producer visibleChanged(); protected: - void paintEvent(QPaintEvent *e) override; private: void updateControlsGeometry(QSize size); void updateVisible(); + void paintWebPage(Painter &p); + void paintEditMessage(Painter &p); + struct Preview { WebPageData *data = nullptr; Ui::Text::String title; @@ -121,6 +124,21 @@ void FieldHeader::init() { updateControlsGeometry(size); }, lifetime()); + paintRequest( + ) | rpl::start_with_next([=] { + Painter p(this); + p.fillRect(rect(), st::historyComposeAreaBg); + + if (isEditingMessage()) { + const auto position = st::historyReplyIconPosition; + st::historyEditIcon.paint(p, position, width()); + } + + ShowWebPagePreview(_preview.data) + ? paintWebPage(p) + : paintEditMessage(p); + }, lifetime()); + const auto checkPreview = [=](not_null item) { _preview = {}; if (const auto media = item->media()) { @@ -152,6 +170,7 @@ void FieldHeader::init() { } else { _editMsgId = {}; } + updateVisible(); }); _title.value( @@ -198,57 +217,51 @@ void FieldHeader::previewRequested( } -void FieldHeader::paintEvent(QPaintEvent *e) { - Painter p(this); +void FieldHeader::paintWebPage(Painter &p) { + Expects(ShowWebPagePreview(_preview.data)); - const auto replySkip = st::historyReplySkip; - const auto drawWebPagePreview = ShowWebPagePreview(_preview.data); + const auto textTop = st::msgReplyPadding.top(); + auto previewLeft = st::historyReplySkip + st::webPageLeft; + p.fillRect( + st::historyReplySkip, + textTop, + st::webPageBar, + st::msgReplyBarSize.height(), + st::msgInReplyBarColor); - p.fillRect(rect(), st::historyComposeAreaBg); - - st::historyEditIcon.paint(p, st::historyReplyIconPosition, width()); - - if (drawWebPagePreview) { - const auto textTop = st::msgReplyPadding.top(); - auto previewLeft = st::historyReplySkip + st::webPageLeft; - p.fillRect( - st::historyReplySkip, - textTop, - st::webPageBar, - st::msgReplyBarSize.height(), - st::msgInReplyBarColor); - - const QRect to( - previewLeft, - textTop, - st::msgReplyBarSize.height(), - st::msgReplyBarSize.height()); - if (HistoryView::DrawWebPageDataPreview(p, _preview.data, to)) { - previewLeft += st::msgReplyBarSize.height() - + st::msgReplyBarSkip - - st::msgReplyBarSize.width() - - st::msgReplyBarPos.x(); - } - p.setPen(st::historyReplyNameFg); - const auto elidedWidth = width() - - previewLeft - - _cancel->width() - - st::msgReplyPadding.right(); - - _preview.title.drawElided( - p, - previewLeft, - textTop, - elidedWidth); - p.setPen(st::historyComposeAreaFg); - _preview.description.drawElided( - p, - previewLeft, - textTop + st::msgServiceNameFont->height, - elidedWidth); - return; + const QRect to( + previewLeft, + textTop, + st::msgReplyBarSize.height(), + st::msgReplyBarSize.height()); + if (HistoryView::DrawWebPageDataPreview(p, _preview.data, to)) { + previewLeft += st::msgReplyBarSize.height() + + st::msgReplyBarSkip + - st::msgReplyBarSize.width() + - st::msgReplyBarPos.x(); } + const auto elidedWidth = width() + - previewLeft + - _cancel->width() + - st::msgReplyPadding.right(); + p.setPen(st::historyReplyNameFg); + _preview.title.drawElided( + p, + previewLeft, + textTop, + elidedWidth); + + p.setPen(st::historyComposeAreaFg); + _preview.description.drawElided( + p, + previewLeft, + textTop + st::msgServiceNameFont->height, + elidedWidth); +} + +void FieldHeader::paintEditMessage(Painter &p) { + const auto replySkip = st::historyReplySkip; p.setPen(st::historyReplyNameFg); p.setFont(st::msgServiceNameFont); p.drawTextLeft( @@ -288,6 +301,10 @@ bool FieldHeader::hasPreview() const { return _preview.data != nullptr; } +WebPageId FieldHeader::webPageId() const { + return hasPreview() ? _preview.data->id : CancelledWebPageId; +} + void FieldHeader::updateControlsGeometry(QSize size) { _cancel->moveToRight(0, 0); } @@ -933,4 +950,8 @@ void ComposeControls::initWebpageProcess() { } +WebPageId ComposeControls::webPageId() const { + return _header->webPageId(); +} + } // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_compose_controls.h b/Telegram/SourceFiles/history/view/history_view_compose_controls.h index 7e47e310f5..42dee7fd57 100644 --- a/Telegram/SourceFiles/history/view/history_view_compose_controls.h +++ b/Telegram/SourceFiles/history/view/history_view_compose_controls.h @@ -104,6 +104,7 @@ public: void cancelEditMessage(); [[nodiscard]] TextWithTags getTextWithAppliedMarkdown() const; + [[nodiscard]] WebPageId webPageId() const; void clear(); void hidePanelsAnimated(); diff --git a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp index 011532ac71..9cf9c9b5ef 100644 --- a/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp +++ b/Telegram/SourceFiles/history/view/history_view_scheduled_section.cpp @@ -484,7 +484,7 @@ void ScheduledWidget::send() { } void ScheduledWidget::send(Api::SendOptions options) { - const auto webPageId = 0;/* _previewCancelled + const auto webPageId = _composeControls->webPageId();/* _previewCancelled ? CancelledWebPageId : ((_previewData && _previewData->pendingTill >= 0) ? _previewData->id