2016-07-11 18:05:46 +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-07-11 18:05:46 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
class TWidget;
|
|
|
|
|
2016-10-26 10:06:00 +00:00
|
|
|
#include "styles/style_widgets.h"
|
|
|
|
|
2016-07-11 18:05:46 +00:00
|
|
|
namespace Ui {
|
|
|
|
|
|
|
|
class FadeAnimation {
|
|
|
|
public:
|
2017-03-07 09:46:01 +00:00
|
|
|
FadeAnimation(TWidget *widget, bool scaled = false);
|
2016-07-11 18:05:46 +00:00
|
|
|
|
|
|
|
bool paint(Painter &p);
|
2016-07-12 11:38:16 +00:00
|
|
|
void refreshCache();
|
2016-07-11 18:05:46 +00:00
|
|
|
|
2016-11-20 12:54:07 +00:00
|
|
|
using FinishedCallback = base::lambda<void()>;
|
2016-07-11 18:05:46 +00:00
|
|
|
void setFinishedCallback(FinishedCallback &&callback);
|
|
|
|
|
2016-11-20 12:54:07 +00:00
|
|
|
using UpdatedCallback = base::lambda<void(float64)>;
|
2016-07-12 11:38:16 +00:00
|
|
|
void setUpdatedCallback(UpdatedCallback &&callback);
|
|
|
|
|
2016-07-11 18:05:46 +00:00
|
|
|
void show();
|
|
|
|
void hide();
|
|
|
|
|
|
|
|
void fadeIn(int duration);
|
|
|
|
void fadeOut(int duration);
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void finish() {
|
|
|
|
_animation.finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool animating() const {
|
|
|
|
return _animation.animating();
|
|
|
|
}
|
2017-05-05 10:14:40 +00:00
|
|
|
bool visible() const {
|
|
|
|
return _visible;
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2016-07-11 18:05:46 +00:00
|
|
|
private:
|
|
|
|
void startAnimation(int duration);
|
|
|
|
void stopAnimation();
|
|
|
|
|
|
|
|
void updateCallback();
|
2017-03-07 09:46:01 +00:00
|
|
|
QPixmap grabContent();
|
|
|
|
|
|
|
|
TWidget *_widget = nullptr;
|
|
|
|
bool _scaled = false;
|
2016-07-11 18:05:46 +00:00
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _animation;
|
2017-03-07 09:46:01 +00:00
|
|
|
QSize _size;
|
2016-07-11 18:05:46 +00:00
|
|
|
QPixmap _cache;
|
|
|
|
bool _visible = false;
|
|
|
|
|
|
|
|
FinishedCallback _finishedCallback;
|
2016-07-12 11:38:16 +00:00
|
|
|
UpdatedCallback _updatedCallback;
|
2016-07-11 18:05:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-10-26 10:06:00 +00:00
|
|
|
template <typename Widget>
|
2016-10-26 11:03:33 +00:00
|
|
|
class WidgetFadeWrap;
|
2016-10-26 10:06:00 +00:00
|
|
|
|
|
|
|
template <>
|
|
|
|
class WidgetFadeWrap<TWidget> : public TWidget {
|
|
|
|
public:
|
2016-12-13 17:07:56 +00:00
|
|
|
WidgetFadeWrap(QWidget *parent
|
|
|
|
, object_ptr<TWidget> entity
|
|
|
|
, int duration = st::widgetFadeDuration
|
2017-03-07 09:46:01 +00:00
|
|
|
, base::lambda<void()> updateCallback = base::lambda<void()>()
|
|
|
|
, bool scaled = false);
|
2016-10-26 10:06:00 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void showAnimated() {
|
2017-03-15 15:10:18 +00:00
|
|
|
toggleAnimated(true);
|
2016-10-26 10:06:00 +00:00
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
void hideAnimated() {
|
2017-03-15 15:10:18 +00:00
|
|
|
toggleAnimated(false);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2017-03-15 15:10:18 +00:00
|
|
|
void toggleAnimated(bool visible) {
|
|
|
|
if (visible) {
|
|
|
|
_animation.fadeIn(_duration);
|
|
|
|
} else {
|
|
|
|
_animation.fadeOut(_duration);
|
2016-10-26 10:06:00 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-15 15:10:18 +00:00
|
|
|
void showFast() {
|
|
|
|
toggleFast(true);
|
|
|
|
}
|
2016-10-26 10:06:00 +00:00
|
|
|
void hideFast() {
|
2017-03-15 15:10:18 +00:00
|
|
|
toggleFast(false);
|
|
|
|
}
|
|
|
|
void toggleFast(bool visible) {
|
|
|
|
if (visible) {
|
|
|
|
_animation.show();
|
|
|
|
} else {
|
|
|
|
_animation.hide();
|
|
|
|
}
|
2016-10-26 10:06:00 +00:00
|
|
|
if (_updateCallback) {
|
|
|
|
_updateCallback();
|
|
|
|
}
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
void finishAnimation() {
|
|
|
|
_animation.finish();
|
|
|
|
}
|
2016-10-26 10:06:00 +00:00
|
|
|
|
2017-05-05 10:14:40 +00:00
|
|
|
bool isHiddenOrHiding() const {
|
|
|
|
return !_animation.visible();
|
|
|
|
}
|
|
|
|
|
2016-10-26 10:06:00 +00:00
|
|
|
TWidget *entity() {
|
|
|
|
return _entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TWidget *entity() const {
|
|
|
|
return _entity;
|
|
|
|
}
|
|
|
|
|
2016-12-02 19:16:35 +00:00
|
|
|
QMargins getMargins() const override {
|
|
|
|
return _entity->getMargins();
|
|
|
|
}
|
|
|
|
int naturalWidth() const override {
|
|
|
|
return _entity->naturalWidth();
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
bool animating() const {
|
|
|
|
return _animation.animating();
|
|
|
|
}
|
2017-03-21 11:42:04 +00:00
|
|
|
void setUpdateCallback(base::lambda<void()> callback) {
|
|
|
|
_updateCallback = std::move(callback);
|
|
|
|
installCallbacks();
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2016-10-26 10:06:00 +00:00
|
|
|
protected:
|
|
|
|
bool eventFilter(QObject *object, QEvent *event) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
2017-03-21 11:42:04 +00:00
|
|
|
void installCallbacks();
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<TWidget> _entity;
|
2016-10-26 10:06:00 +00:00
|
|
|
int _duration;
|
2016-11-20 12:54:07 +00:00
|
|
|
base::lambda<void()> _updateCallback;
|
2016-10-26 10:06:00 +00:00
|
|
|
|
|
|
|
FadeAnimation _animation;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-10-26 11:03:33 +00:00
|
|
|
template <typename Widget>
|
|
|
|
class WidgetFadeWrap : public WidgetFadeWrap<TWidget> {
|
|
|
|
public:
|
2016-12-13 17:07:56 +00:00
|
|
|
WidgetFadeWrap(QWidget *parent
|
|
|
|
, object_ptr<Widget> entity
|
|
|
|
, int duration = st::widgetFadeDuration
|
2017-03-07 09:46:01 +00:00
|
|
|
, base::lambda<void()> updateCallback = base::lambda<void()>()
|
|
|
|
, bool scaled = false) : WidgetFadeWrap<TWidget>(parent
|
2017-02-21 13:45:56 +00:00
|
|
|
, std::move(entity)
|
2016-12-13 17:07:56 +00:00
|
|
|
, duration
|
2017-03-07 09:46:01 +00:00
|
|
|
, std::move(updateCallback)
|
|
|
|
, scaled) {
|
2016-10-26 11:03:33 +00:00
|
|
|
}
|
|
|
|
Widget *entity() {
|
|
|
|
return static_cast<Widget*>(WidgetFadeWrap<TWidget>::entity());
|
|
|
|
}
|
|
|
|
const Widget *entity() const {
|
|
|
|
return static_cast<const Widget*>(WidgetFadeWrap<TWidget>::entity());
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-03-07 09:46:01 +00:00
|
|
|
template <typename Widget>
|
|
|
|
class WidgetScaledFadeWrap : public WidgetFadeWrap<Widget> {
|
|
|
|
public:
|
|
|
|
WidgetScaledFadeWrap(QWidget *parent
|
|
|
|
, object_ptr<Widget> entity
|
|
|
|
, int duration = st::widgetFadeDuration
|
|
|
|
, base::lambda<void()> updateCallback = base::lambda<void()>()) : WidgetFadeWrap<Widget>(parent
|
|
|
|
, std::move(entity)
|
|
|
|
, duration
|
|
|
|
, std::move(updateCallback)
|
|
|
|
, true) {
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-07-11 18:05:46 +00:00
|
|
|
} // namespace Ui
|