fixed message expanding not working

This commit is contained in:
fourtf
2018-05-25 12:45:18 +02:00
parent d775123ed0
commit f72e1b5d82
3 changed files with 24 additions and 19 deletions
+7 -3
View File
@@ -80,6 +80,10 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
layoutRequired |= timestampFormatChanged; layoutRequired |= timestampFormatChanged;
// check if layout was requested manually
layoutRequired |= bool(this->flags & RequiresLayout);
this->flags &= ~RequiresLayout;
// check if dpi changed // check if dpi changed
bool scaleChanged = this->scale != scale; bool scaleChanged = this->scale != scale;
layoutRequired |= scaleChanged; layoutRequired |= scaleChanged;
@@ -87,7 +91,7 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
imagesChanged |= scaleChanged; imagesChanged |= scaleChanged;
textChanged |= scaleChanged; textChanged |= scaleChanged;
// assert(layoutRequired); // assert(layoutRequired);
// update word sizes if needed // update word sizes if needed
if (imagesChanged) { if (imagesChanged) {
@@ -122,7 +126,7 @@ void MessageLayout::actuallyLayout(int width, MessageElement::Flags _flags)
if (this->flags & MessageLayout::Expanded || if (this->flags & MessageLayout::Expanded ||
(_flags & MessageElement::ModeratorTools && (_flags & MessageElement::ModeratorTools &&
!(this->message->flags & Message::MessageFlags::Disabled))) { !(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); this->container.begin(width, this->scale, messageFlags);
@@ -209,7 +213,7 @@ void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection
this->bufferValid = true; this->bufferValid = true;
} }
void MessageLayout::updateBuffer(QPixmap *buffer, int messageIndex, Selection &selection) void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selection & /*selection*/)
{ {
auto app = getApp(); auto app = getApp();
+10 -7
View File
@@ -11,24 +11,27 @@
#define MARK(x) \ #define MARK(x) \
qDebug() << BOOST_CURRENT_FUNCTION << __LINE__ \ qDebug() << BOOST_CURRENT_FUNCTION << __LINE__ \
<< static_cast<float>(x.nsecsElapsed()) / 100000.0 << "ms"; << static_cast<float>(x.nsecsElapsed()) / 1000000.0 << "ms";
class BenchmarkGuard : boost::noncopyable { class BenchmarkGuard : boost::noncopyable
{
QElapsedTimer timer; QElapsedTimer timer;
QString name; QString name;
public: public:
BenchmarkGuard(const QString &_name) BenchmarkGuard(const QString &_name)
:name(_name) : name(_name)
{ {
timer.start(); timer.start();
} }
~BenchmarkGuard() { ~BenchmarkGuard()
qDebug() << this->name << float(timer.nsecsElapsed()) / 100000.0 << "ms"; {
qDebug() << this->name << float(timer.nsecsElapsed()) / 1000000.0f << "ms";
} }
qreal getElapsedMs() { qreal getElapsedMs()
return qreal(timer.nsecsElapsed()) / 100000.0; {
return qreal(timer.nsecsElapsed()) / 1000000.0;
} }
}; };
+7 -9
View File
@@ -175,9 +175,10 @@ void ChannelView::layoutMessages()
void ChannelView::actuallyLayoutMessages(bool causedByScrollbar) void ChannelView::actuallyLayoutMessages(bool causedByScrollbar)
{ {
BenchmarkGuard benchmark("layout messages");
auto app = getApp(); auto app = getApp();
BENCH(timer)
auto messagesSnapshot = this->getMessagesSnapshot(); auto messagesSnapshot = this->getMessagesSnapshot();
if (messagesSnapshot.getLength() == 0) { if (messagesSnapshot.getLength() == 0) {
@@ -264,8 +265,6 @@ void ChannelView::actuallyLayoutMessages(bool causedByScrollbar)
this->messageWasAdded = false; this->messageWasAdded = false;
} }
MARK(timer);
if (redrawRequired) { if (redrawRequired) {
this->queueUpdate(); this->queueUpdate();
} }
@@ -580,7 +579,7 @@ bool ChannelView::isPaused()
void ChannelView::paintEvent(QPaintEvent * /*event*/) void ChannelView::paintEvent(QPaintEvent * /*event*/)
{ {
BENCH(timer); BenchmarkGuard benchmark("paint event");
QPainter painter(this); QPainter painter(this);
@@ -588,8 +587,6 @@ void ChannelView::paintEvent(QPaintEvent * /*event*/)
// draw messages // draw messages
this->drawMessages(painter); this->drawMessages(painter);
MARK(timer);
} }
// if overlays is false then it draws the message, if true then it draws things such as the grey // 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(); auto messagesSnapshot = this->getMessagesSnapshot();
size_t start = this->scrollBar.getCurrentValue(); size_t start = size_t(this->scrollBar.getCurrentValue());
if (start >= messagesSnapshot.getLength()) { if (start >= messagesSnapshot.getLength()) {
return; return;
} }
int y = -(messagesSnapshot[start].get()->getHeight() * int y = int(-(messagesSnapshot[start].get()->getHeight() *
(fmod(this->scrollBar.getCurrentValue(), 1))); (fmod(this->scrollBar.getCurrentValue(), 1))));
messages::MessageLayout *end = nullptr; messages::MessageLayout *end = nullptr;
bool windowFocused = this->window() == QApplication::activeWindow(); bool windowFocused = this->window() == QApplication::activeWindow();
@@ -925,6 +922,7 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
// message under cursor is collapsed // message under cursor is collapsed
if (layout->flags & MessageLayout::Collapsed) { if (layout->flags & MessageLayout::Collapsed) {
layout->flags |= MessageLayout::Expanded; layout->flags |= MessageLayout::Expanded;
layout->flags |= MessageLayout::RequiresLayout;
this->layoutMessages(); this->layoutMessages();
return; return;