2017-03-29 17:04:00 +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-03-29 17:04:00 +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-03-29 17:04:00 +03:00
|
|
|
*/
|
2017-04-06 17:38:10 +03:00
|
|
|
#include "chat_helpers/emoji_list_widget.h"
|
2017-03-29 17:04:00 +03:00
|
|
|
|
2019-04-02 13:13:30 +04:00
|
|
|
#include "ui/effects/animations.h"
|
2017-03-29 18:09:16 +03:00
|
|
|
#include "ui/widgets/buttons.h"
|
2017-03-29 17:04:00 +03:00
|
|
|
#include "ui/widgets/shadow.h"
|
2018-10-13 20:35:30 +03:00
|
|
|
#include "ui/emoji_config.h"
|
2017-04-13 11:27:10 +03:00
|
|
|
#include "lang/lang_keys.h"
|
2018-08-02 17:50:00 +02:00
|
|
|
#include "emoji_suggestions_data.h"
|
|
|
|
#include "emoji_suggestions_helper.h"
|
|
|
|
#include "facades.h"
|
2018-10-13 20:35:30 +03:00
|
|
|
#include "styles/style_chat_helpers.h"
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
namespace ChatHelpers {
|
|
|
|
|
2018-11-21 22:14:48 +04:00
|
|
|
class EmojiColorPicker : public Ui::RpWidget {
|
|
|
|
public:
|
|
|
|
EmojiColorPicker(QWidget *parent);
|
|
|
|
|
|
|
|
void showEmoji(EmojiPtr emoji);
|
|
|
|
|
|
|
|
void clearSelection();
|
|
|
|
void handleMouseMove(QPoint globalPos);
|
|
|
|
void handleMouseRelease(QPoint globalPos);
|
|
|
|
void setSingleSize(QSize size);
|
|
|
|
|
|
|
|
void showAnimated();
|
|
|
|
void hideAnimated();
|
|
|
|
void hideFast();
|
|
|
|
|
|
|
|
rpl::producer<EmojiPtr> chosen() const;
|
|
|
|
rpl::producer<> hidden() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void animationCallback();
|
|
|
|
void updateSize();
|
|
|
|
|
|
|
|
void drawVariant(Painter &p, int variant);
|
|
|
|
|
|
|
|
void updateSelected();
|
|
|
|
void setSelected(int newSelected);
|
|
|
|
|
|
|
|
bool _ignoreShow = false;
|
|
|
|
|
|
|
|
QVector<EmojiPtr> _variants;
|
|
|
|
|
|
|
|
int _selected = -1;
|
|
|
|
int _pressedSel = -1;
|
|
|
|
QPoint _lastMousePos;
|
|
|
|
QSize _singleSize;
|
|
|
|
|
|
|
|
bool _hiding = false;
|
|
|
|
QPixmap _cache;
|
2019-04-02 13:13:30 +04:00
|
|
|
Ui::Animations::Simple _a_opacity;
|
2018-11-21 22:14:48 +04:00
|
|
|
|
|
|
|
rpl::event_stream<EmojiPtr> _chosen;
|
|
|
|
rpl::event_stream<> _hidden;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-04-08 18:20:12 +03:00
|
|
|
class EmojiListWidget::Footer : public TabbedSelector::InnerFooter {
|
2017-03-29 18:09:16 +03:00
|
|
|
public:
|
2017-08-17 11:31:24 +03:00
|
|
|
Footer(not_null<EmojiListWidget*> parent);
|
2017-03-29 18:09:16 +03:00
|
|
|
|
|
|
|
void setCurrentSectionIcon(Section section);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void processPanelHideFinished() override;
|
2017-11-12 13:54:18 +04:00
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
2017-03-29 18:09:16 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
void prepareSection(int &left, int top, int _width, Ui::IconButton *sectionIcon, Section section);
|
|
|
|
void setActiveSection(Section section);
|
|
|
|
|
2017-08-17 11:31:24 +03:00
|
|
|
not_null<EmojiListWidget*> _pan;
|
2017-03-29 18:09:16 +03:00
|
|
|
std::array<object_ptr<Ui::IconButton>, kEmojiSectionCount> _sections;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-08-17 11:31:24 +03:00
|
|
|
EmojiListWidget::Footer::Footer(not_null<EmojiListWidget*> parent) : InnerFooter(parent)
|
2017-03-29 18:09:16 +03:00
|
|
|
, _pan(parent)
|
2017-04-01 11:10:13 +03:00
|
|
|
, _sections { {
|
2017-03-29 18:09:16 +03:00
|
|
|
object_ptr<Ui::IconButton>(this, st::emojiCategoryRecent),
|
|
|
|
object_ptr<Ui::IconButton>(this, st::emojiCategoryPeople),
|
|
|
|
object_ptr<Ui::IconButton>(this, st::emojiCategoryNature),
|
|
|
|
object_ptr<Ui::IconButton>(this, st::emojiCategoryFood),
|
|
|
|
object_ptr<Ui::IconButton>(this, st::emojiCategoryActivity),
|
|
|
|
object_ptr<Ui::IconButton>(this, st::emojiCategoryTravel),
|
|
|
|
object_ptr<Ui::IconButton>(this, st::emojiCategoryObjects),
|
|
|
|
object_ptr<Ui::IconButton>(this, st::emojiCategorySymbols),
|
2017-04-01 11:10:13 +03:00
|
|
|
} } {
|
2017-03-29 18:09:16 +03:00
|
|
|
for (auto i = 0; i != _sections.size(); ++i) {
|
2017-11-12 13:54:18 +04:00
|
|
|
auto value = static_cast<Section>(i);
|
|
|
|
_sections[i]->setClickedCallback([=] {
|
|
|
|
setActiveSection(value);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
setCurrentSectionIcon(Section::Recent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::Footer::resizeEvent(QResizeEvent *e) {
|
|
|
|
auto availableWidth = (width() - st::emojiCategorySkip * 2);
|
|
|
|
auto buttonWidth = availableWidth / _sections.size();
|
|
|
|
auto buttonsWidth = buttonWidth * _sections.size();
|
|
|
|
auto left = (width() - buttonsWidth) / 2;
|
|
|
|
for (auto &button : _sections) {
|
|
|
|
button->resizeToWidth(buttonWidth);
|
2017-03-29 18:09:16 +03:00
|
|
|
button->moveToLeft(left, 0);
|
|
|
|
left += button->width();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::Footer::processPanelHideFinished() {
|
2017-05-17 23:59:43 +03:00
|
|
|
// Preserve panel state through visibility toggles.
|
|
|
|
//setCurrentSectionIcon(Section::Recent);
|
2017-03-29 18:09:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::Footer::setCurrentSectionIcon(Section section) {
|
2017-04-01 11:10:13 +03:00
|
|
|
std::array<const style::icon *, kEmojiSectionCount> overrides = { {
|
2017-03-29 18:09:16 +03:00
|
|
|
&st::emojiRecentActive,
|
|
|
|
&st::emojiPeopleActive,
|
|
|
|
&st::emojiNatureActive,
|
|
|
|
&st::emojiFoodActive,
|
|
|
|
&st::emojiActivityActive,
|
|
|
|
&st::emojiTravelActive,
|
|
|
|
&st::emojiObjectsActive,
|
|
|
|
&st::emojiSymbolsActive,
|
2017-04-01 11:10:13 +03:00
|
|
|
} };
|
2017-03-29 18:09:16 +03:00
|
|
|
for (auto i = 0; i != _sections.size(); ++i) {
|
|
|
|
_sections[i]->setIconOverride((section == static_cast<Section>(i)) ? overrides[i] : nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::Footer::setActiveSection(Ui::Emoji::Section section) {
|
|
|
|
_pan->showEmojiSection(section);
|
|
|
|
}
|
|
|
|
|
2018-11-21 22:14:48 +04:00
|
|
|
EmojiColorPicker::EmojiColorPicker(QWidget *parent)
|
|
|
|
: RpWidget(parent) {
|
2017-03-29 17:04:00 +03:00
|
|
|
setMouseTracking(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiColorPicker::showEmoji(EmojiPtr emoji) {
|
|
|
|
if (!emoji || !emoji->hasVariants()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_ignoreShow = false;
|
|
|
|
|
|
|
|
_variants.resize(emoji->variantsCount() + 1);
|
|
|
|
for (auto i = 0, size = _variants.size(); i != size; ++i) {
|
|
|
|
_variants[i] = emoji->variant(i);
|
|
|
|
}
|
|
|
|
|
2017-11-12 13:54:18 +04:00
|
|
|
updateSize();
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
if (!_cache.isNull()) _cache = QPixmap();
|
|
|
|
showAnimated();
|
|
|
|
}
|
|
|
|
|
2017-11-12 13:54:18 +04:00
|
|
|
void EmojiColorPicker::updateSize() {
|
|
|
|
auto width = st::emojiPanMargins.left()
|
|
|
|
+ _singleSize.width() * _variants.size()
|
|
|
|
+ (_variants.size() - 2) * st::emojiColorsPadding
|
|
|
|
+ st::emojiColorsSep
|
|
|
|
+ st::emojiPanMargins.right();
|
|
|
|
auto height = st::emojiPanMargins.top()
|
|
|
|
+ 2 * st::emojiColorsPadding
|
|
|
|
+ _singleSize.height()
|
|
|
|
+ st::emojiPanMargins.bottom();
|
|
|
|
resize(width, height);
|
|
|
|
update();
|
|
|
|
updateSelected();
|
|
|
|
}
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void EmojiColorPicker::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2019-04-02 13:13:30 +04:00
|
|
|
auto opacity = _a_opacity.value(_hiding ? 0. : 1.);
|
2017-03-29 17:04:00 +03:00
|
|
|
if (opacity < 1.) {
|
|
|
|
if (opacity > 0.) {
|
|
|
|
p.setOpacity(opacity);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (e->rect() != rect()) {
|
|
|
|
p.setClipRect(e->rect());
|
|
|
|
}
|
|
|
|
|
|
|
|
auto inner = rect().marginsRemoved(st::emojiPanMargins);
|
|
|
|
if (!_cache.isNull()) {
|
|
|
|
p.drawPixmap(0, 0, _cache);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Ui::Shadow::paint(p, inner, width(), st::defaultRoundShadow);
|
|
|
|
App::roundRect(p, inner, st::boxBg, BoxCorners);
|
|
|
|
|
2017-11-12 13:54:18 +04:00
|
|
|
auto x = st::emojiPanMargins.left() + 2 * st::emojiColorsPadding + _singleSize.width();
|
2017-03-29 17:04:00 +03:00
|
|
|
if (rtl()) x = width() - x - st::emojiColorsSep;
|
|
|
|
p.fillRect(x, st::emojiPanMargins.top() + st::emojiColorsPadding, st::emojiColorsSep, inner.height() - st::emojiColorsPadding * 2, st::emojiColorsSepColor);
|
|
|
|
|
|
|
|
if (_variants.isEmpty()) return;
|
|
|
|
for (auto i = 0, count = _variants.size(); i != count; ++i) {
|
|
|
|
drawVariant(p, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiColorPicker::mousePressEvent(QMouseEvent *e) {
|
|
|
|
if (e->button() != Qt::LeftButton) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_lastMousePos = e->globalPos();
|
|
|
|
updateSelected();
|
|
|
|
_pressedSel = _selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiColorPicker::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
handleMouseRelease(e->globalPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiColorPicker::handleMouseRelease(QPoint globalPos) {
|
|
|
|
_lastMousePos = globalPos;
|
|
|
|
int32 pressed = _pressedSel;
|
|
|
|
_pressedSel = -1;
|
|
|
|
|
|
|
|
updateSelected();
|
|
|
|
if (_selected >= 0 && (pressed < 0 || _selected == pressed)) {
|
2018-11-21 22:14:48 +04:00
|
|
|
_chosen.fire_copy(_variants[_selected]);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
_ignoreShow = true;
|
|
|
|
hideAnimated();
|
|
|
|
}
|
|
|
|
|
2017-11-12 13:54:18 +04:00
|
|
|
void EmojiColorPicker::setSingleSize(QSize size) {
|
|
|
|
_singleSize = size;
|
|
|
|
updateSize();
|
|
|
|
}
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
void EmojiColorPicker::handleMouseMove(QPoint globalPos) {
|
|
|
|
_lastMousePos = globalPos;
|
|
|
|
updateSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiColorPicker::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
handleMouseMove(e->globalPos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiColorPicker::animationCallback() {
|
|
|
|
update();
|
|
|
|
if (!_a_opacity.animating()) {
|
|
|
|
_cache = QPixmap();
|
|
|
|
if (_hiding) {
|
|
|
|
hide();
|
2018-11-21 22:14:48 +04:00
|
|
|
_hidden.fire({});
|
2017-03-29 17:04:00 +03:00
|
|
|
} else {
|
|
|
|
_lastMousePos = QCursor::pos();
|
|
|
|
updateSelected();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiColorPicker::hideFast() {
|
|
|
|
clearSelection();
|
2019-04-02 13:13:30 +04:00
|
|
|
_a_opacity.stop();
|
2017-03-29 17:04:00 +03:00
|
|
|
_cache = QPixmap();
|
|
|
|
hide();
|
2018-11-21 22:14:48 +04:00
|
|
|
_hidden.fire({});
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<EmojiPtr> EmojiColorPicker::chosen() const {
|
|
|
|
return _chosen.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> EmojiColorPicker::hidden() const {
|
|
|
|
return _hidden.events();
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiColorPicker::hideAnimated() {
|
|
|
|
if (_cache.isNull()) {
|
2017-12-26 15:41:48 +03:00
|
|
|
_cache = Ui::GrabWidget(this);
|
2017-03-29 17:04:00 +03:00
|
|
|
clearSelection();
|
|
|
|
}
|
|
|
|
_hiding = true;
|
|
|
|
_a_opacity.start([this] { animationCallback(); }, 1., 0., st::emojiPanDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiColorPicker::showAnimated() {
|
|
|
|
if (_ignoreShow) return;
|
|
|
|
|
|
|
|
if (!isHidden() && !_hiding) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_hiding = false;
|
|
|
|
if (_cache.isNull()) {
|
2017-12-26 15:41:48 +03:00
|
|
|
_cache = Ui::GrabWidget(this);
|
2017-03-29 17:04:00 +03:00
|
|
|
clearSelection();
|
|
|
|
}
|
|
|
|
show();
|
|
|
|
_a_opacity.start([this] { animationCallback(); }, 0., 1., st::emojiPanDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiColorPicker::clearSelection() {
|
|
|
|
_pressedSel = -1;
|
|
|
|
setSelected(-1);
|
|
|
|
_lastMousePos = mapToGlobal(QPoint(-10, -10));
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiColorPicker::updateSelected() {
|
|
|
|
auto newSelected = -1;
|
|
|
|
auto p = mapFromGlobal(_lastMousePos);
|
|
|
|
auto sx = rtl() ? (width() - p.x()) : p.x(), y = p.y() - st::emojiPanMargins.top() - st::emojiColorsPadding;
|
2017-11-12 13:54:18 +04:00
|
|
|
if (y >= 0 && y < _singleSize.height()) {
|
2017-03-29 17:04:00 +03:00
|
|
|
auto x = sx - st::emojiPanMargins.left() - st::emojiColorsPadding;
|
2017-11-12 13:54:18 +04:00
|
|
|
if (x >= 0 && x < _singleSize.width()) {
|
2017-03-29 17:04:00 +03:00
|
|
|
newSelected = 0;
|
|
|
|
} else {
|
2017-11-12 13:54:18 +04:00
|
|
|
x -= _singleSize.width() + 2 * st::emojiColorsPadding + st::emojiColorsSep;
|
|
|
|
if (x >= 0 && x < _singleSize.width() * (_variants.size() - 1)) {
|
|
|
|
newSelected = (x / _singleSize.width()) + 1;
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setSelected(newSelected);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiColorPicker::setSelected(int newSelected) {
|
|
|
|
if (_selected == newSelected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto updateSelectedRect = [this] {
|
|
|
|
if (_selected < 0) return;
|
2017-11-12 13:54:18 +04:00
|
|
|
auto addedSkip = (_selected > 0)
|
|
|
|
? (2 * st::emojiColorsPadding + st::emojiColorsSep)
|
|
|
|
: 0;
|
|
|
|
auto left = st::emojiPanMargins.left()
|
|
|
|
+ st::emojiColorsPadding
|
|
|
|
+ _selected * _singleSize.width()
|
|
|
|
+ addedSkip;
|
|
|
|
rtlupdate(
|
|
|
|
left,
|
|
|
|
st::emojiPanMargins.top() + st::emojiColorsPadding,
|
|
|
|
_singleSize.width(),
|
|
|
|
_singleSize.height());
|
2017-03-29 17:04:00 +03:00
|
|
|
};
|
|
|
|
updateSelectedRect();
|
|
|
|
_selected = newSelected;
|
|
|
|
updateSelectedRect();
|
|
|
|
setCursor((_selected >= 0) ? style::cur_pointer : style::cur_default);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiColorPicker::drawVariant(Painter &p, int variant) {
|
2017-11-12 13:54:18 +04:00
|
|
|
QPoint w(st::emojiPanMargins.left() + st::emojiColorsPadding + variant * _singleSize.width() + (variant ? 2 * st::emojiColorsPadding + st::emojiColorsSep : 0), st::emojiPanMargins.top() + st::emojiColorsPadding);
|
2017-03-29 17:04:00 +03:00
|
|
|
if (variant == _selected) {
|
|
|
|
QPoint tl(w);
|
2017-11-12 13:54:18 +04:00
|
|
|
if (rtl()) tl.setX(width() - tl.x() - _singleSize.width());
|
|
|
|
App::roundRect(p, QRect(tl, _singleSize), st::emojiPanHover, StickerHoverCorners);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2018-10-13 20:35:30 +03:00
|
|
|
const auto esize = Ui::Emoji::GetSizeLarge();
|
|
|
|
Ui::Emoji::Draw(
|
|
|
|
p,
|
|
|
|
_variants[variant],
|
|
|
|
esize,
|
|
|
|
w.x() + (_singleSize.width() - (esize / cIntRetinaFactor())) / 2,
|
|
|
|
w.y() + (_singleSize.height() - (esize / cIntRetinaFactor())) / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
EmojiListWidget::EmojiListWidget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::Controller*> controller)
|
|
|
|
: Inner(parent, controller)
|
2018-11-21 22:14:48 +04:00
|
|
|
, _picker(this)
|
|
|
|
, _showPickerTimer([=] { showPicker(); }) {
|
2017-03-29 17:04:00 +03:00
|
|
|
setMouseTracking(true);
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
|
|
|
|
_picker->hide();
|
|
|
|
|
2018-10-13 20:35:30 +03:00
|
|
|
_esize = Ui::Emoji::GetSizeLarge();
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
for (auto i = 0; i != kEmojiSectionCount; ++i) {
|
2017-03-29 18:09:16 +03:00
|
|
|
_counts[i] = Ui::Emoji::GetSectionCount(static_cast<Section>(i));
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2018-11-21 22:14:48 +04:00
|
|
|
_picker->chosen(
|
|
|
|
) | rpl::start_with_next([=](EmojiPtr emoji) {
|
|
|
|
colorChosen(emoji);
|
|
|
|
}, lifetime());
|
|
|
|
_picker->hidden(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
pickerHidden();
|
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<EmojiPtr> EmojiListWidget::chosen() const {
|
|
|
|
return _chosen.events();
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2017-09-13 19:57:44 +03:00
|
|
|
void EmojiListWidget::visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) {
|
|
|
|
Inner::visibleTopBottomUpdated(visibleTop, visibleBottom);
|
2017-03-29 18:09:16 +03:00
|
|
|
if (_footer) {
|
|
|
|
_footer->setCurrentSectionIcon(currentSection(visibleTop));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-08 18:20:12 +03:00
|
|
|
object_ptr<TabbedSelector::InnerFooter> EmojiListWidget::createFooter() {
|
2017-03-29 18:09:16 +03:00
|
|
|
Expects(_footer == nullptr);
|
|
|
|
auto result = object_ptr<Footer>(this);
|
|
|
|
_footer = result;
|
|
|
|
return std::move(result);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Callback>
|
|
|
|
bool EmojiListWidget::enumerateSections(Callback callback) const {
|
2017-11-14 14:26:12 +04:00
|
|
|
Expects(_columnCount > 0);
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
auto info = SectionInfo();
|
|
|
|
for (auto i = 0; i != kEmojiSectionCount; ++i) {
|
|
|
|
info.section = i;
|
2017-04-01 17:08:56 +03:00
|
|
|
info.count = _counts[i];
|
2017-11-14 14:26:12 +04:00
|
|
|
info.rowsCount = (info.count / _columnCount) + ((info.count % _columnCount) ? 1 : 0);
|
2017-03-29 17:04:00 +03:00
|
|
|
info.rowsTop = info.top + (i == 0 ? st::emojiPanPadding : st::emojiPanHeader);
|
2017-11-12 13:54:18 +04:00
|
|
|
info.rowsBottom = info.rowsTop + info.rowsCount * _singleSize.height();
|
2017-03-29 17:04:00 +03:00
|
|
|
if (!callback(info)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
info.top = info.rowsBottom;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
EmojiListWidget::SectionInfo EmojiListWidget::sectionInfo(int section) const {
|
|
|
|
Expects(section >= 0 && section < kEmojiSectionCount);
|
|
|
|
auto result = SectionInfo();
|
|
|
|
enumerateSections([searchForSection = section, &result](const SectionInfo &info) {
|
|
|
|
if (info.section == searchForSection) {
|
|
|
|
result = info;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
EmojiListWidget::SectionInfo EmojiListWidget::sectionInfoByOffset(int yOffset) const {
|
|
|
|
auto result = SectionInfo();
|
|
|
|
enumerateSections([&result, yOffset](const SectionInfo &info) {
|
|
|
|
if (yOffset < info.rowsBottom || info.section == kEmojiSectionCount - 1) {
|
|
|
|
result = info;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-11-12 13:54:18 +04:00
|
|
|
int EmojiListWidget::countDesiredHeight(int newWidth) {
|
|
|
|
auto fullWidth = (st::buttonRadius + newWidth + st::emojiScroll.width);
|
2017-11-14 14:26:12 +04:00
|
|
|
_columnCount = std::max(
|
|
|
|
(fullWidth - st::emojiPadding * 2) / st::emojiPanDesiredSize,
|
|
|
|
1);
|
|
|
|
|
|
|
|
_rowsLeft = fullWidth / (_columnCount * 4 + 2);
|
2017-11-12 13:54:18 +04:00
|
|
|
auto rowsRight = std::max(_rowsLeft, st::emojiScroll.width);
|
|
|
|
auto singleWidth = (fullWidth - _rowsLeft - rowsRight)
|
2017-11-14 14:26:12 +04:00
|
|
|
/ _columnCount;
|
|
|
|
_rowsLeft -= st::buttonRadius;
|
2017-11-12 13:54:18 +04:00
|
|
|
_singleSize = QSize(singleWidth, singleWidth - 4 * st::lineWidth);
|
|
|
|
_picker->setSingleSize(_singleSize);
|
2017-03-29 18:09:16 +03:00
|
|
|
return sectionInfo(kEmojiSectionCount - 1).rowsBottom + st::emojiPanPadding;
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::ensureLoaded(int section) {
|
2017-03-29 18:09:16 +03:00
|
|
|
Expects(section >= 0 && section < kEmojiSectionCount);
|
2017-03-29 17:04:00 +03:00
|
|
|
if (!_emoji[section].isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-29 18:09:16 +03:00
|
|
|
_emoji[section] = Ui::Emoji::GetSection(static_cast<Section>(section));
|
2017-04-01 17:08:56 +03:00
|
|
|
_counts[section] = _emoji[section].size();
|
2017-03-29 18:09:16 +03:00
|
|
|
if (static_cast<Section>(section) == Section::Recent) {
|
2017-03-29 17:04:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (auto &emoji : _emoji[section]) {
|
|
|
|
if (emoji->hasVariants()) {
|
|
|
|
auto j = cEmojiVariants().constFind(emoji->nonColoredId());
|
|
|
|
if (j != cEmojiVariants().cend()) {
|
|
|
|
emoji = emoji->variant(j.value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
QRect r = e ? e->rect() : rect();
|
|
|
|
if (r != rect()) {
|
|
|
|
p.setClipRect(r);
|
|
|
|
}
|
|
|
|
p.fillRect(r, st::emojiPanBg);
|
|
|
|
|
2017-11-14 14:26:12 +04:00
|
|
|
auto fromColumn = floorclamp(r.x() - _rowsLeft, _singleSize.width(), 0, _columnCount);
|
|
|
|
auto toColumn = ceilclamp(r.x() + r.width() - _rowsLeft, _singleSize.width(), 0, _columnCount);
|
2017-03-29 17:04:00 +03:00
|
|
|
if (rtl()) {
|
|
|
|
qSwap(fromColumn, toColumn);
|
2017-11-14 14:26:12 +04:00
|
|
|
fromColumn = _columnCount - fromColumn;
|
|
|
|
toColumn = _columnCount - toColumn;
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
enumerateSections([this, &p, r, fromColumn, toColumn](const SectionInfo &info) {
|
|
|
|
if (r.top() >= info.rowsBottom) {
|
|
|
|
return true;
|
|
|
|
} else if (r.top() + r.height() <= info.top) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (info.section > 0 && r.top() < info.rowsTop) {
|
|
|
|
p.setFont(st::emojiPanHeaderFont);
|
|
|
|
p.setPen(st::emojiPanHeaderFg);
|
2018-09-11 15:50:40 +03:00
|
|
|
p.drawTextLeft(st::emojiPanHeaderLeft - st::buttonRadius, info.top + st::emojiPanHeaderTop, width(), lang(LangKey(lng_emoji_category1 + info.section - 1)));
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
if (r.top() + r.height() > info.rowsTop) {
|
|
|
|
ensureLoaded(info.section);
|
2017-11-12 13:54:18 +04:00
|
|
|
auto fromRow = floorclamp(r.y() - info.rowsTop, _singleSize.height(), 0, info.rowsCount);
|
|
|
|
auto toRow = ceilclamp(r.y() + r.height() - info.rowsTop, _singleSize.height(), 0, info.rowsCount);
|
2017-03-29 17:04:00 +03:00
|
|
|
for (auto i = fromRow; i < toRow; ++i) {
|
|
|
|
for (auto j = fromColumn; j < toColumn; ++j) {
|
2017-11-14 14:26:12 +04:00
|
|
|
auto index = i * _columnCount + j;
|
2017-03-29 17:04:00 +03:00
|
|
|
if (index >= info.count) break;
|
|
|
|
|
|
|
|
auto selected = (!_picker->isHidden() && info.section * MatrixRowShift + index == _pickerSel) || (info.section * MatrixRowShift + index == _selected);
|
|
|
|
|
2017-11-12 13:54:18 +04:00
|
|
|
auto w = QPoint(_rowsLeft + j * _singleSize.width(), info.rowsTop + i * _singleSize.height());
|
2017-03-29 17:04:00 +03:00
|
|
|
if (selected) {
|
|
|
|
auto tl = w;
|
2017-11-12 13:54:18 +04:00
|
|
|
if (rtl()) tl.setX(width() - tl.x() - _singleSize.width());
|
|
|
|
App::roundRect(p, QRect(tl, _singleSize), st::emojiPanHover, StickerHoverCorners);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
2018-10-13 20:35:30 +03:00
|
|
|
Ui::Emoji::Draw(
|
|
|
|
p,
|
|
|
|
_emoji[info.section][index],
|
|
|
|
_esize,
|
|
|
|
w.x() + (_singleSize.width() - (_esize / cIntRetinaFactor())) / 2,
|
|
|
|
w.y() + (_singleSize.height() - (_esize / cIntRetinaFactor())) / 2);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bool EmojiListWidget::checkPickerHide() {
|
|
|
|
if (!_picker->isHidden() && _pickerSel >= 0) {
|
|
|
|
_picker->hideAnimated();
|
|
|
|
_pickerSel = -1;
|
|
|
|
updateSelected();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::mousePressEvent(QMouseEvent *e) {
|
|
|
|
_lastMousePos = e->globalPos();
|
|
|
|
updateSelected();
|
|
|
|
if (checkPickerHide() || e->button() != Qt::LeftButton) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_pressedSel = _selected;
|
|
|
|
|
|
|
|
if (_selected >= 0) {
|
|
|
|
auto section = (_selected / MatrixRowShift);
|
|
|
|
auto sel = _selected % MatrixRowShift;
|
|
|
|
if (section < kEmojiSectionCount && sel < _emoji[section].size() && _emoji[section][sel]->hasVariants()) {
|
|
|
|
_pickerSel = _selected;
|
|
|
|
setCursor(style::cur_default);
|
|
|
|
if (!cEmojiVariants().contains(_emoji[section][sel]->nonColoredId())) {
|
2018-11-21 22:14:48 +04:00
|
|
|
showPicker();
|
2017-03-29 17:04:00 +03:00
|
|
|
} else {
|
2018-11-21 22:14:48 +04:00
|
|
|
_showPickerTimer.callOnce(500);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
int32 pressed = _pressedSel;
|
|
|
|
_pressedSel = -1;
|
|
|
|
|
|
|
|
_lastMousePos = e->globalPos();
|
|
|
|
if (!_picker->isHidden()) {
|
|
|
|
if (_picker->rect().contains(_picker->mapFromGlobal(_lastMousePos))) {
|
|
|
|
return _picker->handleMouseRelease(QCursor::pos());
|
|
|
|
} else if (_pickerSel >= 0) {
|
|
|
|
auto section = (_pickerSel / MatrixRowShift);
|
|
|
|
auto sel = _pickerSel % MatrixRowShift;
|
|
|
|
if (section < kEmojiSectionCount && sel < _emoji[section].size() && _emoji[section][sel]->hasVariants()) {
|
|
|
|
if (cEmojiVariants().contains(_emoji[section][sel]->nonColoredId())) {
|
|
|
|
_picker->hideAnimated();
|
|
|
|
_pickerSel = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateSelected();
|
|
|
|
|
|
|
|
if (_showPickerTimer.isActive()) {
|
2018-11-21 22:14:48 +04:00
|
|
|
_showPickerTimer.cancel();
|
2017-03-29 17:04:00 +03:00
|
|
|
_pickerSel = -1;
|
|
|
|
_picker->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_selected < 0 || _selected != pressed) return;
|
|
|
|
|
|
|
|
if (_selected >= kEmojiSectionCount * MatrixRowShift) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto section = (_selected / MatrixRowShift);
|
|
|
|
auto sel = _selected % MatrixRowShift;
|
|
|
|
if (sel < _emoji[section].size()) {
|
|
|
|
auto emoji = _emoji[section][sel];
|
|
|
|
if (emoji->hasVariants() && !_picker->isHidden()) return;
|
|
|
|
|
|
|
|
selectEmoji(emoji);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::selectEmoji(EmojiPtr emoji) {
|
2017-07-25 21:16:37 +03:00
|
|
|
Ui::Emoji::AddRecent(emoji);
|
2018-11-21 22:14:48 +04:00
|
|
|
_chosen.fire_copy(emoji);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2018-11-21 22:14:48 +04:00
|
|
|
void EmojiListWidget::showPicker() {
|
2017-03-29 17:04:00 +03:00
|
|
|
if (_pickerSel < 0) return;
|
|
|
|
|
|
|
|
auto section = (_pickerSel / MatrixRowShift);
|
|
|
|
auto sel = _pickerSel % MatrixRowShift;
|
|
|
|
if (section < kEmojiSectionCount && sel < _emoji[section].size() && _emoji[section][sel]->hasVariants()) {
|
|
|
|
_picker->showEmoji(_emoji[section][sel]);
|
|
|
|
|
|
|
|
auto y = emojiRect(section, sel).y();
|
|
|
|
y -= _picker->height() - st::buttonRadius + getVisibleTop();
|
|
|
|
if (y < st::emojiPanHeader) {
|
2017-11-12 13:54:18 +04:00
|
|
|
y += _picker->height() - st::buttonRadius + _singleSize.height() - st::buttonRadius;
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
auto xmax = width() - _picker->width();
|
2017-11-14 14:26:12 +04:00
|
|
|
auto coef = float64(sel % _columnCount) / float64(_columnCount - 1);
|
2017-03-29 17:04:00 +03:00
|
|
|
if (rtl()) coef = 1. - coef;
|
|
|
|
_picker->move(qRound(xmax * coef), y);
|
|
|
|
|
|
|
|
emit disableScroll(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-21 22:14:48 +04:00
|
|
|
void EmojiListWidget::pickerHidden() {
|
2017-03-29 17:04:00 +03:00
|
|
|
_pickerSel = -1;
|
|
|
|
update();
|
|
|
|
emit disableScroll(false);
|
|
|
|
|
|
|
|
_lastMousePos = QCursor::pos();
|
|
|
|
updateSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect EmojiListWidget::emojiRect(int section, int sel) {
|
2017-11-14 14:26:12 +04:00
|
|
|
Expects(_columnCount > 0);
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
auto info = sectionInfo(section);
|
2017-11-14 14:26:12 +04:00
|
|
|
auto countTillItem = (sel - (sel % _columnCount));
|
|
|
|
auto rowsToSkip = (countTillItem / _columnCount) + ((countTillItem % _columnCount) ? 1 : 0);
|
|
|
|
auto x = _rowsLeft + ((sel % _columnCount) * _singleSize.width());
|
2017-11-12 13:54:18 +04:00
|
|
|
auto y = info.rowsTop + rowsToSkip * _singleSize.height();
|
|
|
|
return QRect(x, y, _singleSize.width(), _singleSize.height());
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2018-11-21 22:14:48 +04:00
|
|
|
void EmojiListWidget::colorChosen(EmojiPtr emoji) {
|
2017-03-29 17:04:00 +03:00
|
|
|
if (emoji->hasVariants()) {
|
2018-06-04 21:34:18 +03:00
|
|
|
cRefEmojiVariants().insert(
|
|
|
|
emoji->nonColoredId(),
|
|
|
|
emoji->variantIndex(emoji));
|
|
|
|
Auth().saveSettingsDelayed();
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
if (_pickerSel >= 0) {
|
|
|
|
auto section = (_pickerSel / MatrixRowShift);
|
|
|
|
auto sel = _pickerSel % MatrixRowShift;
|
|
|
|
if (section >= 0 && section < kEmojiSectionCount) {
|
|
|
|
_emoji[section][sel] = emoji;
|
|
|
|
rtlupdate(emojiRect(section, sel));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
selectEmoji(emoji);
|
|
|
|
_picker->hideAnimated();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
_lastMousePos = e->globalPos();
|
|
|
|
if (!_picker->isHidden()) {
|
|
|
|
if (_picker->rect().contains(_picker->mapFromGlobal(_lastMousePos))) {
|
|
|
|
return _picker->handleMouseMove(QCursor::pos());
|
|
|
|
} else {
|
|
|
|
_picker->clearSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::leaveEventHook(QEvent *e) {
|
|
|
|
clearSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::leaveToChildEvent(QEvent *e, QWidget *child) {
|
|
|
|
clearSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::enterFromChildEvent(QEvent *e, QWidget *child) {
|
|
|
|
_lastMousePos = QCursor::pos();
|
|
|
|
updateSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::clearSelection() {
|
|
|
|
_lastMousePos = mapToGlobal(QPoint(-10, -10));
|
|
|
|
_pressedSel = -1;
|
|
|
|
setSelected(-1);
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
Ui::Emoji::Section EmojiListWidget::currentSection(int yOffset) const {
|
|
|
|
return static_cast<Section>(sectionInfoByOffset(yOffset).section);
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:50:00 +02:00
|
|
|
QString EmojiListWidget::tooltipText() const {
|
|
|
|
const auto &replacements = Ui::Emoji::internal::GetAllReplacements();
|
|
|
|
const auto section = (_selected / MatrixRowShift);
|
|
|
|
const auto sel = _selected % MatrixRowShift;
|
|
|
|
if (_selected >= 0 && section < kEmojiSectionCount && sel < _emoji[section].size()) {
|
2018-10-09 13:33:05 +03:00
|
|
|
const auto emoji = _emoji[section][sel]->original();
|
2018-08-02 17:50:00 +02:00
|
|
|
const auto text = emoji->text();
|
|
|
|
// find the replacement belonging to the emoji
|
2018-10-09 13:33:05 +03:00
|
|
|
const auto it = ranges::find_if(replacements, [&](const auto &one) {
|
2018-08-02 17:50:00 +02:00
|
|
|
return text == Ui::Emoji::QStringFromUTF16(one.emoji);
|
|
|
|
});
|
|
|
|
if (it != replacements.end()) {
|
|
|
|
return Ui::Emoji::QStringFromUTF16(it->replacement);
|
|
|
|
}
|
|
|
|
}
|
2018-10-09 13:33:05 +03:00
|
|
|
return {};
|
2018-08-02 17:50:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QPoint EmojiListWidget::tooltipPos() const {
|
|
|
|
return _lastMousePos;
|
|
|
|
}
|
|
|
|
|
2017-04-08 18:20:12 +03:00
|
|
|
TabbedSelector::InnerFooter *EmojiListWidget::getFooter() const {
|
2017-03-29 18:09:16 +03:00
|
|
|
return _footer;
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
void EmojiListWidget::processHideFinished() {
|
2017-03-29 17:04:00 +03:00
|
|
|
if (!_picker->isHidden()) {
|
|
|
|
_picker->hideFast();
|
|
|
|
_pickerSel = -1;
|
|
|
|
}
|
|
|
|
clearSelection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::refreshRecent() {
|
|
|
|
clearSelection();
|
2017-03-29 18:09:16 +03:00
|
|
|
_emoji[0] = Ui::Emoji::GetSection(Section::Recent);
|
2017-04-01 17:08:56 +03:00
|
|
|
_counts[0] = _emoji[0].size();
|
2017-11-12 13:54:18 +04:00
|
|
|
resizeToWidth(width());
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
2017-11-05 21:07:27 +04:00
|
|
|
bool EmojiListWidget::eventHook(QEvent *e) {
|
2017-03-29 17:04:00 +03:00
|
|
|
if (e->type() == QEvent::ParentChange) {
|
|
|
|
if (_picker->parentWidget() != parentWidget()) {
|
|
|
|
_picker->setParent(parentWidget());
|
|
|
|
}
|
|
|
|
_picker->raise();
|
|
|
|
}
|
2017-11-05 21:07:27 +04:00
|
|
|
return Inner::eventHook(e);
|
2017-03-29 17:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::updateSelected() {
|
|
|
|
if (_pressedSel >= 0 || _pickerSel >= 0) return;
|
|
|
|
|
|
|
|
auto newSelected = -1;
|
|
|
|
auto p = mapFromGlobal(_lastMousePos);
|
|
|
|
auto info = sectionInfoByOffset(p.y());
|
|
|
|
if (p.y() >= info.rowsTop && p.y() < info.rowsBottom) {
|
2017-11-12 13:54:18 +04:00
|
|
|
auto sx = (rtl() ? width() - p.x() : p.x()) - _rowsLeft;
|
2017-11-14 14:26:12 +04:00
|
|
|
if (sx >= 0 && sx < _columnCount * _singleSize.width()) {
|
|
|
|
newSelected = qFloor((p.y() - info.rowsTop) / _singleSize.height()) * _columnCount + qFloor(sx / _singleSize.width());
|
2017-03-29 17:04:00 +03:00
|
|
|
if (newSelected >= _emoji[info.section].size()) {
|
|
|
|
newSelected = -1;
|
|
|
|
} else {
|
|
|
|
newSelected += info.section * MatrixRowShift;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setSelected(newSelected);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EmojiListWidget::setSelected(int newSelected) {
|
|
|
|
if (_selected == newSelected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto updateSelected = [this]() {
|
|
|
|
if (_selected < 0) return;
|
|
|
|
rtlupdate(emojiRect(_selected / MatrixRowShift, _selected % MatrixRowShift));
|
|
|
|
};
|
|
|
|
updateSelected();
|
|
|
|
_selected = newSelected;
|
|
|
|
updateSelected();
|
|
|
|
|
2018-08-02 17:50:00 +02:00
|
|
|
if (_selected >= 0 && Global::SuggestEmoji()) {
|
|
|
|
Ui::Tooltip::Show(1000, this);
|
|
|
|
}
|
|
|
|
|
2017-03-29 17:04:00 +03:00
|
|
|
setCursor((_selected >= 0) ? style::cur_pointer : style::cur_default);
|
|
|
|
if (_selected >= 0 && !_picker->isHidden()) {
|
|
|
|
if (_selected != _pickerSel) {
|
|
|
|
_picker->hideAnimated();
|
|
|
|
} else {
|
|
|
|
_picker->showAnimated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-29 18:09:16 +03:00
|
|
|
void EmojiListWidget::showEmojiSection(Section section) {
|
2017-03-29 17:04:00 +03:00
|
|
|
clearSelection();
|
|
|
|
|
|
|
|
refreshRecent();
|
|
|
|
|
|
|
|
auto y = 0;
|
|
|
|
enumerateSections([&y, sectionForSearch = section](const SectionInfo &info) {
|
2017-03-29 18:09:16 +03:00
|
|
|
if (static_cast<Section>(info.section) == sectionForSearch) {
|
2017-03-29 17:04:00 +03:00
|
|
|
y = info.top;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2018-11-21 22:14:48 +04:00
|
|
|
scrollTo(y);
|
2017-03-29 17:04:00 +03:00
|
|
|
|
|
|
|
_lastMousePos = QCursor::pos();
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ChatHelpers
|