Skip to content

Commit

Permalink
fix: tooltips dancing around
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Oct 26, 2023
1 parent 5c0219c commit c4a26b0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
6 changes: 0 additions & 6 deletions src/singletons/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions src/singletons/WindowManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Split *> selectSplit;
pajlada::Signals::Signal<SplitContainer *> selectSplitContainer;
pajlada::Signals::Signal<const MessagePtr &> scrollToMessageSignal;
Expand Down Expand Up @@ -159,7 +155,6 @@ class WindowManager final : public Singleton
pajlada::SettingListener wordFlagsListener_;

QTimer *saveTimer;
QTimer miscUpdateTimer_;

friend class Window; // this is for selectedWindow_
};
Expand Down
5 changes: 5 additions & 0 deletions src/widgets/TooltipEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
44 changes: 28 additions & 16 deletions src/widgets/TooltipWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,46 @@ 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();
}
}
});

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)
Expand Down Expand Up @@ -101,6 +112,7 @@ void TooltipWidget::set(const std::vector<TooltipEntry> &entries,
entryWidget->setImageScale(entry.customWidth, entry.customHeight);
}
}
this->adjustSize();
}

void TooltipWidget::setVisibleEntries(int n)
Expand Down

0 comments on commit c4a26b0

Please sign in to comment.