2016-11-11 16:46:04 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-11-11 16:46:04 +03:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-11-11 16:46:04 +03:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ui/abstract_button.h"
|
2019-02-04 16:34:50 +03:00
|
|
|
#include "ui/effects/animations.h"
|
2016-11-11 16:46:04 +03:00
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
|
2016-12-05 14:01:08 +03:00
|
|
|
#include <memory>
|
|
|
|
|
2016-11-11 16:46:04 +03:00
|
|
|
namespace Ui {
|
|
|
|
|
2016-11-15 14:56:49 +03:00
|
|
|
class RippleAnimation;
|
2017-11-24 19:47:07 +04:00
|
|
|
class NumbersAnimation;
|
2016-11-15 14:56:49 +03:00
|
|
|
|
2016-11-16 19:04:25 +03:00
|
|
|
class LinkButton : public AbstractButton {
|
2016-11-11 16:46:04 +03:00
|
|
|
public:
|
2016-11-16 19:04:25 +03:00
|
|
|
LinkButton(QWidget *parent, const QString &text, const style::LinkButton &st = st::defaultLinkButton);
|
2016-11-11 16:46:04 +03:00
|
|
|
|
2016-11-16 19:04:25 +03:00
|
|
|
int naturalWidth() const override;
|
2016-11-11 16:46:04 +03:00
|
|
|
|
|
|
|
void setText(const QString &text);
|
2018-09-21 19:28:46 +03:00
|
|
|
void setColorOverride(std::optional<QColor> textFg);
|
2016-11-15 14:56:49 +03:00
|
|
|
|
2016-11-11 16:46:04 +03:00
|
|
|
protected:
|
2016-11-11 23:01:00 +03:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2016-12-05 14:01:08 +03:00
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
2016-11-11 16:46:04 +03:00
|
|
|
|
|
|
|
private:
|
2018-05-07 20:44:33 +03:00
|
|
|
const style::LinkButton &_st;
|
2016-11-16 19:04:25 +03:00
|
|
|
QString _text;
|
|
|
|
int _textWidth = 0;
|
2018-09-21 19:28:46 +03:00
|
|
|
std::optional<QColor> _textFgOverride;
|
2016-11-15 14:56:49 +03:00
|
|
|
|
2016-11-16 19:04:25 +03:00
|
|
|
};
|
2016-11-11 16:46:04 +03:00
|
|
|
|
2016-11-16 19:04:25 +03:00
|
|
|
class RippleButton : public AbstractButton {
|
|
|
|
public:
|
|
|
|
RippleButton(QWidget *parent, const style::RippleAnimation &st);
|
2016-11-11 16:46:04 +03:00
|
|
|
|
2017-09-20 21:40:23 +03:00
|
|
|
void setForceRippled(
|
|
|
|
bool rippled,
|
|
|
|
anim::type animated = anim::type::normal);
|
2016-11-16 19:04:25 +03:00
|
|
|
bool forceRippled() const {
|
|
|
|
return _forceRippled;
|
|
|
|
}
|
2016-11-11 16:46:04 +03:00
|
|
|
|
2017-07-09 18:06:27 +03:00
|
|
|
static QPoint DisabledRippleStartPosition() {
|
|
|
|
return QPoint(-0x3FFFFFFF, -0x3FFFFFFF);
|
|
|
|
}
|
|
|
|
|
2017-12-05 20:14:15 +04:00
|
|
|
void clearState() override;
|
|
|
|
|
2016-11-16 19:04:25 +03:00
|
|
|
~RippleButton();
|
|
|
|
|
|
|
|
protected:
|
2019-04-02 13:13:30 +04:00
|
|
|
void paintRipple(QPainter &p, int x, int y, const QColor *colorOverride = nullptr);
|
2016-11-16 19:04:25 +03:00
|
|
|
|
2016-12-05 14:01:08 +03:00
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
2016-11-16 19:04:25 +03:00
|
|
|
|
|
|
|
virtual QImage prepareRippleMask() const;
|
|
|
|
virtual QPoint prepareRippleStartPosition() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ensureRipple();
|
2016-11-11 16:46:04 +03:00
|
|
|
|
2016-11-16 19:04:25 +03:00
|
|
|
const style::RippleAnimation &_st;
|
2017-02-21 16:45:56 +03:00
|
|
|
std::unique_ptr<RippleAnimation> _ripple;
|
2016-11-16 19:04:25 +03:00
|
|
|
bool _forceRippled = false;
|
2018-10-25 14:02:37 +04:00
|
|
|
rpl::lifetime _forceRippledSubscription;
|
2016-11-15 14:56:49 +03:00
|
|
|
|
2016-11-11 16:46:04 +03:00
|
|
|
};
|
|
|
|
|
2016-11-16 19:04:25 +03:00
|
|
|
class FlatButton : public RippleButton {
|
2016-11-11 16:46:04 +03:00
|
|
|
public:
|
2016-11-16 19:04:25 +03:00
|
|
|
FlatButton(QWidget *parent, const QString &text, const style::FlatButton &st);
|
2016-11-11 16:46:04 +03:00
|
|
|
|
|
|
|
void setText(const QString &text);
|
2019-06-10 14:50:21 +02:00
|
|
|
void setWidth(int w);
|
|
|
|
void setTextMargins(QMargins margins);
|
2016-11-16 19:04:25 +03:00
|
|
|
|
|
|
|
int32 textWidth() const;
|
2016-11-11 16:46:04 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2016-12-05 14:01:08 +03:00
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
2016-11-11 16:46:04 +03:00
|
|
|
|
|
|
|
private:
|
2019-06-10 14:50:21 +02:00
|
|
|
QString _text;
|
|
|
|
QMargins _textMargins;
|
|
|
|
int _width = 0;
|
2016-11-16 19:04:25 +03:00
|
|
|
|
|
|
|
const style::FlatButton &_st;
|
|
|
|
|
2016-11-11 16:46:04 +03:00
|
|
|
};
|
|
|
|
|
2017-05-30 18:21:05 +03:00
|
|
|
class RoundButton : public RippleButton, private base::Subscriber {
|
2016-11-11 16:46:04 +03:00
|
|
|
public:
|
2018-08-29 16:23:16 +03:00
|
|
|
RoundButton(
|
|
|
|
QWidget *parent,
|
2019-06-18 18:53:27 +02:00
|
|
|
rpl::producer<QString> text,
|
2018-08-29 16:23:16 +03:00
|
|
|
const style::RoundButton &st);
|
2016-11-11 16:46:04 +03:00
|
|
|
|
2019-06-18 18:53:27 +02:00
|
|
|
void setText(rpl::producer<QString> text);
|
2016-12-29 20:31:01 +04:00
|
|
|
|
|
|
|
void setNumbersText(const QString &numbersText) {
|
|
|
|
setNumbersText(numbersText, numbersText.toInt());
|
|
|
|
}
|
|
|
|
void setNumbersText(int numbers) {
|
|
|
|
setNumbersText(QString::number(numbers), numbers);
|
|
|
|
}
|
2018-06-04 18:35:11 +03:00
|
|
|
void setWidthChangedCallback(Fn<void()> callback);
|
2016-12-29 20:31:01 +04:00
|
|
|
void finishNumbersAnimation();
|
2016-11-11 16:46:04 +03:00
|
|
|
|
|
|
|
int contentWidth() const;
|
|
|
|
|
|
|
|
void setFullWidth(int newFullWidth);
|
2018-09-13 23:09:26 +03:00
|
|
|
void setFullRadius(bool enabled);
|
2016-11-11 16:46:04 +03:00
|
|
|
|
|
|
|
enum class TextTransform {
|
|
|
|
NoTransform,
|
|
|
|
ToUpper,
|
|
|
|
};
|
|
|
|
void setTextTransform(TextTransform transform);
|
|
|
|
|
2016-12-29 20:31:01 +04:00
|
|
|
~RoundButton();
|
|
|
|
|
2016-11-11 16:46:04 +03:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2016-11-16 19:04:25 +03:00
|
|
|
QImage prepareRippleMask() const override;
|
|
|
|
QPoint prepareRippleStartPosition() const override;
|
2016-11-11 16:46:04 +03:00
|
|
|
|
|
|
|
private:
|
2016-12-29 20:31:01 +04:00
|
|
|
void setNumbersText(const QString &numbersText, int numbers);
|
|
|
|
void numbersAnimationCallback();
|
2019-06-18 18:53:27 +02:00
|
|
|
void resizeToText(const QString &text);
|
2016-11-11 16:46:04 +03:00
|
|
|
|
2019-06-18 18:53:27 +02:00
|
|
|
rpl::variable<QString> _textFull;
|
2017-05-30 18:21:05 +03:00
|
|
|
QString _text;
|
2016-11-11 16:46:04 +03:00
|
|
|
int _textWidth;
|
|
|
|
|
2017-11-24 19:47:07 +04:00
|
|
|
std::unique_ptr<NumbersAnimation> _numbers;
|
2016-11-11 16:46:04 +03:00
|
|
|
|
|
|
|
int _fullWidthOverride = 0;
|
|
|
|
|
|
|
|
const style::RoundButton &_st;
|
|
|
|
|
|
|
|
TextTransform _transform = TextTransform::ToUpper;
|
2018-09-13 23:09:26 +03:00
|
|
|
bool _fullRadius = false;
|
2016-11-11 16:46:04 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-11-16 19:04:25 +03:00
|
|
|
class IconButton : public RippleButton {
|
2016-11-11 16:46:04 +03:00
|
|
|
public:
|
|
|
|
IconButton(QWidget *parent, const style::IconButton &st);
|
|
|
|
|
|
|
|
// Pass nullptr to restore the default icon.
|
2016-12-05 14:01:08 +03:00
|
|
|
void setIconOverride(const style::icon *iconOverride, const style::icon *iconOverOverride = nullptr);
|
|
|
|
void setRippleColorOverride(const style::color *colorOverride);
|
2016-11-11 16:46:04 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2016-12-05 14:01:08 +03:00
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
2016-11-11 16:46:04 +03:00
|
|
|
|
2016-11-16 19:04:25 +03:00
|
|
|
QImage prepareRippleMask() const override;
|
|
|
|
QPoint prepareRippleStartPosition() const override;
|
2016-11-15 14:56:49 +03:00
|
|
|
|
2016-11-16 19:04:25 +03:00
|
|
|
private:
|
2016-11-11 16:46:04 +03:00
|
|
|
const style::IconButton &_st;
|
|
|
|
const style::icon *_iconOverride = nullptr;
|
|
|
|
const style::icon *_iconOverrideOver = nullptr;
|
2016-12-05 14:01:08 +03:00
|
|
|
const style::color *_rippleColorOverride = nullptr;
|
2016-11-11 16:46:04 +03:00
|
|
|
|
2019-04-02 13:13:30 +04:00
|
|
|
Ui::Animations::Simple _a_over;
|
2016-11-11 16:46:04 +03:00
|
|
|
|
2016-11-16 19:04:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class LeftOutlineButton : public RippleButton {
|
|
|
|
public:
|
|
|
|
LeftOutlineButton(QWidget *parent, const QString &text, const style::OutlineButton &st = st::defaultLeftOutlineButton);
|
|
|
|
|
|
|
|
void setText(const QString &text);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
int resizeGetHeight(int newWidth) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString _text, _fullText;
|
|
|
|
int _textWidth, _fullTextWidth;
|
|
|
|
|
|
|
|
const style::OutlineButton &_st;
|
2016-11-15 14:56:49 +03:00
|
|
|
|
2016-11-11 16:46:04 +03:00
|
|
|
};
|
|
|
|
|
2016-11-21 20:46:29 +03:00
|
|
|
class CrossButton : public RippleButton {
|
|
|
|
public:
|
|
|
|
CrossButton(QWidget *parent, const style::CrossButton &st);
|
|
|
|
|
2017-11-27 15:43:57 +04:00
|
|
|
void toggle(bool shown, anim::type animated);
|
|
|
|
void show(anim::type animated) {
|
|
|
|
return toggle(true, animated);
|
2017-03-31 18:50:02 +03:00
|
|
|
}
|
2017-11-27 15:43:57 +04:00
|
|
|
void hide(anim::type animated) {
|
|
|
|
return toggle(false, animated);
|
2017-03-31 18:50:02 +03:00
|
|
|
}
|
2017-11-27 15:43:57 +04:00
|
|
|
void finishAnimating() {
|
2019-04-01 18:53:18 +04:00
|
|
|
_showAnimation.stop();
|
2017-11-27 15:43:57 +04:00
|
|
|
animationCallback();
|
2017-03-31 18:50:02 +03:00
|
|
|
}
|
2016-11-21 20:46:29 +03:00
|
|
|
|
2017-11-27 15:43:57 +04:00
|
|
|
bool toggled() const {
|
2016-11-21 20:46:29 +03:00
|
|
|
return _shown;
|
|
|
|
}
|
2017-04-04 16:19:49 +03:00
|
|
|
void setLoadingAnimation(bool enabled);
|
2016-11-21 20:46:29 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2016-12-05 14:01:08 +03:00
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
2016-11-21 20:46:29 +03:00
|
|
|
|
|
|
|
QImage prepareRippleMask() const override;
|
|
|
|
QPoint prepareRippleStartPosition() const override;
|
|
|
|
|
|
|
|
private:
|
2019-04-01 18:53:18 +04:00
|
|
|
bool loadingCallback(crl::time now);
|
|
|
|
bool stopLoadingAnimation(crl::time now);
|
2016-11-21 20:46:29 +03:00
|
|
|
void animationCallback();
|
|
|
|
|
|
|
|
const style::CrossButton &_st;
|
|
|
|
|
|
|
|
bool _shown = false;
|
2019-04-01 18:53:18 +04:00
|
|
|
Ui::Animations::Simple _showAnimation;
|
2016-11-21 20:46:29 +03:00
|
|
|
|
2019-02-19 10:57:53 +04:00
|
|
|
crl::time _loadingStopMs = 0;
|
2019-04-01 18:53:18 +04:00
|
|
|
Ui::Animations::Basic _loadingAnimation;
|
2017-04-04 16:19:49 +03:00
|
|
|
|
2016-11-21 20:46:29 +03:00
|
|
|
};
|
|
|
|
|
2016-11-11 16:46:04 +03:00
|
|
|
} // namespace Ui
|