mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
feat: add custom emoji preview support
This commit is contained in:
parent
31d486c2e2
commit
bfeb225bc2
2 changed files with 47 additions and 2 deletions
|
@ -48,6 +48,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "styles/style_chat_helpers.h"
|
#include "styles/style_chat_helpers.h"
|
||||||
#include "styles/style_menu_icons.h"
|
#include "styles/style_menu_icons.h"
|
||||||
|
|
||||||
|
// AyuGram includes
|
||||||
|
#include "data/data_file_origin.h"
|
||||||
|
#include "qapplication.h"
|
||||||
|
|
||||||
|
|
||||||
namespace ChatHelpers {
|
namespace ChatHelpers {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -473,7 +478,8 @@ EmojiListWidget::EmojiListWidget(
|
||||||
, _overBg(st::emojiPanRadius, st().overBg)
|
, _overBg(st::emojiPanRadius, st().overBg)
|
||||||
, _collapsedBg(st::emojiPanExpand.height / 2, st().headerFg)
|
, _collapsedBg(st::emojiPanExpand.height / 2, st().headerFg)
|
||||||
, _picker(this, st())
|
, _picker(this, st())
|
||||||
, _showPickerTimer([=] { showPicker(); }) {
|
, _showPickerTimer([=] { showPicker(); })
|
||||||
|
, _previewTimer([=] { showPreview(); }) {
|
||||||
setMouseTracking(true);
|
setMouseTracking(true);
|
||||||
if (st().bg->c.alpha() > 0) {
|
if (st().bg->c.alpha() > 0) {
|
||||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||||
|
@ -1585,11 +1591,20 @@ void EmojiListWidget::mousePressEvent(QMouseEvent *e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_previewTimer.callOnce(QApplication::startDragTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmojiListWidget::mouseReleaseEvent(QMouseEvent *e) {
|
void EmojiListWidget::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
|
_previewTimer.cancel();
|
||||||
|
|
||||||
auto pressed = _pressed;
|
auto pressed = _pressed;
|
||||||
setPressed(v::null);
|
setPressed(v::null);
|
||||||
|
if (_previewShown) {
|
||||||
|
_previewShown = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_lastMousePos = e->globalPos();
|
_lastMousePos = e->globalPos();
|
||||||
if (!_picker->isHidden()) {
|
if (!_picker->isHidden()) {
|
||||||
if (_picker->rect().contains(_picker->mapFromGlobal(_lastMousePos))) {
|
if (_picker->rect().contains(_picker->mapFromGlobal(_lastMousePos))) {
|
||||||
|
@ -2327,7 +2342,7 @@ bool EmojiListWidget::eventHook(QEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmojiListWidget::updateSelected() {
|
void EmojiListWidget::updateSelected() {
|
||||||
if (!v::is_null(_pressed) || !v::is_null(_pickerSelected)) {
|
if ((!v::is_null(_pressed) || !v::is_null(_pickerSelected)) && !_previewShown) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2388,6 +2403,31 @@ void EmojiListWidget::setSelected(OverState newSelected) {
|
||||||
_picker->showAnimated();
|
_picker->showAnimated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_previewShown && _pressed != _selected) {
|
||||||
|
if (const auto over = std::get_if<OverEmoji>(&_selected)) {
|
||||||
|
_pressed = _selected;
|
||||||
|
|
||||||
|
const auto section = over ? over->section : -1;
|
||||||
|
const auto index = over ? over->index : -1;
|
||||||
|
|
||||||
|
if (const auto document = lookupCustomEmoji(index, section)) {
|
||||||
|
_show->showMediaPreview(document->stickerSetOrigin(), document);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmojiListWidget::showPreview() {
|
||||||
|
if (const auto over = std::get_if<OverEmoji>(&_selected)) {
|
||||||
|
const auto section = over ? over->section : -1;
|
||||||
|
const auto index = over ? over->index : -1;
|
||||||
|
|
||||||
|
if (const auto document = lookupCustomEmoji(index, section)) {
|
||||||
|
_show->showMediaPreview(document->stickerSetOrigin(), document);
|
||||||
|
_previewShown = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmojiListWidget::setPressed(OverState newPressed) {
|
void EmojiListWidget::setPressed(OverState newPressed) {
|
||||||
|
|
|
@ -364,6 +364,8 @@ private:
|
||||||
|
|
||||||
void applyNextSearchQuery();
|
void applyNextSearchQuery();
|
||||||
|
|
||||||
|
void showPreview();
|
||||||
|
|
||||||
const std::shared_ptr<Show> _show;
|
const std::shared_ptr<Show> _show;
|
||||||
const ComposeFeatures _features;
|
const ComposeFeatures _features;
|
||||||
Mode _mode = Mode::Full;
|
Mode _mode = Mode::Full;
|
||||||
|
@ -433,6 +435,9 @@ private:
|
||||||
rpl::event_stream<FileChosen> _customChosen;
|
rpl::event_stream<FileChosen> _customChosen;
|
||||||
rpl::event_stream<> _jumpedToPremium;
|
rpl::event_stream<> _jumpedToPremium;
|
||||||
|
|
||||||
|
base::Timer _previewTimer;
|
||||||
|
bool _previewShown = false;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
tr::phrase<> EmojiCategoryTitle(int index);
|
tr::phrase<> EmojiCategoryTitle(int index);
|
||||||
|
|
Loading…
Add table
Reference in a new issue