2021-03-11 15:28:31 +00:00
|
|
|
// This file is part of Desktop App Toolkit,
|
|
|
|
// a set of libraries for developing nice desktop applications.
|
|
|
|
//
|
|
|
|
// For license and copyright information please follow this link:
|
|
|
|
// https://github.com/desktop-app/legal/blob/master/LEGAL
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "base/unique_qptr.h"
|
|
|
|
#include "ui/effects/animations.h"
|
|
|
|
#include "ui/effects/cross_line.h"
|
|
|
|
#include "ui/effects/gradient.h"
|
|
|
|
#include "ui/effects/radial_animation.h"
|
2021-05-28 10:47:41 +00:00
|
|
|
#include "ui/widgets/tooltip.h"
|
2021-03-11 15:28:31 +00:00
|
|
|
#include "lottie/lottie_icon.h"
|
|
|
|
|
2021-04-26 09:21:01 +00:00
|
|
|
namespace style {
|
|
|
|
struct CallMuteButton;
|
|
|
|
} // namespace style
|
|
|
|
|
2021-04-27 08:46:51 +00:00
|
|
|
namespace st {
|
|
|
|
extern const style::InfiniteRadialAnimation &callConnectingRadial;
|
|
|
|
} // namespace st
|
|
|
|
|
2021-03-11 15:28:31 +00:00
|
|
|
namespace Ui {
|
|
|
|
|
|
|
|
class BlobsWidget;
|
|
|
|
|
|
|
|
class AbstractButton;
|
|
|
|
class FlatLabel;
|
|
|
|
class RpWidget;
|
|
|
|
class AnimatedLabel;
|
|
|
|
|
|
|
|
struct CallButtonColors;
|
|
|
|
|
|
|
|
enum class CallMuteButtonType {
|
|
|
|
Connecting,
|
|
|
|
Active,
|
|
|
|
Muted,
|
|
|
|
ForceMuted,
|
|
|
|
RaisedHand,
|
2021-04-05 12:28:25 +00:00
|
|
|
ScheduledCanStart,
|
|
|
|
ScheduledSilent,
|
|
|
|
ScheduledNotify,
|
2021-03-11 15:28:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CallMuteButtonState {
|
|
|
|
QString text;
|
|
|
|
QString subtext;
|
2021-05-28 10:47:41 +00:00
|
|
|
QString tooltip;
|
2021-03-11 15:28:31 +00:00
|
|
|
CallMuteButtonType type = CallMuteButtonType::Connecting;
|
|
|
|
};
|
|
|
|
|
2021-05-28 10:47:41 +00:00
|
|
|
class CallMuteButton final : private AbstractTooltipShower {
|
2021-03-11 15:28:31 +00:00
|
|
|
public:
|
|
|
|
explicit CallMuteButton(
|
|
|
|
not_null<RpWidget*> parent,
|
2021-04-26 09:21:01 +00:00
|
|
|
const style::CallMuteButton &st,
|
2021-03-11 15:28:31 +00:00
|
|
|
rpl::producer<bool> &&hideBlobs,
|
|
|
|
CallMuteButtonState initial = CallMuteButtonState());
|
|
|
|
~CallMuteButton();
|
|
|
|
|
|
|
|
void setState(const CallMuteButtonState &state);
|
2021-04-26 09:21:01 +00:00
|
|
|
void setStyle(const style::CallMuteButton &st);
|
2021-03-11 15:28:31 +00:00
|
|
|
void setLevel(float level);
|
|
|
|
[[nodiscard]] rpl::producer<Qt::MouseButton> clicks();
|
|
|
|
|
|
|
|
[[nodiscard]] QSize innerSize() const;
|
|
|
|
[[nodiscard]] QRect innerGeometry() const;
|
|
|
|
void moveInner(QPoint position);
|
|
|
|
|
|
|
|
void shake();
|
|
|
|
|
|
|
|
void setVisible(bool visible);
|
|
|
|
void show() {
|
|
|
|
setVisible(true);
|
|
|
|
}
|
|
|
|
void hide() {
|
|
|
|
setVisible(false);
|
|
|
|
}
|
2021-05-11 13:17:35 +00:00
|
|
|
[[nodiscard]] bool isHidden() const;
|
2021-03-11 15:28:31 +00:00
|
|
|
void raise();
|
|
|
|
void lower();
|
|
|
|
|
2021-05-28 15:08:11 +00:00
|
|
|
[[nodiscard]] not_null<RpWidget*> outer() const;
|
2021-03-11 15:28:31 +00:00
|
|
|
[[nodiscard]] rpl::producer<CallButtonColors> colorOverrides() const;
|
|
|
|
|
|
|
|
[[nodiscard]] rpl::lifetime &lifetime();
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum class HandleMouseState {
|
|
|
|
Enabled,
|
|
|
|
Blocked,
|
|
|
|
Disabled,
|
|
|
|
};
|
|
|
|
struct RadialInfo {
|
|
|
|
std::optional<RadialState> state = std::nullopt;
|
|
|
|
bool isDirectionToShow = false;
|
|
|
|
rpl::variable<float64> rawShowProgress = 0.;
|
|
|
|
float64 realShowProgress = 0.;
|
|
|
|
const style::InfiniteRadialAnimation &st = st::callConnectingRadial;
|
|
|
|
};
|
|
|
|
struct IconState {
|
2021-04-08 16:25:50 +00:00
|
|
|
int index = -1;
|
2021-03-11 15:28:31 +00:00
|
|
|
int frameFrom = 0;
|
|
|
|
int frameTo = 0;
|
|
|
|
|
|
|
|
inline bool operator==(const IconState &other) const {
|
2021-04-08 16:25:50 +00:00
|
|
|
return (index == other.index)
|
2021-03-11 15:28:31 +00:00
|
|
|
&& (frameFrom == other.frameFrom)
|
2021-04-08 16:25:50 +00:00
|
|
|
&& (frameTo == other.frameTo);
|
2021-03-11 15:28:31 +00:00
|
|
|
}
|
|
|
|
inline bool operator!=(const IconState &other) const {
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
2021-04-08 16:25:50 +00:00
|
|
|
|
|
|
|
bool valid() const {
|
|
|
|
return (index >= 0);
|
|
|
|
}
|
|
|
|
explicit operator bool() const {
|
|
|
|
return valid();
|
|
|
|
}
|
2021-03-11 15:28:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void init();
|
2021-04-26 09:21:01 +00:00
|
|
|
void refreshIcons();
|
|
|
|
void refreshGradients();
|
|
|
|
void refreshLabels();
|
2021-03-11 15:28:31 +00:00
|
|
|
void overridesColors(
|
|
|
|
CallMuteButtonType fromType,
|
|
|
|
CallMuteButtonType toType,
|
|
|
|
float64 progress);
|
|
|
|
|
|
|
|
void setHandleMouseState(HandleMouseState state);
|
|
|
|
void updateCenterLabelGeometry(QRect my, QSize size);
|
|
|
|
void updateLabelGeometry(QRect my, QSize size);
|
|
|
|
void updateSublabelGeometry(QRect my, QSize size);
|
|
|
|
void updateLabelsGeometry();
|
|
|
|
|
|
|
|
[[nodiscard]] IconState iconStateFrom(CallMuteButtonType previous);
|
|
|
|
[[nodiscard]] IconState randomWavingState();
|
2021-04-08 16:25:50 +00:00
|
|
|
[[nodiscard]] IconState iconStateAnimated(CallMuteButtonType previous);
|
2021-03-11 15:28:31 +00:00
|
|
|
void scheduleIconState(const IconState &state);
|
|
|
|
void startIconState(const IconState &state);
|
|
|
|
void iconAnimationCallback();
|
|
|
|
|
2021-05-28 10:47:41 +00:00
|
|
|
QString tooltipText() const override;
|
|
|
|
QPoint tooltipPos() const override;
|
|
|
|
bool tooltipWindowActive() const override;
|
|
|
|
const style::Tooltip *tooltipSt() const override;
|
|
|
|
|
2021-03-11 15:28:31 +00:00
|
|
|
[[nodiscard]] static HandleMouseState HandleMouseStateFromType(
|
|
|
|
CallMuteButtonType type);
|
|
|
|
|
|
|
|
rpl::variable<CallMuteButtonState> _state;
|
|
|
|
float _level = 0.;
|
|
|
|
QRect _muteIconRect;
|
|
|
|
HandleMouseState _handleMouseState = HandleMouseState::Enabled;
|
|
|
|
|
2021-04-26 09:21:01 +00:00
|
|
|
not_null<const style::CallMuteButton*> _st;
|
2021-03-11 15:28:31 +00:00
|
|
|
|
|
|
|
const base::unique_qptr<BlobsWidget> _blobs;
|
|
|
|
const base::unique_qptr<AbstractButton> _content;
|
2021-04-26 09:21:01 +00:00
|
|
|
base::unique_qptr<AnimatedLabel> _centerLabel;
|
|
|
|
base::unique_qptr<AnimatedLabel> _label;
|
|
|
|
base::unique_qptr<AnimatedLabel> _sublabel;
|
2021-03-11 15:28:31 +00:00
|
|
|
int _labelShakeShift = 0;
|
|
|
|
|
|
|
|
RadialInfo _radialInfo;
|
|
|
|
std::unique_ptr<InfiniteRadialAnimation> _radial;
|
|
|
|
const base::flat_map<CallMuteButtonType, anim::gradient_colors> _colors;
|
2021-04-26 09:21:01 +00:00
|
|
|
anim::linear_gradients<CallMuteButtonType> _linearGradients;
|
|
|
|
anim::radial_gradients<CallMuteButtonType> _glowGradients;
|
2021-03-11 15:28:31 +00:00
|
|
|
|
2021-04-08 16:25:50 +00:00
|
|
|
std::array<std::optional<Lottie::Icon>, 2> _icons;
|
2021-03-11 15:28:31 +00:00
|
|
|
IconState _iconState;
|
|
|
|
std::optional<IconState> _scheduledState;
|
|
|
|
|
|
|
|
Animations::Simple _switchAnimation;
|
|
|
|
Animations::Simple _shakeAnimation;
|
|
|
|
|
|
|
|
rpl::event_stream<CallButtonColors> _colorOverrides;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Ui
|