2017-06-06 17:18:23 +02:00
|
|
|
#pragma once
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "messages/LimitedQueue.hpp"
|
|
|
|
#include "singletons/SettingsManager.hpp"
|
|
|
|
#include "widgets/BaseWidget.hpp"
|
|
|
|
#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>
|
2018-04-03 02:55:32 +02:00
|
|
|
#include <pajlada/signals/signal.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-09-16 00:05:06 +02:00
|
|
|
class ChannelView;
|
2017-06-26 16:41:20 +02:00
|
|
|
|
2018-01-06 03:48:56 +01:00
|
|
|
class Scrollbar : public BaseWidget
|
2017-01-03 21:19:33 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2018-05-26 17:11:09 +02:00
|
|
|
Scrollbar(ChannelView *parent = nullptr);
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2018-01-06 03:48:56 +01:00
|
|
|
void addHighlight(ScrollbarHighlight highlight);
|
2018-06-13 13:27:10 +02:00
|
|
|
void addHighlightsAtStart(const std::vector<ScrollbarHighlight> &highlights_);
|
2018-01-06 03:48:56 +01:00
|
|
|
void replaceHighlight(size_t index, ScrollbarHighlight replacement);
|
2017-04-12 17:46:44 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
void pauseHighlights();
|
|
|
|
void unpauseHighlights();
|
|
|
|
|
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;
|
2018-06-13 13:27:10 +02:00
|
|
|
|
2017-12-18 18:55:09 +01:00
|
|
|
// offset the desired value without breaking smooth scolling
|
|
|
|
void offset(qreal value);
|
2018-04-03 02:55:32 +02:00
|
|
|
pajlada::Signals::NoArgSignal &getCurrentValueChanged();
|
2018-06-13 13:27:10 +02:00
|
|
|
pajlada::Signals::NoArgSignal &getDesiredValueChanged();
|
2017-04-12 17:46:44 +02:00
|
|
|
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;
|
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
Q_PROPERTY(qreal desiredValue_ READ getDesiredValue WRITE setDesiredValue)
|
2018-01-06 03:48:56 +01:00
|
|
|
|
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:
|
2018-06-13 13:27:10 +02:00
|
|
|
Q_PROPERTY(qreal currentValue_ READ getCurrentValue WRITE setCurrentValue)
|
2017-02-02 00:25:57 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
QMutex mutex_;
|
2017-01-26 04:26:40 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
QPropertyAnimation currentValueAnimation_;
|
2017-01-26 04:26:40 +01:00
|
|
|
|
2018-06-28 19:38:57 +02:00
|
|
|
LimitedQueue<ScrollbarHighlight> highlights_;
|
2018-06-13 13:27:10 +02:00
|
|
|
bool highlightsPaused_{false};
|
2018-06-28 19:38:57 +02:00
|
|
|
LimitedQueueSnapshot<ScrollbarHighlight> highlightSnapshot_;
|
|
|
|
LimitedQueueSnapshot<ScrollbarHighlight> getHighlightSnapshot();
|
2017-05-27 16:16:39 +02:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
bool atBottom_{false};
|
2017-12-18 22:13:46 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
int mouseOverIndex_ = -1;
|
|
|
|
int mouseDownIndex_ = -1;
|
|
|
|
QPoint lastMousePosition_;
|
2017-01-03 21:19:33 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
int buttonHeight_ = 0;
|
|
|
|
int trackHeight_ = 100;
|
2017-01-18 04:33:30 +01:00
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
QRect thumbRect_;
|
2017-01-18 04:33:30 +01:00
|
|
|
|
2018-06-13 13:27:10 +02: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
|
|
|
|
2018-06-13 13:27:10 +02:00
|
|
|
pajlada::Signals::NoArgSignal currentValueChanged_;
|
|
|
|
pajlada::Signals::NoArgSignal desiredValueChanged_;
|
2017-01-26 04:26:40 +01:00
|
|
|
|
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 chatterino
|