tdesktop/Telegram/SourceFiles/window/window_connecting_widget.h

100 lines
2.1 KiB
C
Raw Normal View History

2018-05-07 17:44:33 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "base/timer.h"
2019-02-10 16:29:55 +00:00
#include "base/unique_qptr.h"
2019-04-02 09:13:30 +00:00
#include "ui/effects/animations.h"
2018-05-07 17:44:33 +00:00
namespace Ui {
2019-02-10 16:29:55 +00:00
class RpWidget;
2018-05-07 17:44:33 +00:00
} // namespace Ui
2020-06-10 14:52:44 +00:00
namespace Main {
class Account;
} // namespace Main
2018-05-07 17:44:33 +00:00
namespace Window {
class ConnectionState {
2018-05-07 17:44:33 +00:00
public:
2019-02-10 16:29:55 +00:00
ConnectionState(
not_null<Ui::RpWidget*> parent,
2020-06-10 14:52:44 +00:00
not_null<Main::Account*> account,
2018-05-07 17:44:33 +00:00
rpl::producer<bool> shown);
2019-02-10 16:29:55 +00:00
void raise();
void setForceHidden(bool hidden);
void setBottomSkip(int skip);
2018-05-07 17:44:33 +00:00
2019-02-10 16:29:55 +00:00
rpl::lifetime &lifetime() {
return _lifetime;
}
2018-05-07 17:44:33 +00:00
private:
2019-02-10 16:29:55 +00:00
class Widget;
2018-05-07 17:44:33 +00:00
struct State {
enum class Type {
Connected,
Connecting,
Waiting,
};
Type type = Type::Connected;
bool useProxy = false;
bool exposed = false;
2018-05-07 17:44:33 +00:00
bool underCursor = false;
bool updateReady = false;
2018-05-07 17:44:33 +00:00
int waitTillRetry = 0;
bool operator==(const State &other) const;
};
struct Layout {
bool visible = false;
bool hasRetry = false;
bool proxyEnabled = false;
bool progressShown = false;
int contentWidth = 0;
QString text;
int textWidth = 0;
};
2019-02-10 16:29:55 +00:00
void createWidget();
void finishAnimating();
2018-05-07 17:44:33 +00:00
void refreshState();
void applyState(const State &state);
void changeVisibilityWithLayout(const Layout &layout);
Layout computeLayout(const State &state) const;
void setLayout(const Layout &layout);
float64 currentVisibility() const;
2019-02-10 16:29:55 +00:00
rpl::producer<float64> visibility() const;
void updateWidth();
void updateVisibility();
void refreshProgressVisibility();
2018-05-07 17:44:33 +00:00
2020-06-10 14:52:44 +00:00
const not_null<Main::Account*> _account;
2019-02-10 16:29:55 +00:00
not_null<Ui::RpWidget*> _parent;
base::unique_qptr<QObject> _exposeFilter;
rpl::variable<int> _bottomSkip;
2019-02-10 16:29:55 +00:00
base::unique_qptr<Widget> _widget;
bool _forceHidden = false;
2018-05-07 17:44:33 +00:00
base::Timer _refreshTimer;
State _state;
Layout _currentLayout;
crl::time _connectingStartedAt = 0;
2019-04-02 09:13:30 +00:00
Ui::Animations::Simple _contentWidth;
Ui::Animations::Simple _visibility;
2018-05-07 17:44:33 +00:00
rpl::event_stream<float64> _visibilityValues;
2019-02-10 16:29:55 +00:00
rpl::lifetime _lifetime;
2018-05-07 17:44:33 +00:00
};
} // namespace Window