2017-07-19 21:37:49 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-07-19 21:37:49 +03:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-07-19 21:37:49 +03:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2019-04-01 15:16:16 +04:00
|
|
|
#include "ui/effects/animations.h"
|
2019-03-30 14:00:31 +04:00
|
|
|
#include "ui/rp_widget.h"
|
2018-11-21 14:09:46 +04:00
|
|
|
#include "base/unique_qptr.h"
|
2019-03-30 12:06:15 +04:00
|
|
|
#include "base/timer.h"
|
2017-07-22 11:35:18 +03:00
|
|
|
|
2019-09-04 10:19:15 +03:00
|
|
|
#include <QtWidgets/QTextEdit>
|
|
|
|
|
2023-05-17 15:51:04 +04:00
|
|
|
namespace style {
|
|
|
|
struct EmojiSuggestions;
|
|
|
|
} // namespace style
|
|
|
|
|
2019-08-02 11:40:35 +01:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2017-07-22 11:35:18 +03:00
|
|
|
namespace Ui {
|
|
|
|
class InnerDropdown;
|
2018-11-21 14:09:46 +04:00
|
|
|
class InputField;
|
2022-07-22 14:39:28 +03:00
|
|
|
} // namespace Ui
|
|
|
|
|
2022-07-25 11:30:38 +03:00
|
|
|
namespace Ui::Text {
|
|
|
|
class CustomEmoji;
|
|
|
|
} // namespace Ui::Text
|
2017-07-22 11:35:18 +03:00
|
|
|
|
2022-07-22 14:39:28 +03:00
|
|
|
namespace Ui::Emoji {
|
2017-07-22 11:35:18 +03:00
|
|
|
|
2023-05-17 15:51:04 +04:00
|
|
|
class SuggestionsWidget;
|
2022-07-18 20:30:28 +03:00
|
|
|
|
2023-05-17 15:51:04 +04:00
|
|
|
using SuggestionsQuery = std::variant<QString, EmojiPtr>;
|
2017-07-22 11:35:18 +03:00
|
|
|
|
2024-09-13 17:39:15 +04:00
|
|
|
class SuggestionsController final : public QObject {
|
2017-07-22 11:35:18 +03:00
|
|
|
public:
|
2019-05-27 12:16:14 +02:00
|
|
|
struct Options {
|
2022-08-02 19:23:06 +03:00
|
|
|
bool suggestExactFirstWord = true;
|
|
|
|
bool suggestCustomEmoji = false;
|
|
|
|
Fn<bool(not_null<DocumentData*>)> allowCustomWithoutPremium;
|
2023-05-17 15:51:04 +04:00
|
|
|
const style::EmojiSuggestions *st = nullptr;
|
2019-05-27 12:16:14 +02:00
|
|
|
};
|
|
|
|
|
2018-11-21 14:09:46 +04:00
|
|
|
SuggestionsController(
|
2024-09-13 17:39:15 +04:00
|
|
|
not_null<QWidget*> parent,
|
2018-11-21 14:09:46 +04:00
|
|
|
not_null<QWidget*> outer,
|
2019-05-27 12:16:14 +02:00
|
|
|
not_null<QTextEdit*> field,
|
2019-08-02 11:40:35 +01:00
|
|
|
not_null<Main::Session*> session,
|
2019-05-27 12:16:14 +02:00
|
|
|
const Options &options);
|
2017-07-22 11:35:18 +03:00
|
|
|
|
|
|
|
void raise();
|
2018-06-04 18:35:11 +03:00
|
|
|
void setReplaceCallback(Fn<void(
|
2018-05-13 18:56:08 +03:00
|
|
|
int from,
|
|
|
|
int till,
|
2022-07-18 20:30:28 +03:00
|
|
|
const QString &replacement,
|
|
|
|
const QString &customEmojiData)> callback);
|
2017-07-22 11:35:18 +03:00
|
|
|
|
2022-08-03 20:41:01 +03:00
|
|
|
static not_null<SuggestionsController*> Init(
|
|
|
|
not_null<QWidget*> outer,
|
|
|
|
not_null<Ui::InputField*> field,
|
|
|
|
not_null<Main::Session*> session) {
|
|
|
|
return Init(outer, field, session, {});
|
|
|
|
}
|
2022-08-02 19:23:06 +03:00
|
|
|
static not_null<SuggestionsController*> Init(
|
2018-11-21 14:09:46 +04:00
|
|
|
not_null<QWidget*> outer,
|
2019-05-27 12:16:14 +02:00
|
|
|
not_null<Ui::InputField*> field,
|
2019-08-02 11:40:35 +01:00
|
|
|
not_null<Main::Session*> session,
|
2022-08-03 20:41:01 +03:00
|
|
|
const Options &options);
|
2017-07-22 11:35:18 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
void handleCursorPositionChange();
|
|
|
|
void handleTextChange();
|
2022-08-02 17:57:59 +03:00
|
|
|
void showWithQuery(SuggestionsQuery query);
|
|
|
|
[[nodiscard]] SuggestionsQuery getEmojiQuery();
|
2017-07-22 11:35:18 +03:00
|
|
|
void suggestionsUpdated(bool visible);
|
|
|
|
void updateGeometry();
|
|
|
|
void updateForceHidden();
|
2022-07-18 20:30:28 +03:00
|
|
|
void replaceCurrent(
|
|
|
|
const QString &replacement,
|
|
|
|
const QString &customEmojiData);
|
2018-11-21 14:09:46 +04:00
|
|
|
bool fieldFilter(not_null<QEvent*> event);
|
|
|
|
bool outerFilter(not_null<QEvent*> event);
|
2017-07-22 11:35:18 +03:00
|
|
|
|
2023-05-17 15:51:04 +04:00
|
|
|
const style::EmojiSuggestions &_st;
|
2017-07-22 11:35:18 +03:00
|
|
|
bool _shown = false;
|
|
|
|
bool _forceHidden = false;
|
|
|
|
int _queryStartPosition = 0;
|
2022-08-08 15:24:11 +03:00
|
|
|
int _emojiQueryLength = 0;
|
2017-07-22 11:35:18 +03:00
|
|
|
bool _ignoreCursorPositionChange = false;
|
|
|
|
bool _textChangeAfterKeyPress = false;
|
|
|
|
QPointer<QTextEdit> _field;
|
2019-08-02 11:40:35 +01:00
|
|
|
const not_null<Main::Session*> _session;
|
2018-06-04 18:35:11 +03:00
|
|
|
Fn<void(
|
2018-05-13 18:56:08 +03:00
|
|
|
int from,
|
|
|
|
int till,
|
2022-07-18 20:30:28 +03:00
|
|
|
const QString &replacement,
|
|
|
|
const QString &customEmojiData)> _replaceCallback;
|
2018-11-21 14:09:46 +04:00
|
|
|
base::unique_qptr<InnerDropdown> _container;
|
2017-07-22 11:35:18 +03:00
|
|
|
QPointer<SuggestionsWidget> _suggestions;
|
2018-11-21 14:09:46 +04:00
|
|
|
base::unique_qptr<QObject> _fieldFilter;
|
|
|
|
base::unique_qptr<QObject> _outerFilter;
|
2019-03-30 12:06:15 +04:00
|
|
|
base::Timer _showExactTimer;
|
|
|
|
bool _keywordsRefreshed = false;
|
2022-08-02 17:57:59 +03:00
|
|
|
SuggestionsQuery _lastShownQuery;
|
2019-05-27 12:16:14 +02:00
|
|
|
Options _options;
|
2018-11-21 14:09:46 +04:00
|
|
|
|
|
|
|
rpl::lifetime _lifetime;
|
2017-07-22 11:35:18 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-07-22 14:39:28 +03:00
|
|
|
} // namespace Ui::Emoji
|