Extract TooltipWidget updating into a separate class

This commit is contained in:
rexim 2019-06-12 01:03:04 +07:00
parent 3f4d3ce14a
commit 3838157d82
5 changed files with 56 additions and 16 deletions

View file

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

View 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

View 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

View file

@ -23,6 +23,7 @@
#include "widgets/dialogs/UserInfoPopup.hpp"
#include "widgets/helper/EffectLabel.hpp"
#include "widgets/splits/Split.hpp"
#include "TooltipPreviewImage.hpp"
#include <QClipboard>
#include <QDebug>
@ -105,8 +106,6 @@ namespace {
}
} // namespace
ImagePtr ChannelView::currentPreviewImage = nullptr;
ChannelView::ChannelView(BaseWidget *parent)
: BaseWidget(parent)
, scrollBar_(new Scrollbar(this))
@ -314,16 +313,6 @@ void ChannelView::queueUpdate()
// 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->updateTimer.start();
@ -1230,11 +1219,12 @@ void ChannelView::mouseMoveEvent(QMouseEvent *event)
}
else
{
auto tooltipPreviewImage = TooltipPreviewImage::getInstance();
auto emoteElement = dynamic_cast<const EmoteElement*>(&hoverLayoutElement->getCreator());
if (emoteElement && getSettings()->emotesTooltipPreview.getValue()) {
ChannelView::currentPreviewImage = emoteElement->getEmote()->images.getImage(3.0);
tooltipPreviewImage->setImage(emoteElement->getEmote()->images.getImage(3.0));
} else {
ChannelView::currentPreviewImage = nullptr;
tooltipPreviewImage->setImage(nullptr);
}
tooltipWidget->moveTo(this, event->globalPos());

View file

@ -210,8 +210,6 @@ private:
static constexpr int leftPadding = 8;
static constexpr int scrollbarPadding = 8;
static ImagePtr currentPreviewImage;
private slots:
void wordFlagsChanged()
{