From c4a26b02c29e772e531d97fb5b614e09aa208fa3 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Wed, 25 Oct 2023 17:49:12 +0200 Subject: [PATCH] fix: tooltips dancing around --- src/singletons/WindowManager.cpp | 6 ---- src/singletons/WindowManager.hpp | 5 ---- src/widgets/TooltipEntryWidget.cpp | 5 ++++ src/widgets/TooltipWidget.cpp | 44 +++++++++++++++++++----------- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index 43188682290..a86fdbc5ac1 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -125,12 +125,6 @@ WindowManager::WindowManager() QObject::connect(this->saveTimer, &QTimer::timeout, [] { getApp()->windows->save(); }); - - this->miscUpdateTimer_.start(100); - - QObject::connect(&this->miscUpdateTimer_, &QTimer::timeout, [this] { - this->miscUpdate.invoke(); - }); } WindowManager::~WindowManager() = default; diff --git a/src/singletons/WindowManager.hpp b/src/singletons/WindowManager.hpp index 78b7b9e534f..22a68655cfb 100644 --- a/src/singletons/WindowManager.hpp +++ b/src/singletons/WindowManager.hpp @@ -122,10 +122,6 @@ class WindowManager final : public Singleton pajlada::Signals::NoArgSignal wordFlagsChanged; - // This signal fires every 100ms and can be used to trigger random things that require a recheck. - // It is currently being used by the "Tooltip Preview Image" system to recheck if an image is ready to be rendered. - pajlada::Signals::NoArgSignal miscUpdate; - pajlada::Signals::Signal selectSplit; pajlada::Signals::Signal selectSplitContainer; pajlada::Signals::Signal scrollToMessageSignal; @@ -159,7 +155,6 @@ class WindowManager final : public Singleton pajlada::SettingListener wordFlagsListener_; QTimer *saveTimer; - QTimer miscUpdateTimer_; friend class Window; // this is for selectedWindow_ }; diff --git a/src/widgets/TooltipEntryWidget.cpp b/src/widgets/TooltipEntryWidget.cpp index 6fbaec1fdd2..ff56928125e 100644 --- a/src/widgets/TooltipEntryWidget.cpp +++ b/src/widgets/TooltipEntryWidget.cpp @@ -91,6 +91,11 @@ bool TooltipEntryWidget::refreshPixmap() this->displayImage_->setPixmap(pixmap->scaled(this->customImgWidth_, this->customImgHeight_, Qt::KeepAspectRatio)); + if (this->displayImage_->size() != + QSize{this->customImgWidth_, this->customImgHeight_}) + { + this->adjustSize(); + } } else { diff --git a/src/widgets/TooltipWidget.cpp b/src/widgets/TooltipWidget.cpp index f979c03d28c..dba8afc77fb 100644 --- a/src/widgets/TooltipWidget.cpp +++ b/src/widgets/TooltipWidget.cpp @@ -37,11 +37,16 @@ TooltipWidget::TooltipWidget(BaseWidget *parent) }); this->updateFont(); - auto windows = getApp()->windows; + auto *windows = getApp()->windows; this->connections_.managedConnect(windows->gifRepaintRequested, [this] { + if (!this->isVisible()) + { + return; + } + for (int i = 0; i < this->visibleEntries_; ++i) { - auto entry = this->entryAt(i); + auto *entry = this->entryAt(i); if (entry && entry->animated()) { entry->refreshPixmap(); @@ -49,23 +54,29 @@ TooltipWidget::TooltipWidget(BaseWidget *parent) } }); - this->connections_.managedConnect(windows->miscUpdate, [this] { - bool needSizeAdjustment = false; - for (int i = 0; i < this->visibleEntries_; ++i) - { - auto entry = this->entryAt(i); - if (entry->hasImage() && entry->attemptRefresh()) + this->connections_.managedConnect( + windows->layoutRequested, [this](auto *chan) { + if (chan != nullptr || !this->isVisible()) { - bool successfullyUpdated = entry->refreshPixmap(); - needSizeAdjustment |= successfullyUpdated; + return; } - } - if (needSizeAdjustment) - { - this->adjustSize(); - } - }); + bool needSizeAdjustment = false; + for (int i = 0; i < this->visibleEntries_; ++i) + { + auto *entry = this->entryAt(i); + if (entry->hasImage() && entry->attemptRefresh()) + { + bool successfullyUpdated = entry->refreshPixmap(); + needSizeAdjustment |= successfullyUpdated; + } + } + + if (needSizeAdjustment) + { + this->adjustSize(); + } + }); } void TooltipWidget::setOne(const TooltipEntry &entry, TooltipStyle style) @@ -101,6 +112,7 @@ void TooltipWidget::set(const std::vector &entries, entryWidget->setImageScale(entry.customWidth, entry.customHeight); } } + this->adjustSize(); } void TooltipWidget::setVisibleEntries(int n)