From 1947d8e5bef39229801cb2a59ad228bf23abc66d Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 6 Apr 2016 16:02:00 +0400 Subject: [PATCH] Click on sticker now opens sticker pack, if the sticker is from pack. --- Telegram/SourceFiles/history.cpp | 36 ++++++++++++++++++++++++++ Telegram/SourceFiles/history.h | 1 + Telegram/SourceFiles/historywidget.cpp | 19 ++++++++------ 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index 940b3990d..a00ac63b0 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -5138,6 +5138,33 @@ bool HistoryGif::dataLoaded() const { return (!_parent || _parent->id > 0) ? _data->loaded() : false; } +namespace { + +class StickerClickHandler : public LeftButtonClickHandler { +public: + StickerClickHandler(const HistoryItem *item) : _item(item) { + } + +protected: + void onClickImpl() const override { + if (HistoryMedia *media = _item->getMedia()) { + if (DocumentData *document = media->getDocument()) { + if (StickerData *sticker = document->sticker()) { + if (sticker->set.type() != mtpc_inputStickerSetEmpty && App::main()) { + App::main()->stickersBox(sticker->set); + } + } + } + } + } + +private: + const HistoryItem *_item; + +}; + +} // namespace + HistorySticker::HistorySticker(DocumentData *document) : HistoryMedia() , _pixw(1) , _pixh(1) @@ -5150,6 +5177,9 @@ HistorySticker::HistorySticker(DocumentData *document) : HistoryMedia() } void HistorySticker::initDimensions(const HistoryItem *parent) { + if (!_packLink && _data->sticker() && _data->sticker()->set.type() != mtpc_inputStickerSetEmpty) { + _packLink = ClickHandlerPtr(new StickerClickHandler(parent)); + } _pixw = _data->dimensions.width(); _pixh = _data->dimensions.height(); if (_pixw > st::maxStickerSize) { @@ -5262,6 +5292,12 @@ void HistorySticker::getState(ClickHandlerPtr &lnk, HistoryCursorState &state, i state = HistoryInDateCursorState; } } + + int pixLeft = usex + (usew - _pixw) / 2, pixTop = (_minh - _pixh) / 2; + if (x >= pixLeft && x < pixLeft + _pixw && y >= pixTop && y < pixTop + _pixh) { + lnk = _packLink; + return; + } } const QString HistorySticker::inDialogsText() const { diff --git a/Telegram/SourceFiles/history.h b/Telegram/SourceFiles/history.h index 2a41230cc..c90fcc9f3 100644 --- a/Telegram/SourceFiles/history.h +++ b/Telegram/SourceFiles/history.h @@ -2485,6 +2485,7 @@ public: private: int16 _pixw, _pixh; + ClickHandlerPtr _packLink; DocumentData *_data; QString _emoji; diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index b1619a2e7..f76585098 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -1020,7 +1020,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _menu->addAction(lang(ispinned ? lng_context_unpin_msg : lng_context_pin_msg), _widget, ispinned ? SLOT(onUnpinMessage()) : SLOT(onPinMessage())); } } - if (item && !isUponSelected && !_contextMenuLnk) { + if (item && !isUponSelected) { if (HistoryMedia *media = (msg ? msg->getMedia() : 0)) { if (media->type() == MediaTypeWebPage && static_cast(media)->attach()) { media = static_cast(media)->attach(); @@ -1032,7 +1032,7 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { } _menu->addAction(lang(lng_context_save_image), this, SLOT(saveContextFile()))->setEnabled(true); - } else if (media->type() == MediaTypeGif) { + } else if (media->type() == MediaTypeGif && !_contextMenuLnk) { DocumentData *doc = media->getDocument(); if (doc) { if (doc->loading()) { @@ -7287,11 +7287,14 @@ void HistoryWidget::onFieldBarCancel() { } void HistoryWidget::onStickerPackInfo() { - if (HistoryMedia *media = (App::contextItem() ? App::contextItem()->getMedia() : 0)) { - if (media->type() == MediaTypeSticker) { - DocumentData *doc = media->getDocument(); - if (doc && doc->sticker() && doc->sticker()->set.type() != mtpc_inputStickerSetEmpty) { - App::main()->stickersBox(doc->sticker()->set); + if (!App::contextItem()) return; + + if (HistoryMedia *media = App::contextItem()->getMedia()) { + if (DocumentData *doc = media->getDocument()) { + if (StickerData *sticker = doc->sticker()) { + if (sticker->set.type() != mtpc_inputStickerSetEmpty) { + App::main()->stickersBox(sticker->set); + } } } } @@ -7300,7 +7303,7 @@ void HistoryWidget::onStickerPackInfo() { void HistoryWidget::previewCancel() { MTP::cancel(_previewRequest); _previewRequest = 0; - _previewData = 0; + _previewData = nullptr; _previewLinks.clear(); updatePreview(); if (!_editMsgId && !_replyToId && !readyToForward() && !_kbReplyTo) {