From f72e1b5d823be1276b50820db186c861af731b2f Mon Sep 17 00:00:00 2001 From: fourtf Date: Fri, 25 May 2018 12:45:18 +0200 Subject: [PATCH] fixed message expanding not working --- src/messages/layouts/messagelayout.cpp | 10 +++++++--- src/util/benchmark.hpp | 17 ++++++++++------- src/widgets/helper/channelview.cpp | 16 +++++++--------- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/messages/layouts/messagelayout.cpp b/src/messages/layouts/messagelayout.cpp index 860fb243f..be2f211c5 100644 --- a/src/messages/layouts/messagelayout.cpp +++ b/src/messages/layouts/messagelayout.cpp @@ -80,6 +80,10 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags) layoutRequired |= timestampFormatChanged; + // check if layout was requested manually + layoutRequired |= bool(this->flags & RequiresLayout); + this->flags &= ~RequiresLayout; + // check if dpi changed bool scaleChanged = this->scale != scale; layoutRequired |= scaleChanged; @@ -87,7 +91,7 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags) imagesChanged |= scaleChanged; textChanged |= scaleChanged; -// assert(layoutRequired); + // assert(layoutRequired); // update word sizes if needed if (imagesChanged) { @@ -122,7 +126,7 @@ void MessageLayout::actuallyLayout(int width, MessageElement::Flags _flags) if (this->flags & MessageLayout::Expanded || (_flags & MessageElement::ModeratorTools && !(this->message->flags & Message::MessageFlags::Disabled))) { - messageFlags = (Message::MessageFlags)(messageFlags & ~Message::MessageFlags::Collapsed); + messageFlags = Message::MessageFlags(messageFlags & ~Message::MessageFlags::Collapsed); } this->container.begin(width, this->scale, messageFlags); @@ -209,7 +213,7 @@ void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection this->bufferValid = true; } -void MessageLayout::updateBuffer(QPixmap *buffer, int messageIndex, Selection &selection) +void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selection & /*selection*/) { auto app = getApp(); diff --git a/src/util/benchmark.hpp b/src/util/benchmark.hpp index 0093bd769..c41caa411 100644 --- a/src/util/benchmark.hpp +++ b/src/util/benchmark.hpp @@ -11,24 +11,27 @@ #define MARK(x) \ qDebug() << BOOST_CURRENT_FUNCTION << __LINE__ \ - << static_cast(x.nsecsElapsed()) / 100000.0 << "ms"; + << static_cast(x.nsecsElapsed()) / 1000000.0 << "ms"; -class BenchmarkGuard : boost::noncopyable { +class BenchmarkGuard : boost::noncopyable +{ QElapsedTimer timer; QString name; public: BenchmarkGuard(const QString &_name) - :name(_name) + : name(_name) { timer.start(); } - ~BenchmarkGuard() { - qDebug() << this->name << float(timer.nsecsElapsed()) / 100000.0 << "ms"; + ~BenchmarkGuard() + { + qDebug() << this->name << float(timer.nsecsElapsed()) / 1000000.0f << "ms"; } - qreal getElapsedMs() { - return qreal(timer.nsecsElapsed()) / 100000.0; + qreal getElapsedMs() + { + return qreal(timer.nsecsElapsed()) / 1000000.0; } }; diff --git a/src/widgets/helper/channelview.cpp b/src/widgets/helper/channelview.cpp index a7a086054..38c1e9631 100644 --- a/src/widgets/helper/channelview.cpp +++ b/src/widgets/helper/channelview.cpp @@ -175,9 +175,10 @@ void ChannelView::layoutMessages() void ChannelView::actuallyLayoutMessages(bool causedByScrollbar) { + BenchmarkGuard benchmark("layout messages"); + auto app = getApp(); - BENCH(timer) auto messagesSnapshot = this->getMessagesSnapshot(); if (messagesSnapshot.getLength() == 0) { @@ -264,8 +265,6 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar) this->messageWasAdded = false; } - MARK(timer); - if (redrawRequired) { this->queueUpdate(); } @@ -580,7 +579,7 @@ bool ChannelView::isPaused() void ChannelView::paintEvent(QPaintEvent * /*event*/) { - BENCH(timer); + BenchmarkGuard benchmark("paint event"); QPainter painter(this); @@ -588,8 +587,6 @@ void ChannelView::paintEvent(QPaintEvent * /*event*/) // draw messages this->drawMessages(painter); - - MARK(timer); } // if overlays is false then it draws the message, if true then it draws things such as the grey @@ -600,14 +597,14 @@ void ChannelView::drawMessages(QPainter &painter) auto messagesSnapshot = this->getMessagesSnapshot(); - size_t start = this->scrollBar.getCurrentValue(); + size_t start = size_t(this->scrollBar.getCurrentValue()); if (start >= messagesSnapshot.getLength()) { return; } - int y = -(messagesSnapshot[start].get()->getHeight() * - (fmod(this->scrollBar.getCurrentValue(), 1))); + int y = int(-(messagesSnapshot[start].get()->getHeight() * + (fmod(this->scrollBar.getCurrentValue(), 1)))); messages::MessageLayout *end = nullptr; bool windowFocused = this->window() == QApplication::activeWindow(); @@ -925,6 +922,7 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event) // message under cursor is collapsed if (layout->flags & MessageLayout::Collapsed) { layout->flags |= MessageLayout::Expanded; + layout->flags |= MessageLayout::RequiresLayout; this->layoutMessages(); return;