open twitch usercard on middle mouse (#1669)

Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
Daniel Pasch 2020-05-10 12:45:19 +02:00 committed by GitHub
parent 8532c6d3bc
commit be6ef6dcd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 7 deletions

View file

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

View file

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

View file

@ -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 <QApplication>
@ -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")

12
src/util/Twitch.cpp Normal file
View file

@ -0,0 +1,12 @@
#include "util/Twitch.hpp"
#include <QDesktopServices>
namespace chatterino {
void openTwitchUsercard(QString channel, QString username)
{
QDesktopServices::openUrl("https://www.twitch.tv/popout/" + channel +
"/viewercard/" + username);
}
} // namespace chatterino

9
src/util/Twitch.hpp Normal file
View file

@ -0,0 +1,9 @@
#pragma once
#include <QString>
namespace chatterino {
void openTwitchUsercard(const QString channel, const QString username);
} // namespace chatterino

View file

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