2016-10-12 19:34:25 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-10-12 19:34:25 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-10-12 19:34:25 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
namespace Ui {
|
|
|
|
|
|
|
|
class ContinuousSlider : public TWidget {
|
|
|
|
public:
|
|
|
|
ContinuousSlider(QWidget *parent);
|
|
|
|
|
|
|
|
enum class Direction {
|
|
|
|
Horizontal,
|
|
|
|
Vertical,
|
|
|
|
};
|
|
|
|
void setDirection(Direction direction) {
|
|
|
|
_direction = direction;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
float64 value() const;
|
2017-05-18 16:10:39 +00:00
|
|
|
void setValue(float64 value);
|
2016-10-12 19:34:25 +00:00
|
|
|
void setFadeOpacity(float64 opacity);
|
|
|
|
void setDisabled(bool disabled);
|
2016-10-14 17:10:15 +00:00
|
|
|
bool isDisabled() const {
|
|
|
|
return _disabled;
|
|
|
|
}
|
2016-10-12 19:34:25 +00:00
|
|
|
|
2016-11-20 12:54:07 +00:00
|
|
|
using Callback = base::lambda<void(float64)>;
|
2016-10-12 19:34:25 +00:00
|
|
|
void setChangeProgressCallback(Callback &&callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_changeProgressCallback = std::move(callback);
|
2016-10-12 19:34:25 +00:00
|
|
|
}
|
|
|
|
void setChangeFinishedCallback(Callback &&callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_changeFinishedCallback = std::move(callback);
|
2016-10-12 19:34:25 +00:00
|
|
|
}
|
|
|
|
bool isChanging() const {
|
|
|
|
return _mouseDown;
|
|
|
|
}
|
|
|
|
|
2016-10-18 15:19:13 +00:00
|
|
|
void setMoveByWheel(bool move);
|
2016-10-13 08:33:12 +00:00
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
protected:
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
2016-10-13 08:33:12 +00:00
|
|
|
void wheelEvent(QWheelEvent *e) override;
|
2017-02-11 11:24:37 +00:00
|
|
|
void enterEventHook(QEvent *e) override;
|
|
|
|
void leaveEventHook(QEvent *e) override;
|
2016-10-12 19:34:25 +00:00
|
|
|
|
|
|
|
float64 fadeOpacity() const {
|
|
|
|
return _fadeOpacity;
|
|
|
|
}
|
2017-05-18 16:10:39 +00:00
|
|
|
float64 getCurrentValue() {
|
|
|
|
return _mouseDown ? _downValue : _value;
|
2016-10-12 19:34:25 +00:00
|
|
|
}
|
2016-12-01 19:20:33 +00:00
|
|
|
float64 getCurrentOverFactor(TimeMs ms) {
|
2016-10-13 09:12:12 +00:00
|
|
|
return _disabled ? 0. : _a_over.current(ms, _over ? 1. : 0.);
|
2016-10-12 19:34:25 +00:00
|
|
|
}
|
|
|
|
Direction getDirection() const {
|
|
|
|
return _direction;
|
|
|
|
}
|
|
|
|
bool isHorizontal() const {
|
|
|
|
return (_direction == Direction::Horizontal);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual QRect getSeekRect() const = 0;
|
|
|
|
virtual float64 getOverDuration() const = 0;
|
|
|
|
|
2016-10-18 15:19:13 +00:00
|
|
|
bool moveByWheel() const {
|
|
|
|
return _byWheelFinished != nullptr;
|
|
|
|
}
|
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
void setOver(bool over);
|
|
|
|
float64 computeValue(const QPoint &pos) const;
|
|
|
|
void updateDownValueFromPos(const QPoint &pos);
|
|
|
|
|
|
|
|
Direction _direction = Direction::Horizontal;
|
|
|
|
bool _disabled = false;
|
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<SingleTimer> _byWheelFinished;
|
2016-10-13 08:33:12 +00:00
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
Callback _changeProgressCallback;
|
|
|
|
Callback _changeFinishedCallback;
|
|
|
|
|
|
|
|
bool _over = false;
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_over;
|
2016-10-12 19:34:25 +00:00
|
|
|
|
2017-05-18 16:10:39 +00:00
|
|
|
float64 _value = 0.;
|
2016-10-12 19:34:25 +00:00
|
|
|
|
|
|
|
bool _mouseDown = false;
|
|
|
|
float64 _downValue = 0.;
|
|
|
|
|
|
|
|
float64 _fadeOpacity = 1.;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
class FilledSlider : public ContinuousSlider {
|
|
|
|
public:
|
|
|
|
FilledSlider(QWidget *parent, const style::FilledSlider &st);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QRect getSeekRect() const override;
|
|
|
|
float64 getOverDuration() const override;
|
|
|
|
|
|
|
|
const style::FilledSlider &_st;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class MediaSlider : public ContinuousSlider {
|
|
|
|
public:
|
|
|
|
MediaSlider(QWidget *parent, const style::MediaSlider &st);
|
|
|
|
|
|
|
|
void setAlwaysDisplayMarker(bool alwaysDisplayMarker) {
|
|
|
|
_alwaysDisplayMarker = alwaysDisplayMarker;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QRect getSeekRect() const override;
|
|
|
|
float64 getOverDuration() const override;
|
|
|
|
|
|
|
|
const style::MediaSlider &_st;
|
|
|
|
bool _alwaysDisplayMarker = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
} // namespace Ui
|