2016-04-29 13:46:16 +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.
|
2016-04-29 13:46:16 +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
|
2016-04-29 13:46:16 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2019-07-02 14:29:26 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2018-11-21 18:14:48 +00:00
|
|
|
#include "base/timer.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "base/object_ptr.h"
|
2017-11-05 17:07:27 +00:00
|
|
|
#include "chat_helpers/stickers.h"
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2016-11-16 10:44:06 +00:00
|
|
|
namespace Ui {
|
|
|
|
class ScrollArea;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2019-07-02 14:29:26 +00:00
|
|
|
namespace Lottie {
|
|
|
|
class SinglePlayer;
|
|
|
|
class FrameRenderer;
|
|
|
|
} // namespace Lottie;
|
|
|
|
|
2019-08-02 10:40:35 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2016-04-29 13:46:16 +00:00
|
|
|
namespace internal {
|
|
|
|
|
2019-07-02 14:29:26 +00:00
|
|
|
struct StickerSuggestion {
|
|
|
|
not_null<DocumentData*> document;
|
|
|
|
std::unique_ptr<Lottie::SinglePlayer> animated;
|
|
|
|
};
|
|
|
|
|
2016-04-29 13:46:16 +00:00
|
|
|
using MentionRows = QList<UserData*>;
|
|
|
|
using HashtagRows = QList<QString>;
|
|
|
|
using BotCommandRows = QList<QPair<UserData*, const BotCommand*>>;
|
2019-07-02 14:29:26 +00:00
|
|
|
using StickerRows = std::vector<StickerSuggestion>;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
|
|
|
class FieldAutocompleteInner;
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
2019-07-02 14:29:26 +00:00
|
|
|
class FieldAutocomplete final : public Ui::RpWidget {
|
2016-04-29 13:46:16 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2019-08-02 10:40:35 +00:00
|
|
|
FieldAutocomplete(QWidget *parent, not_null<Main::Session*> session);
|
2019-07-02 14:29:26 +00:00
|
|
|
~FieldAutocomplete();
|
2016-04-29 13:46:16 +00:00
|
|
|
|
|
|
|
bool clearFilteredBotCommands();
|
2018-06-26 20:15:29 +00:00
|
|
|
void showFiltered(
|
|
|
|
not_null<PeerData*> peer,
|
|
|
|
QString query,
|
|
|
|
bool addInlineBots);
|
2016-04-29 13:46:16 +00:00
|
|
|
void showStickers(EmojiPtr emoji);
|
|
|
|
void setBoundings(QRect boundings);
|
|
|
|
|
|
|
|
const QString &filter() const;
|
|
|
|
ChatData *chat() const;
|
|
|
|
ChannelData *channel() const;
|
|
|
|
UserData *user() const;
|
|
|
|
|
|
|
|
int32 innerTop();
|
|
|
|
int32 innerBottom();
|
|
|
|
|
2016-05-10 13:39:42 +00:00
|
|
|
bool eventFilter(QObject *obj, QEvent *e) override;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
|
|
|
enum class ChooseMethod {
|
|
|
|
ByEnter,
|
|
|
|
ByTab,
|
|
|
|
ByClick,
|
|
|
|
};
|
|
|
|
bool chooseSelected(ChooseMethod method) const;
|
|
|
|
|
|
|
|
bool stickersShown() const {
|
2018-03-07 21:25:03 +00:00
|
|
|
return !_srows.empty();
|
2016-04-29 13:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool overlaps(const QRect &globalRect) {
|
|
|
|
if (isHidden() || !testAttribute(Qt::WA_OpaquePaintEvent)) return false;
|
|
|
|
|
|
|
|
return rect().contains(QRect(mapFromGlobal(globalRect.topLeft()), globalRect.size()));
|
|
|
|
}
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
void hideFast();
|
|
|
|
|
2016-04-29 13:46:16 +00:00
|
|
|
signals:
|
|
|
|
void mentionChosen(UserData *user, FieldAutocomplete::ChooseMethod method) const;
|
|
|
|
void hashtagChosen(QString hashtag, FieldAutocomplete::ChooseMethod method) const;
|
|
|
|
void botCommandChosen(QString command, FieldAutocomplete::ChooseMethod method) const;
|
2018-07-16 19:41:43 +00:00
|
|
|
void stickerChosen(not_null<DocumentData*> sticker, FieldAutocomplete::ChooseMethod method) const;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2016-06-24 16:58:41 +00:00
|
|
|
void moderateKeyActivate(int key, bool *outHandled) const;
|
2016-06-22 18:41:13 +00:00
|
|
|
|
2016-04-29 13:46:16 +00:00
|
|
|
public slots:
|
2016-10-26 16:43:13 +00:00
|
|
|
void showAnimated();
|
|
|
|
void hideAnimated();
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2016-10-01 12:34:23 +00:00
|
|
|
protected:
|
2016-04-29 13:46:16 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2016-10-01 12:34:23 +00:00
|
|
|
private:
|
2016-12-07 13:32:25 +00:00
|
|
|
void animationCallback();
|
2016-10-26 16:43:13 +00:00
|
|
|
void hideFinish();
|
|
|
|
|
2016-04-29 13:46:16 +00:00
|
|
|
void updateFiltered(bool resetScroll = false);
|
|
|
|
void recount(bool resetScroll = false);
|
2019-07-02 14:29:26 +00:00
|
|
|
internal::StickerRows getStickerSuggestions();
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2019-08-02 10:40:35 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
2016-04-29 13:46:16 +00:00
|
|
|
QPixmap _cache;
|
|
|
|
internal::MentionRows _mrows;
|
|
|
|
internal::HashtagRows _hrows;
|
|
|
|
internal::BotCommandRows _brows;
|
2018-03-07 21:25:03 +00:00
|
|
|
internal::StickerRows _srows;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2019-07-02 14:29:26 +00:00
|
|
|
void rowsUpdated(
|
|
|
|
internal::MentionRows &&mrows,
|
|
|
|
internal::HashtagRows &&hrows,
|
|
|
|
internal::BotCommandRows &&brows,
|
|
|
|
internal::StickerRows &&srows,
|
|
|
|
bool resetScroll);
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<Ui::ScrollArea> _scroll;
|
|
|
|
QPointer<internal::FieldAutocompleteInner> _inner;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2016-10-01 12:34:23 +00:00
|
|
|
ChatData *_chat = nullptr;
|
|
|
|
UserData *_user = nullptr;
|
|
|
|
ChannelData *_channel = nullptr;
|
2016-04-29 13:46:16 +00:00
|
|
|
EmojiPtr _emoji;
|
2018-03-07 21:25:03 +00:00
|
|
|
uint64 _stickersSeed = 0;
|
2016-05-08 16:11:47 +00:00
|
|
|
enum class Type {
|
|
|
|
Mentions,
|
|
|
|
Hashtags,
|
|
|
|
BotCommands,
|
|
|
|
Stickers,
|
|
|
|
};
|
|
|
|
Type _type = Type::Mentions;
|
2016-04-29 13:46:16 +00:00
|
|
|
QString _filter;
|
|
|
|
QRect _boundings;
|
|
|
|
bool _addInlineBots;
|
|
|
|
|
|
|
|
int32 _width, _height;
|
2016-10-01 12:34:23 +00:00
|
|
|
bool _hiding = false;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple _a_opacity;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
|
|
|
friend class internal::FieldAutocompleteInner;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
2019-07-02 14:29:26 +00:00
|
|
|
class FieldAutocompleteInner final
|
|
|
|
: public Ui::RpWidget
|
|
|
|
, private base::Subscriber {
|
2016-04-29 13:46:16 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2019-07-02 14:29:26 +00:00
|
|
|
FieldAutocompleteInner(
|
|
|
|
not_null<FieldAutocomplete*> parent,
|
|
|
|
not_null<MentionRows*> mrows,
|
|
|
|
not_null<HashtagRows*> hrows,
|
|
|
|
not_null<BotCommandRows*> brows,
|
|
|
|
not_null<StickerRows*> srows);
|
2016-04-29 13:46:16 +00:00
|
|
|
|
|
|
|
void clearSel(bool hidden = false);
|
|
|
|
bool moveSel(int key);
|
|
|
|
bool chooseSelected(FieldAutocomplete::ChooseMethod method) const;
|
|
|
|
|
|
|
|
void setRecentInlineBotsInRows(int32 bots);
|
2019-07-02 14:29:26 +00:00
|
|
|
void rowsUpdated();
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2016-07-13 17:34:57 +00:00
|
|
|
signals:
|
2016-04-29 13:46:16 +00:00
|
|
|
void mentionChosen(UserData *user, FieldAutocomplete::ChooseMethod method) const;
|
|
|
|
void hashtagChosen(QString hashtag, FieldAutocomplete::ChooseMethod method) const;
|
|
|
|
void botCommandChosen(QString command, FieldAutocomplete::ChooseMethod method) const;
|
2018-07-16 19:41:43 +00:00
|
|
|
void stickerChosen(not_null<DocumentData*> sticker, FieldAutocomplete::ChooseMethod method) const;
|
2016-04-29 13:46:16 +00:00
|
|
|
void mustScrollTo(int scrollToTop, int scrollToBottom);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void onParentGeometryChanged();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
2017-02-11 11:24:37 +00:00
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
|
|
|
|
void updateSelectedRow();
|
|
|
|
void setSel(int sel, bool scroll = false);
|
2018-11-21 18:14:48 +00:00
|
|
|
void showPreview();
|
2018-12-25 12:41:40 +00:00
|
|
|
void selectByMouse(QPoint global);
|
2018-11-21 18:14:48 +00:00
|
|
|
|
2019-07-19 15:19:13 +00:00
|
|
|
QSize stickerBoundingBox() const;
|
2019-07-02 14:29:26 +00:00
|
|
|
void setupLottie(StickerSuggestion &suggestion);
|
|
|
|
void repaintSticker(not_null<DocumentData*> document);
|
|
|
|
std::shared_ptr<Lottie::FrameRenderer> getLottieRenderer();
|
|
|
|
|
|
|
|
not_null<FieldAutocomplete*> _parent;
|
|
|
|
not_null<MentionRows*> _mrows;
|
|
|
|
not_null<HashtagRows*> _hrows;
|
|
|
|
not_null<BotCommandRows*> _brows;
|
|
|
|
not_null<StickerRows*> _srows;
|
|
|
|
rpl::lifetime _stickersLifetime;
|
|
|
|
std::weak_ptr<Lottie::FrameRenderer> _lottieRenderer;
|
2018-11-21 18:14:48 +00:00
|
|
|
int _stickersPerRow = 1;
|
|
|
|
int _recentInlineBotsInRows = 0;
|
|
|
|
int _sel = -1;
|
|
|
|
int _down = -1;
|
2018-12-25 12:41:40 +00:00
|
|
|
std::optional<QPoint> _lastMousePosition;
|
|
|
|
bool _mouseSelection = false;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2018-11-21 18:14:48 +00:00
|
|
|
bool _overDelete = false;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2018-11-21 18:14:48 +00:00
|
|
|
bool _previewShown = false;
|
2016-04-29 13:46:16 +00:00
|
|
|
|
2018-11-21 18:14:48 +00:00
|
|
|
base::Timer _previewTimer;
|
2016-07-13 17:34:57 +00:00
|
|
|
|
2016-04-29 13:46:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace internal
|