tdesktop/Telegram/SourceFiles/chat_helpers/message_field.h

114 lines
2.7 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 "ui/widgets/input_fields.h"
2018-05-21 21:31:46 +00:00
#include "base/timer.h"
#include "base/qt_connection.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;
} // namespace Main
namespace Window {
class SessionController;
} // namespace Window
namespace Ui {
class PopupMenu;
class Show;
} // namespace Ui
QString PrepareMentionTag(not_null<UserData*> user);
TextWithTags PrepareEditText(not_null<HistoryItem*> item);
Fn<bool(
Ui::InputField::EditLinkSelection selection,
QString text,
QString link,
Ui::InputField::EditLinkAction action)> DefaultEditLinkCallback(
std::shared_ptr<Ui::Show> show,
not_null<Main::Session*> session,
not_null<Ui::InputField*> field,
const style::InputField *fieldStyle = nullptr);
void InitMessageField(
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field);
void InitSpellchecker(
std::shared_ptr<Ui::Show> show,
not_null<Main::Session*> session,
not_null<Ui::InputField*> field,
bool skipDictionariesManager = false);
void InitSpellchecker(
2020-06-10 18:08:17 +00:00
not_null<Window::SessionController*> controller,
not_null<Ui::InputField*> field);
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);
class MessageLinksParser : private QObject {
public:
MessageLinksParser(not_null<Ui::InputField*> field);
void parseNow();
[[nodiscard]] const rpl::variable<QStringList> &list() const;
protected:
2018-05-21 21:31:46 +00:00
bool eventFilter(QObject *object, QEvent *event) override;
private:
2018-05-21 21:31:46 +00:00
struct LinkRange {
int start;
int length;
QString custom;
2018-05-21 21:31:46 +00:00
};
friend inline bool operator==(const LinkRange &a, const LinkRange &b) {
return (a.start == b.start)
&& (a.length == b.length)
&& (a.custom == b.custom);
2018-05-21 21:31:46 +00:00
}
friend inline bool operator!=(const LinkRange &a, const LinkRange &b) {
return !(a == b);
}
2018-05-21 21:31:46 +00:00
void parse();
void apply(const QString &text, const QVector<LinkRange> &ranges);
not_null<Ui::InputField*> _field;
rpl::variable<QStringList> _list;
int _lastLength = 0;
base::Timer _timer;
base::qt_connection _connection;
2018-05-21 21:31:46 +00:00
2019-07-26 16:06:22 +00:00
};