2017-04-08 15:20:12 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-04-08 15:20:12 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-04-08 15:20:12 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2020-07-24 08:22:45 +00:00
|
|
|
#include "api/api_common.h"
|
2017-09-13 16:57:44 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2019-04-02 09:13:30 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2017-04-08 15:20:12 +00:00
|
|
|
#include "ui/effects/panel_animation.h"
|
|
|
|
#include "mtproto/sender.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "base/object_ptr.h"
|
2017-04-08 15:20:12 +00:00
|
|
|
|
|
|
|
namespace InlineBots {
|
2020-11-12 15:46:17 +00:00
|
|
|
struct ResultSelected;
|
2017-04-08 15:20:12 +00:00
|
|
|
} // namespace InlineBots
|
|
|
|
|
2020-06-18 12:47:09 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
namespace Ui {
|
|
|
|
class PlainShadow;
|
2020-07-25 15:07:14 +00:00
|
|
|
class PopupMenu;
|
2017-04-08 15:20:12 +00:00
|
|
|
class ScrollArea;
|
|
|
|
class SettingsSlider;
|
2017-06-11 18:33:20 +00:00
|
|
|
class FlatLabel;
|
2020-06-18 12:47:09 +00:00
|
|
|
} // namespace Ui
|
2017-04-08 15:20:12 +00:00
|
|
|
|
|
|
|
namespace Window {
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2017-04-08 15:20:12 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2020-08-10 12:22:54 +00:00
|
|
|
namespace SendMenu {
|
|
|
|
enum class Type;
|
|
|
|
} // namespace SendMenu
|
2020-07-25 16:50:19 +00:00
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
namespace ChatHelpers {
|
|
|
|
|
2017-05-24 10:10:04 +00:00
|
|
|
enum class SelectorTab {
|
|
|
|
Emoji,
|
|
|
|
Stickers,
|
|
|
|
Gifs,
|
|
|
|
};
|
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
class EmojiListWidget;
|
|
|
|
class StickersListWidget;
|
|
|
|
class GifsListWidget;
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
class TabbedSelector : public Ui::RpWidget, private base::Subscriber {
|
2017-04-08 15:20:12 +00:00
|
|
|
public:
|
2020-07-24 08:22:45 +00:00
|
|
|
struct FileChosen {
|
|
|
|
not_null<DocumentData*> document;
|
|
|
|
Api::SendOptions options;
|
|
|
|
};
|
2020-08-07 16:13:47 +00:00
|
|
|
struct PhotoChosen {
|
|
|
|
not_null<PhotoData*> photo;
|
|
|
|
Api::SendOptions options;
|
|
|
|
};
|
2020-11-12 15:46:17 +00:00
|
|
|
using InlineChosen = InlineBots::ResultSelected;
|
2018-11-22 10:30:48 +00:00
|
|
|
enum class Mode {
|
|
|
|
Full,
|
|
|
|
EmojiOnly
|
|
|
|
};
|
2018-11-21 18:14:48 +00:00
|
|
|
|
2018-11-22 10:30:48 +00:00
|
|
|
TabbedSelector(
|
|
|
|
QWidget *parent,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2018-11-22 10:30:48 +00:00
|
|
|
Mode mode = Mode::Full);
|
2019-07-24 11:13:51 +00:00
|
|
|
~TabbedSelector();
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
Main::Session &session() const;
|
2017-04-08 15:20:12 +00:00
|
|
|
|
2018-11-21 18:14:48 +00:00
|
|
|
rpl::producer<EmojiPtr> emojiChosen() const;
|
2020-07-24 08:22:45 +00:00
|
|
|
rpl::producer<FileChosen> fileChosen() const;
|
2020-08-07 16:13:47 +00:00
|
|
|
rpl::producer<PhotoChosen> photoChosen() const;
|
2018-11-21 18:14:48 +00:00
|
|
|
rpl::producer<InlineChosen> inlineResultChosen() const;
|
|
|
|
|
|
|
|
rpl::producer<> cancelled() const;
|
|
|
|
rpl::producer<> checkForHide() const;
|
|
|
|
rpl::producer<> slideFinished() const;
|
2021-01-07 22:38:09 +00:00
|
|
|
rpl::producer<> contextMenuRequested() const;
|
2018-11-21 18:14:48 +00:00
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
void setRoundRadius(int radius);
|
|
|
|
void refreshStickers();
|
2017-06-11 18:33:20 +00:00
|
|
|
void setCurrentPeer(PeerData *peer);
|
2017-04-08 15:20:12 +00:00
|
|
|
|
|
|
|
void hideFinished();
|
|
|
|
void showStarted();
|
|
|
|
void beforeHiding();
|
|
|
|
void afterShown();
|
|
|
|
|
2017-04-15 21:05:57 +00:00
|
|
|
int marginTop() const;
|
|
|
|
int marginBottom() const;
|
2018-11-22 10:30:48 +00:00
|
|
|
int scrollTop() const;
|
2017-04-15 21:05:57 +00:00
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
bool preventAutoHide() const;
|
|
|
|
bool isSliding() const {
|
|
|
|
return _a_slide.animating();
|
|
|
|
}
|
2020-07-25 15:07:14 +00:00
|
|
|
bool hasMenu() const;
|
2017-04-08 15:20:12 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setAfterShownCallback(Fn<void(SelectorTab)> callback) {
|
2017-04-11 14:02:11 +00:00
|
|
|
_afterShownCallback = std::move(callback);
|
|
|
|
}
|
2018-06-04 15:35:11 +00:00
|
|
|
void setBeforeHidingCallback(Fn<void(SelectorTab)> callback) {
|
2017-04-11 14:02:11 +00:00
|
|
|
_beforeHidingCallback = std::move(callback);
|
|
|
|
}
|
|
|
|
|
2021-01-07 22:38:09 +00:00
|
|
|
void showMenuWithType(SendMenu::Type type);
|
2020-07-25 16:50:19 +00:00
|
|
|
|
2017-05-22 15:25:49 +00:00
|
|
|
// Float player interface.
|
2020-06-25 14:17:37 +00:00
|
|
|
bool floatPlayerHandleWheelEvent(QEvent *e);
|
|
|
|
QRect floatPlayerAvailableRect() const;
|
2017-05-22 15:25:49 +00:00
|
|
|
|
2017-09-27 12:04:19 +00:00
|
|
|
auto showRequests() const {
|
2017-09-16 16:53:41 +00:00
|
|
|
return _showRequests.events();
|
|
|
|
}
|
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
class Inner;
|
|
|
|
class InnerFooter;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
class Tab {
|
|
|
|
public:
|
|
|
|
static constexpr auto kCount = 3;
|
|
|
|
|
2017-05-24 10:10:04 +00:00
|
|
|
Tab(SelectorTab type, object_ptr<Inner> widget);
|
2017-04-08 15:20:12 +00:00
|
|
|
|
|
|
|
object_ptr<Inner> takeWidget();
|
|
|
|
void returnWidget(object_ptr<Inner> widget);
|
|
|
|
|
2017-05-24 10:10:04 +00:00
|
|
|
SelectorTab type() const {
|
2017-04-08 15:20:12 +00:00
|
|
|
return _type;
|
|
|
|
}
|
2018-11-22 10:30:48 +00:00
|
|
|
Inner *widget() const {
|
2017-04-08 15:20:12 +00:00
|
|
|
return _weak;
|
|
|
|
}
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<InnerFooter*> footer() const {
|
2017-04-08 15:20:12 +00:00
|
|
|
return _footer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void saveScrollTop();
|
|
|
|
void saveScrollTop(int scrollTop) {
|
|
|
|
_scrollTop = scrollTop;
|
|
|
|
}
|
|
|
|
int getScrollTop() const {
|
|
|
|
return _scrollTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-05-24 10:10:04 +00:00
|
|
|
SelectorTab _type = SelectorTab::Emoji;
|
2017-04-08 15:20:12 +00:00
|
|
|
object_ptr<Inner> _widget = { nullptr };
|
|
|
|
QPointer<Inner> _weak;
|
|
|
|
object_ptr<InnerFooter> _footer;
|
|
|
|
int _scrollTop = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-11-22 10:30:48 +00:00
|
|
|
bool full() const;
|
2019-07-24 11:13:51 +00:00
|
|
|
Tab createTab(SelectorTab type);
|
2018-11-22 10:30:48 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
void paintSlideFrame(Painter &p);
|
2017-04-08 15:20:12 +00:00
|
|
|
void paintContent(Painter &p);
|
|
|
|
|
2017-06-11 18:33:20 +00:00
|
|
|
void checkRestrictedPeer();
|
|
|
|
bool isRestrictedView();
|
2017-11-14 08:15:14 +00:00
|
|
|
void updateRestrictedLabelGeometry();
|
2018-11-21 18:14:48 +00:00
|
|
|
void handleScroll();
|
2017-06-11 18:33:20 +00:00
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
QImage grabForAnimation();
|
|
|
|
|
|
|
|
void scrollToY(int y);
|
|
|
|
|
|
|
|
void showAll();
|
|
|
|
void hideForSliding();
|
|
|
|
|
2017-06-11 18:33:20 +00:00
|
|
|
bool hasSectionIcons() const;
|
2017-04-08 15:20:12 +00:00
|
|
|
void setWidgetToScrollArea();
|
|
|
|
void createTabsSlider();
|
|
|
|
void switchTab();
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<Tab*> getTab(SelectorTab type) {
|
2017-04-08 15:20:12 +00:00
|
|
|
return &_tabs[static_cast<int>(type)];
|
|
|
|
}
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<const Tab*> getTab(SelectorTab type) const {
|
2017-04-08 15:20:12 +00:00
|
|
|
return &_tabs[static_cast<int>(type)];
|
|
|
|
}
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<Tab*> currentTab() {
|
2017-04-08 15:20:12 +00:00
|
|
|
return getTab(_currentTabType);
|
|
|
|
}
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<const Tab*> currentTab() const {
|
2017-04-08 15:20:12 +00:00
|
|
|
return getTab(_currentTabType);
|
|
|
|
}
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<EmojiListWidget*> emoji() const;
|
|
|
|
not_null<StickersListWidget*> stickers() const;
|
|
|
|
not_null<GifsListWidget*> gifs() const;
|
2017-04-08 15:20:12 +00:00
|
|
|
|
2019-07-24 11:13:51 +00:00
|
|
|
const not_null<Window::SessionController*> _controller;
|
|
|
|
|
2018-11-22 10:30:48 +00:00
|
|
|
Mode _mode = Mode::Full;
|
2017-04-08 15:20:12 +00:00
|
|
|
int _roundRadius = 0;
|
|
|
|
int _footerTop = 0;
|
2017-06-11 18:33:20 +00:00
|
|
|
PeerData *_currentPeer = nullptr;
|
2017-04-08 15:20:12 +00:00
|
|
|
|
|
|
|
class SlideAnimation;
|
|
|
|
std::unique_ptr<SlideAnimation> _slideAnimation;
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple _a_slide;
|
2017-04-08 15:20:12 +00:00
|
|
|
|
|
|
|
object_ptr<Ui::SettingsSlider> _tabsSlider = { nullptr };
|
|
|
|
object_ptr<Ui::PlainShadow> _topShadow;
|
|
|
|
object_ptr<Ui::PlainShadow> _bottomShadow;
|
|
|
|
object_ptr<Ui::ScrollArea> _scroll;
|
2017-06-11 18:33:20 +00:00
|
|
|
object_ptr<Ui::FlatLabel> _restrictedLabel = { nullptr };
|
2017-04-08 15:20:12 +00:00
|
|
|
std::array<Tab, Tab::kCount> _tabs;
|
2017-05-24 10:10:04 +00:00
|
|
|
SelectorTab _currentTabType = SelectorTab::Emoji;
|
2017-04-08 15:20:12 +00:00
|
|
|
|
2020-07-25 15:07:14 +00:00
|
|
|
base::unique_qptr<Ui::PopupMenu> _menu;
|
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(SelectorTab)> _afterShownCallback;
|
|
|
|
Fn<void(SelectorTab)> _beforeHidingCallback;
|
2017-04-11 14:02:11 +00:00
|
|
|
|
2017-09-16 16:53:41 +00:00
|
|
|
rpl::event_stream<> _showRequests;
|
2018-11-21 18:14:48 +00:00
|
|
|
rpl::event_stream<> _slideFinished;
|
2017-09-16 16:53:41 +00:00
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
};
|
|
|
|
|
2017-11-05 17:07:27 +00:00
|
|
|
class TabbedSelector::Inner : public Ui::RpWidget {
|
2017-04-08 15:20:12 +00:00
|
|
|
public:
|
2019-06-06 10:21:40 +00:00
|
|
|
Inner(QWidget *parent, not_null<Window::SessionController*> controller);
|
2017-04-08 15:20:12 +00:00
|
|
|
|
2019-07-02 11:46:37 +00:00
|
|
|
not_null<Window::SessionController*> controller() const {
|
|
|
|
return _controller;
|
|
|
|
}
|
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
int getVisibleTop() const {
|
|
|
|
return _visibleTop;
|
|
|
|
}
|
|
|
|
int getVisibleBottom() const {
|
|
|
|
return _visibleBottom;
|
|
|
|
}
|
2017-11-12 09:54:18 +00:00
|
|
|
void setMinimalHeight(int newWidth, int newMinimalHeight);
|
2017-04-08 15:20:12 +00:00
|
|
|
|
|
|
|
virtual void refreshRecent() = 0;
|
|
|
|
virtual void preloadImages() {
|
|
|
|
}
|
|
|
|
void hideFinished();
|
|
|
|
void panelHideFinished();
|
|
|
|
virtual void clearSelection() = 0;
|
|
|
|
|
|
|
|
virtual void afterShown() {
|
|
|
|
}
|
|
|
|
virtual void beforeHiding() {
|
|
|
|
}
|
2020-07-25 16:50:19 +00:00
|
|
|
virtual void fillContextMenu(
|
|
|
|
not_null<Ui::PopupMenu*> menu,
|
2020-08-10 12:22:54 +00:00
|
|
|
SendMenu::Type type) {
|
2020-07-25 15:07:14 +00:00
|
|
|
}
|
2017-04-08 15:20:12 +00:00
|
|
|
|
2018-11-21 18:14:48 +00:00
|
|
|
rpl::producer<int> scrollToRequests() const;
|
|
|
|
rpl::producer<bool> disableScrollRequests() const;
|
2017-04-08 15:20:12 +00:00
|
|
|
|
2018-11-21 18:14:48 +00:00
|
|
|
virtual object_ptr<InnerFooter> createFooter() = 0;
|
2017-04-08 15:20:12 +00:00
|
|
|
|
|
|
|
protected:
|
2017-09-13 16:57:44 +00:00
|
|
|
void visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) override;
|
2017-09-16 16:53:41 +00:00
|
|
|
int minimalHeight() const;
|
2017-11-12 09:54:18 +00:00
|
|
|
int resizeGetHeight(int newWidth) override final;
|
2017-09-13 16:57:44 +00:00
|
|
|
|
2017-11-12 09:54:18 +00:00
|
|
|
virtual int countDesiredHeight(int newWidth) = 0;
|
2017-04-08 15:20:12 +00:00
|
|
|
virtual InnerFooter *getFooter() const = 0;
|
|
|
|
virtual void processHideFinished() {
|
|
|
|
}
|
|
|
|
virtual void processPanelHideFinished() {
|
|
|
|
}
|
|
|
|
|
2018-11-21 18:14:48 +00:00
|
|
|
void scrollTo(int y);
|
|
|
|
void disableScroll(bool disabled);
|
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
private:
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> _controller;
|
2017-04-08 15:20:12 +00:00
|
|
|
|
|
|
|
int _visibleTop = 0;
|
|
|
|
int _visibleBottom = 0;
|
2017-09-16 16:53:41 +00:00
|
|
|
int _minimalHeight = 0;
|
2017-04-08 15:20:12 +00:00
|
|
|
|
2018-11-21 18:14:48 +00:00
|
|
|
rpl::event_stream<int> _scrollToRequests;
|
|
|
|
rpl::event_stream<bool> _disableScrollRequests;
|
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
};
|
|
|
|
|
2020-07-01 08:03:34 +00:00
|
|
|
class TabbedSelector::InnerFooter : public Ui::RpWidget {
|
2017-04-08 15:20:12 +00:00
|
|
|
public:
|
|
|
|
InnerFooter(QWidget *parent);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void processHideFinished() {
|
|
|
|
}
|
|
|
|
virtual void processPanelHideFinished() {
|
|
|
|
}
|
|
|
|
friend class Inner;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ChatHelpers
|