tdesktop/Telegram/SourceFiles/chat_helpers/message_field.h

146 lines
3.8 KiB
C
Raw Normal View History

/*
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
#include "base/qt/qt_compare.h"
2018-05-21 21:31:46 +00:00
#include "base/timer.h"
#include "chat_helpers/compose/compose_features.h"
#include "ui/widgets/fields/input_field.h"
#ifndef TDESKTOP_DISABLE_SPELLCHECK
2020-02-21 09:48:24 +00:00
#include "boxes/dictionaries_manager.h"
#include "spellcheck/spelling_highlighter.h"
#endif // TDESKTOP_DISABLE_SPELLCHECK
2019-09-04 07:19:15 +00:00
#include <QtGui/QClipboard>
namespace Main {
class Session;
class SessionShow;
} // namespace Main
namespace Window {
class SessionController;
} // namespace Window
namespace ChatHelpers {
enum class PauseReason;
class Show;
} // namespace ChatHelpers
namespace Ui {
class PopupMenu;
} // namespace Ui
2023-08-21 09:00:38 +00:00
[[nodiscard]] QString PrepareMentionTag(not_null<UserData*> user);
[[nodiscard]] TextWithTags PrepareEditText(not_null<HistoryItem*> item);
[[nodiscard]] bool EditTextChanged(
not_null<HistoryItem*> item,
const TextWithTags &updated);
Fn<bool(
Ui::InputField::EditLinkSelection selection,
QString text,
QString link,
Ui::InputField::EditLinkAction action)> DefaultEditLinkCallback(
std::shared_ptr<Main::SessionShow> show,
not_null<Ui::InputField*> field,
const style::InputField *fieldStyle = nullptr);
void InitMessageFieldHandlers(
not_null<Main::Session*> session,
std::shared_ptr<Main::SessionShow> show, // may be null
not_null<Ui::InputField*> field,
Fn<bool()> customEmojiPaused,
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji = nullptr,
const style::InputField *fieldStyle = nullptr);
void InitMessageFieldHandlers(
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field,
ChatHelpers::PauseReason pauseReasonLevel,
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji = nullptr);
void InitMessageField(
std::shared_ptr<ChatHelpers::Show> show,
not_null<Ui::InputField*> field,
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji);
void InitMessageField(
not_null<Window::SessionController*> controller,
2022-07-15 14:52:36 +00:00
not_null<Ui::InputField*> field,
Fn<bool(not_null<DocumentData*>)> allowPremiumEmoji);
void InitSpellchecker(
std::shared_ptr<Main::SessionShow> show,
not_null<Ui::InputField*> field,
bool skipDictionariesManager = false);
2018-05-21 21:31:46 +00:00
bool HasSendText(not_null<const Ui::InputField*> field);
2018-05-21 21:31:46 +00:00
struct InlineBotQuery {
QString query;
QString username;
UserData *bot = nullptr;
bool lookingUpBot = false;
};
2020-06-08 09:06:50 +00:00
InlineBotQuery ParseInlineBotQuery(
not_null<Main::Session*> session,
not_null<const Ui::InputField*> field);
2018-05-21 21:31:46 +00:00
struct AutocompleteQuery {
QString query;
bool fromStart = false;
};
AutocompleteQuery ParseMentionHashtagBotCommandQuery(
not_null<const Ui::InputField*> field,
ChatHelpers::ComposeFeatures features);
2018-05-21 21:31:46 +00:00
struct MessageLinkRange {
int start = 0;
int length = 0;
QString custom;
friend inline auto operator<=>(
const MessageLinkRange&,
const MessageLinkRange&) = default;
friend inline bool operator==(
const MessageLinkRange&,
const MessageLinkRange&) = default;
};
2023-10-26 05:26:45 +00:00
class MessageLinksParser final : private QObject {
2018-05-21 21:31:46 +00:00
public:
MessageLinksParser(not_null<Ui::InputField*> field);
void parseNow();
2023-08-21 09:00:38 +00:00
void setDisabled(bool disabled);
[[nodiscard]] const rpl::variable<QStringList> &list() const {
return _list;
}
[[nodiscard]] const std::vector<MessageLinkRange> &ranges() const {
return _ranges;
}
2023-10-26 05:26:45 +00:00
private:
bool eventFilter(QObject *object, QEvent *event) override;
2018-05-21 21:31:46 +00:00
void parse();
2023-10-26 05:26:45 +00:00
void applyRanges(const QString &text);
2018-05-21 21:31:46 +00:00
not_null<Ui::InputField*> _field;
rpl::variable<QStringList> _list;
std::vector<MessageLinkRange> _ranges;
2018-05-21 21:31:46 +00:00
int _lastLength = 0;
2023-08-21 09:00:38 +00:00
bool _disabled = false;
2018-05-21 21:31:46 +00:00
base::Timer _timer;
rpl::lifetime _lifetime;
2018-05-21 21:31:46 +00:00
2019-07-26 16:06:22 +00:00
};
[[nodiscard]] base::unique_qptr<Ui::RpWidget> CreateDisabledFieldView(
QWidget *parent,
not_null<PeerData*> peer);