Display check on the active account.

This commit is contained in:
John Preston 2020-06-23 13:20:38 +04:00
parent 51c2bc7349
commit 34ef54e40b
13 changed files with 91 additions and 27 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -92,6 +92,15 @@ Session::Session(
_api->instance().setUserPhone(_user->phone());
// Load current userpic and keep it loaded.
changes().peerFlagsValue(
_user,
Data::PeerUpdate::Flag::Photo
) | rpl::start_with_next([=] {
[[maybe_unused]] const auto image = _user->currentUserpic(
_selfUserpicView);
}, lifetime());
crl::on_main(this, [=] {
using Flag = Data::PeerUpdate::Flag;
changes().peerUpdates(

View File

@ -31,6 +31,7 @@ class Templates;
namespace Data {
class Session;
class Changes;
class CloudImageView;
} // namespace Data
namespace Storage {
@ -174,6 +175,8 @@ private:
const std::unique_ptr<Support::Helper> _supportHelper;
std::shared_ptr<Data::CloudImageView> _selfUserpicView;
base::flat_set<not_null<Window::SessionController*>> _windows;
base::Timer _saveSettingsTimer;

View File

@ -243,15 +243,6 @@ MainWidget::MainWidget(
floatPlayerClosed(itemId);
}, lifetime());
// Load current userpic and keep it loaded.
session().changes().peerFlagsValue(
session().user(),
Data::PeerUpdate::Flag::Photo
) | rpl::start_with_next([=] {
[[maybe_unused]] const auto image = session().user()->currentUserpic(
_selfUserpicView);
}, lifetime());
updateScrollColors();
setupConnectingWidget();

View File

@ -34,7 +34,6 @@ class Session;
namespace Data {
class WallPaper;
class CloudImageView;
} // namespace Data
namespace Dialogs {
@ -360,8 +359,6 @@ private:
int _thirdColumnWidth = 0;
Ui::Animations::Simple _a_dialogsWidth;
std::shared_ptr<Data::CloudImageView> _selfUserpicView;
object_ptr<Ui::PlainShadow> _sideShadow;
object_ptr<Ui::PlainShadow> _thirdShadow = { nullptr };
object_ptr<Ui::ResizeArea> _firstColumnResizeArea = { nullptr };

View File

@ -145,8 +145,18 @@ mainMenuReload: icon {{ "menu_reload", menuIconFg }};
mainMenuReloadOver: icon {{ "menu_reload", menuIconFgOver }};
mainMenuFixOrder: icon {{ "menu_fix_order", menuIconFg }};
mainMenuFixOrderOver: icon {{ "menu_fix_order", menuIconFgOver }};
mainMenuAddAccount: icon {{ "menu_fix_order", menuIconFg }};
mainMenuAddAccountOver: icon {{ "menu_fix_order", menuIconFgOver }};
mainMenuAddAccount: icon {{ "menu_add_account", menuIconFg }};
mainMenuAddAccountOver: icon {{ "menu_add_account", menuIconFgOver }};
mainMenuAccountSize: 32px;
mainMenuAccountCheckPosition: point(7px, 5px);
mainMenuAccountCheckLine: 2px;
mainMenuAccountCheck: RoundCheckbox(defaultRoundCheckbox) {
size: 18px;
bgInactive: overviewCheckBg;
bgActive: overviewCheckBgActive;
check: icon {{ "account_check", overviewCheckFgActive }};
}
mainMenuFooterLeft: 30px;
mainMenuTelegramLabel: FlatLabel(defaultFlatLabel) {
align: align(left);

View File

@ -88,10 +88,13 @@ public:
private:
void paintEvent(QPaintEvent *e) override;
void paintUserpic(Painter &p);
const not_null<Main::Account*> _account;
const style::Menu &_st;
std::shared_ptr<Data::CloudImageView> _userpicView;
InMemoryKey _userpicKey = {};
QImage _userpicCache;
Dialogs::Layout::UnreadBadgeStyle _unreadSt;
int _unreadBadge = 0;
@ -154,26 +157,68 @@ MainMenu::AccountButton::AccountButton(
}, lifetime());
}
void MainMenu::AccountButton::paintEvent(QPaintEvent *e) {
void MainMenu::AccountButton::paintUserpic(Painter &p) {
Expects(_account->sessionExists());
const auto &session = _account->session();
const auto size = st::mainMenuAccountSize;
const auto iconSize = height() - 2 * _st.itemIconPosition.y();
const auto shift = (size - iconSize) / 2;
const auto x = _st.itemIconPosition.x() - shift;
const auto y = (height() - size) / 2;
const auto check = (_account == &Core::App().domain().active());
const auto user = _account->session().user();
if (!check) {
user->paintUserpicLeft(p, _userpicView, x, y, width(), size);
return;
}
const auto added = y;
const auto cacheSize = QSize(size + added, size + added)
* cIntRetinaFactor();
const auto key = user->userpicUniqueKey(_userpicView);
if (_userpicKey != key) {
_userpicKey = key;
if (_userpicCache.size() != cacheSize) {
_userpicCache = QImage(cacheSize, QImage::Format_ARGB32_Premultiplied);
_userpicCache.setDevicePixelRatio(cRetinaFactor());
}
_userpicCache.fill(Qt::transparent);
auto q = Painter(&_userpicCache);
user->paintUserpicLeft(q, _userpicView, 0, 0, width(), size);
const auto iconDiameter = st::mainMenuAccountCheck.size;
const auto iconLeft = size + st::mainMenuAccountCheckPosition.x() - iconDiameter;
const auto iconTop = size + st::mainMenuAccountCheckPosition.y() - iconDiameter;
const auto iconEllipse = QRect(iconLeft, iconTop, iconDiameter, iconDiameter);
auto iconBorderPen = QPen(Qt::transparent);
const auto line = st::mainMenuAccountCheckLine;
iconBorderPen.setWidth(line);
PainterHighQualityEnabler hq(q);
q.setCompositionMode(QPainter::CompositionMode_Source);
q.setPen(iconBorderPen);
q.setBrush(st::dialogsUnreadBg);
q.drawEllipse(iconEllipse);
q.setCompositionMode(QPainter::CompositionMode_SourceOver);
st::mainMenuAccountCheck.check.paintInCenter(q, iconEllipse);
}
p.drawImage(x, y, _userpicCache);
}
void MainMenu::AccountButton::paintEvent(QPaintEvent *e) {
Expects(_account->sessionExists());
auto p = Painter(this);
const auto over = isOver();
p.fillRect(rect(), over ? _st.itemBgOver : _st.itemBg);
paintRipple(p, 0, 0);
session.user()->paintUserpicLeft(
p,
_userpicView,
_st.itemIconPosition.x(),
_st.itemIconPosition.y(),
width(),
height() - 2 * _st.itemIconPosition.y());
paintUserpic(p);
auto available = width() - _st.itemPadding.left();
if (_unreadBadge && _account != &Core::App().domain().active()) {
if (_unreadBadge) {
_unreadSt.muted = _unreadBadgeMuted;
const auto string = (_unreadBadge > 99)
? "99+"
@ -196,7 +241,7 @@ void MainMenu::AccountButton::paintEvent(QPaintEvent *e) {
}
p.setPen(over ? _st.itemFgOver : _st.itemFg);
session.user()->nameText().drawElided(
_account->session().user()->nameText().drawElided(
p,
_st.itemPadding.left(),
_st.itemPadding.top(),
@ -514,7 +559,12 @@ void MainMenu::rebuildAccounts() {
const auto inner = _accounts->entity();
auto count = 0;
for (auto &[account, button] : _watched) {
for (const auto &[index, pointer] : Core::App().domain().accounts()) {
const auto account = pointer.get();
auto i = _watched.find(account);
Assert(i != _watched.end());
auto &button = i->second;
if (!account->sessionExists()) {
button = nullptr;
} else if (!button) {
@ -522,6 +572,10 @@ void MainMenu::rebuildAccounts() {
++count,
object_ptr<AccountButton>(inner, account)));
button->setClickedCallback([=] {
if (account == &Core::App().domain().active()) {
closeLayer();
return;
}
auto activate = [=, guard = _accountSwitchGuard.make_guard()]{
if (guard) {
Core::App().domain().activate(account);

@ -1 +1 @@
Subproject commit d31d94e8fb47b8492fbf341b93c19ddfbcb42fa2
Subproject commit 2a0d189ee22d8573bd4f9f0971ef1aa27a12f02d