2017-06-06 17:18:23 +02:00
|
|
|
#pragma once
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-12-31 00:50:07 +01:00
|
|
|
#include "singletons/settingsmanager.hpp"
|
2017-06-26 16:41:20 +02:00
|
|
|
#include "widgets/basewidget.hpp"
|
2017-11-12 17:21:50 +01:00
|
|
|
#include "widgets/helper/scrollbarhighlight.hpp"
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-01-18 04:52:47 +01:00
|
|
|
#include <QMutex>
|
2017-01-26 04:26:40 +01:00
|
|
|
#include <QPropertyAnimation>
|
2017-01-18 04:52:47 +01:00
|
|
|
#include <QWidget>
|
2017-01-26 04:26:40 +01:00
|
|
|
#include <boost/signals2.hpp>
|
2017-01-18 04:52:47 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
2017-06-26 16:41:20 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace widgets {
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-09-16 00:05:06 +02:00
|
|
|
class ChannelView;
|
2017-06-26 16:41:20 +02:00
|
|
|
|
|
|
|
class ScrollBar : public BaseWidget
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2017-09-16 00:05:06 +02:00
|
|
|
ScrollBar(ChannelView *parent = 0);
|
2017-01-03 21:19:33 +01:00
|
|
|
~ScrollBar();
|
|
|
|
|
2017-01-11 18:52:09 +01:00
|
|
|
void removeHighlightsWhere(std::function<bool(ScrollBarHighlight &)> func);
|
|
|
|
void addHighlight(ScrollBarHighlight *highlight);
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-12-19 01:11:35 +01:00
|
|
|
Q_PROPERTY(qreal desiredValue READ getDesiredValue WRITE setDesiredValue)
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-01-05 03:14:46 +01:00
|
|
|
void scrollToBottom(bool animate = false);
|
2017-06-06 17:18:23 +02:00
|
|
|
|
|
|
|
bool isAtBottom() const;
|
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
void setMaximum(qreal value);
|
|
|
|
void setMinimum(qreal value);
|
|
|
|
void setLargeChange(qreal value);
|
|
|
|
void setSmallChange(qreal value);
|
|
|
|
void setDesiredValue(qreal value, bool animated = false);
|
|
|
|
qreal getMaximum() const;
|
|
|
|
qreal getMinimum() const;
|
|
|
|
qreal getLargeChange() const;
|
|
|
|
qreal getSmallChange() const;
|
|
|
|
qreal getDesiredValue() const;
|
|
|
|
qreal getCurrentValue() const;
|
2017-12-18 18:55:09 +01:00
|
|
|
// offset the desired value without breaking smooth scolling
|
|
|
|
void offset(qreal value);
|
2017-04-12 17:46:44 +02:00
|
|
|
boost::signals2::signal<void()> &getCurrentValueChanged();
|
|
|
|
void setCurrentValue(qreal value);
|
2017-01-26 04:26:40 +01:00
|
|
|
|
2017-06-06 17:18:23 +02:00
|
|
|
void printCurrentState(const QString &prefix = QString()) const;
|
|
|
|
|
2017-12-26 16:54:39 +01:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *) override;
|
|
|
|
void resizeEvent(QResizeEvent *) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
|
|
|
void leaveEvent(QEvent *) override;
|
|
|
|
|
2017-01-03 21:19:33 +01:00
|
|
|
private:
|
2017-12-19 01:11:35 +01:00
|
|
|
Q_PROPERTY(qreal currentValue READ getCurrentValue WRITE setCurrentValue)
|
2017-02-02 00:25:57 +01:00
|
|
|
|
2017-12-19 01:11:35 +01:00
|
|
|
QMutex mutex;
|
2017-01-26 04:26:40 +01:00
|
|
|
|
2017-12-19 01:11:35 +01:00
|
|
|
QPropertyAnimation currentValueAnimation;
|
2017-01-26 04:26:40 +01:00
|
|
|
|
2017-12-19 01:11:35 +01:00
|
|
|
ScrollBarHighlight *highlights;
|
2017-05-27 16:16:39 +02:00
|
|
|
|
2017-12-18 22:13:46 +01:00
|
|
|
bool atBottom = false;
|
|
|
|
|
2017-12-19 01:11:35 +01:00
|
|
|
int mouseOverIndex = -1;
|
|
|
|
int mouseDownIndex = -1;
|
|
|
|
QPoint lastMousePosition;
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2017-12-26 16:54:39 +01:00
|
|
|
// int buttonHeight = 16;
|
|
|
|
int buttonHeight = 0;
|
2017-12-19 01:11:35 +01:00
|
|
|
int trackHeight = 100;
|
2017-01-18 04:33:30 +01:00
|
|
|
|
2017-12-19 01:11:35 +01:00
|
|
|
QRect thumbRect;
|
2017-01-18 04:33:30 +01:00
|
|
|
|
2017-12-19 01:11:35 +01:00
|
|
|
qreal maximum = 0;
|
|
|
|
qreal minimum = 0;
|
|
|
|
qreal largeChange = 0;
|
|
|
|
qreal smallChange = 5;
|
|
|
|
qreal desiredValue = 0;
|
|
|
|
qreal currentValue = 0;
|
|
|
|
qreal smoothScrollingOffset = 0;
|
2017-01-18 04:33:30 +01:00
|
|
|
|
2017-12-19 01:11:35 +01:00
|
|
|
boost::signals2::signal<void()> currentValueChanged;
|
2017-01-26 04:26:40 +01:00
|
|
|
|
2017-12-18 18:55:09 +01:00
|
|
|
pajlada::Settings::Setting<bool> &smoothScrollingSetting;
|
|
|
|
|
2017-01-18 04:33:30 +01:00
|
|
|
void updateScroll();
|
2017-01-03 21:19:33 +01:00
|
|
|
};
|
|
|
|
|
2017-06-06 17:18:23 +02:00
|
|
|
} // namespace widgets
|
|
|
|
} // namespace chatterino
|