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
6 changed files with 47 additions and 7 deletions
@@ -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
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
View File
@@ -0,0 +1,9 @@
#pragma once
#include <QString>
namespace chatterino {
void openTwitchUsercard(const QString channel, const QString username);
} // namespace chatterino
+20 -5
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;