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"
|
2019-03-07 11:35:28 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2018-06-15 18:56:17 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2019-01-18 11:26:43 +00:00
|
|
|
namespace base {
|
|
|
|
class Timer;
|
|
|
|
} // namespace base
|
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
namespace Ui {
|
|
|
|
|
2018-06-15 18:56:17 +00:00
|
|
|
class ContinuousSlider : public RpWidget {
|
2016-10-12 19:34:25 +00:00
|
|
|
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);
|
2019-03-05 11:06:54 +00:00
|
|
|
void setValue(float64 value, float64 receivedTill);
|
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
|
|
|
|
2018-06-15 18:56:17 +00:00
|
|
|
void setAdjustCallback(Fn<float64(float64)> callback) {
|
|
|
|
_adjustCallback = std::move(callback);
|
|
|
|
}
|
|
|
|
void setChangeProgressCallback(Fn<void(float64)> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_changeProgressCallback = std::move(callback);
|
2016-10-12 19:34:25 +00:00
|
|
|
}
|
2018-06-15 18:56:17 +00:00
|
|
|
void setChangeFinishedCallback(Fn<void(float64)> 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;
|
|
|
|
}
|
2019-03-05 11:06:54 +00:00
|
|
|
float64 getCurrentValue() const {
|
2017-05-18 16:10:39 +00:00
|
|
|
return _mouseDown ? _downValue : _value;
|
2016-10-12 19:34:25 +00:00
|
|
|
}
|
2019-03-05 11:06:54 +00:00
|
|
|
float64 getCurrentReceivedTill() const {
|
|
|
|
return _receivedTill;
|
|
|
|
}
|
2019-03-07 11:35:28 +00:00
|
|
|
float64 getCurrentOverFactor() {
|
2019-04-01 14:53:18 +00:00
|
|
|
return _disabled ? 0. : _overAnimation.value(_over ? 1. : 0.);
|
2016-10-12 19:34:25 +00:00
|
|
|
}
|
|
|
|
Direction getDirection() const {
|
|
|
|
return _direction;
|
|
|
|
}
|
|
|
|
bool isHorizontal() const {
|
|
|
|
return (_direction == Direction::Horizontal);
|
|
|
|
}
|
2019-03-05 11:06:54 +00:00
|
|
|
QRect getSeekRect() const;
|
|
|
|
virtual QSize getSeekDecreaseSize() const = 0;
|
2016-10-12 19:34:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
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;
|
|
|
|
|
2019-01-18 11:26:43 +00:00
|
|
|
std::unique_ptr<base::Timer> _byWheelFinished;
|
2016-10-13 08:33:12 +00:00
|
|
|
|
2018-06-15 18:56:17 +00:00
|
|
|
Fn<float64(float64)> _adjustCallback;
|
|
|
|
Fn<void(float64)> _changeProgressCallback;
|
|
|
|
Fn<void(float64)> _changeFinishedCallback;
|
2016-10-12 19:34:25 +00:00
|
|
|
|
|
|
|
bool _over = false;
|
2019-04-01 14:53:18 +00:00
|
|
|
Ui::Animations::Simple _overAnimation;
|
2016-10-12 19:34:25 +00:00
|
|
|
|
2017-05-18 16:10:39 +00:00
|
|
|
float64 _value = 0.;
|
2019-03-05 11:06:54 +00:00
|
|
|
float64 _receivedTill = 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:
|
2019-03-05 11:06:54 +00:00
|
|
|
QSize getSeekDecreaseSize() const override;
|
2016-11-22 09:48:13 +00:00
|
|
|
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();
|
|
|
|
}
|
2018-06-06 08:56:39 +00:00
|
|
|
void disablePaint(bool disabled);
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2018-08-31 13:01:42 +00:00
|
|
|
template <
|
|
|
|
typename Value,
|
|
|
|
typename Convert,
|
|
|
|
typename Callback,
|
|
|
|
typename = std::enable_if_t<
|
|
|
|
rpl::details::is_callable_plain_v<Callback, Value>
|
|
|
|
&& std::is_same_v<Value, decltype(std::declval<Convert>()(1))>>>
|
|
|
|
void setPseudoDiscrete(
|
|
|
|
int valuesCount,
|
|
|
|
Convert &&convert,
|
|
|
|
Value current,
|
|
|
|
Callback &&callback) {
|
|
|
|
Expects(valuesCount > 1);
|
|
|
|
|
|
|
|
setAlwaysDisplayMarker(true);
|
|
|
|
setDirection(Ui::ContinuousSlider::Direction::Horizontal);
|
|
|
|
|
|
|
|
const auto sectionsCount = (valuesCount - 1);
|
2019-03-01 14:20:04 +00:00
|
|
|
setValue(1.);
|
2018-08-31 13:01:42 +00:00
|
|
|
for (auto index = index_type(); index != valuesCount; ++index) {
|
|
|
|
if (current <= convert(index)) {
|
|
|
|
setValue(index / float64(sectionsCount));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setAdjustCallback([=](float64 value) {
|
|
|
|
return std::round(value * sectionsCount) / sectionsCount;
|
|
|
|
});
|
|
|
|
setChangeProgressCallback([
|
|
|
|
=,
|
|
|
|
convert = std::forward<Convert>(convert),
|
|
|
|
callback = std::forward<Callback>(callback)
|
|
|
|
](float64 value) {
|
|
|
|
const auto index = int(std::round(value * sectionsCount));
|
|
|
|
callback(convert(index));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-01-30 11:43:46 +00:00
|
|
|
void addDivider(float64 atValue, const QSize &size);
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
2021-01-30 11:43:46 +00:00
|
|
|
struct Divider {
|
|
|
|
const float64 atValue;
|
|
|
|
const QSize size;
|
|
|
|
};
|
|
|
|
|
2019-03-05 11:06:54 +00:00
|
|
|
QSize getSeekDecreaseSize() const override;
|
2016-11-22 09:48:13 +00:00
|
|
|
float64 getOverDuration() const override;
|
|
|
|
|
|
|
|
const style::MediaSlider &_st;
|
|
|
|
bool _alwaysDisplayMarker = false;
|
2018-06-06 08:56:39 +00:00
|
|
|
bool _paintDisabled = false;
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2021-01-30 11:43:46 +00:00
|
|
|
std::vector<Divider> _dividers;
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
};
|
|
|
|
|
2016-10-12 19:34:25 +00:00
|
|
|
} // namespace Ui
|