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"
|
2022-02-08 19:20:37 +00:00
|
|
|
#include "ui/effects/message_sending_animation_common.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,
|
2021-03-15 10:51:13 +00:00
|
|
|
Masks,
|
2017-05-24 10:10:04 +00:00
|
|
|
};
|
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
class EmojiListWidget;
|
|
|
|
class StickersListWidget;
|
|
|
|
class GifsListWidget;
|
|
|
|
|
2021-07-15 11:12:38 +00:00
|
|
|
class TabbedSelector : public Ui::RpWidget {
|
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;
|
2022-02-08 19:20:37 +00:00
|
|
|
Ui::MessageSendingAnimationFrom messageSendingFrom;
|
2020-07-24 08:22:45 +00:00
|
|
|
};
|
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,
|
2021-03-15 10:51:13 +00:00
|
|
|
EmojiOnly,
|
|
|
|
MediaEditor,
|
2018-11-22 10:30:48 +00:00
|
|
|
};
|
2021-08-30 15:05:07 +00:00
|
|
|
enum class Action {
|
|
|
|
Update,
|
|
|
|
Cancel,
|
|
|
|
};
|
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;
|
2021-08-30 15:05:07 +00:00
|
|
|
rpl::producer<Action> choosingStickerUpdated() 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:
|
2021-03-15 10:51:13 +00:00
|
|
|
Tab(SelectorTab type, int index, 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;
|
|
|
|
}
|
2021-03-15 10:51:13 +00:00
|
|
|
int index() const {
|
|
|
|
return _index;
|
|
|
|
}
|
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:
|
2021-03-15 10:51:13 +00:00
|
|
|
const SelectorTab _type;
|
|
|
|
const int _index;
|
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;
|
2021-03-15 10:51:13 +00:00
|
|
|
bool mediaEditor() const;
|
|
|
|
bool tabbed() const;
|
|
|
|
bool hasEmojiTab() const;
|
|
|
|
bool hasStickersTab() const;
|
|
|
|
bool hasGifsTab() const;
|
|
|
|
bool hasMasksTab() const;
|
|
|
|
Tab createTab(SelectorTab type, int index);
|
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();
|
|
|
|
|
2021-03-15 10:51:13 +00:00
|
|
|
SelectorTab typeByIndex(int index) const;
|
|
|
|
int indexByType(SelectorTab type) const;
|
|
|
|
|
2017-06-11 18:33:20 +00:00
|
|
|
bool hasSectionIcons() const;
|
2017-04-08 15:20:12 +00:00
|
|
|
void setWidgetToScrollArea();
|
|
|
|
void createTabsSlider();
|
2021-03-31 00:26:32 +00:00
|
|
|
void fillTabsSliderSections();
|
|
|
|
void updateTabsSliderGeometry();
|
2017-04-08 15:20:12 +00:00
|
|
|
void switchTab();
|
2021-03-15 10:51:13 +00:00
|
|
|
|
|
|
|
not_null<Tab*> getTab(int index);
|
|
|
|
not_null<const Tab*> getTab(int index) const;
|
|
|
|
not_null<Tab*> currentTab();
|
|
|
|
not_null<const Tab*> currentTab() const;
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<EmojiListWidget*> emoji() const;
|
|
|
|
not_null<StickersListWidget*> stickers() const;
|
|
|
|
not_null<GifsListWidget*> gifs() const;
|
2021-03-15 10:51:13 +00:00
|
|
|
not_null<StickersListWidget*> masks() 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 };
|
2021-03-15 10:51:13 +00:00
|
|
|
std::vector<Tab> _tabs;
|
2017-05-24 10:10:04 +00:00
|
|
|
SelectorTab _currentTabType = SelectorTab::Emoji;
|
2017-04-08 15:20:12 +00:00
|
|
|
|
2021-03-15 10:51:13 +00:00
|
|
|
const bool _hasEmojiTab;
|
|
|
|
const bool _hasStickersTab;
|
|
|
|
const bool _hasGifsTab;
|
|
|
|
const bool _hasMasksTab;
|
|
|
|
const bool _tabbed;
|
|
|
|
|
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
|