Fix right-clicking of emotes

There are a few more actions that we might want to add at a later date,
      but a simple feature set has been implemented

Fix #386
This commit is contained in:
Rasmus Karlsson 2018-05-16 03:55:56 +02:00
parent 454b6bcb70
commit 64160e60af
4 changed files with 68 additions and 4 deletions

View file

@ -169,7 +169,6 @@ public:
// b) which size it wants // b) which size it wants
class EmoteElement : public MessageElement class EmoteElement : public MessageElement
{ {
const util::EmoteData data;
std::unique_ptr<TextElement> textElement; std::unique_ptr<TextElement> textElement;
public: public:
@ -177,6 +176,8 @@ public:
~EmoteElement() override = default; ~EmoteElement() override = default;
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) override; void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) override;
const util::EmoteData data;
}; };
// contains a text, formated depending on the preferences // contains a text, formated depending on the preferences

View file

@ -135,8 +135,12 @@ void EmoteManager::reloadBTTVChannelEmotes(const QString &channelName,
link = link.replace("{{id}}", id).replace("{{image}}", "1x"); link = link.replace("{{id}}", id).replace("{{image}}", "1x");
auto emote = this->getBTTVChannelEmoteFromCaches().getOrAdd(id, [&code, &link] { auto emote = this->getBTTVChannelEmoteFromCaches().getOrAdd(id, [&id, &code, &link] {
return util::EmoteData(new Image(link, 1, code, code + "<br/>Channel BTTV Emote")); util::EmoteData emoteData(
new Image(link, 1, code, code + "<br/>Channel BTTV Emote"));
emoteData.pageLink = "https://manage.betterttv.net/emotes/" + id;
return emoteData;
}); });
this->bttvChannelEmotes.insert(code, emote); this->bttvChannelEmotes.insert(code, emote);
@ -182,9 +186,11 @@ void EmoteManager::reloadFFZChannelEmotes(const QString &channelName,
QJsonObject urls = emoteObject.value("urls").toObject(); QJsonObject urls = emoteObject.value("urls").toObject();
auto emote = this->getFFZChannelEmoteFromCaches().getOrAdd(id, [&code, &urls] { auto emote = this->getFFZChannelEmoteFromCaches().getOrAdd(id, [id, &code, &urls] {
util::EmoteData emoteData; util::EmoteData emoteData;
FillInFFZEmoteData(urls, code, code + "<br/>Channel FFZ Emote", emoteData); FillInFFZEmoteData(urls, code, code + "<br/>Channel FFZ Emote", emoteData);
emoteData.pageLink =
QString("https://www.frankerfacez.com/emoticon/%1-%2").arg(id).arg(code);
return emoteData; return emoteData;
}); });
@ -483,6 +489,7 @@ void EmoteManager::loadBTTVEmotes()
code + "<br />Global BTTV Emote"); code + "<br />Global BTTV Emote");
emoteData.image3x = new Image(GetBTTVEmoteLink(urlTemplate, id, "3x"), 0.25, code, emoteData.image3x = new Image(GetBTTVEmoteLink(urlTemplate, id, "3x"), 0.25, code,
code + "<br />Global BTTV Emote"); code + "<br />Global BTTV Emote");
emoteData.pageLink = "https://manage.betterttv.net/emotes/" + id;
this->bttvGlobalEmotes.insert(code, emoteData); this->bttvGlobalEmotes.insert(code, emoteData);
codes.push_back(code.toStdString()); codes.push_back(code.toStdString());
@ -510,10 +517,13 @@ void EmoteManager::loadFFZEmotes()
QJsonObject object = emote.toObject(); QJsonObject object = emote.toObject();
QString code = object.value("name").toString(); QString code = object.value("name").toString();
int id = object.value("id").toInt();
QJsonObject urls = object.value("urls").toObject(); QJsonObject urls = object.value("urls").toObject();
util::EmoteData emoteData; util::EmoteData emoteData;
FillInFFZEmoteData(urls, code, code + "<br/>Global FFZ Emote", emoteData); FillInFFZEmoteData(urls, code, code + "<br/>Global FFZ Emote", emoteData);
emoteData.pageLink =
QString("https://www.frankerfacez.com/emoticon/%1-%2").arg(id).arg(code);
this->ffzGlobalEmotes.insert(code, emoteData); this->ffzGlobalEmotes.insert(code, emoteData);
codes.push_back(code.toStdString()); codes.push_back(code.toStdString());

View file

@ -23,6 +23,9 @@ struct EmoteData {
messages::Image *image1x = nullptr; messages::Image *image1x = nullptr;
messages::Image *image2x = nullptr; messages::Image *image2x = nullptr;
messages::Image *image3x = nullptr; messages::Image *image3x = nullptr;
// Link to the emote page i.e. https://www.frankerfacez.com/emoticon/144722-pajaCringe
QString pageLink;
}; };
using EmoteMap = ConcurrentMap<QString, EmoteData>; using EmoteMap = ConcurrentMap<QString, EmoteData>;

View file

@ -883,6 +883,56 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
return; return;
} }
const auto &creator = hoverLayoutElement->getCreator();
auto creatorFlags = creator.getFlags();
if ((creatorFlags & (MessageElement::Flags::EmoteImages | MessageElement::Flags::EmojiImage)) !=
0) {
if (event->button() == Qt::RightButton) {
static QMenu *menu = new QMenu;
menu->clear();
const auto &emoteElement = static_cast<const messages::EmoteElement &>(creator);
// TODO: We might want to add direct "Open image" variants alongside the Copy actions
if (emoteElement.data.image1x != nullptr) {
menu->addAction("Copy 1x link", [url = emoteElement.data.image1x->getUrl()] {
QApplication::clipboard()->setText(url); //
});
}
if (emoteElement.data.image2x != nullptr) {
menu->addAction("Copy 2x link", [url = emoteElement.data.image2x->getUrl()] {
QApplication::clipboard()->setText(url); //
});
}
if (emoteElement.data.image3x != nullptr) {
menu->addAction("Copy 3x link", [url = emoteElement.data.image3x->getUrl()] {
QApplication::clipboard()->setText(url); //
});
}
if ((creatorFlags & MessageElement::Flags::BttvEmote) != 0) {
menu->addSeparator();
QString emotePageLink = emoteElement.data.pageLink;
menu->addAction("Copy BTTV emote link", [emotePageLink] {
QApplication::clipboard()->setText(emotePageLink); //
});
} else if ((creatorFlags & MessageElement::Flags::FfzEmote) != 0) {
menu->addSeparator();
QString emotePageLink = emoteElement.data.pageLink;
menu->addAction("Copy FFZ emote link", [emotePageLink] {
QApplication::clipboard()->setText(emotePageLink); //
});
}
menu->move(QCursor::pos());
menu->show();
return;
}
}
auto &link = hoverLayoutElement->getLink(); auto &link = hoverLayoutElement->getLink();
if (event->button() != Qt::LeftButton || !app->settings->linksDoubleClickOnly) { if (event->button() != Qt::LeftButton || !app->settings->linksDoubleClickOnly) {
this->handleLinkClick(event, link, layout.get()); this->handleLinkClick(event, link, layout.get());