Click on sticker now opens sticker pack, if the sticker is from pack.

This commit is contained in:
John Preston 2016-04-06 16:02:00 +04:00
parent 259a996276
commit 1947d8e5be
3 changed files with 48 additions and 8 deletions

View File

@ -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 {

View File

@ -2485,6 +2485,7 @@ public:
private:
int16 _pixw, _pixh;
ClickHandlerPtr _packLink;
DocumentData *_data;
QString _emoji;

View File

@ -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<HistoryWebPage*>(media)->attach()) {
media = static_cast<HistoryWebPage*>(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) {