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
+41 -3
View File
@@ -4,7 +4,9 @@
#include "widgets/scrollbarhighlight.h"
#include <QMutex>
#include <QPropertyAnimation>
#include <QWidget>
#include <boost/signals2.hpp>
#include <functional>
namespace chatterino {
@@ -21,6 +23,8 @@ public:
void removeHighlightsWhere(std::function<bool(ScrollBarHighlight &)> func);
void addHighlight(ScrollBarHighlight *highlight);
Q_PROPERTY(qreal value READ getValue WRITE setValue)
void
setMaximum(qreal value)
{
@@ -54,11 +58,26 @@ public:
}
void
setValue(qreal value)
setValue(qreal value, bool animated = false)
{
this->value = value;
value = std::max(this->minimum,
std::min(this->maximum - this->largeChange, value));
this->updateScroll();
if (this->value != value) {
if (animated) {
this->valueAnimation.stop();
this->valueAnimation.setStartValue(this->value);
this->valueAnimation.setEndValue(value);
this->valueAnimation.start();
} else {
this->value = value;
}
this->updateScroll();
this->valueChanged();
this->repaint();
}
}
qreal
@@ -91,10 +110,27 @@ public:
return this->value;
}
boost::signals2::signal<void()> &
getValueChanged()
{
return valueChanged;
}
private:
QMutex mutex;
ScrollBarHighlight *highlights;
QPropertyAnimation valueAnimation;
void paintEvent(QPaintEvent *);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void leaveEvent(QEvent *);
int mouseOverIndex;
int mouseDownIndex;
QPoint lastMousePosition;
int buttonHeight;
int trackHeight;
@@ -107,6 +143,8 @@ private:
qreal smallChange;
qreal value;
boost::signals2::signal<void()> valueChanged;
void updateScroll();
};
}