diff --git a/widgets/chatwidget.cpp b/widgets/chatwidget.cpp index 81b077830..184271374 100644 --- a/widgets/chatwidget.cpp +++ b/widgets/chatwidget.cpp @@ -61,7 +61,7 @@ ChatWidget::setChannelName(const QString &name) } this->view.layoutMessages(); - this->view.repaint(); + this->view.update(); } void diff --git a/widgets/chatwidgetheader.cpp b/widgets/chatwidgetheader.cpp index 5e215a1c2..f68fd5f34 100644 --- a/widgets/chatwidgetheader.cpp +++ b/widgets/chatwidgetheader.cpp @@ -127,7 +127,7 @@ ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event) auto originalLocation = page->removeFromLayout(chatWidget); - // page->repaint(); + // page->update(); QDrag *drag = new QDrag(chatWidget); QMimeData *mimeData = new QMimeData; diff --git a/widgets/chatwidgetheaderbutton.cpp b/widgets/chatwidgetheaderbutton.cpp index 514366792..fb62ad5ae 100644 --- a/widgets/chatwidgetheaderbutton.cpp +++ b/widgets/chatwidgetheaderbutton.cpp @@ -53,7 +53,7 @@ ChatWidgetHeaderButton::mousePressEvent(QMouseEvent *event) if (event->button() == Qt::LeftButton) { this->mouseDown = true; - repaint(); + update(); } } @@ -63,7 +63,7 @@ ChatWidgetHeaderButton::mouseReleaseEvent(QMouseEvent *event) if (event->button() == Qt::LeftButton) { this->mouseDown = false; - repaint(); + update(); emit clicked(); } @@ -74,7 +74,7 @@ ChatWidgetHeaderButton::enterEvent(QEvent *) { this->mouseOver = true; - repaint(); + update(); } void @@ -82,7 +82,7 @@ ChatWidgetHeaderButton::leaveEvent(QEvent *) { this->mouseOver = false; - repaint(); + update(); } void @@ -90,7 +90,7 @@ ChatWidgetHeaderButton::labelMouseUp() { this->mouseDown = false; - repaint(); + update(); emit clicked(); } @@ -100,7 +100,7 @@ ChatWidgetHeaderButton::labelMouseDown() { this->mouseDown = true; - repaint(); + update(); } } } diff --git a/widgets/chatwidgetview.cpp b/widgets/chatwidgetview.cpp index a57864c97..59ab12b6c 100644 --- a/widgets/chatwidgetview.cpp +++ b/widgets/chatwidgetview.cpp @@ -23,7 +23,7 @@ ChatWidgetView::ChatWidgetView(ChatWidget *parent) QObject::connect(&Settings::getInstance(), &Settings::wordTypeMaskChanged, this, &ChatWidgetView::wordTypeMaskChanged); - this->scrollbar.getValueChanged().connect([this] { repaint(); }); + this->scrollbar.getValueChanged().connect([this] { update(); }); } ChatWidgetView::~ChatWidgetView() @@ -38,8 +38,13 @@ ChatWidgetView::layoutMessages() { auto c = this->chatWidget->getChannel(); - if (c == NULL) + if (c == NULL) { + this->scrollbar.hide(); + return false; + } + + bool showScrollbar = false; auto messages = c->getMessagesClone(); @@ -49,23 +54,29 @@ ChatWidgetView::layoutMessages() redraw |= message.get()->layout(this->width(), true); } - updateScrollbar(); + int h = this->height(); - return redraw; -} + for (int i = messages.size() - 1; i >= 0; i--) { + auto *message = messages[i].get(); -void -ChatWidgetView::updateScrollbar() -{ - auto c = this->chatWidget->getChannel(); + message->layout(this->width(), true); - if (c == NULL) { - return; + h -= message->getHeight(); + + if (h < 0) { + this->scrollbar.setLargeChange((messages.length() - i) + + (qreal)h / message->getHeight()); + this->scrollbar.setValue(this->scrollbar.getValue()); + + showScrollbar = true; + } } - // this->scrollbar.setValue(0); - this->scrollbar.setLargeChange(10); + this->scrollbar.setVisible(showScrollbar); + this->scrollbar.setMaximum(c->getMessages().size()); + + return redraw; } void @@ -161,6 +172,8 @@ ChatWidgetView::paintEvent(QPaintEvent *) else { QColor color = wordPart.getWord().getColor(); + ColorScheme::getInstance().normalizeColor(color); + painter.setPen(color); painter.setFont(wordPart.getWord().getFont()); diff --git a/widgets/chatwidgetview.h b/widgets/chatwidgetview.h index e4a744590..f2e57820a 100644 --- a/widgets/chatwidgetview.h +++ b/widgets/chatwidgetview.h @@ -24,16 +24,12 @@ public: bool layoutMessages(); - void updateScrollbar(); - protected: void resizeEvent(QResizeEvent *); void paintEvent(QPaintEvent *); void wheelEvent(QWheelEvent *event); - void scroll(int dx, int dy); - private: ChatWidget *chatWidget; @@ -44,7 +40,7 @@ private slots: wordTypeMaskChanged() { if (layoutMessages()) { - repaint(); + update(); } } }; diff --git a/widgets/mainwindow.cpp b/widgets/mainwindow.cpp index 64e1930e8..1d2b2c823 100644 --- a/widgets/mainwindow.cpp +++ b/widgets/mainwindow.cpp @@ -42,7 +42,7 @@ MainWindow::layoutVisibleChatWidgets(Channel *channel) if (channel == NULL || channel == widget->getChannel()) { if (widget->getView().layoutMessages()) { - widget->repaint(); + widget->update(); } } } @@ -64,7 +64,7 @@ MainWindow::repaintVisibleChatWidgets(Channel *channel) if (channel == NULL || channel == widget->getChannel()) { widget->getView().layoutMessages(); - widget->repaint(); + widget->update(); } } } diff --git a/widgets/notebookbutton.cpp b/widgets/notebookbutton.cpp index 9c40cac36..d4742f6f4 100644 --- a/widgets/notebookbutton.cpp +++ b/widgets/notebookbutton.cpp @@ -93,7 +93,7 @@ NotebookButton::mousePressEvent(QMouseEvent *event) if (event->button() == Qt::LeftButton) { mouseDown = true; - this->repaint(); + this->update(); } } @@ -103,7 +103,7 @@ NotebookButton::mouseReleaseEvent(QMouseEvent *event) if (event->button() == Qt::LeftButton) { mouseDown = false; - this->repaint(); + this->update(); emit clicked(); } @@ -114,7 +114,7 @@ NotebookButton::enterEvent(QEvent *) { mouseOver = true; - this->repaint(); + this->update(); } void @@ -122,7 +122,7 @@ NotebookButton::leaveEvent(QEvent *) { mouseOver = false; - this->repaint(); + this->update(); } } } diff --git a/widgets/notebooktab.cpp b/widgets/notebooktab.cpp index 94222275f..592a933fd 100644 --- a/widgets/notebooktab.cpp +++ b/widgets/notebooktab.cpp @@ -140,7 +140,7 @@ NotebookTab::mousePressEvent(QMouseEvent *event) this->mouseDown = true; this->mouseDownX = this->getXRect().contains(event->pos()); - this->repaint(); + this->update(); this->notebook->select(page); } @@ -155,7 +155,7 @@ NotebookTab::mouseReleaseEvent(QMouseEvent *event) this->notebook->removePage(this->page); } else { - repaint(); + update(); } } @@ -164,7 +164,7 @@ NotebookTab::enterEvent(QEvent *) { this->mouseOver = true; - repaint(); + update(); } void @@ -172,7 +172,7 @@ NotebookTab::leaveEvent(QEvent *) { this->mouseOverX = this->mouseOver = false; - repaint(); + update(); } void @@ -189,7 +189,7 @@ NotebookTab::mouseMoveEvent(QMouseEvent *event) if (overX != this->mouseOverX) { this->mouseOverX = overX; - this->repaint(); + this->update(); } if (this->mouseDown && !this->getDesiredRect().contains(event->pos())) { diff --git a/widgets/notebooktab.h b/widgets/notebooktab.h index 360495b8c..db080f61c 100644 --- a/widgets/notebooktab.h +++ b/widgets/notebooktab.h @@ -50,7 +50,7 @@ public: setSelected(bool value) { this->selected = value; - repaint(); + update(); } HighlightStyle @@ -63,7 +63,7 @@ public: setHighlightStyle(HighlightStyle style) { this->highlightStyle = style; - repaint(); + update(); } void moveAnimated(QPoint pos, bool animated = true); @@ -115,7 +115,7 @@ private slots: hideTabXChanged(bool) { calcSize(); - repaint(); + update(); } }; } diff --git a/widgets/scrollbar.cpp b/widgets/scrollbar.cpp index ffd6dc911..9fc66cd8a 100644 --- a/widgets/scrollbar.cpp +++ b/widgets/scrollbar.cpp @@ -135,7 +135,7 @@ ScrollBar::mouseMoveEvent(QMouseEvent *event) } if (oldIndex != this->mouseOverIndex) { - this->repaint(); + this->update(); } } else if (this->mouseDownIndex == 2) { int delta = event->pos().y() - lastMousePosition.y(); @@ -191,7 +191,7 @@ ScrollBar::mouseReleaseEvent(QMouseEvent *event) } this->mouseDownIndex = -1; - repaint(); + update(); } void @@ -199,7 +199,7 @@ ScrollBar::leaveEvent(QEvent *) { this->mouseOverIndex = -1; - repaint(); + update(); } void @@ -216,7 +216,7 @@ ScrollBar::updateScroll() (int)(this->largeChange / this->maximum * this->trackHeight) + MIN_THUMB_HEIGHT); - repaint(); + update(); } } } diff --git a/widgets/scrollbar.h b/widgets/scrollbar.h index b647c7860..d814e04eb 100644 --- a/widgets/scrollbar.h +++ b/widgets/scrollbar.h @@ -77,7 +77,7 @@ public: this->updateScroll(); this->valueChanged(); - this->repaint(); + this->update(); } }