mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-26 19:14:02 +02:00
Display connecting state in history top bar.
This commit is contained in:
parent
710b9bf454
commit
4d84781a65
3 changed files with 117 additions and 14 deletions
|
@ -24,6 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "ui/unread_badge.h"
|
#include "ui/unread_badge.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/widgets/dropdown_menu.h"
|
#include "ui/widgets/dropdown_menu.h"
|
||||||
|
#include "ui/effects/radial_animation.h"
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
#include "window/window_peer_menu.h"
|
#include "window/window_peer_menu.h"
|
||||||
#include "calls/calls_instance.h"
|
#include "calls/calls_instance.h"
|
||||||
|
@ -124,10 +125,38 @@ TopBarWidget::TopBarWidget(
|
||||||
[this] { updateInfoToggleActive(); },
|
[this] { updateInfoToggleActive(); },
|
||||||
lifetime());
|
lifetime());
|
||||||
|
|
||||||
|
rpl::single(rpl::empty_value()) | rpl::then(
|
||||||
|
base::ObservableViewer(Global::RefConnectionTypeChanged())
|
||||||
|
) | rpl::start_with_next(
|
||||||
|
[=] { updateConnectingState(); },
|
||||||
|
lifetime());
|
||||||
|
|
||||||
setCursor(style::cur_pointer);
|
setCursor(style::cur_pointer);
|
||||||
updateControlsVisibility();
|
updateControlsVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TopBarWidget::updateConnectingState() {
|
||||||
|
const auto mtp = MTP::dcstate();
|
||||||
|
if (mtp == MTP::ConnectedState) {
|
||||||
|
if (_connecting) {
|
||||||
|
_connecting = nullptr;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
} else if (!_connecting) {
|
||||||
|
_connecting = std::make_unique<Ui::InfiniteRadialAnimation>(
|
||||||
|
animation(this, &TopBarWidget::step_connecting),
|
||||||
|
st::topBarConnectingAnimation);
|
||||||
|
_connecting->start();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TopBarWidget::step_connecting(TimeMs ms, bool timer) {
|
||||||
|
if (timer) {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TopBarWidget::refreshLang() {
|
void TopBarWidget::refreshLang() {
|
||||||
InvokeQueued(this, [this] { updateControlsGeometry(); });
|
InvokeQueued(this, [this] { updateControlsGeometry(); });
|
||||||
}
|
}
|
||||||
|
@ -300,24 +329,71 @@ void TopBarWidget::paintTopBar(Painter &p, TimeMs ms) {
|
||||||
history->peer->dialogName().drawElided(p, nameleft, nametop, namewidth);
|
history->peer->dialogName().drawElided(p, nameleft, nametop, namewidth);
|
||||||
|
|
||||||
p.setFont(st::dialogsTextFont);
|
p.setFont(st::dialogsTextFont);
|
||||||
if (!history->paintSendAction(p, nameleft, statustop, namewidth, width(), st::historyStatusFgTyping, ms)) {
|
if (paintConnectingState(p, nameleft, statustop, width(), ms)) {
|
||||||
auto statustext = _titlePeerText;
|
return;
|
||||||
auto statuswidth = _titlePeerTextWidth;
|
} else if (history->paintSendAction(
|
||||||
if (statuswidth > namewidth) {
|
p,
|
||||||
statustext = st::dialogsTextFont->elided(
|
nameleft,
|
||||||
statustext,
|
statustop,
|
||||||
namewidth,
|
namewidth,
|
||||||
Qt::ElideLeft);
|
width(),
|
||||||
statuswidth = st::dialogsTextFont->width(statustext);
|
st::historyStatusFgTyping,
|
||||||
}
|
ms)) {
|
||||||
p.setPen(_titlePeerTextOnline
|
return;
|
||||||
? st::historyStatusFgActive
|
} else {
|
||||||
: st::historyStatusFg);
|
paintStatus(p, nameleft, statustop, namewidth, width());
|
||||||
p.drawTextLeft(nameleft, statustop, width(), statustext, statuswidth);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TopBarWidget::paintConnectingState(
|
||||||
|
Painter &p,
|
||||||
|
int left,
|
||||||
|
int top,
|
||||||
|
int outerWidth,
|
||||||
|
TimeMs ms) {
|
||||||
|
if (_connecting) {
|
||||||
|
_connecting->step(ms);
|
||||||
|
}
|
||||||
|
if (!_connecting) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_connecting->draw(
|
||||||
|
p,
|
||||||
|
{
|
||||||
|
st::topBarConnectingPosition.x() + left,
|
||||||
|
st::topBarConnectingPosition.y() + top
|
||||||
|
},
|
||||||
|
outerWidth);
|
||||||
|
left += st::topBarConnectingPosition.x()
|
||||||
|
+ st::topBarConnectingAnimation.size.width()
|
||||||
|
+ st::topBarConnectingSkip;
|
||||||
|
p.setPen(st::historyStatusFg);
|
||||||
|
p.drawTextLeft(left, top, outerWidth, lang(lng_status_connecting));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TopBarWidget::paintStatus(
|
||||||
|
Painter &p,
|
||||||
|
int left,
|
||||||
|
int top,
|
||||||
|
int availableWidth,
|
||||||
|
int outerWidth) {
|
||||||
|
auto statustext = _titlePeerText;
|
||||||
|
auto statuswidth = _titlePeerTextWidth;
|
||||||
|
if (statuswidth > availableWidth) {
|
||||||
|
statustext = st::dialogsTextFont->elided(
|
||||||
|
statustext,
|
||||||
|
availableWidth,
|
||||||
|
Qt::ElideLeft);
|
||||||
|
statuswidth = st::dialogsTextFont->width(statustext);
|
||||||
|
}
|
||||||
|
p.setPen(_titlePeerTextOnline
|
||||||
|
? st::historyStatusFgActive
|
||||||
|
: st::historyStatusFg);
|
||||||
|
p.drawTextLeft(left, top, outerWidth, statustext, statuswidth);
|
||||||
|
}
|
||||||
|
|
||||||
QRect TopBarWidget::getMembersShowAreaGeometry() const {
|
QRect TopBarWidget::getMembersShowAreaGeometry() const {
|
||||||
int membersTextLeft = _leftTaken;
|
int membersTextLeft = _leftTaken;
|
||||||
int membersTextTop = st::topBarHeight - st::topBarArrowPadding.bottom() - st::dialogsTextFont->height;
|
int membersTextTop = st::topBarHeight - st::topBarArrowPadding.bottom() - st::dialogsTextFont->height;
|
||||||
|
@ -765,4 +841,6 @@ void TopBarWidget::updateOnlineDisplayIn(TimeMs timeout) {
|
||||||
_onlineUpdater.callOnce(timeout);
|
_onlineUpdater.callOnce(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TopBarWidget::~TopBarWidget() = default;
|
||||||
|
|
||||||
} // namespace HistoryView
|
} // namespace HistoryView
|
||||||
|
|
|
@ -17,6 +17,7 @@ class RoundButton;
|
||||||
class IconButton;
|
class IconButton;
|
||||||
class DropdownMenu;
|
class DropdownMenu;
|
||||||
class UnreadBadge;
|
class UnreadBadge;
|
||||||
|
class InfiniteRadialAnimation;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
||||||
namespace Window {
|
namespace Window {
|
||||||
|
@ -38,6 +39,8 @@ public:
|
||||||
int canForwardCount = 0;
|
int canForwardCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
~TopBarWidget();
|
||||||
|
|
||||||
void updateControlsVisibility();
|
void updateControlsVisibility();
|
||||||
void finishAnimating();
|
void finishAnimating();
|
||||||
void showSelected(SelectedState state);
|
void showSelected(SelectedState state);
|
||||||
|
@ -78,10 +81,24 @@ private:
|
||||||
void showMenu();
|
void showMenu();
|
||||||
void toggleInfoSection();
|
void toggleInfoSection();
|
||||||
|
|
||||||
|
void updateConnectingState();
|
||||||
void updateAdaptiveLayout();
|
void updateAdaptiveLayout();
|
||||||
int countSelectedButtonsTop(float64 selectedShown);
|
int countSelectedButtonsTop(float64 selectedShown);
|
||||||
|
void step_connecting(TimeMs ms, bool timer);
|
||||||
|
|
||||||
void paintTopBar(Painter &p, TimeMs ms);
|
void paintTopBar(Painter &p, TimeMs ms);
|
||||||
|
void paintStatus(
|
||||||
|
Painter &p,
|
||||||
|
int left,
|
||||||
|
int top,
|
||||||
|
int availableWidth,
|
||||||
|
int outerWidth);
|
||||||
|
bool paintConnectingState(
|
||||||
|
Painter &p,
|
||||||
|
int left,
|
||||||
|
int top,
|
||||||
|
int outerWidth,
|
||||||
|
TimeMs ms);
|
||||||
QRect getMembersShowAreaGeometry() const;
|
QRect getMembersShowAreaGeometry() const;
|
||||||
void updateMembersShowArea();
|
void updateMembersShowArea();
|
||||||
void updateOnlineDisplay();
|
void updateOnlineDisplay();
|
||||||
|
@ -125,6 +142,7 @@ private:
|
||||||
int _leftTaken = 0;
|
int _leftTaken = 0;
|
||||||
int _rightTaken = 0;
|
int _rightTaken = 0;
|
||||||
bool _animatingMode = false;
|
bool _animatingMode = false;
|
||||||
|
std::unique_ptr<Ui::InfiniteRadialAnimation> _connecting;
|
||||||
|
|
||||||
int _unreadCounterSubscription = 0;
|
int _unreadCounterSubscription = 0;
|
||||||
base::Timer _onlineUpdater;
|
base::Timer _onlineUpdater;
|
||||||
|
|
|
@ -704,5 +704,12 @@ topBarFeedInfoButton: FeedUserpicButton(defaultFeedUserpicButton) {
|
||||||
photoSize: 20px;
|
photoSize: 20px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
topBarConnectingPosition: point(2px, 5px);
|
||||||
|
topBarConnectingSkip: 6px;
|
||||||
|
topBarConnectingAnimation: InfiniteRadialAnimation(defaultInfiniteRadialAnimation) {
|
||||||
|
color: windowSubTextFg;
|
||||||
|
thickness: 1px;
|
||||||
|
size: size(8px, 8px);
|
||||||
|
}
|
||||||
|
|
||||||
infoFeedLeaveIconMargins: margins(10px, 12px, 20px, 10px);
|
infoFeedLeaveIconMargins: margins(10px, 12px, 20px, 10px);
|
||||||
|
|
Loading…
Add table
Reference in a new issue