2016-11-11 13:46:04 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-11-11 13:46:04 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ui/abstract_button.h"
|
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
namespace Ui {
|
|
|
|
|
2016-11-15 11:56:49 +00:00
|
|
|
class RippleAnimation;
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
class LinkButton : public AbstractButton {
|
2016-11-11 13:46:04 +00:00
|
|
|
public:
|
2016-11-16 16:04:25 +00:00
|
|
|
LinkButton(QWidget *parent, const QString &text, const style::LinkButton &st = st::defaultLinkButton);
|
2016-11-11 13:46:04 +00:00
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
int naturalWidth() const override;
|
2016-11-11 13:46:04 +00:00
|
|
|
|
|
|
|
void setText(const QString &text);
|
2016-11-15 11:56:49 +00:00
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
protected:
|
2016-11-11 20:01:00 +00:00
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
2016-11-11 13:46:04 +00:00
|
|
|
|
|
|
|
private:
|
2016-11-16 16:04:25 +00:00
|
|
|
QString _text;
|
|
|
|
int _textWidth = 0;
|
|
|
|
const style::LinkButton &_st;
|
2016-11-15 11:56:49 +00:00
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
};
|
2016-11-11 13:46:04 +00:00
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
class RippleButton : public AbstractButton {
|
|
|
|
public:
|
|
|
|
RippleButton(QWidget *parent, const style::RippleAnimation &st);
|
2016-11-11 13:46:04 +00:00
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
// Displays full ripple circle constantly.
|
|
|
|
enum class SetForceRippledWay {
|
|
|
|
Default,
|
|
|
|
SkipAnimation,
|
|
|
|
};
|
|
|
|
void setForceRippled(bool rippled, SetForceRippledWay way = SetForceRippledWay::Default);
|
|
|
|
bool forceRippled() const {
|
|
|
|
return _forceRippled;
|
|
|
|
}
|
2016-11-11 13:46:04 +00:00
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
~RippleButton();
|
|
|
|
|
|
|
|
protected:
|
2016-12-02 19:16:35 +00:00
|
|
|
void paintRipple(QPainter &p, int x, int y, TimeMs ms, const QColor *colorOverride = nullptr);
|
2016-11-16 16:04:25 +00:00
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
2016-11-16 16:04:25 +00:00
|
|
|
|
|
|
|
virtual QImage prepareRippleMask() const;
|
|
|
|
virtual QPoint prepareRippleStartPosition() const;
|
2016-12-02 19:16:35 +00:00
|
|
|
QPoint disabledRippleStartPosition() const {
|
|
|
|
return QPoint(-0x3FFFFFFF, -0x3FFFFFFF);
|
|
|
|
}
|
2016-12-26 22:46:36 +00:00
|
|
|
void resetRipples();
|
2016-11-16 16:04:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void ensureRipple();
|
|
|
|
void handleRipples(bool wasDown, bool wasPress);
|
2016-11-11 13:46:04 +00:00
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
const style::RippleAnimation &_st;
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<RippleAnimation> _ripple;
|
2016-11-16 16:04:25 +00:00
|
|
|
bool _forceRippled = false;
|
2016-11-15 11:56:49 +00:00
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
class FlatButton : public RippleButton {
|
2016-11-11 13:46:04 +00:00
|
|
|
public:
|
2016-11-16 16:04:25 +00:00
|
|
|
FlatButton(QWidget *parent, const QString &text, const style::FlatButton &st);
|
2016-11-11 13:46:04 +00:00
|
|
|
|
|
|
|
void setText(const QString &text);
|
2016-11-16 16:04:25 +00:00
|
|
|
void setWidth(int32 w);
|
|
|
|
|
|
|
|
int32 textWidth() const;
|
2016-11-11 13:46:04 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
2016-11-11 13:46:04 +00:00
|
|
|
|
|
|
|
private:
|
2016-11-16 16:04:25 +00:00
|
|
|
QString _text, _textForAutoSize;
|
|
|
|
int _width;
|
|
|
|
|
|
|
|
const style::FlatButton &_st;
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
class RoundButton : public RippleButton {
|
2016-11-11 13:46:04 +00:00
|
|
|
public:
|
|
|
|
RoundButton(QWidget *parent, const QString &text, const style::RoundButton &st);
|
|
|
|
|
|
|
|
void setText(const QString &text);
|
2016-12-29 16:31:01 +00:00
|
|
|
|
|
|
|
void setNumbersText(const QString &numbersText) {
|
|
|
|
setNumbersText(numbersText, numbersText.toInt());
|
|
|
|
}
|
|
|
|
void setNumbersText(int numbers) {
|
|
|
|
setNumbersText(QString::number(numbers), numbers);
|
|
|
|
}
|
|
|
|
void setWidthChangedCallback(base::lambda<void()> &&callback);
|
|
|
|
void stepNumbersAnimation(TimeMs ms);
|
|
|
|
void finishNumbersAnimation();
|
2016-11-11 13:46:04 +00:00
|
|
|
|
|
|
|
int contentWidth() const;
|
|
|
|
|
|
|
|
void setFullWidth(int newFullWidth);
|
|
|
|
|
|
|
|
enum class TextTransform {
|
|
|
|
NoTransform,
|
|
|
|
ToUpper,
|
|
|
|
};
|
|
|
|
void setTextTransform(TextTransform transform);
|
|
|
|
|
2016-12-29 16:31:01 +00:00
|
|
|
~RoundButton();
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
QImage prepareRippleMask() const override;
|
|
|
|
QPoint prepareRippleStartPosition() const override;
|
2016-11-11 13:46:04 +00:00
|
|
|
|
|
|
|
private:
|
2016-12-29 16:31:01 +00:00
|
|
|
void setNumbersText(const QString &numbersText, int numbers);
|
|
|
|
void numbersAnimationCallback();
|
2016-11-11 13:46:04 +00:00
|
|
|
void updateText();
|
|
|
|
void resizeToText();
|
|
|
|
|
|
|
|
QString _text, _fullText;
|
|
|
|
int _textWidth;
|
|
|
|
|
2016-12-29 16:31:01 +00:00
|
|
|
class Numbers;
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<Numbers> _numbers;
|
2016-11-11 13:46:04 +00:00
|
|
|
|
|
|
|
int _fullWidthOverride = 0;
|
|
|
|
|
|
|
|
const style::RoundButton &_st;
|
|
|
|
|
|
|
|
TextTransform _transform = TextTransform::ToUpper;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
class IconButton : public RippleButton {
|
2016-11-11 13:46:04 +00:00
|
|
|
public:
|
|
|
|
IconButton(QWidget *parent, const style::IconButton &st);
|
|
|
|
|
|
|
|
// Pass nullptr to restore the default icon.
|
2016-12-05 11:01:08 +00:00
|
|
|
void setIconOverride(const style::icon *iconOverride, const style::icon *iconOverOverride = nullptr);
|
|
|
|
void setRippleColorOverride(const style::color *colorOverride);
|
2016-11-11 13:46:04 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
2016-11-11 13:46:04 +00:00
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
QImage prepareRippleMask() const override;
|
|
|
|
QPoint prepareRippleStartPosition() const override;
|
2016-11-15 11:56:49 +00:00
|
|
|
|
2016-11-16 16:04:25 +00:00
|
|
|
private:
|
2016-11-11 13:46:04 +00:00
|
|
|
const style::IconButton &_st;
|
|
|
|
const style::icon *_iconOverride = nullptr;
|
|
|
|
const style::icon *_iconOverrideOver = nullptr;
|
2016-12-05 11:01:08 +00:00
|
|
|
const style::color *_rippleColorOverride = nullptr;
|
2016-11-11 13:46:04 +00:00
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_over;
|
2016-11-11 13:46:04 +00:00
|
|
|
|
2016-11-16 16:04:25 +00: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 11:56:49 +00:00
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
};
|
|
|
|
|
2016-11-21 17:46:29 +00:00
|
|
|
class CrossButton : public RippleButton {
|
|
|
|
public:
|
|
|
|
CrossButton(QWidget *parent, const style::CrossButton &st);
|
|
|
|
|
|
|
|
void showAnimated();
|
2017-02-03 20:07:26 +00:00
|
|
|
void showFast();
|
2016-11-21 17:46:29 +00:00
|
|
|
void hideAnimated();
|
|
|
|
void hideFast();
|
|
|
|
|
|
|
|
bool isShown() const {
|
|
|
|
return _shown;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
2016-12-05 11:01:08 +00:00
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
2016-11-21 17:46:29 +00:00
|
|
|
|
|
|
|
QImage prepareRippleMask() const override;
|
|
|
|
QPoint prepareRippleStartPosition() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void startAnimation(bool shown);
|
|
|
|
void animationCallback();
|
|
|
|
|
|
|
|
const style::CrossButton &_st;
|
|
|
|
|
|
|
|
bool _shown = false;
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_show;
|
2016-11-21 17:46:29 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-11-11 13:46:04 +00:00
|
|
|
} // namespace Ui
|