2017-07-19 18:37:49 +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-07-19 18:37:49 +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-07-19 18:37:49 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-07-22 08:35:18 +00:00
|
|
|
#include "ui/effects/panel_animation.h"
|
2018-11-21 10:09:46 +00:00
|
|
|
#include "base/unique_qptr.h"
|
2017-07-22 08:35:18 +00:00
|
|
|
|
|
|
|
namespace Ui {
|
|
|
|
|
|
|
|
class InnerDropdown;
|
2018-11-21 10:09:46 +00:00
|
|
|
class InputField;
|
2017-07-22 08:35:18 +00:00
|
|
|
|
|
|
|
namespace Emoji {
|
|
|
|
|
|
|
|
class SuggestionsWidget : public TWidget {
|
|
|
|
public:
|
|
|
|
SuggestionsWidget(QWidget *parent, const style::Menu &st);
|
|
|
|
|
|
|
|
void showWithQuery(const QString &query);
|
|
|
|
void handleKeyEvent(int key);
|
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
rpl::producer<bool> toggleAnimated() const;
|
|
|
|
rpl::producer<QString> triggered() const;
|
2017-07-22 08:35:18 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
class Row;
|
|
|
|
|
2017-07-25 18:16:37 +00:00
|
|
|
std::vector<Row> getRowsByQuery() const;
|
2017-07-22 08:35:18 +00:00
|
|
|
void resizeToRows();
|
|
|
|
int countWidth(const Row &row);
|
|
|
|
void setSelected(int selected);
|
|
|
|
void setPressed(int pressed);
|
|
|
|
void clearMouseSelection();
|
|
|
|
void clearSelection();
|
|
|
|
void updateSelectedItem();
|
|
|
|
int itemTop(int index);
|
|
|
|
void updateItem(int index);
|
2018-12-25 12:41:40 +00:00
|
|
|
void selectByMouse(QPoint globalPosition);
|
2017-07-27 10:22:51 +00:00
|
|
|
void triggerSelectedRow();
|
|
|
|
void triggerRow(const Row &row);
|
2017-07-22 08:35:18 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<const style::Menu*> _st;
|
2017-07-22 08:35:18 +00:00
|
|
|
|
|
|
|
QString _query;
|
|
|
|
std::vector<Row> _rows;
|
|
|
|
|
|
|
|
int _rowHeight = 0;
|
2018-12-25 12:41:40 +00:00
|
|
|
std::optional<QPoint> _lastMousePosition;
|
2017-07-22 08:35:18 +00:00
|
|
|
bool _mouseSelection = false;
|
|
|
|
int _selected = -1;
|
|
|
|
int _pressed = -1;
|
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
rpl::event_stream<bool> _toggleAnimated;
|
|
|
|
rpl::event_stream<QString> _triggered;
|
|
|
|
|
2017-07-22 08:35:18 +00:00
|
|
|
};
|
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
class SuggestionsController {
|
2017-07-22 08:35:18 +00:00
|
|
|
public:
|
2018-11-21 10:09:46 +00:00
|
|
|
SuggestionsController(
|
|
|
|
not_null<QWidget*> outer,
|
|
|
|
not_null<QTextEdit*> field);
|
2017-07-22 08:35:18 +00:00
|
|
|
|
|
|
|
void raise();
|
2018-06-04 15:35:11 +00:00
|
|
|
void setReplaceCallback(Fn<void(
|
2018-05-13 15:56:08 +00:00
|
|
|
int from,
|
|
|
|
int till,
|
|
|
|
const QString &replacement)> callback);
|
2017-07-22 08:35:18 +00:00
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
static SuggestionsController *Init(
|
|
|
|
not_null<QWidget*> outer,
|
|
|
|
not_null<Ui::InputField*> field);
|
2017-07-22 08:35:18 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void handleCursorPositionChange();
|
|
|
|
void handleTextChange();
|
|
|
|
QString getEmojiQuery();
|
|
|
|
void suggestionsUpdated(bool visible);
|
|
|
|
void updateGeometry();
|
|
|
|
void updateForceHidden();
|
|
|
|
void replaceCurrent(const QString &replacement);
|
2018-11-21 10:09:46 +00:00
|
|
|
bool fieldFilter(not_null<QEvent*> event);
|
|
|
|
bool outerFilter(not_null<QEvent*> event);
|
2017-07-22 08:35:18 +00:00
|
|
|
|
|
|
|
bool _shown = false;
|
|
|
|
bool _forceHidden = false;
|
|
|
|
int _queryStartPosition = 0;
|
|
|
|
bool _ignoreCursorPositionChange = false;
|
|
|
|
bool _textChangeAfterKeyPress = false;
|
|
|
|
QPointer<QTextEdit> _field;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void(
|
2018-05-13 15:56:08 +00:00
|
|
|
int from,
|
|
|
|
int till,
|
|
|
|
const QString &replacement)> _replaceCallback;
|
2018-11-21 10:09:46 +00:00
|
|
|
base::unique_qptr<InnerDropdown> _container;
|
2017-07-22 08:35:18 +00:00
|
|
|
QPointer<SuggestionsWidget> _suggestions;
|
2018-11-21 10:09:46 +00:00
|
|
|
base::unique_qptr<QObject> _fieldFilter;
|
|
|
|
base::unique_qptr<QObject> _outerFilter;
|
|
|
|
|
|
|
|
rpl::lifetime _lifetime;
|
2017-07-22 08:35:18 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Emoji
|
|
|
|
} // namespace Ui
|