mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Extract TooltipWidget updating into a separate class
This commit is contained in:
parent
3f4d3ce14a
commit
3838157d82
5 changed files with 56 additions and 16 deletions
|
@ -139,6 +139,7 @@ SOURCES += \
|
||||||
src/singletons/Toasts.cpp \
|
src/singletons/Toasts.cpp \
|
||||||
src/singletons/Updates.cpp \
|
src/singletons/Updates.cpp \
|
||||||
src/singletons/WindowManager.cpp \
|
src/singletons/WindowManager.cpp \
|
||||||
|
src/singletons/TooltipPreviewImage.cpp \
|
||||||
src/util/DebugCount.cpp \
|
src/util/DebugCount.cpp \
|
||||||
src/util/FormatTime.cpp \
|
src/util/FormatTime.cpp \
|
||||||
src/util/IncognitoBrowser.cpp \
|
src/util/IncognitoBrowser.cpp \
|
||||||
|
@ -301,6 +302,7 @@ HEADERS += \
|
||||||
src/providers/twitch/TwitchServer.hpp \
|
src/providers/twitch/TwitchServer.hpp \
|
||||||
src/providers/twitch/TwitchUser.hpp \
|
src/providers/twitch/TwitchUser.hpp \
|
||||||
src/RunGui.hpp \
|
src/RunGui.hpp \
|
||||||
|
src/singletons/TooltipPreviewImage.hpp \
|
||||||
src/singletons/Badges.hpp \
|
src/singletons/Badges.hpp \
|
||||||
src/singletons/Emotes.hpp \
|
src/singletons/Emotes.hpp \
|
||||||
src/singletons/helper/GifTimer.hpp \
|
src/singletons/helper/GifTimer.hpp \
|
||||||
|
|
32
src/singletons/TooltipPreviewImage.cpp
Normal file
32
src/singletons/TooltipPreviewImage.cpp
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#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
|
18
src/singletons/TooltipPreviewImage.hpp
Normal file
18
src/singletons/TooltipPreviewImage.hpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "messages/Image.hpp"
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
class TooltipPreviewImage {
|
||||||
|
public:
|
||||||
|
static TooltipPreviewImage &getInstance();
|
||||||
|
void setImage(ImagePtr image);
|
||||||
|
|
||||||
|
private:
|
||||||
|
TooltipPreviewImage();
|
||||||
|
|
||||||
|
private:
|
||||||
|
ImagePtr image_ = nullptr;
|
||||||
|
std::vector<pajlada::Signals::ScopedConnection> connections_;
|
||||||
|
};
|
||||||
|
} // namespace chatterino
|
|
@ -23,6 +23,7 @@
|
||||||
#include "widgets/dialogs/UserInfoPopup.hpp"
|
#include "widgets/dialogs/UserInfoPopup.hpp"
|
||||||
#include "widgets/helper/EffectLabel.hpp"
|
#include "widgets/helper/EffectLabel.hpp"
|
||||||
#include "widgets/splits/Split.hpp"
|
#include "widgets/splits/Split.hpp"
|
||||||
|
#include "TooltipPreviewImage.hpp"
|
||||||
|
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
@ -105,8 +106,6 @@ namespace {
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
ImagePtr ChannelView::currentPreviewImage = nullptr;
|
|
||||||
|
|
||||||
ChannelView::ChannelView(BaseWidget *parent)
|
ChannelView::ChannelView(BaseWidget *parent)
|
||||||
: BaseWidget(parent)
|
: BaseWidget(parent)
|
||||||
, scrollBar_(new Scrollbar(this))
|
, scrollBar_(new Scrollbar(this))
|
||||||
|
@ -314,16 +313,6 @@ void ChannelView::queueUpdate()
|
||||||
|
|
||||||
// this->repaint();
|
// this->repaint();
|
||||||
|
|
||||||
auto tooltipWidget = TooltipWidget::getInstance();
|
|
||||||
if (ChannelView::currentPreviewImage) {
|
|
||||||
auto pixmap = ChannelView::currentPreviewImage->pixmap();
|
|
||||||
if (pixmap) {
|
|
||||||
tooltipWidget->setImage(*pixmap);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
tooltipWidget->clearImage();
|
|
||||||
}
|
|
||||||
|
|
||||||
this->update();
|
this->update();
|
||||||
|
|
||||||
// this->updateTimer.start();
|
// this->updateTimer.start();
|
||||||
|
@ -1230,11 +1219,12 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
auto tooltipPreviewImage = TooltipPreviewImage::getInstance();
|
||||||
auto emoteElement = dynamic_cast<const EmoteElement*>(&hoverLayoutElement->getCreator());
|
auto emoteElement = dynamic_cast<const EmoteElement*>(&hoverLayoutElement->getCreator());
|
||||||
if (emoteElement && getSettings()->emotesTooltipPreview.getValue()) {
|
if (emoteElement && getSettings()->emotesTooltipPreview.getValue()) {
|
||||||
ChannelView::currentPreviewImage = emoteElement->getEmote()->images.getImage(3.0);
|
tooltipPreviewImage->setImage(emoteElement->getEmote()->images.getImage(3.0));
|
||||||
} else {
|
} else {
|
||||||
ChannelView::currentPreviewImage = nullptr;
|
tooltipPreviewImage->setImage(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
tooltipWidget->moveTo(this, event->globalPos());
|
tooltipWidget->moveTo(this, event->globalPos());
|
||||||
|
|
|
@ -210,8 +210,6 @@ private:
|
||||||
static constexpr int leftPadding = 8;
|
static constexpr int leftPadding = 8;
|
||||||
static constexpr int scrollbarPadding = 8;
|
static constexpr int scrollbarPadding = 8;
|
||||||
|
|
||||||
static ImagePtr currentPreviewImage;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void wordFlagsChanged()
|
void wordFlagsChanged()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue