Skip to content

Commit

Permalink
Merge branch 'master' into feature/automod-notification
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada authored Dec 25, 2023
2 parents 5a40a9c + 1006bf9 commit 8cc39c5
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 22 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
- Bugfix: Fixed some windows appearing between screens. (#4797)
- Bugfix: Fixed a crash that could occur when using certain features in a Usercard after closing the split from which it was created. (#5034)
- Bugfix: Fixed a crash that could occur when using certain features in a Reply popup after closing the split from which it was created. (#5036)
- Bugfix: Fixed a bug on Wayland where tooltips would spawn as separate windows instead of behaving like tooltips. (#4998)
- Bugfix: Fixed a bug on Wayland where tooltips would spawn as separate windows instead of behaving like tooltips. (#4998, #5040)
- Bugfix: Fixes to section deletion in text input fields. (#5013)
- Bugfix: Show user text input within watch streak notices. (#5029)
- Dev: Run miniaudio in a separate thread, and simplify it to not manage the device ourselves. There's a chance the simplification is a bad idea. (#4978)
Expand Down Expand Up @@ -99,6 +99,7 @@
- Dev: BREAKING: Replace custom `import()` with normal Lua `require()`. (#5014)
- Dev: Fixed most compiler warnings. (#5028)
- Dev: Added the ability to show `ChannelView`s without a `Split`. (#4747)
- Dev: Channels without any animated elements on screen will skip updates from the GIF timer. (#5042)

## 2.4.6

Expand Down
9 changes: 7 additions & 2 deletions src/messages/layouts/MessageLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ void MessageLayout::actuallyLayout(int width, MessageElementFlags flags)
}

// Painting
void MessageLayout::paint(const MessagePaintContext &ctx)
MessagePaintResult MessageLayout::paint(const MessagePaintContext &ctx)
{
MessagePaintResult result;

QPixmap *pixmap = this->ensureBuffer(ctx.painter, ctx.canvasWidth);

if (!this->bufferValid_)
Expand All @@ -209,7 +211,8 @@ void MessageLayout::paint(const MessagePaintContext &ctx)
ctx.painter.drawPixmap(0, ctx.y, *pixmap);

// draw gif emotes
this->container_.paintAnimatedElements(ctx.painter, ctx.y);
result.hasAnimatedElements =
this->container_.paintAnimatedElements(ctx.painter, ctx.y);

// draw disabled
if (this->message_->flags.has(MessageFlag::Disabled))
Expand Down Expand Up @@ -270,6 +273,8 @@ void MessageLayout::paint(const MessagePaintContext &ctx)
}

this->bufferValid_ = true;

return result;
}

QPixmap *MessageLayout::ensureBuffer(QPainter &painter, int width)
Expand Down
6 changes: 5 additions & 1 deletion src/messages/layouts/MessageLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ enum class MessageLayoutFlag : uint8_t {
};
using MessageLayoutFlags = FlagsEnum<MessageLayoutFlag>;

struct MessagePaintResult {
bool hasAnimatedElements = false;
};

class MessageLayout
{
public:
Expand All @@ -55,7 +59,7 @@ class MessageLayout
bool layout(int width, float scale_, MessageElementFlags flags);

// Painting
void paint(const MessagePaintContext &ctx);
MessagePaintResult paint(const MessagePaintContext &ctx);
void invalidateBuffer();
void deleteBuffer();
void deleteCache();
Expand Down
6 changes: 4 additions & 2 deletions src/messages/layouts/MessageLayoutContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,15 @@ void MessageLayoutContainer::paintElements(QPainter &painter,
}
}

void MessageLayoutContainer::paintAnimatedElements(QPainter &painter,
bool MessageLayoutContainer::paintAnimatedElements(QPainter &painter,
int yOffset) const
{
bool anyAnimatedElement = false;
for (const auto &element : this->elements_)
{
element->paintAnimated(painter, yOffset);
anyAnimatedElement |= element->paintAnimated(painter, yOffset);
}
return anyAnimatedElement;
}

void MessageLayoutContainer::paintSelection(QPainter &painter,
Expand Down
3 changes: 2 additions & 1 deletion src/messages/layouts/MessageLayoutContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ struct MessageLayoutContainer {

/**
* Paint the animated elements in this message
* @returns true if this container contains at least one animated element
*/
void paintAnimatedElements(QPainter &painter, int yOffset) const;
bool paintAnimatedElements(QPainter &painter, int yOffset) const;

/**
* Paint the selection for this container
Expand Down
20 changes: 14 additions & 6 deletions src/messages/layouts/MessageLayoutElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ void ImageLayoutElement::paint(QPainter &painter,
}
}

void ImageLayoutElement::paintAnimated(QPainter &painter, int yOffset)
bool ImageLayoutElement::paintAnimated(QPainter &painter, int yOffset)
{
if (this->image_ == nullptr)
{
return;
return false;
}

if (this->image_->animated())
Expand All @@ -167,8 +167,10 @@ void ImageLayoutElement::paintAnimated(QPainter &painter, int yOffset)
auto rect = this->getRect();
rect.moveTop(rect.y() + yOffset);
painter.drawPixmap(QRectF(rect), *pixmap, QRectF());
return true;
}
}
return false;
}

int ImageLayoutElement::getMouseOverIndex(const QPoint &abs) const
Expand Down Expand Up @@ -265,7 +267,7 @@ void LayeredImageLayoutElement::paint(QPainter &painter,
}
}

void LayeredImageLayoutElement::paintAnimated(QPainter &painter, int yOffset)
bool LayeredImageLayoutElement::paintAnimated(QPainter &painter, int yOffset)
{
auto fullRect = QRectF(this->getRect());
fullRect.moveTop(fullRect.y() + yOffset);
Expand Down Expand Up @@ -297,6 +299,7 @@ void LayeredImageLayoutElement::paintAnimated(QPainter &painter, int yOffset)
}
}
}
return animatedFlag;
}

int LayeredImageLayoutElement::getMouseOverIndex(const QPoint &abs) const
Expand Down Expand Up @@ -446,8 +449,9 @@ void TextLayoutElement::paint(QPainter &painter,
QTextOption(Qt::AlignLeft | Qt::AlignTop));
}

void TextLayoutElement::paintAnimated(QPainter &, int)
bool TextLayoutElement::paintAnimated(QPainter & /*painter*/, int /*yOffset*/)
{
return false;
}

int TextLayoutElement::getMouseOverIndex(const QPoint &abs) const
Expand Down Expand Up @@ -567,8 +571,10 @@ void TextIconLayoutElement::paint(QPainter &painter,
}
}

void TextIconLayoutElement::paintAnimated(QPainter &painter, int yOffset)
bool TextIconLayoutElement::paintAnimated(QPainter & /*painter*/,
int /*yOffset*/)
{
return false;
}

int TextIconLayoutElement::getMouseOverIndex(const QPoint &abs) const
Expand Down Expand Up @@ -640,8 +646,10 @@ void ReplyCurveLayoutElement::paint(QPainter &painter,
painter.drawPath(path);
}

void ReplyCurveLayoutElement::paintAnimated(QPainter &painter, int yOffset)
bool ReplyCurveLayoutElement::paintAnimated(QPainter & /*painter*/,
int /*yOffset*/)
{
return false;
}

int ReplyCurveLayoutElement::getMouseOverIndex(const QPoint &abs) const
Expand Down
13 changes: 7 additions & 6 deletions src/messages/layouts/MessageLayoutElement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class MessageLayoutElement
virtual size_t getSelectionIndexCount() const = 0;
virtual void paint(QPainter &painter,
const MessageColors &messageColors) = 0;
virtual void paintAnimated(QPainter &painter, int yOffset) = 0;
/// @returns true if anything was painted
virtual bool paintAnimated(QPainter &painter, int yOffset) = 0;
virtual int getMouseOverIndex(const QPoint &abs) const = 0;
virtual int getXFromIndex(size_t index) = 0;

Expand Down Expand Up @@ -86,7 +87,7 @@ class ImageLayoutElement : public MessageLayoutElement
uint32_t to = UINT32_MAX) const override;
size_t getSelectionIndexCount() const override;
void paint(QPainter &painter, const MessageColors &messageColors) override;
void paintAnimated(QPainter &painter, int yOffset) override;
bool paintAnimated(QPainter &painter, int yOffset) override;
int getMouseOverIndex(const QPoint &abs) const override;
int getXFromIndex(size_t index) override;

Expand All @@ -105,7 +106,7 @@ class LayeredImageLayoutElement : public MessageLayoutElement
uint32_t to = UINT32_MAX) const override;
size_t getSelectionIndexCount() const override;
void paint(QPainter &painter, const MessageColors &messageColors) override;
void paintAnimated(QPainter &painter, int yOffset) override;
bool paintAnimated(QPainter &painter, int yOffset) override;
int getMouseOverIndex(const QPoint &abs) const override;
int getXFromIndex(size_t index) override;

Expand Down Expand Up @@ -158,7 +159,7 @@ class TextLayoutElement : public MessageLayoutElement
uint32_t to = UINT32_MAX) const override;
size_t getSelectionIndexCount() const override;
void paint(QPainter &painter, const MessageColors &messageColors) override;
void paintAnimated(QPainter &painter, int yOffset) override;
bool paintAnimated(QPainter &painter, int yOffset) override;
int getMouseOverIndex(const QPoint &abs) const override;
int getXFromIndex(size_t index) override;

Expand All @@ -182,7 +183,7 @@ class TextIconLayoutElement : public MessageLayoutElement
uint32_t to = UINT32_MAX) const override;
size_t getSelectionIndexCount() const override;
void paint(QPainter &painter, const MessageColors &messageColors) override;
void paintAnimated(QPainter &painter, int yOffset) override;
bool paintAnimated(QPainter &painter, int yOffset) override;
int getMouseOverIndex(const QPoint &abs) const override;
int getXFromIndex(size_t index) override;

Expand All @@ -200,7 +201,7 @@ class ReplyCurveLayoutElement : public MessageLayoutElement

protected:
void paint(QPainter &painter, const MessageColors &messageColors) override;
void paintAnimated(QPainter &painter, int yOffset) override;
bool paintAnimated(QPainter &painter, int yOffset) override;
int getMouseOverIndex(const QPoint &abs) const override;
int getXFromIndex(size_t index) override;
void addCopyTextToString(QString &str, uint32_t from = 0,
Expand Down
23 changes: 22 additions & 1 deletion src/widgets/TooltipWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,34 @@
// number of columns in grid mode
#define GRID_NUM_COLS 3

namespace {

#ifdef Q_OS_WIN
template <typename T>
inline constexpr T *tooltipParentFor(T * /*desiredParent*/)
{
return nullptr;
}
#else
template <typename T>
inline constexpr T *tooltipParentFor(T *desiredParent)
{
return desiredParent;
}
#endif

} // namespace

namespace chatterino {

TooltipWidget::TooltipWidget(BaseWidget *parent)
: BaseWindow({BaseWindow::TopMost, BaseWindow::DontFocus,
BaseWindow::DisableLayoutSave},
parent)
tooltipParentFor(parent))
{
assert(parent != nullptr);
QObject::connect(parent, &QObject::destroyed, this, &QObject::deleteLater);

this->setStyleSheet("color: #fff; background: rgba(11, 11, 11, 0.8)");
this->setAttribute(Qt::WA_TranslucentBackground);
this->setWindowFlag(Qt::WindowStaysOnTopHint, true);
Expand Down
10 changes: 8 additions & 2 deletions src/widgets/helper/ChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,10 @@ void ChannelView::initializeSignals()

this->signalHolder_.managedConnect(getApp()->windows->gifRepaintRequested,
[&] {
this->queueUpdate();
if (this->anyAnimationShown_)
{
this->queueUpdate();
}
});

this->signalHolder_.managedConnect(
Expand Down Expand Up @@ -1471,6 +1474,8 @@ void ChannelView::drawMessages(QPainter &painter)
};
bool showLastMessageIndicator = getSettings()->showLastMessageIndicator;

bool anyAnimation = false;

for (; ctx.messageIndex < messagesSnapshot.size(); ++ctx.messageIndex)
{
MessageLayout *layout = messagesSnapshot[ctx.messageIndex].get();
Expand All @@ -1484,7 +1489,7 @@ void ChannelView::drawMessages(QPainter &painter)
ctx.isLastReadMessage = false;
}

layout->paint(ctx);
anyAnimation |= layout->paint(ctx).hasAnimatedElements;

if (this->highlightedMessage_ == layout)
{
Expand All @@ -1505,6 +1510,7 @@ void ChannelView::drawMessages(QPainter &painter)
break;
}
}
this->anyAnimationShown_ = anyAnimation;

if (end == nullptr)
{
Expand Down
3 changes: 3 additions & 0 deletions src/widgets/helper/ChannelView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ class ChannelView final : public BaseWidget
bool lastMessageHasAlternateBackground_ = false;
bool lastMessageHasAlternateBackgroundReverse_ = true;

/// Tracks if this view has painted any animated element in the last #paintEvent().
bool anyAnimationShown_ = false;

bool pausable_ = false;
QTimer pauseTimer_;
std::unordered_map<PauseReason, std::optional<SteadyClock::time_point>>
Expand Down

0 comments on commit 8cc39c5

Please sign in to comment.