scrollbar values based on messages
This commit is contained in:
@@ -61,7 +61,7 @@ ChatWidget::setChannelName(const QString &name)
|
||||
}
|
||||
|
||||
this->view.layoutMessages();
|
||||
this->view.repaint();
|
||||
this->view.update();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+26
-13
@@ -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());
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -77,7 +77,7 @@ public:
|
||||
this->updateScroll();
|
||||
this->valueChanged();
|
||||
|
||||
this->repaint();
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user