mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Merge pull request #1091 from tsoding/976
(#976) Implement Emote preview on mouse hover
This commit is contained in:
commit
b7372c911b
8 changed files with 92 additions and 0 deletions
|
@ -139,6 +139,7 @@ SOURCES += \
|
|||
src/singletons/Toasts.cpp \
|
||||
src/singletons/Updates.cpp \
|
||||
src/singletons/WindowManager.cpp \
|
||||
src/singletons/TooltipPreviewImage.cpp \
|
||||
src/util/DebugCount.cpp \
|
||||
src/util/FormatTime.cpp \
|
||||
src/util/IncognitoBrowser.cpp \
|
||||
|
@ -301,6 +302,7 @@ HEADERS += \
|
|||
src/providers/twitch/TwitchServer.hpp \
|
||||
src/providers/twitch/TwitchUser.hpp \
|
||||
src/RunGui.hpp \
|
||||
src/singletons/TooltipPreviewImage.hpp \
|
||||
src/singletons/Badges.hpp \
|
||||
src/singletons/Emotes.hpp \
|
||||
src/singletons/helper/GifTimer.hpp \
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
virtual void paintAnimated(QPainter &painter, int yOffset) = 0;
|
||||
virtual int getMouseOverIndex(const QPoint &abs) const = 0;
|
||||
virtual int getXFromIndex(int index) = 0;
|
||||
|
||||
const Link &getLink() const;
|
||||
const QString &getText() const;
|
||||
FlagsEnum<MessageElementFlag> getFlags() const;
|
||||
|
|
|
@ -192,6 +192,7 @@ public:
|
|||
QStringSetting currentVersion = {"/misc/currentVersion", ""};
|
||||
BoolSetting loadTwitchMessageHistoryOnConnect = {
|
||||
"/misc/twitch/loadMessageHistoryOnConnect", true};
|
||||
IntSetting emotesTooltipPreview = {"/misc/emotesTooltipPreview", 0};
|
||||
|
||||
QStringSetting cachePath = {"/cache/path", ""};
|
||||
|
||||
|
|
37
src/singletons/TooltipPreviewImage.cpp
Normal file
37
src/singletons/TooltipPreviewImage.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include "TooltipPreviewImage.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
#include "widgets/TooltipWidget.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
TooltipPreviewImage &TooltipPreviewImage::getInstance()
|
||||
{
|
||||
static TooltipPreviewImage *instance = new TooltipPreviewImage();
|
||||
return *instance;
|
||||
}
|
||||
|
||||
TooltipPreviewImage::TooltipPreviewImage()
|
||||
{
|
||||
connections_.push_back(getApp()->windows->gifRepaintRequested.connect([&] {
|
||||
auto tooltipWidget = TooltipWidget::getInstance();
|
||||
if (this->image_ && !tooltipWidget->isHidden())
|
||||
{
|
||||
auto pixmap = this->image_->pixmap();
|
||||
if (pixmap)
|
||||
{
|
||||
tooltipWidget->setImage(*pixmap);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tooltipWidget->clearImage();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void TooltipPreviewImage::setImage(ImagePtr image)
|
||||
{
|
||||
this->image_ = image;
|
||||
}
|
||||
} // namespace chatterino
|
21
src/singletons/TooltipPreviewImage.hpp
Normal file
21
src/singletons/TooltipPreviewImage.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include "messages/Image.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
class TooltipPreviewImage
|
||||
{
|
||||
public:
|
||||
static TooltipPreviewImage &getInstance();
|
||||
void setImage(ImagePtr image);
|
||||
|
||||
TooltipPreviewImage(const TooltipPreviewImage &) = delete;
|
||||
|
||||
private:
|
||||
TooltipPreviewImage();
|
||||
|
||||
private:
|
||||
ImagePtr image_ = nullptr;
|
||||
std::vector<pajlada::Signals::ScopedConnection> connections_;
|
||||
};
|
||||
} // namespace chatterino
|
|
@ -15,6 +15,7 @@
|
|||
#include "providers/twitch/TwitchServer.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "singletons/Theme.hpp"
|
||||
#include "singletons/TooltipPreviewImage.hpp"
|
||||
#include "singletons/WindowManager.hpp"
|
||||
#include "util/DistanceBetweenPoints.hpp"
|
||||
#include "util/IncognitoBrowser.hpp"
|
||||
|
@ -311,6 +312,7 @@ void ChannelView::queueUpdate()
|
|||
// }
|
||||
|
||||
// this->repaint();
|
||||
|
||||
this->update();
|
||||
|
||||
// this->updateTimer.start();
|
||||
|
@ -1217,6 +1219,28 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
|||
}
|
||||
else
|
||||
{
|
||||
auto &tooltipPreviewImage = TooltipPreviewImage::getInstance();
|
||||
auto emoteElement = dynamic_cast<const EmoteElement *>(
|
||||
&hoverLayoutElement->getCreator());
|
||||
|
||||
if (emoteElement && getSettings()->emotesTooltipPreview.getValue())
|
||||
{
|
||||
if (event->modifiers() == Qt::ShiftModifier ||
|
||||
getSettings()->emotesTooltipPreview.getValue() == 1)
|
||||
{
|
||||
tooltipPreviewImage.setImage(
|
||||
emoteElement->getEmote()->images.getImage(3.0));
|
||||
}
|
||||
else
|
||||
{
|
||||
tooltipPreviewImage.setImage(nullptr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tooltipPreviewImage.setImage(nullptr);
|
||||
}
|
||||
|
||||
tooltipWidget->moveTo(this, event->globalPos());
|
||||
tooltipWidget->setWordWrap(isLinkValid);
|
||||
tooltipWidget->setText(tooltip);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "messages/LimitedQueue.hpp"
|
||||
#include "messages/LimitedQueueSnapshot.hpp"
|
||||
#include "messages/Selection.hpp"
|
||||
#include "messages/Image.hpp"
|
||||
#include "widgets/BaseWidget.hpp"
|
||||
|
||||
#include <QPaintEvent>
|
||||
|
|
|
@ -270,6 +270,11 @@ void GeneralPage::initLayout(SettingsLayout &layout)
|
|||
layout.addCheckbox("Double click links to open", s.linksDoubleClickOnly);
|
||||
layout.addCheckbox("Unshorten links", s.unshortLinks);
|
||||
layout.addCheckbox("Show live indicator in tabs", s.showTabLive);
|
||||
layout.addDropdown<int>(
|
||||
"Show emote preview in tooltip on hover",
|
||||
{"Don't show", "Always show", "Hold shift"}, s.emotesTooltipPreview,
|
||||
[](int index) { return index; }, [](auto args) { return args.index; },
|
||||
false);
|
||||
|
||||
layout.addSpacing(16);
|
||||
layout.addSeperator();
|
||||
|
|
Loading…
Reference in a new issue