tdesktop/Telegram/SourceFiles/history/feed/history_feed_section.h

180 lines
4.8 KiB
C
Raw Normal View History

2018-01-09 17:08:31 +00:00
/*
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
2019-04-02 09:13:30 +00:00
#include "ui/effects/animations.h"
2018-01-09 17:08:31 +00:00
#include "history/view/history_view_list_widget.h"
#include "window/section_widget.h"
#include "window/section_memento.h"
#include "data/data_feed.h"
2018-02-05 20:19:51 +00:00
#include "history/history_item.h"
#include "history/admin_log/history_admin_log_item.h"
2018-01-09 17:08:31 +00:00
namespace Ui {
class ScrollArea;
class PlainShadow;
class FlatButton;
2018-02-04 19:57:03 +00:00
class HistoryDownButton;
2018-01-09 17:08:31 +00:00
} // namespace Ui
namespace HistoryView {
class ListWidget;
class TopBarWidget;
2018-02-02 12:51:18 +00:00
class Element;
2018-01-09 17:08:31 +00:00
} // namespace HistoryView
2018-02-21 23:59:56 +00:00
namespace Window {
class DateClickHandler;
} // namespace Window
2018-01-09 17:08:31 +00:00
namespace HistoryFeed {
class Memento;
class Widget final
: public Window::SectionWidget
, public HistoryView::ListDelegate {
public:
2018-02-02 12:51:18 +00:00
using Element = HistoryView::Element;
2018-01-09 17:08:31 +00:00
Widget(
QWidget *parent,
not_null<Window::Controller*> controller,
not_null<Data::Feed*> feed);
Dialogs::RowDescriptor activeChat() const override;
2018-01-09 17:08:31 +00:00
bool hasTopBarShadow() const override {
return true;
}
QPixmap grabForShowAnimation(
const Window::SectionSlideParams &params) override;
bool showInternal(
not_null<Window::SectionMemento*> memento,
const Window::SectionShow &params) override;
std::unique_ptr<Window::SectionMemento> createMemento() override;
void setInternalState(
const QRect &geometry,
not_null<Memento*> memento);
// Float player interface.
bool wheelEventFromFloatPlayer(QEvent *e) override;
QRect rectForFloatPlayer() const override;
// HistoryView::ListDelegate interface.
HistoryView::Context listContext() override;
2018-01-09 17:08:31 +00:00
void listScrollTo(int top) override;
void listCancelRequest() override;
void listDeleteRequest() override;
2018-01-09 17:08:31 +00:00
rpl::producer<Data::MessagesSlice> listSource(
Data::MessagePosition aroundId,
int limitBefore,
int limitAfter) override;
bool listAllowsMultiSelect() override;
bool listIsLessInOrder(
not_null<HistoryItem*> first,
not_null<HistoryItem*> second) override;
void listSelectionChanged(
HistoryView::SelectedItems &&items) override;
2018-02-02 12:51:18 +00:00
void listVisibleItemsChanged(HistoryItemsList &&items) override;
2018-09-21 16:28:46 +00:00
std::optional<int> listUnreadBarView(
2018-02-02 12:51:18 +00:00
const std::vector<not_null<Element*>> &elements) override;
2018-02-04 19:57:03 +00:00
void listContentRefreshed() override;
2018-02-21 23:59:56 +00:00
ClickHandlerPtr listDateLink(not_null<Element*> view) override;
2018-01-09 17:08:31 +00:00
protected:
void resizeEvent(QResizeEvent *e) override;
void paintEvent(QPaintEvent *e) override;
void showAnimatedHook(
const Window::SectionSlideParams &params) override;
void showFinishedHook() override;
void doSetInnerFocus() override;
private:
void checkForSingleChannelFeed();
2018-01-09 17:08:31 +00:00
void onScroll();
void updateInnerVisibleArea();
void updateControlsGeometry();
void updateAdaptiveLayout();
void saveState(not_null<Memento*> memento);
void restoreState(not_null<Memento*> memento);
2018-02-04 19:57:03 +00:00
void showAtPosition(Data::MessagePosition position);
bool showAtPositionNow(Data::MessagePosition position);
2018-02-05 20:19:51 +00:00
void validateEmptyTextItem();
2018-02-04 19:57:03 +00:00
void setupScrollDownButton();
void scrollDownClicked();
void scrollDownAnimationFinish();
void updateScrollDownVisibility();
void updateScrollDownPosition();
2018-01-09 17:08:31 +00:00
void forwardSelected();
void confirmDeleteSelected();
void clearSelected();
2018-11-16 12:15:14 +00:00
void setupShortcuts();
2018-01-09 17:08:31 +00:00
not_null<Data::Feed*> _feed;
object_ptr<Ui::ScrollArea> _scroll;
QPointer<HistoryView::ListWidget> _inner;
object_ptr<HistoryView::TopBarWidget> _topBar;
object_ptr<Ui::PlainShadow> _topBarShadow;
object_ptr<Ui::FlatButton> _showNext;
2018-02-02 12:51:18 +00:00
bool _skipScrollEvent = false;
2018-01-09 17:08:31 +00:00
bool _undefinedAroundPosition = false;
2018-02-05 20:19:51 +00:00
std::unique_ptr<HistoryItem, HistoryItem::Destroyer> _emptyTextItem;
std::unique_ptr<HistoryView::Element> _emptyTextView;
2018-01-09 17:08:31 +00:00
FullMsgId _currentMessageId;
2018-02-16 17:59:35 +00:00
FullMsgId _highlightMessageId;
2018-09-21 16:28:46 +00:00
std::optional<Data::MessagePosition> _nextAnimatedScrollPosition;
2018-02-04 19:57:03 +00:00
int _nextAnimatedScrollDelta = 0;
2019-04-02 09:13:30 +00:00
Ui::Animations::Simple _scrollDownShown;
2018-02-04 19:57:03 +00:00
bool _scrollDownIsShown = false;
object_ptr<Ui::HistoryDownButton> _scrollDown;
2018-02-21 23:59:56 +00:00
std::shared_ptr<Window::DateClickHandler> _dateLink;
2018-02-04 19:57:03 +00:00
2018-01-09 17:08:31 +00:00
};
class Memento : public Window::SectionMemento {
public:
explicit Memento(
not_null<Data::Feed*> feed,
Data::MessagePosition position = Data::UnreadMessagePosition);
2018-01-09 17:08:31 +00:00
~Memento();
object_ptr<Window::SectionWidget> createWidget(
QWidget *parent,
not_null<Window::Controller*> controller,
Window::Column column,
const QRect &geometry) override;
not_null<Data::Feed*> feed() const {
return _feed;
}
Data::MessagePosition position() const {
return _position;
}
2018-01-09 17:08:31 +00:00
not_null<HistoryView::ListMemento*> list() const {
return _list.get();
}
private:
not_null<Data::Feed*> _feed;
Data::MessagePosition _position;
2018-01-09 17:08:31 +00:00
std::unique_ptr<HistoryView::ListMemento> _list;
};
} // namespace HistoryFeed