added scrollbar and smooth scrolling

This commit is contained in:
fourtf
2017-01-26 04:26:40 +01:00
parent 3d6b9f7645
commit 700c756f5a
12 changed files with 333 additions and 10 deletions
+29 -4
View File
@@ -8,7 +8,6 @@
#include <math.h>
#include <QPainter>
#include <QScroller>
#include <functional>
namespace chatterino {
@@ -19,12 +18,12 @@ ChatWidgetView::ChatWidgetView(ChatWidget *parent)
, chatWidget(parent)
, scrollbar(this)
{
auto scroll = QScroller::scroller(this);
scroll->scrollTo(QPointF(0, 100));
this->scrollbar.setSmallChange(2);
QObject::connect(&Settings::getInstance(), &Settings::wordTypeMaskChanged,
this, &ChatWidgetView::wordTypeMaskChanged);
this->scrollbar.getValueChanged().connect([this] { repaint(); });
}
ChatWidgetView::~ChatWidgetView()
@@ -50,9 +49,25 @@ ChatWidgetView::layoutMessages()
redraw |= message.get()->layout(this->width(), true);
}
updateScrollbar();
return redraw;
}
void
ChatWidgetView::updateScrollbar()
{
auto c = this->chatWidget->getChannel();
if (c == NULL) {
return;
}
// this->scrollbar.setValue(0);
this->scrollbar.setLargeChange(10);
this->scrollbar.setMaximum(c->getMessages().size());
}
void
ChatWidgetView::resizeEvent(QResizeEvent *)
{
@@ -163,5 +178,15 @@ ChatWidgetView::paintEvent(QPaintEvent *)
}
}
}
void
ChatWidgetView::wheelEvent(QWheelEvent *event)
{
this->scrollbar.setValue(
this->scrollbar.getValue() -
event->delta() / 10.0 *
Settings::getInstance().mouseScrollMultiplier.get(),
true);
}
}
}