diff --git a/CHANGELOG.md b/CHANGELOG.md index cf2f27245..8227a15d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unversioned - Major: We now support image thumbnails coming from the link resolver. This feature is off by default and can be enabled in the settings with the "Show link thumbnail" setting. This feature also requires the "Show link info when hovering" setting to be enabled (#1664) - Major: Added image upload functionality to i.nuuls.com. This works by dragging and dropping an image into a split, or pasting an image into the text edit field. (#1332) +- Minor: You can now open the Twitch User Card by middle-mouse clicking a username. (#1669) - Minor: Emotes in the emote popup are now sorted in the same order as the tab completion (#1549) - Minor: Removed "Online Logs" functionality as services are shut down (#1640) - Bugfix: Fix preview on hover not working when Animated emotes options was disabled (#1546) diff --git a/chatterino.pro b/chatterino.pro index 883089dab..da773884b 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -217,6 +217,7 @@ SOURCES += \ src/util/JsonQuery.cpp \ src/util/RapidjsonHelpers.cpp \ src/util/StreamLink.cpp \ + src/util/Twitch.cpp \ src/util/NuulsUploader.cpp \ src/util/WindowsHelper.cpp \ src/widgets/AccountSwitchPopup.cpp \ @@ -429,6 +430,7 @@ HEADERS += \ src/util/PostToThread.hpp \ src/util/QObjectRef.hpp \ src/util/QStringHash.hpp \ + src/util/Twitch.hpp \ src/util/rangealgorithm.hpp \ src/util/RapidjsonHelpers.hpp \ src/util/RapidJsonSerializeQString.hpp \ diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index f44be76c1..748f6318b 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -16,6 +16,7 @@ #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" #include "util/CombinePath.hpp" +#include "util/Twitch.hpp" #include "widgets/dialogs/UserInfoPopup.hpp" #include @@ -437,8 +438,8 @@ QString CommandController::execCommand(const QString &textNoEmoji, channelName.remove(0, 1); } } - QDesktopServices::openUrl("https://www.twitch.tv/popout/" + - channelName + "/viewercard/" + words[1]); + openTwitchUsercard(channelName, words[1]); + return ""; } else if (commandName == "/usercard") diff --git a/src/util/Twitch.cpp b/src/util/Twitch.cpp new file mode 100644 index 000000000..ca1cf62c0 --- /dev/null +++ b/src/util/Twitch.cpp @@ -0,0 +1,12 @@ +#include "util/Twitch.hpp" + +#include + +namespace chatterino { + +void openTwitchUsercard(QString channel, QString username) +{ + QDesktopServices::openUrl("https://www.twitch.tv/popout/" + channel + + "/viewercard/" + username); +} +} // namespace chatterino diff --git a/src/util/Twitch.hpp b/src/util/Twitch.hpp new file mode 100644 index 000000000..7250b79a3 --- /dev/null +++ b/src/util/Twitch.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace chatterino { + +void openTwitchUsercard(const QString channel, const QString username); + +} // namespace chatterino diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index ab25a2367..8538d3d68 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -34,6 +34,7 @@ #include "util/Clipboard.hpp" #include "util/DistanceBetweenPoints.hpp" #include "util/IncognitoBrowser.hpp" +#include "util/Twitch.hpp" #include "widgets/Scrollbar.hpp" #include "widgets/TooltipWidget.hpp" #include "widgets/dialogs/UserInfoPopup.hpp" @@ -1403,6 +1404,10 @@ void ChannelView::mousePressEvent(QMouseEvent *event) { if (this->isScrolling_) this->disableScrolling(); + else if (hoverLayoutElement != nullptr && + hoverLayoutElement->getFlags().has( + MessageElementFlag::Username)) + break; else this->enableScrolling(event->screenPos()); } @@ -1424,7 +1429,7 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event) QPoint relativePos; int messageIndex; - bool foundMessage = + bool foundElement = tryGetMessageAt(event->pos(), layout, relativePos, messageIndex); // check if mouse was pressed @@ -1486,13 +1491,23 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event) return; } - else if (foundMessage) + else if (foundElement) { const MessageLayoutElement *hoverLayoutElement = layout->getElementAt(relativePos); - if (hoverLayoutElement == nullptr || - hoverLayoutElement->getLink().isUrl() == false) + if (hoverLayoutElement == nullptr) + { + return; + } + else if (hoverLayoutElement->getFlags().has( + MessageElementFlag::Username)) + { + openTwitchUsercard(this->channel_->getName(), + hoverLayoutElement->getLink().value); + return; + } + else if (hoverLayoutElement->getLink().isUrl() == false) { return; } @@ -1505,7 +1520,7 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event) } // no message found - if (!foundMessage) + if (!foundElement) { // No message at clicked position return;