2016-10-05 18:37:48 +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-05 18:37:48 +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-05 18:37:48 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2019-04-02 09:13:30 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2016-11-22 09:48:13 +00:00
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
|
2016-10-05 18:37:48 +00:00
|
|
|
namespace Ui {
|
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
class RippleAnimation;
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
class DiscreteSlider : public RpWidget {
|
2016-10-05 18:37:48 +00:00
|
|
|
public:
|
|
|
|
DiscreteSlider(QWidget *parent);
|
|
|
|
|
2016-10-06 16:41:09 +00:00
|
|
|
void addSection(const QString &label);
|
2016-11-22 09:48:13 +00:00
|
|
|
void setSections(const QStringList &labels);
|
2016-10-05 18:37:48 +00:00
|
|
|
int activeSection() const {
|
|
|
|
return _activeIndex;
|
|
|
|
}
|
|
|
|
void setActiveSection(int index);
|
|
|
|
void setActiveSectionFast(int index);
|
2017-09-30 19:20:40 +00:00
|
|
|
void finishAnimating();
|
2016-10-06 16:41:09 +00:00
|
|
|
|
2017-09-27 12:04:19 +00:00
|
|
|
auto sectionActivated() const {
|
2017-09-13 16:57:44 +00:00
|
|
|
return _sectionActivated.events();
|
|
|
|
}
|
2016-10-05 18:37:48 +00:00
|
|
|
|
|
|
|
protected:
|
2016-12-02 19:16:35 +00:00
|
|
|
void timerEvent(QTimerEvent *e) override;
|
2016-10-05 18:37:48 +00:00
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *e) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
int resizeGetHeight(int newWidth) override = 0;
|
2016-10-05 18:37:48 +00:00
|
|
|
|
|
|
|
struct Section {
|
2016-11-22 09:48:13 +00:00
|
|
|
Section(const QString &label, const style::font &font);
|
2016-10-05 18:37:48 +00:00
|
|
|
|
|
|
|
int left, width;
|
|
|
|
QString label;
|
|
|
|
int labelWidth;
|
2017-12-18 10:38:14 +00:00
|
|
|
std::unique_ptr<RippleAnimation> ripple;
|
2016-10-05 18:37:48 +00:00
|
|
|
};
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
int getCurrentActiveLeft();
|
2016-11-22 09:48:13 +00:00
|
|
|
|
|
|
|
int getSectionsCount() const {
|
|
|
|
return _sections.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Lambda>
|
|
|
|
void enumerateSections(Lambda callback);
|
|
|
|
|
2017-11-12 13:47:11 +00:00
|
|
|
template <typename Lambda>
|
|
|
|
void enumerateSections(Lambda callback) const;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
virtual void startRipple(int sectionIndex) {
|
2016-12-02 19:16:35 +00:00
|
|
|
}
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
void stopAnimation() {
|
2019-04-02 09:13:30 +00:00
|
|
|
_a_left.stop();
|
2016-11-22 09:48:13 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
void setSelectOnPress(bool selectOnPress);
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
private:
|
2016-12-02 19:16:35 +00:00
|
|
|
void activateCallback();
|
2016-11-22 09:48:13 +00:00
|
|
|
virtual const style::font &getLabelFont() const = 0;
|
|
|
|
virtual int getAnimationDuration() const = 0;
|
|
|
|
|
|
|
|
int getIndexFromPosition(QPoint pos);
|
|
|
|
void setSelectedSection(int index);
|
|
|
|
|
2017-12-18 10:38:14 +00:00
|
|
|
std::vector<Section> _sections;
|
2016-10-05 18:37:48 +00:00
|
|
|
int _activeIndex = 0;
|
2016-11-22 09:48:13 +00:00
|
|
|
bool _selectOnPress = true;
|
2016-10-05 18:37:48 +00:00
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
rpl::event_stream<int> _sectionActivated;
|
2016-10-06 16:41:09 +00:00
|
|
|
|
2016-12-05 08:45:56 +00:00
|
|
|
int _pressed = -1;
|
2016-10-05 18:37:48 +00:00
|
|
|
int _selected = 0;
|
2019-04-02 09:13:30 +00:00
|
|
|
Ui::Animations::Simple _a_left;
|
2016-11-22 09:48:13 +00:00
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
int _timerId = -1;
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time _callbackAfterMs = 0;
|
2016-12-02 19:16:35 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SettingsSlider : public DiscreteSlider {
|
|
|
|
public:
|
|
|
|
SettingsSlider(QWidget *parent, const style::SettingsSlider &st = st::defaultSettingsSlider);
|
|
|
|
|
2017-04-08 15:20:12 +00:00
|
|
|
void setRippleTopRoundRadius(int radius);
|
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void startRipple(int sectionIndex) override;
|
2016-12-02 19:16:35 +00:00
|
|
|
|
2016-11-22 09:48:13 +00:00
|
|
|
private:
|
|
|
|
const style::font &getLabelFont() const override;
|
|
|
|
int getAnimationDuration() const override;
|
2016-12-13 17:07:56 +00:00
|
|
|
QImage prepareRippleMask(int sectionIndex, const Section §ion);
|
2016-11-22 09:48:13 +00:00
|
|
|
|
|
|
|
void resizeSections(int newWidth);
|
2017-11-12 13:47:11 +00:00
|
|
|
std::vector<float64> countSectionsWidths(int newWidth) const;
|
2016-11-22 09:48:13 +00:00
|
|
|
|
|
|
|
const style::SettingsSlider &_st;
|
2017-04-08 15:20:12 +00:00
|
|
|
int _rippleTopRoundRadius = 0;
|
2016-10-05 18:37:48 +00:00
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
|
2016-10-05 18:37:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Ui
|