mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
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:
parent
454b6bcb70
commit
64160e60af
4 changed files with 68 additions and 4 deletions
|
@ -169,7 +169,6 @@ public:
|
|||
// b) which size it wants
|
||||
class EmoteElement : public MessageElement
|
||||
{
|
||||
const util::EmoteData data;
|
||||
std::unique_ptr<TextElement> textElement;
|
||||
|
||||
public:
|
||||
|
@ -177,6 +176,8 @@ public:
|
|||
~EmoteElement() override = default;
|
||||
|
||||
void addToContainer(MessageLayoutContainer &container, MessageElement::Flags flags) override;
|
||||
|
||||
const util::EmoteData data;
|
||||
};
|
||||
|
||||
// contains a text, formated depending on the preferences
|
||||
|
|
|
@ -135,8 +135,12 @@ void EmoteManager::reloadBTTVChannelEmotes(const QString &channelName,
|
|||
|
||||
link = link.replace("{{id}}", id).replace("{{image}}", "1x");
|
||||
|
||||
auto emote = this->getBTTVChannelEmoteFromCaches().getOrAdd(id, [&code, &link] {
|
||||
return util::EmoteData(new Image(link, 1, code, code + "<br/>Channel BTTV Emote"));
|
||||
auto emote = this->getBTTVChannelEmoteFromCaches().getOrAdd(id, [&id, &code, &link] {
|
||||
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);
|
||||
|
@ -182,9 +186,11 @@ void EmoteManager::reloadFFZChannelEmotes(const QString &channelName,
|
|||
|
||||
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;
|
||||
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;
|
||||
});
|
||||
|
@ -483,6 +489,7 @@ void EmoteManager::loadBTTVEmotes()
|
|||
code + "<br />Global BTTV Emote");
|
||||
emoteData.image3x = new Image(GetBTTVEmoteLink(urlTemplate, id, "3x"), 0.25, code,
|
||||
code + "<br />Global BTTV Emote");
|
||||
emoteData.pageLink = "https://manage.betterttv.net/emotes/" + id;
|
||||
|
||||
this->bttvGlobalEmotes.insert(code, emoteData);
|
||||
codes.push_back(code.toStdString());
|
||||
|
@ -510,10 +517,13 @@ void EmoteManager::loadFFZEmotes()
|
|||
QJsonObject object = emote.toObject();
|
||||
|
||||
QString code = object.value("name").toString();
|
||||
int id = object.value("id").toInt();
|
||||
QJsonObject urls = object.value("urls").toObject();
|
||||
|
||||
util::EmoteData 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);
|
||||
codes.push_back(code.toStdString());
|
||||
|
|
|
@ -23,6 +23,9 @@ struct EmoteData {
|
|||
messages::Image *image1x = nullptr;
|
||||
messages::Image *image2x = 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>;
|
||||
|
|
|
@ -883,6 +883,56 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
|||
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();
|
||||
if (event->button() != Qt::LeftButton || !app->settings->linksDoubleClickOnly) {
|
||||
this->handleLinkClick(event, link, layout.get());
|
||||
|
|
Loading…
Reference in a new issue