diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index a0894fe1d..b4deb047a 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -564,6 +564,8 @@ PRIVATE history/view/history_view_cursor_state.h history/view/history_view_element.cpp history/view/history_view_element.h + history/view/history_view_empty_list_bubble.cpp + history/view/history_view_empty_list_bubble.h history/view/history_view_group_call_tracker.cpp history/view/history_view_group_call_tracker.h history/view/history_view_list_widget.cpp diff --git a/Telegram/SourceFiles/history/view/history_view_empty_list_bubble.cpp b/Telegram/SourceFiles/history/view/history_view_empty_list_bubble.cpp new file mode 100644 index 000000000..5e189791b --- /dev/null +++ b/Telegram/SourceFiles/history/view/history_view_empty_list_bubble.cpp @@ -0,0 +1,76 @@ +/* +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 "history/view/history_view_empty_list_bubble.h" + +#include "history/view/history_view_list_widget.h" +#include "history/view/history_view_service_message.h" + +namespace HistoryView { + +EmptyListBubbleWidget::EmptyListBubbleWidget( + not_null parent, + const style::margins &padding) +: RpWidget(parent) +, _padding(padding) { + + parent->sizeValue( + ) | rpl::start_with_next([=](const QSize &s) { + updateGeometry(s); + }, lifetime()); +} + +void EmptyListBubbleWidget::updateGeometry(const QSize &size) { + const auto w = _forceWidth + ? _forceWidth + : std::min( + _text.maxWidth() + _padding.left() + _padding.right(), + size.width()); + _innerWidth = w - _padding.left() - _padding.right(); + const auto h = _padding.top() + + _text.countHeight(_innerWidth) + + _padding.bottom(); + resize(w, h); + move((size.width() - w) / 2, (size.height() - h) / 3); +} + +void EmptyListBubbleWidget::paintEvent(QPaintEvent *e) { + Painter p(this); + + const auto r = rect(); + HistoryView::ServiceMessagePainter::paintBubble( + p, + r.x(), + r.y(), + r.width(), + r.height()); + + p.setPen(st::msgServiceFg); + _text.draw( + p, + r.x() + _padding.left(), + r.y() + _padding.top(), + _innerWidth, + style::al_top); +} + +void EmptyListBubbleWidget::setText( + const TextWithEntities &textWithEntities) { + auto options = _defaultOptions; + options.flags |= TextParseMarkdown; + _text.setMarkedText(st::defaultTextStyle, textWithEntities, options); + updateGeometry(size()); +} + +void EmptyListBubbleWidget::setForceWidth(int width) { + if (_forceWidth != width) { + _forceWidth = width; + updateGeometry(size()); + } +} + +} // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_empty_list_bubble.h b/Telegram/SourceFiles/history/view/history_view_empty_list_bubble.h new file mode 100644 index 000000000..9a789b828 --- /dev/null +++ b/Telegram/SourceFiles/history/view/history_view_empty_list_bubble.h @@ -0,0 +1,38 @@ +/* +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 + +#include "ui/rp_widget.h" + +namespace HistoryView { + +class ListWidget; + +class EmptyListBubbleWidget : public Ui::RpWidget { +public: + EmptyListBubbleWidget( + not_null parent, + const style::margins &padding); + + void setText(const TextWithEntities &textWithEntities); + void setForceWidth(int width); + +protected: + void paintEvent(QPaintEvent *e) override; + +private: + void updateGeometry(const QSize &size); + + const style::margins &_padding; + Ui::Text::String _text; + int _innerWidth = 0; + int _forceWidth = 0; + +}; + +} // namespace HistoryView diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp index 65d1c2ee4..8d02dab71 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.cpp +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.cpp @@ -382,6 +382,9 @@ void ListWidget::refreshRows(const Data::MessagesSlice &old) { if (!_itemsRevealHeight) { mouseActionUpdate(QCursor::pos()); } + if (_emptyInfo) { + _emptyInfo->setVisible(isEmpty()); + } _delegate->listContentRefreshed(); } @@ -2940,6 +2943,10 @@ void ListWidget::replyNextMessage(FullMsgId fullId, bool next) { } } +void ListWidget::setEmptyInfoWidget(base::unique_qptr &&w) { + _emptyInfo = std::move(w); +} + ListWidget::~ListWidget() = default; void ConfirmDeleteSelectedItems(not_null widget) { diff --git a/Telegram/SourceFiles/history/view/history_view_list_widget.h b/Telegram/SourceFiles/history/view/history_view_list_widget.h index 67c256cde..f35dd363a 100644 --- a/Telegram/SourceFiles/history/view/history_view_list_widget.h +++ b/Telegram/SourceFiles/history/view/history_view_list_widget.h @@ -257,6 +257,8 @@ public: bool elementIsChatWide() override; not_null elementPathShiftGradient() override; + void setEmptyInfoWidget(base::unique_qptr &&w); + ~ListWidget(); protected: @@ -524,6 +526,8 @@ private: const std::unique_ptr _pathGradient; + base::unique_qptr _emptyInfo = nullptr; + int _minHeight = 0; int _visibleTop = 0; int _visibleBottom = 0;