From 95a896004f5d8292227ea4f616d108f4ec766f32 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 20 Jul 2021 21:18:53 +0300 Subject: [PATCH] Added bubble widget for empty list info in modern history view list. --- Telegram/CMakeLists.txt | 2 + .../view/history_view_empty_list_bubble.cpp | 76 +++++++++++++++++++ .../view/history_view_empty_list_bubble.h | 38 ++++++++++ .../history/view/history_view_list_widget.cpp | 7 ++ .../history/view/history_view_list_widget.h | 4 + 5 files changed, 127 insertions(+) create mode 100644 Telegram/SourceFiles/history/view/history_view_empty_list_bubble.cpp create mode 100644 Telegram/SourceFiles/history/view/history_view_empty_list_bubble.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index a0894fe1d3..b4deb047a0 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 0000000000..5e189791be --- /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 0000000000..9a789b8289 --- /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 65d1c2ee4c..8d02dab719 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 67c256cdee..f35dd363ac 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;