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
|
|
|
|
*/
|
|
|
|
#include "window/window_connecting_widget.h"
|
|
|
|
|
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/effects/radial_animation.h"
|
2018-05-10 10:34:06 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
2018-05-07 17:44:33 +00:00
|
|
|
#include "boxes/connection_box.h"
|
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "styles/style_window.h"
|
|
|
|
|
|
|
|
namespace Window {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kIgnoreStartConnectingFor = TimeMs(3000);
|
|
|
|
constexpr auto kConnectingStateDelay = TimeMs(1000);
|
|
|
|
constexpr auto kRefreshTimeout = TimeMs(200);
|
|
|
|
constexpr auto kMinimalWaitingStateDuration = TimeMs(4000);
|
|
|
|
|
|
|
|
class Progress : public Ui::RpWidget {
|
|
|
|
public:
|
|
|
|
Progress(QWidget *parent);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void step(TimeMs ms, bool timer);
|
|
|
|
|
|
|
|
Ui::InfiniteRadialAnimation _animation;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Progress::Progress(QWidget *parent)
|
|
|
|
: RpWidget(parent)
|
|
|
|
, _animation(animation(this, &Progress::step), st::connectingRadial) {
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
resize(st::connectingRadial.size);
|
2019-02-10 16:29:55 +00:00
|
|
|
_animation.start(st::connectingRadial.sineDuration);
|
2018-05-07 17:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Progress::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
p.fillRect(e->rect(), st::windowBg);
|
|
|
|
const auto &st = st::connectingRadial;
|
|
|
|
const auto shift = st.thickness - (st.thickness / 2);
|
|
|
|
_animation.draw(
|
|
|
|
p,
|
|
|
|
{ shift, shift },
|
|
|
|
QSize(st.size.width() - 2 * shift, st.size.height() - 2 * shift),
|
|
|
|
width());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Progress::step(TimeMs ms, bool timer) {
|
2018-09-20 16:39:59 +00:00
|
|
|
if (timer && !anim::Disabled()) {
|
2018-05-07 17:44:33 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
class ConnectionState::Widget : public Ui::AbstractButton {
|
|
|
|
public:
|
|
|
|
Widget(QWidget *parent, const Layout &layout);
|
|
|
|
|
|
|
|
void refreshRetryLink(bool hasRetry);
|
|
|
|
void setLayout(const Layout &layout);
|
|
|
|
void setProgressVisibility(bool visible);
|
|
|
|
|
|
|
|
rpl::producer<> refreshStateRequests() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
void onStateChanged(State was, StateChangeSource source) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
class ProxyIcon;
|
|
|
|
using State = ConnectionState::State;
|
|
|
|
using Layout = ConnectionState::Layout;
|
|
|
|
|
|
|
|
void updateRetryGeometry();
|
|
|
|
QRect innerRect() const;
|
|
|
|
QRect contentRect() const;
|
|
|
|
QRect textRect() const;
|
|
|
|
|
|
|
|
Layout _currentLayout;
|
|
|
|
base::unique_qptr<Ui::LinkButton> _retry;
|
|
|
|
QPointer<Ui::RpWidget> _progress;
|
|
|
|
QPointer<ProxyIcon> _proxyIcon;
|
|
|
|
rpl::event_stream<> _refreshStateRequests;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConnectionState::Widget::ProxyIcon
|
2018-05-10 10:34:06 +00:00
|
|
|
: public Ui::RpWidget
|
|
|
|
, private base::Subscriber {
|
2018-05-07 17:44:33 +00:00
|
|
|
public:
|
|
|
|
ProxyIcon(QWidget *parent);
|
|
|
|
|
|
|
|
void setToggled(bool toggled);
|
|
|
|
void setOpacity(float64 opacity);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
private:
|
2018-05-10 10:34:06 +00:00
|
|
|
void refreshCacheImages();
|
|
|
|
|
2018-05-07 17:44:33 +00:00
|
|
|
float64 _opacity = 1.;
|
|
|
|
QPixmap _cacheOn;
|
|
|
|
QPixmap _cacheOff;
|
|
|
|
bool _toggled = true;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
ConnectionState::Widget::ProxyIcon::ProxyIcon(QWidget *parent) : RpWidget(parent) {
|
2018-05-07 17:44:33 +00:00
|
|
|
resize(
|
|
|
|
std::max(
|
|
|
|
st::connectingRadial.size.width(),
|
|
|
|
st::connectingProxyOn.width()),
|
|
|
|
std::max(
|
|
|
|
st::connectingRadial.size.height(),
|
|
|
|
st::connectingProxyOn.height()));
|
|
|
|
|
2018-05-10 10:34:06 +00:00
|
|
|
using namespace Window::Theme;
|
|
|
|
subscribe(Background(), [=](const BackgroundUpdate &update) {
|
|
|
|
if (update.paletteChanged()) {
|
|
|
|
refreshCacheImages();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
refreshCacheImages();
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::Widget::ProxyIcon::refreshCacheImages() {
|
2018-05-07 17:44:33 +00:00
|
|
|
const auto prepareCache = [&](const style::icon &icon) {
|
|
|
|
auto image = QImage(
|
|
|
|
size() * cIntRetinaFactor(),
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
2018-05-10 10:34:06 +00:00
|
|
|
image.setDevicePixelRatio(cRetinaFactor());
|
2018-05-07 17:44:33 +00:00
|
|
|
image.fill(st::windowBg->c);
|
|
|
|
{
|
|
|
|
Painter p(&image);
|
|
|
|
icon.paint(
|
|
|
|
p,
|
|
|
|
(width() - icon.width()) / 2,
|
|
|
|
(height() - icon.height()) / 2,
|
|
|
|
width());
|
|
|
|
}
|
|
|
|
return App::pixmapFromImageInPlace(std::move(image));
|
|
|
|
};
|
|
|
|
_cacheOn = prepareCache(st::connectingProxyOn);
|
|
|
|
_cacheOff = prepareCache(st::connectingProxyOff);
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::Widget::ProxyIcon::setToggled(bool toggled) {
|
2018-05-07 17:44:33 +00:00
|
|
|
if (_toggled != toggled) {
|
|
|
|
_toggled = toggled;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::Widget::ProxyIcon::setOpacity(float64 opacity) {
|
2018-05-07 17:44:33 +00:00
|
|
|
_opacity = opacity;
|
|
|
|
if (_opacity == 0.) {
|
|
|
|
hide();
|
|
|
|
} else if (isHidden()) {
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::Widget::ProxyIcon::paintEvent(QPaintEvent *e) {
|
2018-05-07 17:44:33 +00:00
|
|
|
Painter p(this);
|
|
|
|
p.setOpacity(_opacity);
|
|
|
|
p.drawPixmap(0, 0, _toggled ? _cacheOn : _cacheOff);
|
|
|
|
}
|
|
|
|
|
2019-02-11 12:55:54 +00:00
|
|
|
bool ConnectionState::State::operator==(const State &other) const {
|
2018-05-07 17:44:33 +00:00
|
|
|
return (type == other.type)
|
|
|
|
&& (useProxy == other.useProxy)
|
|
|
|
&& (underCursor == other.underCursor)
|
|
|
|
&& (waitTillRetry == other.waitTillRetry);
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
ConnectionState::ConnectionState(
|
|
|
|
not_null<Ui::RpWidget*> parent,
|
|
|
|
rpl::producer<bool> shown)
|
|
|
|
: _parent(parent)
|
2018-05-07 17:44:33 +00:00
|
|
|
, _refreshTimer([=] { refreshState(); })
|
|
|
|
, _currentLayout(computeLayout(_state)) {
|
2019-02-10 16:29:55 +00:00
|
|
|
rpl::combine(
|
|
|
|
std::move(shown),
|
|
|
|
visibility()
|
|
|
|
) | rpl::start_with_next([=](bool shown, float64 visible) {
|
|
|
|
if (!shown || visible == 0.) {
|
|
|
|
_widget = nullptr;
|
|
|
|
} else if (!_widget) {
|
|
|
|
createWidget();
|
|
|
|
}
|
|
|
|
}, _lifetime);
|
2018-05-07 17:44:33 +00:00
|
|
|
|
|
|
|
subscribe(Global::RefConnectionTypeChanged(), [=] {
|
|
|
|
refreshState();
|
|
|
|
});
|
|
|
|
refreshState();
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::createWidget() {
|
|
|
|
_widget = base::make_unique_q<Widget>(_parent, _currentLayout);
|
|
|
|
_widget->setVisible(!_forceHidden);
|
2018-05-07 17:44:33 +00:00
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
updateWidth();
|
2018-05-07 17:44:33 +00:00
|
|
|
|
|
|
|
rpl::combine(
|
2019-02-10 16:29:55 +00:00
|
|
|
visibility(),
|
|
|
|
_parent->heightValue()
|
2018-05-10 10:24:40 +00:00
|
|
|
) | rpl::start_with_next([=](float64 visible, int height) {
|
2019-02-10 16:29:55 +00:00
|
|
|
_widget->moveToLeft(0, anim::interpolate(
|
2018-05-07 17:44:33 +00:00
|
|
|
height - st::connectingMargin.top(),
|
2019-02-10 16:29:55 +00:00
|
|
|
height - _widget->height(),
|
2018-05-07 17:44:33 +00:00
|
|
|
visible));
|
2019-02-10 16:29:55 +00:00
|
|
|
}, _widget->lifetime());
|
2018-05-07 17:44:33 +00:00
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
_widget->refreshStateRequests(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
refreshState();
|
|
|
|
}, _widget->lifetime());
|
2018-05-07 17:44:33 +00:00
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::raise() {
|
|
|
|
if (_widget) {
|
|
|
|
_widget->raise();
|
2018-05-07 17:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::finishAnimating() {
|
|
|
|
if (_contentWidth.animating()) {
|
|
|
|
_contentWidth.finish();
|
|
|
|
updateWidth();
|
2018-05-07 17:44:33 +00:00
|
|
|
}
|
2019-02-10 16:29:55 +00:00
|
|
|
if (_visibility.animating()) {
|
|
|
|
_visibility.finish();
|
|
|
|
updateVisibility();
|
2018-05-07 17:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::setForceHidden(bool hidden) {
|
|
|
|
_forceHidden = hidden;
|
|
|
|
if (_widget) {
|
|
|
|
_widget->setVisible(!hidden);
|
2018-05-07 17:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::refreshState() {
|
2018-05-07 17:44:33 +00:00
|
|
|
const auto state = [&]() -> State {
|
2019-02-10 16:29:55 +00:00
|
|
|
const auto under = _widget && _widget->isOver();
|
2018-05-07 17:44:33 +00:00
|
|
|
const auto mtp = MTP::dcstate();
|
2018-11-05 13:58:24 +00:00
|
|
|
const auto throughProxy
|
|
|
|
= (Global::ProxySettings() == ProxyData::Settings::Enabled);
|
2018-05-07 17:44:33 +00:00
|
|
|
if (mtp == MTP::ConnectingState
|
|
|
|
|| mtp == MTP::DisconnectedState
|
|
|
|
|| (mtp < 0 && mtp > -600)) {
|
|
|
|
return { State::Type::Connecting, throughProxy, under };
|
|
|
|
} else if (mtp < 0
|
|
|
|
&& mtp >= -kMinimalWaitingStateDuration
|
|
|
|
&& _state.type != State::Type::Waiting) {
|
|
|
|
return { State::Type::Connecting, throughProxy, under };
|
|
|
|
} else if (mtp < 0) {
|
|
|
|
const auto seconds = ((-mtp) / 1000) + 1;
|
|
|
|
return { State::Type::Waiting, throughProxy, under, seconds };
|
|
|
|
}
|
|
|
|
return { State::Type::Connected, throughProxy, under };
|
|
|
|
}();
|
|
|
|
if (state.waitTillRetry > 0) {
|
|
|
|
_refreshTimer.callOnce(kRefreshTimeout);
|
|
|
|
}
|
|
|
|
if (state == _state) {
|
|
|
|
return;
|
|
|
|
} else if (state.type == State::Type::Connecting
|
|
|
|
&& _state.type == State::Type::Connected) {
|
|
|
|
const auto now = getms();
|
|
|
|
if (!_connectingStartedAt) {
|
|
|
|
_connectingStartedAt = now;
|
|
|
|
_refreshTimer.callOnce(kConnectingStateDelay);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto applyConnectingAt = std::max(
|
|
|
|
_connectingStartedAt + kConnectingStateDelay,
|
|
|
|
kIgnoreStartConnectingFor);
|
|
|
|
if (now < applyConnectingAt) {
|
|
|
|
_refreshTimer.callOnce(applyConnectingAt - now);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
applyState(state);
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::applyState(const State &state) {
|
2018-05-07 17:44:33 +00:00
|
|
|
const auto newLayout = computeLayout(state);
|
2019-02-10 16:29:55 +00:00
|
|
|
const auto guard = gsl::finally([&] { updateWidth(); });
|
2018-05-07 17:44:33 +00:00
|
|
|
|
|
|
|
_state = state;
|
|
|
|
if (_currentLayout.visible != newLayout.visible) {
|
|
|
|
changeVisibilityWithLayout(newLayout);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_currentLayout.contentWidth != newLayout.contentWidth) {
|
|
|
|
if (!_currentLayout.contentWidth
|
|
|
|
|| !newLayout.contentWidth
|
|
|
|
|| _contentWidth.animating()) {
|
|
|
|
_contentWidth.start(
|
|
|
|
[=] { updateWidth(); },
|
|
|
|
_currentLayout.contentWidth,
|
|
|
|
newLayout.contentWidth,
|
|
|
|
st::connectingDuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto saved = _currentLayout;
|
|
|
|
setLayout(newLayout);
|
|
|
|
if (_currentLayout.text.isEmpty()
|
|
|
|
&& !saved.text.isEmpty()
|
|
|
|
&& _contentWidth.animating()) {
|
|
|
|
_currentLayout.text = saved.text;
|
|
|
|
_currentLayout.textWidth = saved.textWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::changeVisibilityWithLayout(const Layout &layout) {
|
2018-05-07 17:44:33 +00:00
|
|
|
Expects(_currentLayout.visible != layout.visible);
|
|
|
|
|
|
|
|
const auto changeLayout = !_currentLayout.visible;
|
|
|
|
_visibility.start(
|
|
|
|
[=] { updateVisibility(); },
|
|
|
|
layout.visible ? 0. : 1.,
|
|
|
|
layout.visible ? 1. : 0.,
|
|
|
|
st::connectingDuration);
|
|
|
|
if (_contentWidth.animating()) {
|
|
|
|
_contentWidth.start(
|
|
|
|
[=] { updateWidth(); },
|
|
|
|
_currentLayout.contentWidth,
|
|
|
|
(changeLayout ? layout : _currentLayout).contentWidth,
|
|
|
|
st::connectingDuration);
|
|
|
|
}
|
|
|
|
if (changeLayout) {
|
|
|
|
setLayout(layout);
|
|
|
|
} else {
|
|
|
|
_currentLayout.visible = layout.visible;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::setLayout(const Layout &layout) {
|
2018-05-07 17:44:33 +00:00
|
|
|
_currentLayout = layout;
|
2019-02-10 16:29:55 +00:00
|
|
|
if (_widget) {
|
|
|
|
_widget->setLayout(layout);
|
|
|
|
}
|
|
|
|
refreshProgressVisibility();
|
2018-05-07 17:44:33 +00:00
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::refreshProgressVisibility() {
|
|
|
|
if (_widget) {
|
|
|
|
_widget->setProgressVisibility(_contentWidth.animating()
|
|
|
|
|| _currentLayout.progressShown);
|
2018-05-07 17:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::updateVisibility() {
|
2018-05-07 17:44:33 +00:00
|
|
|
const auto value = currentVisibility();
|
|
|
|
if (value == 0. && _contentWidth.animating()) {
|
|
|
|
_contentWidth.finish();
|
|
|
|
updateWidth();
|
|
|
|
}
|
|
|
|
_visibilityValues.fire_copy(value);
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
float64 ConnectionState::currentVisibility() const {
|
2018-05-07 17:44:33 +00:00
|
|
|
return _visibility.current(_currentLayout.visible ? 1. : 0.);
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
rpl::producer<float64> ConnectionState::visibility() const {
|
|
|
|
return _visibilityValues.events_starting_with(currentVisibility());
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ConnectionState::computeLayout(const State &state) const -> Layout {
|
2018-05-07 17:44:33 +00:00
|
|
|
auto result = Layout();
|
|
|
|
result.proxyEnabled = state.useProxy;
|
|
|
|
result.progressShown = (state.type != State::Type::Connected);
|
|
|
|
result.visible = state.useProxy
|
|
|
|
|| state.type == State::Type::Connecting
|
|
|
|
|| state.type == State::Type::Waiting;
|
|
|
|
switch (state.type) {
|
|
|
|
case State::Type::Connecting:
|
|
|
|
result.text = state.underCursor ? lang(lng_connecting) : QString();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case State::Type::Waiting:
|
|
|
|
Assert(state.waitTillRetry > 0);
|
|
|
|
result.text = lng_reconnecting(lt_count, state.waitTillRetry);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
result.textWidth = st::normalFont->width(result.text);
|
|
|
|
const auto maxTextWidth = (state.type == State::Type::Waiting)
|
|
|
|
? st::normalFont->width(lng_reconnecting(lt_count, 88))
|
|
|
|
: result.textWidth;
|
|
|
|
result.contentWidth = (result.textWidth > 0)
|
|
|
|
? (st::connectingTextPadding.left()
|
|
|
|
+ result.textWidth
|
|
|
|
+ st::connectingTextPadding.right())
|
|
|
|
: 0;
|
|
|
|
if (state.type == State::Type::Waiting) {
|
|
|
|
result.contentWidth += st::connectingRetryLink.padding.left()
|
|
|
|
+ st::connectingRetryLink.font->width(
|
|
|
|
lang(lng_reconnecting_try_now))
|
|
|
|
+ st::connectingRetryLink.padding.right();
|
|
|
|
}
|
|
|
|
result.hasRetry = (state.type == State::Type::Waiting);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-02-10 16:29:55 +00:00
|
|
|
void ConnectionState::updateWidth() {
|
2018-05-07 17:44:33 +00:00
|
|
|
const auto current = _contentWidth.current(_currentLayout.contentWidth);
|
|
|
|
const auto height = st::connectingLeft.height();
|
|
|
|
const auto desired = QRect(0, 0, current, height).marginsAdded(
|
|
|
|
style::margins(
|
|
|
|
st::connectingLeft.width(),
|
|
|
|
0,
|
|
|
|
st::connectingRight.width(),
|
|
|
|
0)
|
|
|
|
).marginsAdded(
|
|
|
|
st::connectingMargin
|
|
|
|
);
|
2019-02-10 16:29:55 +00:00
|
|
|
if (_widget) {
|
|
|
|
_widget->resize(desired.size());
|
|
|
|
_widget->update();
|
|
|
|
}
|
|
|
|
refreshProgressVisibility();
|
|
|
|
}
|
|
|
|
|
|
|
|
ConnectionState::Widget::Widget(QWidget *parent, const Layout &layout)
|
|
|
|
: AbstractButton(parent)
|
|
|
|
, _currentLayout(layout) {
|
|
|
|
_proxyIcon = Ui::CreateChild<ProxyIcon>(this);
|
|
|
|
_progress = Ui::CreateChild<Progress>(this);
|
|
|
|
|
|
|
|
addClickHandler([=] {
|
|
|
|
Ui::show(ProxiesBoxController::CreateOwningBox());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionState::Widget::onStateChanged(
|
|
|
|
AbstractButton::State was,
|
|
|
|
StateChangeSource source) {
|
|
|
|
Ui::PostponeCall(crl::guard(this, [=] {
|
|
|
|
_refreshStateRequests.fire({});
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<> ConnectionState::Widget::refreshStateRequests() const {
|
|
|
|
return _refreshStateRequests.events();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionState::Widget::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st::windowBg);
|
|
|
|
const auto inner = innerRect();
|
|
|
|
const auto content = contentRect();
|
|
|
|
const auto text = textRect();
|
|
|
|
const auto left = inner.topLeft();
|
|
|
|
const auto right = content.topLeft() + QPoint(content.width(), 0);
|
|
|
|
st::connectingLeftShadow.paint(p, left, width());
|
|
|
|
st::connectingLeft.paint(p, left, width());
|
|
|
|
st::connectingRightShadow.paint(p, right, width());
|
|
|
|
st::connectingRight.paint(p, right, width());
|
|
|
|
st::connectingBodyShadow.fill(p, content);
|
|
|
|
st::connectingBody.fill(p, content);
|
|
|
|
|
|
|
|
const auto available = text.width();
|
|
|
|
if (available > 0 && !_currentLayout.text.isEmpty()) {
|
|
|
|
p.setFont(st::normalFont);
|
|
|
|
p.setPen(st::windowSubTextFg);
|
|
|
|
if (available >= _currentLayout.textWidth) {
|
|
|
|
p.drawTextLeft(
|
|
|
|
text.x(),
|
|
|
|
text.y(),
|
|
|
|
width(),
|
|
|
|
_currentLayout.text,
|
|
|
|
_currentLayout.textWidth);
|
|
|
|
} else {
|
|
|
|
p.drawTextLeft(
|
|
|
|
text.x(),
|
|
|
|
text.y(),
|
|
|
|
width(),
|
|
|
|
st::normalFont->elided(_currentLayout.text, available));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect ConnectionState::Widget::innerRect() const {
|
|
|
|
return rect().marginsRemoved(
|
|
|
|
st::connectingMargin
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect ConnectionState::Widget::contentRect() const {
|
|
|
|
return innerRect().marginsRemoved(style::margins(
|
|
|
|
st::connectingLeft.width(),
|
|
|
|
0,
|
|
|
|
st::connectingRight.width(),
|
|
|
|
0));
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect ConnectionState::Widget::textRect() const {
|
|
|
|
return contentRect().marginsRemoved(
|
|
|
|
st::connectingTextPadding
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionState::Widget::resizeEvent(QResizeEvent *e) {
|
|
|
|
{
|
|
|
|
const auto xShift = (height() - _progress->width()) / 2;
|
|
|
|
const auto yShift = (height() - _progress->height()) / 2;
|
|
|
|
_progress->moveToLeft(xShift, yShift);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
const auto xShift = (height() - _proxyIcon->width()) / 2;
|
|
|
|
const auto yShift = (height() - _proxyIcon->height()) / 2;
|
|
|
|
_proxyIcon->moveToRight(xShift, yShift);
|
|
|
|
}
|
|
|
|
updateRetryGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionState::Widget::updateRetryGeometry() {
|
|
|
|
if (!_retry) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto text = textRect();
|
|
|
|
const auto available = text.width() - _currentLayout.textWidth;
|
|
|
|
if (available <= 0) {
|
|
|
|
_retry->hide();
|
|
|
|
} else {
|
|
|
|
_retry->show();
|
|
|
|
_retry->resize(
|
|
|
|
std::min(available, _retry->naturalWidth()),
|
|
|
|
innerRect().height());
|
|
|
|
_retry->moveToLeft(
|
|
|
|
text.x() + text.width() - _retry->width(),
|
|
|
|
st::connectingMargin.top());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionState::Widget::setLayout(const Layout &layout) {
|
|
|
|
_currentLayout = layout;
|
|
|
|
_proxyIcon->setToggled(_currentLayout.proxyEnabled);
|
|
|
|
refreshRetryLink(_currentLayout.hasRetry);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionState::Widget::setProgressVisibility(bool visible) {
|
|
|
|
if (_progress->isHidden() == visible) {
|
|
|
|
_progress->setVisible(visible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectionState::Widget::refreshRetryLink(bool hasRetry) {
|
|
|
|
if (hasRetry && !_retry) {
|
|
|
|
_retry = base::make_unique_q<Ui::LinkButton>(
|
|
|
|
this,
|
|
|
|
lang(lng_reconnecting_try_now),
|
|
|
|
st::connectingRetryLink);
|
|
|
|
_retry->addClickHandler([=] {
|
|
|
|
MTP::restart();
|
|
|
|
});
|
|
|
|
updateRetryGeometry();
|
|
|
|
} else if (!hasRetry) {
|
|
|
|
_retry = nullptr;
|
2018-05-07 17:44:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<bool> AdaptiveIsOneColumn() {
|
|
|
|
return rpl::single(
|
|
|
|
Adaptive::OneColumn()
|
|
|
|
) | rpl::then(base::ObservableViewer(
|
|
|
|
Adaptive::Changed()
|
|
|
|
) | rpl::map([] {
|
|
|
|
return Adaptive::OneColumn();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Window
|