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
|
|
|
*/
|
|
|
|
#include "chat_helpers/emoji_suggestions_widget.h"
|
|
|
|
|
2019-03-28 08:48:32 +00:00
|
|
|
#include "chat_helpers/emoji_keywords.h"
|
2019-09-17 16:13:12 +00:00
|
|
|
#include "emoji_suggestions_helper.h"
|
2017-07-22 08:35:18 +00:00
|
|
|
#include "ui/effects/ripple_animation.h"
|
|
|
|
#include "ui/widgets/shadow.h"
|
2018-10-13 17:35:30 +00:00
|
|
|
#include "ui/widgets/inner_dropdown.h"
|
2018-11-21 10:09:46 +00:00
|
|
|
#include "ui/widgets/input_fields.h"
|
2018-10-13 17:35:30 +00:00
|
|
|
#include "ui/emoji_config.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2017-07-22 08:35:18 +00:00
|
|
|
#include "platform/platform_specific.h"
|
2019-03-28 08:48:32 +00:00
|
|
|
#include "core/application.h"
|
2018-11-21 10:09:46 +00:00
|
|
|
#include "core/event_filter.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "app.h"
|
2017-07-22 08:35:18 +00:00
|
|
|
#include "styles/style_chat_helpers.h"
|
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtWidgets/QApplication>
|
|
|
|
#include <QtGui/QTextBlock>
|
|
|
|
|
2017-07-22 08:35:18 +00:00
|
|
|
namespace Ui {
|
|
|
|
namespace Emoji {
|
|
|
|
namespace {
|
|
|
|
|
2019-03-30 08:06:15 +00:00
|
|
|
constexpr auto kShowExactDelay = crl::time(300);
|
2019-03-30 10:00:31 +00:00
|
|
|
constexpr auto kMaxNonScrolledEmoji = 7;
|
2019-04-01 11:16:16 +00:00
|
|
|
constexpr auto kAnimationDuration = crl::time(120);
|
2017-07-24 16:18:39 +00:00
|
|
|
|
2017-07-22 08:35:18 +00:00
|
|
|
} // namespace
|
|
|
|
|
2019-03-30 10:00:31 +00:00
|
|
|
SuggestionsWidget::SuggestionsWidget(QWidget *parent)
|
|
|
|
: RpWidget(parent)
|
|
|
|
, _oneWidth(st::emojiSuggestionSize)
|
|
|
|
, _padding(st::emojiSuggestionsPadding) {
|
|
|
|
resize(
|
|
|
|
_oneWidth + _padding.left() + _padding.right(),
|
|
|
|
_oneWidth + _padding.top() + _padding.bottom());
|
2017-07-22 08:35:18 +00:00
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
rpl::producer<bool> SuggestionsWidget::toggleAnimated() const {
|
|
|
|
return _toggleAnimated.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<QString> SuggestionsWidget::triggered() const {
|
|
|
|
return _triggered.events();
|
|
|
|
}
|
|
|
|
|
2019-03-29 16:04:05 +00:00
|
|
|
void SuggestionsWidget::showWithQuery(const QString &query, bool force) {
|
|
|
|
if (!force && (_query == query)) {
|
2017-07-22 08:35:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
_query = query;
|
2017-07-25 18:16:37 +00:00
|
|
|
auto rows = getRowsByQuery();
|
2017-07-22 08:35:18 +00:00
|
|
|
if (rows.empty()) {
|
2018-11-21 10:09:46 +00:00
|
|
|
_toggleAnimated.fire(false);
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
|
|
|
clearSelection();
|
2019-04-01 10:35:32 +00:00
|
|
|
setPressed(-1);
|
2017-07-22 08:35:18 +00:00
|
|
|
_rows = std::move(rows);
|
|
|
|
resizeToRows();
|
|
|
|
update();
|
2019-03-30 10:00:31 +00:00
|
|
|
|
|
|
|
Ui::PostponeCall(this, [=] {
|
|
|
|
if (!_rows.empty()) {
|
|
|
|
_toggleAnimated.fire(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsWidget::selectFirstResult() {
|
|
|
|
if (!_rows.empty() && _selected < 0) {
|
2017-07-22 08:35:18 +00:00
|
|
|
setSelected(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-30 10:00:31 +00:00
|
|
|
SuggestionsWidget::Row::Row(
|
|
|
|
not_null<EmojiPtr> emoji,
|
|
|
|
const QString &replacement)
|
|
|
|
: emoji(emoji)
|
|
|
|
, replacement(replacement) {
|
|
|
|
}
|
|
|
|
|
|
|
|
auto SuggestionsWidget::getRowsByQuery() const -> std::vector<Row> {
|
2017-07-25 18:16:37 +00:00
|
|
|
if (_query.isEmpty()) {
|
2019-03-30 10:00:31 +00:00
|
|
|
return {};
|
2017-07-25 18:16:37 +00:00
|
|
|
}
|
2019-03-29 13:51:18 +00:00
|
|
|
const auto middle = (_query[0] == ':');
|
|
|
|
const auto real = middle ? _query.mid(1) : _query;
|
|
|
|
const auto simple = [&] {
|
|
|
|
if (!middle || _query.size() > 2) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Suggest :D and :-P only as exact matches.
|
|
|
|
return ranges::find_if(_query, [](QChar ch) { return ch.isLower(); })
|
|
|
|
== _query.end();
|
|
|
|
}();
|
|
|
|
const auto exact = !middle || simple;
|
2019-03-30 10:00:31 +00:00
|
|
|
const auto list = Core::App().emojiKeywords().query(real, exact);
|
|
|
|
if (list.empty()) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
using Entry = ChatHelpers::EmojiKeywords::Result;
|
|
|
|
auto result = ranges::view::all(
|
|
|
|
list
|
|
|
|
) | ranges::view::transform([](const Entry &result) {
|
|
|
|
return Row(result.emoji, result.replacement);
|
|
|
|
}) | ranges::to_vector;
|
|
|
|
|
|
|
|
auto lastRecent = begin(result);
|
2019-09-13 10:24:06 +00:00
|
|
|
const auto &recent = GetRecentEmoji();
|
2019-03-28 08:48:32 +00:00
|
|
|
for (const auto &item : recent) {
|
|
|
|
const auto emoji = item.first->original()
|
|
|
|
? item.first->original()
|
|
|
|
: item.first;
|
2019-03-30 10:00:31 +00:00
|
|
|
const auto it = ranges::find(result, emoji, [](const Row &row) {
|
|
|
|
return row.emoji.get();
|
2019-03-28 08:48:32 +00:00
|
|
|
});
|
2019-03-30 10:00:31 +00:00
|
|
|
if (it > lastRecent && it != end(result)) {
|
|
|
|
std::rotate(lastRecent, it, it + 1);
|
|
|
|
++lastRecent;
|
2019-03-28 08:48:32 +00:00
|
|
|
}
|
2017-07-25 18:16:37 +00:00
|
|
|
}
|
|
|
|
|
2019-03-30 10:00:31 +00:00
|
|
|
for (auto &item : result) {
|
|
|
|
item.emoji = [&] {
|
|
|
|
const auto result = item.emoji;
|
2019-03-28 08:48:32 +00:00
|
|
|
const auto &variants = cEmojiVariants();
|
|
|
|
const auto i = result->hasVariants()
|
|
|
|
? variants.constFind(result->nonColoredId())
|
|
|
|
: variants.cend();
|
|
|
|
return (i != variants.cend())
|
|
|
|
? result->variant(i.value())
|
|
|
|
: result.get();
|
|
|
|
}();
|
2017-07-25 18:16:37 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-07-22 08:35:18 +00:00
|
|
|
void SuggestionsWidget::resizeToRows() {
|
2019-03-30 10:00:31 +00:00
|
|
|
const auto count = int(_rows.size());
|
|
|
|
const auto scrolled = (count > kMaxNonScrolledEmoji);
|
|
|
|
const auto fullWidth = count * _oneWidth;
|
|
|
|
const auto newWidth = scrolled
|
|
|
|
? st::emojiSuggestionsScrolledWidth
|
|
|
|
: fullWidth;
|
|
|
|
_scrollMax = std::max(0, fullWidth - newWidth);
|
2019-04-01 11:16:16 +00:00
|
|
|
if (_scrollValue > _scrollMax || scrollCurrent() > _scrollMax) {
|
|
|
|
scrollTo(std::min(_scrollValue, _scrollMax));
|
|
|
|
}
|
2019-03-30 10:00:31 +00:00
|
|
|
resize(_padding.left() + newWidth + _padding.right(), height());
|
|
|
|
update();
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
|
|
|
|
2019-03-30 10:00:31 +00:00
|
|
|
bool SuggestionsWidget::eventHook(QEvent *e) {
|
|
|
|
if (e->type() == QEvent::Wheel) {
|
|
|
|
selectByMouse(QCursor::pos());
|
|
|
|
if (_selected >= 0 && _pressed < 0) {
|
|
|
|
scrollByWheelEvent(static_cast<QWheelEvent*>(e));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return RpWidget::eventHook(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsWidget::scrollByWheelEvent(not_null<QWheelEvent*> e) {
|
|
|
|
const auto horizontal = (e->angleDelta().x() != 0)
|
|
|
|
|| (e->orientation() == Qt::Horizontal);
|
|
|
|
const auto vertical = (e->angleDelta().y() != 0)
|
|
|
|
|| (e->orientation() == Qt::Vertical);
|
2019-04-01 11:16:16 +00:00
|
|
|
const auto current = scrollCurrent();
|
2019-03-30 10:00:31 +00:00
|
|
|
const auto scroll = [&] {
|
|
|
|
if (horizontal) {
|
|
|
|
const auto delta = e->pixelDelta().x()
|
|
|
|
? e->pixelDelta().x()
|
|
|
|
: e->angleDelta().x();
|
2019-04-01 11:16:16 +00:00
|
|
|
return snap(current - ((rtl() ? -1 : 1) * delta), 0, _scrollMax);
|
2019-03-30 10:00:31 +00:00
|
|
|
} else if (vertical) {
|
|
|
|
const auto delta = e->pixelDelta().y()
|
|
|
|
? e->pixelDelta().y()
|
|
|
|
: e->angleDelta().y();
|
2019-04-01 11:16:16 +00:00
|
|
|
return snap(current - delta, 0, _scrollMax);
|
2019-03-30 10:00:31 +00:00
|
|
|
}
|
2019-04-01 11:16:16 +00:00
|
|
|
return current;
|
2019-03-30 10:00:31 +00:00
|
|
|
}();
|
2019-04-01 11:16:16 +00:00
|
|
|
if (current != scroll) {
|
|
|
|
scrollTo(scroll);
|
2019-03-30 10:00:31 +00:00
|
|
|
if (!_lastMousePosition) {
|
|
|
|
_lastMousePosition = QCursor::pos();
|
|
|
|
}
|
|
|
|
selectByMouse(*_lastMousePosition);
|
|
|
|
update();
|
|
|
|
}
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2019-03-30 10:00:31 +00:00
|
|
|
const auto clip = e->rect();
|
|
|
|
p.fillRect(clip, st::boxBg);
|
|
|
|
|
|
|
|
const auto shift = innerShift();
|
|
|
|
p.translate(-shift);
|
|
|
|
const auto paint = clip.translated(shift);
|
|
|
|
const auto from = std::max(paint.x(), 0) / _oneWidth;
|
|
|
|
const auto till = std::min(
|
|
|
|
(paint.x() + paint.width() + _oneWidth - 1) / _oneWidth,
|
|
|
|
int(_rows.size()));
|
|
|
|
|
2019-04-01 11:16:16 +00:00
|
|
|
const auto selected = (_pressed >= 0)
|
|
|
|
? _pressed
|
|
|
|
: _selectedAnimation.value(_selected);
|
|
|
|
if (selected > -1.) {
|
|
|
|
App::roundRect(
|
|
|
|
p,
|
|
|
|
QRect(selected * _oneWidth, 0, _oneWidth, _oneWidth),
|
|
|
|
st::emojiPanHover,
|
|
|
|
StickerHoverCorners);
|
|
|
|
}
|
|
|
|
|
2019-03-30 10:00:31 +00:00
|
|
|
for (auto i = from; i != till; ++i) {
|
|
|
|
const auto &row = _rows[i];
|
|
|
|
const auto emoji = row.emoji;
|
|
|
|
const auto esize = Ui::Emoji::GetSizeLarge();
|
|
|
|
const auto x = i * _oneWidth;
|
|
|
|
const auto y = 0;
|
2018-10-13 17:35:30 +00:00
|
|
|
Ui::Emoji::Draw(
|
|
|
|
p,
|
|
|
|
emoji,
|
|
|
|
esize,
|
2019-03-30 10:00:31 +00:00
|
|
|
x + (_oneWidth - (esize / cIntRetinaFactor())) / 2,
|
|
|
|
y + (_oneWidth - (esize / cIntRetinaFactor())) / 2);
|
|
|
|
}
|
|
|
|
paintFadings(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsWidget::paintFadings(Painter &p) const {
|
2019-04-01 11:16:16 +00:00
|
|
|
const auto scroll = scrollCurrent();
|
2019-03-30 10:00:31 +00:00
|
|
|
const auto o_left = snap(
|
2019-04-01 11:16:16 +00:00
|
|
|
scroll / float64(st::emojiSuggestionsFadeAfter),
|
2019-03-30 10:00:31 +00:00
|
|
|
0.,
|
|
|
|
1.);
|
|
|
|
const auto shift = innerShift();
|
|
|
|
if (o_left > 0.) {
|
|
|
|
p.setOpacity(o_left);
|
|
|
|
const auto rect = myrtlrect(
|
|
|
|
shift.x(),
|
|
|
|
0,
|
|
|
|
st::emojiSuggestionsFadeLeft.width(),
|
|
|
|
height());
|
|
|
|
st::emojiSuggestionsFadeLeft.fill(p, rect);
|
|
|
|
p.setOpacity(1.);
|
|
|
|
}
|
|
|
|
const auto o_right = snap(
|
2019-04-01 11:16:16 +00:00
|
|
|
(_scrollMax - scroll) / float64(st::emojiSuggestionsFadeAfter),
|
2019-03-30 10:00:31 +00:00
|
|
|
0.,
|
|
|
|
1.);
|
|
|
|
if (o_right > 0.) {
|
|
|
|
p.setOpacity(o_right);
|
|
|
|
const auto rect = myrtlrect(
|
|
|
|
shift.x() + width() - st::emojiSuggestionsFadeRight.width(),
|
|
|
|
0,
|
|
|
|
st::emojiSuggestionsFadeRight.width(),
|
|
|
|
height());
|
|
|
|
st::emojiSuggestionsFadeRight.fill(p, rect);
|
|
|
|
p.setOpacity(1.);
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsWidget::keyPressEvent(QKeyEvent *e) {
|
|
|
|
handleKeyEvent(e->key());
|
|
|
|
}
|
|
|
|
|
2019-03-30 10:00:31 +00:00
|
|
|
bool SuggestionsWidget::handleKeyEvent(int key) {
|
|
|
|
if (key == Qt::Key_Enter || key == Qt::Key_Return) {
|
|
|
|
return triggerSelectedRow();
|
2019-07-04 11:26:39 +00:00
|
|
|
} else if (key == Qt::Key_Tab) {
|
2019-03-30 10:00:31 +00:00
|
|
|
if (_selected < 0 || _selected >= _rows.size()) {
|
|
|
|
setSelected(0);
|
|
|
|
}
|
|
|
|
return triggerSelectedRow();
|
|
|
|
} else if (_rows.empty()
|
|
|
|
|| (key != Qt::Key_Up
|
|
|
|
&& key != Qt::Key_Down
|
|
|
|
&& key != Qt::Key_Left
|
|
|
|
&& key != Qt::Key_Right)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto delta = (key == Qt::Key_Down || key == Qt::Key_Right)
|
|
|
|
? 1
|
|
|
|
: -1;
|
|
|
|
if (delta < 0 && _selected < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto start = _selected;
|
2017-07-22 08:35:18 +00:00
|
|
|
if (start < 0 || start >= _rows.size()) {
|
|
|
|
start = (delta > 0) ? (_rows.size() - 1) : 0;
|
|
|
|
}
|
|
|
|
auto newSelected = start + delta;
|
|
|
|
if (newSelected < 0) {
|
2019-03-30 10:00:31 +00:00
|
|
|
newSelected = -1;
|
2017-07-22 08:35:18 +00:00
|
|
|
} else if (newSelected >= _rows.size()) {
|
|
|
|
newSelected -= _rows.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
_mouseSelection = false;
|
2018-12-25 12:41:40 +00:00
|
|
|
_lastMousePosition = std::nullopt;
|
2019-04-01 11:16:16 +00:00
|
|
|
setSelected(newSelected, anim::type::normal);
|
2019-03-30 10:00:31 +00:00
|
|
|
return true;
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-01 11:16:16 +00:00
|
|
|
void SuggestionsWidget::setSelected(int selected, anim::type animated) {
|
2017-07-22 08:35:18 +00:00
|
|
|
if (selected >= _rows.size()) {
|
|
|
|
selected = -1;
|
|
|
|
}
|
2019-04-01 11:16:16 +00:00
|
|
|
if (animated == anim::type::normal) {
|
|
|
|
_selectedAnimation.start(
|
|
|
|
[=] { update(); },
|
|
|
|
_selected,
|
|
|
|
selected,
|
|
|
|
kAnimationDuration,
|
|
|
|
anim::sineInOut);
|
|
|
|
if (_scrollMax > 0) {
|
|
|
|
const auto selectedMax = int(_rows.size()) - 3;
|
|
|
|
const auto selectedForScroll = std::min(
|
|
|
|
std::max(selected, 1) - 1,
|
|
|
|
selectedMax);
|
|
|
|
scrollTo((_scrollMax * selectedForScroll) / selectedMax, animated);
|
|
|
|
}
|
|
|
|
} else if (_selectedAnimation.animating()) {
|
|
|
|
_selectedAnimation.stop();
|
|
|
|
update();
|
|
|
|
}
|
2017-07-22 08:35:18 +00:00
|
|
|
if (_selected != selected) {
|
|
|
|
updateSelectedItem();
|
|
|
|
_selected = selected;
|
|
|
|
updateSelectedItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 11:16:16 +00:00
|
|
|
int SuggestionsWidget::scrollCurrent() const {
|
|
|
|
return _scrollAnimation.value(_scrollValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsWidget::scrollTo(int value, anim::type animated) {
|
|
|
|
if (animated == anim::type::instant) {
|
|
|
|
_scrollAnimation.stop();
|
|
|
|
} else {
|
|
|
|
_scrollAnimation.start(
|
|
|
|
[=] { update(); },
|
|
|
|
_scrollValue,
|
|
|
|
value,
|
|
|
|
kAnimationDuration,
|
|
|
|
anim::sineInOut);
|
|
|
|
}
|
|
|
|
_scrollValue = value;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsWidget::stopAnimations() {
|
|
|
|
_scrollValue = _scrollAnimation.value(_scrollValue);
|
|
|
|
_scrollAnimation.stop();
|
|
|
|
}
|
|
|
|
|
2017-07-22 08:35:18 +00:00
|
|
|
void SuggestionsWidget::setPressed(int pressed) {
|
|
|
|
if (pressed >= _rows.size()) {
|
|
|
|
pressed = -1;
|
|
|
|
}
|
|
|
|
if (_pressed != pressed) {
|
|
|
|
_pressed = pressed;
|
2019-04-01 10:35:32 +00:00
|
|
|
if (_pressed >= 0) {
|
|
|
|
_mousePressPosition = QCursor::pos();
|
|
|
|
}
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsWidget::clearMouseSelection() {
|
|
|
|
if (_mouseSelection) {
|
|
|
|
clearSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsWidget::clearSelection() {
|
|
|
|
_mouseSelection = false;
|
2018-12-25 12:41:40 +00:00
|
|
|
_lastMousePosition = std::nullopt;
|
2017-07-22 08:35:18 +00:00
|
|
|
setSelected(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsWidget::updateItem(int index) {
|
|
|
|
if (index >= 0 && index < _rows.size()) {
|
2019-03-30 10:00:31 +00:00
|
|
|
update(
|
2019-04-01 11:16:16 +00:00
|
|
|
_padding.left() + index * _oneWidth - scrollCurrent(),
|
2019-03-30 10:00:31 +00:00
|
|
|
_padding.top(),
|
|
|
|
_oneWidth,
|
|
|
|
_oneWidth);
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsWidget::updateSelectedItem() {
|
|
|
|
updateItem(_selected);
|
|
|
|
}
|
|
|
|
|
2019-03-30 10:00:31 +00:00
|
|
|
QRect SuggestionsWidget::inner() const {
|
|
|
|
return QRect(0, 0, _rows.size() * _oneWidth, _oneWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint SuggestionsWidget::innerShift() const {
|
2019-04-01 11:16:16 +00:00
|
|
|
return QPoint(scrollCurrent() - _padding.left(), -_padding.top());
|
2019-03-30 10:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QPoint SuggestionsWidget::mapToInner(QPoint globalPosition) const {
|
|
|
|
return mapFromGlobal(globalPosition) + innerShift();
|
|
|
|
}
|
|
|
|
|
2017-07-22 08:35:18 +00:00
|
|
|
void SuggestionsWidget::mouseMoveEvent(QMouseEvent *e) {
|
2019-03-30 10:00:31 +00:00
|
|
|
const auto globalPosition = e->globalPos();
|
2019-04-01 10:35:32 +00:00
|
|
|
if (_dragScrollStart >= 0) {
|
|
|
|
const auto delta = (_mousePressPosition.x() - globalPosition.x());
|
|
|
|
const auto scroll = snap(
|
|
|
|
_dragScrollStart + (rtl() ? -1 : 1) * delta,
|
|
|
|
0,
|
|
|
|
_scrollMax);
|
2019-04-01 11:16:16 +00:00
|
|
|
if (scrollCurrent() != scroll) {
|
|
|
|
scrollTo(scroll);
|
2019-04-01 10:35:32 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else if ((_pressed >= 0)
|
|
|
|
&& (_scrollMax > 0)
|
|
|
|
&& ((_mousePressPosition - globalPosition).manhattanLength()
|
|
|
|
>= QApplication::startDragDistance())) {
|
2019-04-01 11:16:16 +00:00
|
|
|
_dragScrollStart = scrollCurrent();
|
2019-04-01 10:35:32 +00:00
|
|
|
_mousePressPosition = globalPosition;
|
2019-04-01 11:16:16 +00:00
|
|
|
scrollTo(_dragScrollStart);
|
2019-04-01 10:35:32 +00:00
|
|
|
}
|
2019-03-30 10:00:31 +00:00
|
|
|
if (inner().contains(mapToInner(globalPosition))) {
|
2018-12-25 12:41:40 +00:00
|
|
|
if (!_lastMousePosition) {
|
|
|
|
_lastMousePosition = globalPosition;
|
|
|
|
return;
|
|
|
|
} else if (!_mouseSelection
|
|
|
|
&& *_lastMousePosition == globalPosition) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
selectByMouse(globalPosition);
|
2017-07-22 08:35:18 +00:00
|
|
|
} else {
|
|
|
|
clearMouseSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-25 12:41:40 +00:00
|
|
|
void SuggestionsWidget::selectByMouse(QPoint globalPosition) {
|
|
|
|
_mouseSelection = true;
|
|
|
|
_lastMousePosition = globalPosition;
|
2019-03-30 10:00:31 +00:00
|
|
|
const auto p = mapToInner(globalPosition);
|
|
|
|
const auto selected = (p.x() >= 0) ? (p.x() / _oneWidth) : -1;
|
2017-07-22 08:35:18 +00:00
|
|
|
setSelected((selected >= 0 && selected < _rows.size()) ? selected : -1);
|
|
|
|
}
|
2018-12-25 12:41:40 +00:00
|
|
|
|
2017-07-22 08:35:18 +00:00
|
|
|
void SuggestionsWidget::mousePressEvent(QMouseEvent *e) {
|
2018-12-25 12:41:40 +00:00
|
|
|
selectByMouse(e->globalPos());
|
2019-04-01 10:35:32 +00:00
|
|
|
if (_selected >= 0) {
|
2017-07-22 08:35:18 +00:00
|
|
|
setPressed(_selected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsWidget::mouseReleaseEvent(QMouseEvent *e) {
|
2019-04-01 10:35:32 +00:00
|
|
|
if (_pressed >= 0) {
|
|
|
|
const auto pressed = _pressed;
|
2017-07-22 08:35:18 +00:00
|
|
|
setPressed(-1);
|
2019-04-01 10:35:32 +00:00
|
|
|
if (_dragScrollStart >= 0) {
|
|
|
|
_dragScrollStart = -1;
|
|
|
|
} else if (pressed == _selected) {
|
2017-07-27 10:22:51 +00:00
|
|
|
triggerRow(_rows[_selected]);
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-30 10:00:31 +00:00
|
|
|
bool SuggestionsWidget::triggerSelectedRow() const {
|
2019-04-01 10:35:32 +00:00
|
|
|
if (_selected >= 0) {
|
2017-07-27 10:22:51 +00:00
|
|
|
triggerRow(_rows[_selected]);
|
2019-03-30 10:00:31 +00:00
|
|
|
return true;
|
2017-07-27 10:22:51 +00:00
|
|
|
}
|
2019-03-30 10:00:31 +00:00
|
|
|
return false;
|
2017-07-27 10:22:51 +00:00
|
|
|
}
|
|
|
|
|
2019-03-30 10:00:31 +00:00
|
|
|
void SuggestionsWidget::triggerRow(const Row &row) const {
|
|
|
|
_triggered.fire(row.emoji->text());
|
2017-07-27 10:22:51 +00:00
|
|
|
}
|
|
|
|
|
2017-07-22 08:35:18 +00:00
|
|
|
void SuggestionsWidget::enterEventHook(QEvent *e) {
|
2019-03-30 10:00:31 +00:00
|
|
|
if (!inner().contains(mapToInner(QCursor::pos()))) {
|
2017-07-22 08:35:18 +00:00
|
|
|
clearMouseSelection();
|
|
|
|
}
|
|
|
|
return TWidget::enterEventHook(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsWidget::leaveEventHook(QEvent *e) {
|
|
|
|
clearMouseSelection();
|
|
|
|
return TWidget::leaveEventHook(e);
|
|
|
|
}
|
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
SuggestionsController::SuggestionsController(
|
|
|
|
not_null<QWidget*> outer,
|
2019-05-27 10:16:14 +00:00
|
|
|
not_null<QTextEdit*> field,
|
2019-08-02 10:40:35 +00:00
|
|
|
not_null<Main::Session*> session,
|
2019-05-27 10:16:14 +00:00
|
|
|
const Options &options)
|
2019-03-30 08:06:15 +00:00
|
|
|
: _field(field)
|
2019-08-02 10:40:35 +00:00
|
|
|
, _session(session)
|
2019-05-27 10:16:14 +00:00
|
|
|
, _showExactTimer([=] { showWithQuery(getEmojiQuery()); })
|
|
|
|
, _options(options) {
|
2018-11-21 10:09:46 +00:00
|
|
|
_container = base::make_unique_q<InnerDropdown>(
|
|
|
|
outer,
|
|
|
|
st::emojiSuggestionsDropdown);
|
2017-07-22 08:35:18 +00:00
|
|
|
_container->setAutoHiding(false);
|
2018-11-21 10:09:46 +00:00
|
|
|
_suggestions = _container->setOwnedWidget(
|
2019-03-30 10:00:31 +00:00
|
|
|
object_ptr<Ui::Emoji::SuggestionsWidget>(_container));
|
2017-07-22 08:35:18 +00:00
|
|
|
|
2018-05-13 15:56:08 +00:00
|
|
|
setReplaceCallback(nullptr);
|
|
|
|
|
2019-09-05 10:51:36 +00:00
|
|
|
const auto fieldCallback = [=](not_null<QEvent*> event) {
|
|
|
|
return fieldFilter(event)
|
|
|
|
? Core::EventFilter::Result::Cancel
|
|
|
|
: Core::EventFilter::Result::Continue;
|
|
|
|
};
|
|
|
|
_fieldFilter.reset(Core::InstallEventFilter(_field, fieldCallback));
|
|
|
|
|
|
|
|
const auto outerCallback = [=](not_null<QEvent*> event) {
|
|
|
|
return outerFilter(event)
|
|
|
|
? Core::EventFilter::Result::Cancel
|
|
|
|
: Core::EventFilter::Result::Continue;
|
|
|
|
};
|
|
|
|
_outerFilter.reset(Core::InstallEventFilter(outer, outerCallback));
|
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
QObject::connect(
|
|
|
|
_field,
|
|
|
|
&QTextEdit::textChanged,
|
|
|
|
_container,
|
|
|
|
[=] { handleTextChange(); });
|
|
|
|
QObject::connect(
|
|
|
|
_field,
|
|
|
|
&QTextEdit::cursorPositionChanged,
|
|
|
|
_container,
|
|
|
|
[=] { handleCursorPositionChange(); });
|
|
|
|
|
|
|
|
_suggestions->toggleAnimated(
|
|
|
|
) | rpl::start_with_next([=](bool visible) {
|
|
|
|
suggestionsUpdated(visible);
|
|
|
|
}, _lifetime);
|
|
|
|
_suggestions->triggered(
|
|
|
|
) | rpl::start_with_next([=](QString replacement) {
|
|
|
|
replaceCurrent(replacement);
|
|
|
|
}, _lifetime);
|
2019-03-29 16:04:05 +00:00
|
|
|
Core::App().emojiKeywords().refreshed(
|
|
|
|
) | rpl::start_with_next([=] {
|
2019-03-30 08:06:15 +00:00
|
|
|
_keywordsRefreshed = true;
|
|
|
|
if (!_showExactTimer.isActive()) {
|
|
|
|
showWithQuery(_lastShownQuery);
|
|
|
|
}
|
2019-03-29 16:04:05 +00:00
|
|
|
}, _lifetime);
|
2017-07-22 08:35:18 +00:00
|
|
|
|
|
|
|
updateForceHidden();
|
|
|
|
|
|
|
|
handleTextChange();
|
|
|
|
}
|
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
SuggestionsController *SuggestionsController::Init(
|
|
|
|
not_null<QWidget*> outer,
|
2019-05-27 10:16:14 +00:00
|
|
|
not_null<Ui::InputField*> field,
|
2019-08-02 10:40:35 +00:00
|
|
|
not_null<Main::Session*> session,
|
2019-05-27 10:16:14 +00:00
|
|
|
const Options &options) {
|
2018-11-21 10:09:46 +00:00
|
|
|
const auto result = Ui::CreateChild<SuggestionsController>(
|
|
|
|
field.get(),
|
|
|
|
outer,
|
2019-05-27 10:16:14 +00:00
|
|
|
field->rawTextEdit(),
|
2019-08-02 10:40:35 +00:00
|
|
|
session,
|
2019-05-27 10:16:14 +00:00
|
|
|
options);
|
2018-11-21 10:09:46 +00:00
|
|
|
result->setReplaceCallback([=](
|
|
|
|
int from,
|
|
|
|
int till,
|
|
|
|
const QString &replacement) {
|
|
|
|
field->commitInstantReplacement(from, till, replacement);
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-05-13 15:56:08 +00:00
|
|
|
void SuggestionsController::setReplaceCallback(
|
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)> callback) {
|
|
|
|
if (callback) {
|
|
|
|
_replaceCallback = std::move(callback);
|
|
|
|
} else {
|
|
|
|
_replaceCallback = [=](int from, int till, const QString &replacement) {
|
|
|
|
auto cursor = _field->textCursor();
|
|
|
|
cursor.setPosition(from);
|
|
|
|
cursor.setPosition(till, QTextCursor::KeepAnchor);
|
|
|
|
cursor.insertText(replacement);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-22 08:35:18 +00:00
|
|
|
void SuggestionsController::handleTextChange() {
|
2019-08-02 10:40:35 +00:00
|
|
|
if (_session->settings().suggestEmoji()
|
|
|
|
&& _field->textCursor().position() > 0) {
|
2019-03-28 08:48:32 +00:00
|
|
|
Core::App().emojiKeywords().refresh();
|
|
|
|
}
|
|
|
|
|
2017-07-22 08:35:18 +00:00
|
|
|
_ignoreCursorPositionChange = true;
|
2018-11-21 10:09:46 +00:00
|
|
|
InvokeQueued(_container, [=] { _ignoreCursorPositionChange = false; });
|
2017-07-22 08:35:18 +00:00
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
const auto query = getEmojiQuery();
|
2017-07-22 08:35:18 +00:00
|
|
|
if (query.isEmpty() || _textChangeAfterKeyPress) {
|
2019-03-30 08:06:15 +00:00
|
|
|
const auto exact = (!query.isEmpty() && query[0] != ':');
|
2019-03-30 10:00:31 +00:00
|
|
|
if (exact) {
|
|
|
|
const auto hidden = _container->isHidden()
|
|
|
|
|| _container->isHiding();
|
|
|
|
_showExactTimer.callOnce(hidden ? kShowExactDelay : 0);
|
2019-03-30 08:06:15 +00:00
|
|
|
} else {
|
|
|
|
showWithQuery(query);
|
2019-03-30 10:00:31 +00:00
|
|
|
_suggestions->selectFirstResult();
|
2019-03-30 08:06:15 +00:00
|
|
|
}
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-30 08:06:15 +00:00
|
|
|
void SuggestionsController::showWithQuery(const QString &query) {
|
|
|
|
_showExactTimer.cancel();
|
|
|
|
const auto force = base::take(_keywordsRefreshed);
|
|
|
|
_lastShownQuery = query;
|
|
|
|
_suggestions->showWithQuery(_lastShownQuery, force);
|
2019-03-29 16:04:05 +00:00
|
|
|
}
|
|
|
|
|
2017-07-22 08:35:18 +00:00
|
|
|
QString SuggestionsController::getEmojiQuery() {
|
2019-08-02 10:40:35 +00:00
|
|
|
if (!_session->settings().suggestEmoji()) {
|
2017-07-25 18:16:37 +00:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2019-03-29 12:21:11 +00:00
|
|
|
const auto cursor = _field->textCursor();
|
2018-05-26 14:58:21 +00:00
|
|
|
if (cursor.hasSelection()) {
|
2017-07-22 08:35:18 +00:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2019-03-29 13:51:18 +00:00
|
|
|
const auto modernLimit = Core::App().emojiKeywords().maxQueryLength();
|
|
|
|
const auto legacyLimit = GetSuggestionMaxLength();
|
2019-03-29 12:21:11 +00:00
|
|
|
const auto position = cursor.position();
|
|
|
|
const auto findTextPart = [&] {
|
2017-07-22 08:35:18 +00:00
|
|
|
auto document = _field->document();
|
|
|
|
auto block = document->findBlock(position);
|
|
|
|
for (auto i = block.begin(); !i.atEnd(); ++i) {
|
|
|
|
auto fragment = i.fragment();
|
|
|
|
if (!fragment.isValid()) continue;
|
|
|
|
|
|
|
|
auto from = fragment.position();
|
|
|
|
auto till = from + fragment.length();
|
|
|
|
if (from >= position || till < position) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (fragment.charFormat().isImageFormat()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
_queryStartPosition = from;
|
2018-03-14 23:10:03 +00:00
|
|
|
return fragment.text();
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
};
|
|
|
|
|
2019-03-29 12:21:11 +00:00
|
|
|
const auto text = findTextPart();
|
2017-07-22 08:35:18 +00:00
|
|
|
if (text.isEmpty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
2019-03-29 13:51:18 +00:00
|
|
|
const auto length = position - _queryStartPosition;
|
|
|
|
for (auto i = length; i != 0;) {
|
2019-03-29 12:21:11 +00:00
|
|
|
if (text[--i] == ':') {
|
2019-03-29 14:23:21 +00:00
|
|
|
const auto previous = (i > 0) ? text[i - 1] : QChar(0);
|
|
|
|
if (i > 0 && (previous.isLetter() || previous.isDigit())) {
|
|
|
|
return QString();
|
|
|
|
} else if (i + 1 == length || text[i + 1].isSpace()) {
|
2019-03-29 13:51:18 +00:00
|
|
|
return QString();
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
2019-03-29 13:51:18 +00:00
|
|
|
_queryStartPosition += i + 2;
|
|
|
|
return text.mid(i, length - i);
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
2019-03-29 13:51:18 +00:00
|
|
|
if (length - i > legacyLimit && length - i > modernLimit) {
|
2017-07-22 08:35:18 +00:00
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
}
|
2019-03-29 13:51:18 +00:00
|
|
|
|
|
|
|
// Exact query should be full input field value.
|
|
|
|
const auto end = [&] {
|
|
|
|
auto cursor = _field->textCursor();
|
|
|
|
cursor.movePosition(QTextCursor::End);
|
|
|
|
return cursor.position();
|
|
|
|
}();
|
2019-03-30 10:00:31 +00:00
|
|
|
const auto is = [&](QLatin1String string) {
|
|
|
|
return (text.compare(string, Qt::CaseInsensitive) == 0);
|
|
|
|
};
|
2019-05-27 10:16:14 +00:00
|
|
|
if (!_options.suggestExactFirstWord
|
|
|
|
|| !length
|
2019-03-29 14:23:21 +00:00
|
|
|
|| text[0].isSpace()
|
|
|
|
|| (length > modernLimit)
|
2019-03-29 13:51:18 +00:00
|
|
|
|| (_queryStartPosition != 0)
|
|
|
|
|| (position != end)) {
|
|
|
|
return QString();
|
|
|
|
}
|
2019-03-30 10:00:31 +00:00
|
|
|
return text;
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsController::replaceCurrent(const QString &replacement) {
|
2019-03-29 12:21:11 +00:00
|
|
|
const auto suggestion = getEmojiQuery();
|
2017-07-22 08:35:18 +00:00
|
|
|
if (suggestion.isEmpty()) {
|
2019-03-30 08:06:15 +00:00
|
|
|
showWithQuery(QString());
|
2017-07-22 08:35:18 +00:00
|
|
|
} else {
|
2018-05-13 15:56:08 +00:00
|
|
|
const auto cursor = _field->textCursor();
|
|
|
|
const auto position = cursor.position();
|
|
|
|
const auto from = position - suggestion.size();
|
|
|
|
_replaceCallback(from, position, replacement);
|
2017-07-25 18:16:37 +00:00
|
|
|
}
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsController::handleCursorPositionChange() {
|
2018-11-21 10:09:46 +00:00
|
|
|
InvokeQueued(_container, [=] {
|
2017-07-22 08:35:18 +00:00
|
|
|
if (_ignoreCursorPositionChange) {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-30 08:06:15 +00:00
|
|
|
showWithQuery(QString());
|
2017-07-22 08:35:18 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsController::suggestionsUpdated(bool visible) {
|
|
|
|
_shown = visible;
|
|
|
|
if (_shown) {
|
|
|
|
_container->resizeToContent();
|
|
|
|
updateGeometry();
|
|
|
|
if (!_forceHidden) {
|
2018-11-21 10:09:46 +00:00
|
|
|
if (_container->isHidden() || _container->isHiding()) {
|
|
|
|
raise();
|
|
|
|
}
|
|
|
|
_container->showAnimated(
|
|
|
|
Ui::PanelAnimation::Origin::BottomLeft);
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
|
|
|
} else if (!_forceHidden) {
|
|
|
|
_container->hideAnimated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsController::updateGeometry() {
|
|
|
|
auto cursor = _field->textCursor();
|
|
|
|
cursor.setPosition(_queryStartPosition);
|
|
|
|
auto aroundRect = _field->cursorRect(cursor);
|
|
|
|
aroundRect.setTopLeft(_field->viewport()->mapToGlobal(aroundRect.topLeft()));
|
|
|
|
aroundRect.setTopLeft(_container->parentWidget()->mapFromGlobal(aroundRect.topLeft()));
|
|
|
|
auto boundingRect = _container->parentWidget()->rect();
|
|
|
|
auto origin = rtl() ? PanelAnimation::Origin::BottomRight : PanelAnimation::Origin::BottomLeft;
|
|
|
|
auto point = rtl() ? (aroundRect.topLeft() + QPoint(aroundRect.width(), 0)) : aroundRect.topLeft();
|
2019-03-30 10:00:31 +00:00
|
|
|
const auto padding = st::emojiSuggestionsDropdown.padding;
|
|
|
|
const auto shift = std::min(_container->width() - padding.left() - padding.right(), st::emojiSuggestionSize) / 2;
|
|
|
|
point -= rtl() ? QPoint(_container->width() - padding.right() - shift, _container->height()) : QPoint(padding.left() + shift, _container->height());
|
2017-07-22 08:35:18 +00:00
|
|
|
if (rtl()) {
|
|
|
|
if (point.x() < boundingRect.x()) {
|
|
|
|
point.setX(boundingRect.x());
|
|
|
|
}
|
|
|
|
if (point.x() + _container->width() > boundingRect.x() + boundingRect.width()) {
|
|
|
|
point.setX(boundingRect.x() + boundingRect.width() - _container->width());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (point.x() + _container->width() > boundingRect.x() + boundingRect.width()) {
|
|
|
|
point.setX(boundingRect.x() + boundingRect.width() - _container->width());
|
|
|
|
}
|
|
|
|
if (point.x() < boundingRect.x()) {
|
|
|
|
point.setX(boundingRect.x());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (point.y() < boundingRect.y()) {
|
|
|
|
point.setY(aroundRect.y() + aroundRect.height());
|
|
|
|
origin = (origin == PanelAnimation::Origin::BottomRight) ? PanelAnimation::Origin::TopRight : PanelAnimation::Origin::TopLeft;
|
|
|
|
}
|
|
|
|
_container->move(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsController::updateForceHidden() {
|
2018-11-21 10:09:46 +00:00
|
|
|
_forceHidden = !_field->isVisible() || !_field->hasFocus();
|
2017-07-22 08:35:18 +00:00
|
|
|
if (_forceHidden) {
|
|
|
|
_container->hideFast();
|
|
|
|
} else if (_shown) {
|
|
|
|
_container->showFast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
bool SuggestionsController::fieldFilter(not_null<QEvent*> event) {
|
|
|
|
auto type = event->type();
|
|
|
|
switch (type) {
|
|
|
|
case QEvent::Move:
|
|
|
|
case QEvent::Resize: {
|
|
|
|
if (_shown) {
|
|
|
|
updateGeometry();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::Show:
|
|
|
|
case QEvent::ShowToParent:
|
|
|
|
case QEvent::Hide:
|
|
|
|
case QEvent::HideToParent:
|
|
|
|
case QEvent::FocusIn:
|
|
|
|
case QEvent::FocusOut: {
|
|
|
|
updateForceHidden();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case QEvent::KeyPress: {
|
|
|
|
const auto key = static_cast<QKeyEvent*>(event.get())->key();
|
|
|
|
switch (key) {
|
|
|
|
case Qt::Key_Enter:
|
|
|
|
case Qt::Key_Return:
|
|
|
|
case Qt::Key_Tab:
|
|
|
|
case Qt::Key_Up:
|
|
|
|
case Qt::Key_Down:
|
2019-03-30 10:00:31 +00:00
|
|
|
case Qt::Key_Left:
|
|
|
|
case Qt::Key_Right:
|
2018-11-21 10:09:46 +00:00
|
|
|
if (_shown && !_forceHidden) {
|
2019-03-30 10:00:31 +00:00
|
|
|
return _suggestions->handleKeyEvent(key);
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
2018-11-21 10:09:46 +00:00
|
|
|
break;
|
2017-07-22 08:35:18 +00:00
|
|
|
|
2018-11-21 10:09:46 +00:00
|
|
|
case Qt::Key_Escape:
|
|
|
|
if (_shown && !_forceHidden) {
|
2019-03-30 08:06:15 +00:00
|
|
|
showWithQuery(QString());
|
2018-11-21 10:09:46 +00:00
|
|
|
return true;
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
2018-11-21 10:09:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
_textChangeAfterKeyPress = true;
|
|
|
|
InvokeQueued(_container, [=] { _textChangeAfterKeyPress = false; });
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SuggestionsController::outerFilter(not_null<QEvent*> event) {
|
|
|
|
auto type = event->type();
|
|
|
|
switch (type) {
|
|
|
|
case QEvent::Move:
|
|
|
|
case QEvent::Resize: {
|
2018-11-22 12:48:50 +00:00
|
|
|
// updateGeometry uses not only container geometry, but also
|
|
|
|
// container children geometries that will be updated later.
|
|
|
|
InvokeQueued(_container, [=] {
|
|
|
|
if (_shown) {
|
|
|
|
updateGeometry();
|
|
|
|
}
|
|
|
|
});
|
2018-11-21 10:09:46 +00:00
|
|
|
} break;
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
2018-11-21 10:09:46 +00:00
|
|
|
return false;
|
2017-07-22 08:35:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SuggestionsController::raise() {
|
|
|
|
_container->raise();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Emoji
|
|
|
|
} // namespace Ui
|