2016-11-11 19:51:59 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-11-11 19:51:59 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-11-11 19:51:59 +00:00
|
|
|
*/
|
|
|
|
#include "window/window_main_menu.h"
|
|
|
|
|
2017-06-29 19:09:10 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
2020-09-16 14:09:04 +00:00
|
|
|
#include "window/window_peer_menu.h"
|
2019-06-06 10:21:40 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2017-04-05 09:21:38 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
2021-01-12 22:59:55 +00:00
|
|
|
#include "ui/widgets/menu/menu.h"
|
|
|
|
#include "ui/widgets/menu/menu_common.h"
|
2021-01-13 01:10:25 +00:00
|
|
|
#include "ui/widgets/menu/menu_toggle.h"
|
2019-05-16 08:39:45 +00:00
|
|
|
#include "ui/widgets/popup_menu.h"
|
2020-06-22 13:01:41 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
|
|
|
#include "ui/widgets/shadow.h"
|
|
|
|
#include "ui/wrap/slide_wrap.h"
|
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2019-06-12 20:11:41 +00:00
|
|
|
#include "ui/text/text_utilities.h"
|
2017-11-13 15:50:10 +00:00
|
|
|
#include "ui/special_buttons.h"
|
2017-12-05 16:48:03 +00:00
|
|
|
#include "ui/empty_userpic.h"
|
2020-06-22 19:01:19 +00:00
|
|
|
#include "dialogs/dialogs_layout.h"
|
2020-06-22 13:01:41 +00:00
|
|
|
#include "base/call_delayed.h"
|
2016-11-11 19:51:59 +00:00
|
|
|
#include "mainwindow.h"
|
2017-06-29 19:09:10 +00:00
|
|
|
#include "storage/localstorage.h"
|
2020-06-09 16:57:05 +00:00
|
|
|
#include "storage/storage_account.h"
|
2018-10-09 13:32:32 +00:00
|
|
|
#include "support/support_templates.h"
|
2019-01-11 09:04:28 +00:00
|
|
|
#include "settings/settings_common.h"
|
2019-09-13 16:45:48 +00:00
|
|
|
#include "base/qt_signal_producer.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/about_box.h"
|
2020-06-30 17:15:35 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2017-08-14 12:53:49 +00:00
|
|
|
#include "boxes/peer_list_controllers.h"
|
2017-04-27 19:04:45 +00:00
|
|
|
#include "calls/calls_box_controller.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-11-11 19:51:59 +00:00
|
|
|
#include "core/click_handler_types.h"
|
2020-06-22 13:01:41 +00:00
|
|
|
#include "core/core_settings.h"
|
|
|
|
#include "core/application.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2020-06-18 12:47:09 +00:00
|
|
|
#include "main/main_session_settings.h"
|
2020-06-22 13:01:41 +00:00
|
|
|
#include "main/main_account.h"
|
|
|
|
#include "main/main_domain.h"
|
|
|
|
#include "mtproto/mtp_instance.h"
|
2020-06-17 09:36:25 +00:00
|
|
|
#include "mtproto/mtproto_config.h"
|
2019-05-16 08:39:45 +00:00
|
|
|
#include "data/data_folder.h"
|
|
|
|
#include "data/data_session.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_user.h"
|
2020-06-12 12:12:34 +00:00
|
|
|
#include "data/data_changes.h"
|
2017-04-11 20:03:34 +00:00
|
|
|
#include "mainwidget.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "app.h"
|
2018-10-20 19:04:10 +00:00
|
|
|
#include "styles/style_window.h"
|
2020-06-22 13:01:41 +00:00
|
|
|
#include "styles/style_widgets.h"
|
2018-10-20 19:04:10 +00:00
|
|
|
#include "styles/style_dialogs.h"
|
|
|
|
#include "styles/style_settings.h"
|
2019-01-11 09:04:28 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2021-01-21 15:57:12 +00:00
|
|
|
#include "styles/style_info.h" // infoTopBarMenu
|
2020-06-30 17:15:35 +00:00
|
|
|
#include "styles/style_layers.h"
|
2016-11-11 19:51:59 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtGui/QWindow>
|
|
|
|
#include <QtGui/QScreen>
|
|
|
|
|
2019-05-24 18:46:52 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr auto kMinDiffIntensity = 0.25;
|
|
|
|
|
2020-06-23 13:29:02 +00:00
|
|
|
[[nodicard]] float64 IntensityOfColor(QColor color) {
|
2019-05-24 18:46:52 +00:00
|
|
|
return (0.299 * color.red()
|
|
|
|
+ 0.587 * color.green()
|
|
|
|
+ 0.114 * color.blue()) / 255.0;
|
|
|
|
}
|
|
|
|
|
2020-06-23 13:29:02 +00:00
|
|
|
[[nodiscard]] bool IsShadowShown(const QImage &img, const QRect r, float64 intensityText) {
|
2019-05-24 18:46:52 +00:00
|
|
|
for (auto x = r.x(); x < r.x() + r.width(); x++) {
|
|
|
|
for (auto y = r.y(); y < r.y() + r.height(); y++) {
|
|
|
|
const auto intensity = IntensityOfColor(QColor(img.pixel(x, y)));
|
|
|
|
if ((std::abs(intensity - intensityText)) < kMinDiffIntensity) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-06-23 13:29:02 +00:00
|
|
|
[[nodiscard]] bool IsFilledCover() {
|
|
|
|
const auto background = Window::Theme::Background();
|
|
|
|
return background->tile()
|
|
|
|
|| background->colorForFill().has_value()
|
|
|
|
|| background->isMonoColorImage()
|
|
|
|
|| background->paper().isPattern()
|
|
|
|
|| Data::IsLegacy1DefaultWallPaper(background->paper());
|
|
|
|
}
|
|
|
|
|
2020-09-17 14:56:01 +00:00
|
|
|
[[nodiscard]] bool IsAltShift(Qt::KeyboardModifiers modifiers) {
|
|
|
|
return (modifiers & Qt::ShiftModifier) && (modifiers & Qt::AltModifier);
|
|
|
|
}
|
|
|
|
|
2021-01-21 15:57:12 +00:00
|
|
|
void ShowCallsBox(not_null<Window::SessionController*> window) {
|
|
|
|
auto controller = std::make_unique<Calls::BoxController>(window);
|
2021-01-26 10:28:25 +00:00
|
|
|
const auto initBox = [
|
|
|
|
window,
|
|
|
|
controller = controller.get()
|
|
|
|
](not_null<PeerListBox*> box) {
|
2021-01-21 15:57:12 +00:00
|
|
|
box->addButton(tr::lng_close(), [=] {
|
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
using MenuPointer = base::unique_qptr<Ui::PopupMenu>;
|
|
|
|
const auto menu = std::make_shared<MenuPointer>();
|
|
|
|
const auto menuButton = box->addTopButton(st::infoTopBarMenu);
|
|
|
|
menuButton->setClickedCallback([=] {
|
|
|
|
*menu = base::make_unique_q<Ui::PopupMenu>(menuButton);
|
|
|
|
const auto showSettings = [=] {
|
|
|
|
window->showSettings(
|
|
|
|
Settings::Type::Calls,
|
|
|
|
Window::SectionShow(anim::type::instant));
|
|
|
|
};
|
|
|
|
const auto clearAll = crl::guard(box, [=] {
|
|
|
|
box->getDelegate()->show(Box(Calls::ClearCallsBox, window));
|
|
|
|
});
|
|
|
|
(*menu)->addAction(
|
|
|
|
tr::lng_settings_section_call_settings(tr::now),
|
|
|
|
showSettings);
|
2021-01-26 10:28:25 +00:00
|
|
|
if (controller->delegate()->peerListFullRowsCount() > 0) {
|
|
|
|
(*menu)->addAction(
|
|
|
|
tr::lng_call_box_clear_all(tr::now),
|
|
|
|
clearAll);
|
|
|
|
}
|
2021-01-21 15:57:12 +00:00
|
|
|
(*menu)->popup(QCursor::pos());
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
Ui::show(Box<PeerListBox>(std::move(controller), initBox));
|
|
|
|
}
|
|
|
|
|
2019-06-12 20:11:41 +00:00
|
|
|
} // namespace
|
2019-05-24 18:46:52 +00:00
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
namespace Window {
|
2018-10-20 19:04:10 +00:00
|
|
|
|
2020-06-23 13:29:02 +00:00
|
|
|
class MainMenu::AccountButton final
|
|
|
|
: public Ui::RippleButton
|
|
|
|
, public base::Subscriber {
|
2020-06-22 13:01:41 +00:00
|
|
|
public:
|
|
|
|
AccountButton(QWidget *parent, not_null<Main::Account*> account);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2020-06-30 17:15:35 +00:00
|
|
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
2020-06-23 09:20:38 +00:00
|
|
|
void paintUserpic(Painter &p);
|
2020-06-22 13:01:41 +00:00
|
|
|
|
2020-06-30 15:13:57 +00:00
|
|
|
const not_null<Main::Session*> _session;
|
2020-06-22 13:01:41 +00:00
|
|
|
const style::Menu &_st;
|
|
|
|
std::shared_ptr<Data::CloudImageView> _userpicView;
|
2020-06-23 09:20:38 +00:00
|
|
|
InMemoryKey _userpicKey = {};
|
|
|
|
QImage _userpicCache;
|
2020-06-30 17:15:35 +00:00
|
|
|
base::unique_qptr<Ui::PopupMenu> _menu;
|
2020-06-22 19:01:19 +00:00
|
|
|
|
|
|
|
Dialogs::Layout::UnreadBadgeStyle _unreadSt;
|
2020-06-22 13:01:41 +00:00
|
|
|
int _unreadBadge = 0;
|
|
|
|
bool _unreadBadgeMuted = true;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-06-22 14:33:35 +00:00
|
|
|
class MainMenu::ToggleAccountsButton final : public Ui::AbstractButton {
|
|
|
|
public:
|
2020-06-23 14:55:08 +00:00
|
|
|
explicit ToggleAccountsButton(QWidget *parent);
|
2020-06-22 14:33:35 +00:00
|
|
|
|
2020-06-23 13:29:02 +00:00
|
|
|
[[nodiscard]] int rightSkip() const {
|
|
|
|
return _rightSkip.current();
|
2020-06-22 14:33:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2020-06-23 13:29:02 +00:00
|
|
|
void paintUnreadBadge(QPainter &p);
|
|
|
|
|
|
|
|
void validateUnreadBadge();
|
|
|
|
[[nodiscard]] QString computeUnreadBadge() const;
|
2020-06-22 14:33:35 +00:00
|
|
|
|
|
|
|
rpl::variable<int> _rightSkip;
|
|
|
|
Ui::Animations::Simple _toggledAnimation;
|
|
|
|
bool _toggled = false;
|
|
|
|
|
2020-06-23 13:29:02 +00:00
|
|
|
QString _unreadBadge;
|
|
|
|
int _unreadBadgeWidth = 0;
|
|
|
|
bool _unreadBadgeStale = false;
|
|
|
|
|
2020-06-22 14:33:35 +00:00
|
|
|
};
|
|
|
|
|
2020-06-22 13:01:41 +00:00
|
|
|
class MainMenu::ResetScaleButton final : public Ui::AbstractButton {
|
2018-10-20 19:04:10 +00:00
|
|
|
public:
|
|
|
|
ResetScaleButton(QWidget *parent);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
static constexpr auto kText = "100%";
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-06-22 13:01:41 +00:00
|
|
|
MainMenu::AccountButton::AccountButton(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Main::Account*> account)
|
|
|
|
: RippleButton(parent, st::defaultRippleAnimation)
|
2020-06-30 15:13:57 +00:00
|
|
|
, _session(&account->session())
|
2020-06-22 13:01:41 +00:00
|
|
|
, _st(st::mainMenu){
|
|
|
|
const auto height = _st.itemPadding.top()
|
|
|
|
+ _st.itemStyle.font->height
|
|
|
|
+ _st.itemPadding.bottom();
|
|
|
|
resize(width(), height);
|
|
|
|
|
2020-06-23 13:29:02 +00:00
|
|
|
subscribe(Window::Theme::Background(), [=](
|
|
|
|
const Window::Theme::BackgroundUpdate &update) {
|
|
|
|
if (update.paletteChanged()) {
|
|
|
|
_userpicKey = {};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-30 15:13:57 +00:00
|
|
|
rpl::single(
|
|
|
|
rpl::empty_value()
|
|
|
|
) | rpl::then(
|
|
|
|
_session->data().unreadBadgeChanges()
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_unreadBadge = _session->data().unreadBadge();
|
|
|
|
_unreadBadgeMuted = _session->data().unreadBadgeMuted();
|
|
|
|
update();
|
2020-06-22 13:01:41 +00:00
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
2020-06-23 09:20:38 +00:00
|
|
|
void MainMenu::AccountButton::paintUserpic(Painter &p) {
|
|
|
|
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;
|
|
|
|
|
2020-06-30 15:13:57 +00:00
|
|
|
const auto check = (&_session->account()
|
|
|
|
== &Core::App().domain().active());
|
|
|
|
const auto user = _session->user();
|
2020-06-23 09:20:38 +00:00
|
|
|
if (!check) {
|
|
|
|
user->paintUserpicLeft(p, _userpicView, x, y, width(), size);
|
|
|
|
return;
|
|
|
|
}
|
2020-06-29 11:07:42 +00:00
|
|
|
const auto added = st::mainMenuAccountCheck.size;
|
2020-06-23 09:20:38 +00:00
|
|
|
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) {
|
2020-06-22 13:01:41 +00:00
|
|
|
auto p = Painter(this);
|
|
|
|
const auto over = isOver();
|
|
|
|
p.fillRect(rect(), over ? _st.itemBgOver : _st.itemBg);
|
|
|
|
paintRipple(p, 0, 0);
|
|
|
|
|
2020-06-23 09:20:38 +00:00
|
|
|
paintUserpic(p);
|
2020-06-22 13:01:41 +00:00
|
|
|
|
2020-06-22 19:01:19 +00:00
|
|
|
auto available = width() - _st.itemPadding.left();
|
2020-06-30 15:13:57 +00:00
|
|
|
if (_unreadBadge
|
|
|
|
&& (&_session->account() != &Core::App().activeAccount())) {
|
2020-06-22 19:01:19 +00:00
|
|
|
_unreadSt.muted = _unreadBadgeMuted;
|
|
|
|
const auto string = (_unreadBadge > 99)
|
|
|
|
? "99+"
|
|
|
|
: QString::number(_unreadBadge);
|
|
|
|
auto unreadWidth = 0;
|
|
|
|
const auto skip = _st.itemPadding.right()
|
|
|
|
- st::mainMenu.itemToggleShift;
|
|
|
|
const auto unreadRight = width() - skip;
|
|
|
|
const auto unreadTop = (height() - _unreadSt.size) / 2;
|
|
|
|
Dialogs::Layout::paintUnreadCount(
|
|
|
|
p,
|
|
|
|
string,
|
|
|
|
unreadRight,
|
|
|
|
unreadTop,
|
|
|
|
_unreadSt,
|
|
|
|
&unreadWidth);
|
|
|
|
available -= unreadWidth + skip + st::mainMenu.itemStyle.font->spacew;
|
|
|
|
} else {
|
|
|
|
available -= _st.itemPadding.right();
|
|
|
|
}
|
|
|
|
|
2020-06-22 13:01:41 +00:00
|
|
|
p.setPen(over ? _st.itemFgOver : _st.itemFg);
|
2020-06-30 15:13:57 +00:00
|
|
|
_session->user()->nameText().drawElided(
|
2020-06-22 13:01:41 +00:00
|
|
|
p,
|
|
|
|
_st.itemPadding.left(),
|
|
|
|
_st.itemPadding.top(),
|
|
|
|
available);
|
|
|
|
}
|
|
|
|
|
2020-06-30 17:15:35 +00:00
|
|
|
void MainMenu::AccountButton::contextMenuEvent(QContextMenuEvent *e) {
|
2020-09-17 14:56:01 +00:00
|
|
|
if (!_menu && IsAltShift(e->modifiers())) {
|
|
|
|
_menu = base::make_unique_q<Ui::PopupMenu>(this);
|
|
|
|
const auto addAction = [&](const QString &text, Fn<void()> callback) {
|
|
|
|
return _menu->addAction(
|
|
|
|
text,
|
|
|
|
crl::guard(this, std::move(callback)));
|
|
|
|
};
|
|
|
|
MenuAddMarkAsReadAllChatsAction(&_session->data(), addAction);
|
|
|
|
_menu->popup(QCursor::pos());
|
|
|
|
return;
|
|
|
|
}
|
2020-06-30 17:15:35 +00:00
|
|
|
if (&_session->account() == &Core::App().activeAccount() || _menu) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_menu = base::make_unique_q<Ui::PopupMenu>(this);
|
|
|
|
_menu->addAction(tr::lng_menu_activate(tr::now), crl::guard(this, [=] {
|
|
|
|
Core::App().domain().activate(&_session->account());
|
|
|
|
}));
|
|
|
|
_menu->addAction(tr::lng_settings_logout(tr::now), crl::guard(this, [=] {
|
|
|
|
const auto session = _session;
|
2020-09-24 12:48:02 +00:00
|
|
|
const auto callback = [=](Fn<void()> &&close) {
|
|
|
|
close();
|
2020-06-30 17:15:35 +00:00
|
|
|
Core::App().logout(&session->account());
|
|
|
|
};
|
2020-09-24 12:48:02 +00:00
|
|
|
Ui::show(Box<ConfirmBox>(
|
2020-06-30 17:15:35 +00:00
|
|
|
tr::lng_sure_logout(tr::now),
|
|
|
|
tr::lng_settings_logout(tr::now),
|
|
|
|
st::attentionBoxButton,
|
|
|
|
crl::guard(session, callback)));
|
|
|
|
}));
|
|
|
|
_menu->popup(QCursor::pos());
|
|
|
|
}
|
|
|
|
|
2020-06-23 14:55:08 +00:00
|
|
|
MainMenu::ToggleAccountsButton::ToggleAccountsButton(QWidget *parent)
|
2020-06-22 14:33:35 +00:00
|
|
|
: AbstractButton(parent) {
|
2020-06-23 13:29:02 +00:00
|
|
|
rpl::single(
|
|
|
|
rpl::empty_value()
|
|
|
|
) | rpl::then(
|
|
|
|
Core::App().unreadBadgeChanges()
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_unreadBadgeStale = true;
|
|
|
|
if (!_toggled) {
|
|
|
|
validateUnreadBadge();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
|
2020-06-23 14:55:08 +00:00
|
|
|
auto &settings = Core::App().settings();
|
|
|
|
if (Core::App().domain().accounts().size() < 2
|
|
|
|
&& settings.mainMenuAccountsShown()) {
|
|
|
|
settings.setMainMenuAccountsShown(false);
|
|
|
|
}
|
|
|
|
settings.mainMenuAccountsShownValue(
|
2020-06-22 14:33:35 +00:00
|
|
|
) | rpl::filter([=](bool value) {
|
|
|
|
return (_toggled != value);
|
|
|
|
}) | rpl::start_with_next([=](bool value) {
|
|
|
|
_toggled = value;
|
|
|
|
_toggledAnimation.start(
|
|
|
|
[=] { update(); },
|
|
|
|
_toggled ? 0. : 1.,
|
|
|
|
_toggled ? 1. : 0.,
|
|
|
|
st::slideWrapDuration);
|
2020-06-23 13:29:02 +00:00
|
|
|
validateUnreadBadge();
|
2020-06-22 14:33:35 +00:00
|
|
|
}, lifetime());
|
|
|
|
_toggledAnimation.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::ToggleAccountsButton::paintEvent(QPaintEvent *e) {
|
2020-06-23 13:29:02 +00:00
|
|
|
auto p = Painter(this);
|
2020-06-22 14:33:35 +00:00
|
|
|
|
|
|
|
const auto toggled = _toggledAnimation.value(_toggled ? 1. : 0.);
|
|
|
|
const auto x = 0. + width() - st::mainMenuTogglePosition.x();
|
|
|
|
const auto y = 0. + height() - st::mainMenuTogglePosition.y();
|
|
|
|
const auto size = st::mainMenuToggleSize;
|
|
|
|
const auto size2 = size / 2.;
|
|
|
|
const auto sqrt2 = sqrt(2.);
|
|
|
|
const auto stroke = (st::mainMenuToggleFourStrokes / 4.) / sqrt2;
|
|
|
|
const auto left = x - size;
|
|
|
|
const auto right = x + size;
|
|
|
|
const auto bottom = y + size2;
|
|
|
|
const auto top = y - size2;
|
|
|
|
constexpr auto kPointCount = 6;
|
|
|
|
std::array<QPointF, kPointCount> points = { {
|
|
|
|
{ left - stroke, bottom - stroke },
|
|
|
|
{ x, bottom - stroke - size - stroke },
|
|
|
|
{ right + stroke, bottom - stroke },
|
|
|
|
{ right - stroke, bottom + stroke },
|
|
|
|
{ x, bottom + stroke - size + stroke },
|
|
|
|
{ left + stroke, bottom + stroke }
|
|
|
|
} };
|
2020-06-23 13:29:02 +00:00
|
|
|
const auto alpha = (toggled - 1.) * M_PI;
|
2020-06-22 14:33:35 +00:00
|
|
|
const auto cosalpha = cos(alpha);
|
|
|
|
const auto sinalpha = sin(alpha);
|
|
|
|
for (auto &point : points) {
|
|
|
|
auto px = point.x() - x;
|
|
|
|
auto py = point.y() - y;
|
|
|
|
point.setX(x + px * cosalpha - py * sinalpha);
|
|
|
|
point.setY(y + py * cosalpha + px * sinalpha);
|
|
|
|
}
|
|
|
|
QPainterPath path;
|
|
|
|
path.moveTo(points[0]);
|
|
|
|
for (int i = 1; i != kPointCount; ++i) {
|
|
|
|
path.lineTo(points[i]);
|
|
|
|
}
|
|
|
|
path.lineTo(points[0]);
|
|
|
|
|
|
|
|
auto hq = PainterHighQualityEnabler(p);
|
|
|
|
p.fillPath(path, st::mainMenuCoverFg);
|
2020-06-23 13:29:02 +00:00
|
|
|
|
2020-06-27 13:11:18 +00:00
|
|
|
paintUnreadBadge(p);
|
2020-06-23 13:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::ToggleAccountsButton::paintUnreadBadge(QPainter &p) {
|
2020-06-27 13:11:18 +00:00
|
|
|
const auto progress = 1. - _toggledAnimation.value(_toggled ? 1. : 0.);
|
|
|
|
if (!progress) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-23 13:29:02 +00:00
|
|
|
validateUnreadBadge();
|
|
|
|
if (_unreadBadge.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Dialogs::Layout::UnreadBadgeStyle st;
|
|
|
|
|
|
|
|
const auto right = width() - st::mainMenuTogglePosition.x() - st::mainMenuToggleSize * 2;
|
|
|
|
const auto top = height() - st::mainMenuTogglePosition.y() - st::mainMenuToggleSize;
|
|
|
|
const auto width = _unreadBadgeWidth;
|
|
|
|
const auto rectHeight = st.size;
|
|
|
|
const auto rectWidth = std::max(width + 2 * st.padding, rectHeight);
|
|
|
|
const auto left = right - rectWidth;
|
|
|
|
const auto textLeft = left + (rectWidth - width) / 2;
|
|
|
|
const auto textTop = top + (st.textTop ? st.textTop : (rectHeight - st.font->height) / 2);
|
|
|
|
|
|
|
|
const auto isFill = IsFilledCover();
|
|
|
|
|
|
|
|
auto hq = PainterHighQualityEnabler(p);
|
2020-06-27 13:11:18 +00:00
|
|
|
auto brush = (isFill ? st::mainMenuCloudBg : st::msgServiceBg)->c;
|
|
|
|
brush.setAlphaF(progress * brush.alphaF());
|
|
|
|
p.setBrush(brush);
|
2020-06-23 13:29:02 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.drawRoundedRect(left, top, rectWidth, rectHeight, rectHeight / 2, rectHeight / 2);
|
|
|
|
|
|
|
|
p.setFont(st.font);
|
2020-06-27 13:11:18 +00:00
|
|
|
auto pen = (isFill ? st::mainMenuCloudFg : st::msgServiceFg)->c;
|
|
|
|
pen.setAlphaF(progress * pen.alphaF());
|
|
|
|
p.setPen(pen);
|
2020-06-23 13:29:02 +00:00
|
|
|
p.drawText(textLeft, textTop + st.font->ascent, _unreadBadge);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::ToggleAccountsButton::validateUnreadBadge() {
|
|
|
|
const auto base = st::mainMenuTogglePosition.x()
|
|
|
|
+ 2 * st::mainMenuToggleSize;
|
|
|
|
if (_toggled) {
|
|
|
|
_rightSkip = base;
|
|
|
|
return;
|
|
|
|
} else if (!_unreadBadgeStale) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_unreadBadge = computeUnreadBadge();
|
|
|
|
|
|
|
|
Dialogs::Layout::UnreadBadgeStyle st;
|
|
|
|
_unreadBadgeWidth = st.font->width(_unreadBadge);
|
|
|
|
const auto rectHeight = st.size;
|
|
|
|
const auto rectWidth = std::max(
|
|
|
|
_unreadBadgeWidth + 2 * st.padding,
|
|
|
|
rectHeight);
|
|
|
|
_rightSkip = base + rectWidth + st::mainMenuToggleSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString MainMenu::ToggleAccountsButton::computeUnreadBadge() const {
|
2020-07-24 05:41:51 +00:00
|
|
|
const auto state = OtherAccountsUnreadStateCurrent();
|
|
|
|
return state.allMuted
|
|
|
|
? QString()
|
|
|
|
: (state.count > 99)
|
2020-06-23 13:29:02 +00:00
|
|
|
? u"99+"_q
|
2020-07-24 05:41:51 +00:00
|
|
|
: (state.count > 0)
|
|
|
|
? QString::number(state.count)
|
2020-06-23 13:29:02 +00:00
|
|
|
: QString();
|
2020-06-22 14:33:35 +00:00
|
|
|
}
|
|
|
|
|
2018-10-20 19:04:10 +00:00
|
|
|
MainMenu::ResetScaleButton::ResetScaleButton(QWidget *parent)
|
|
|
|
: AbstractButton(parent) {
|
|
|
|
const auto margin = st::mainMenuCloudButton.height
|
|
|
|
- st::mainMenuCloudSize;
|
|
|
|
const auto textWidth = st::mainMenuResetScaleFont->width(kText);
|
|
|
|
const auto innerWidth = st::mainMenuResetScaleLeft
|
|
|
|
+ textWidth
|
|
|
|
+ st::mainMenuResetScaleRight;
|
|
|
|
const auto width = margin + innerWidth;
|
|
|
|
resize(width, st::mainMenuCloudButton.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::ResetScaleButton::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
const auto innerHeight = st::mainMenuCloudSize;
|
|
|
|
const auto radius = innerHeight / 2;
|
|
|
|
const auto margin = st::mainMenuCloudButton.height
|
|
|
|
- st::mainMenuCloudSize;
|
|
|
|
const auto textWidth = st::mainMenuResetScaleFont->width(kText);
|
|
|
|
const auto innerWidth = st::mainMenuResetScaleLeft
|
|
|
|
+ textWidth
|
|
|
|
+ st::mainMenuResetScaleRight;
|
|
|
|
const auto left = margin / 2;
|
|
|
|
const auto top = margin / 2;
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(st::mainMenuCloudBg);
|
|
|
|
p.drawRoundedRect(left, top, innerWidth, innerHeight, radius, radius);
|
|
|
|
|
|
|
|
st::settingsIconInterfaceScale.paint(
|
|
|
|
p,
|
|
|
|
left + st::mainMenuResetScaleIconLeft,
|
|
|
|
top + ((innerHeight - st::settingsIconInterfaceScale.height()) / 2),
|
|
|
|
width(),
|
|
|
|
st::mainMenuCloudFg->c);
|
|
|
|
|
|
|
|
p.setFont(st::mainMenuResetScaleFont);
|
|
|
|
p.setPen(st::mainMenuCloudFg);
|
|
|
|
p.drawText(
|
|
|
|
left + st::mainMenuResetScaleLeft,
|
|
|
|
top + st::mainMenuResetScaleTop + st::mainMenuResetScaleFont->ascent,
|
|
|
|
kText);
|
|
|
|
}
|
2016-11-11 19:51:59 +00:00
|
|
|
|
2017-11-13 15:50:10 +00:00
|
|
|
MainMenu::MainMenu(
|
|
|
|
QWidget *parent,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<SessionController*> controller)
|
2019-09-18 11:19:05 +00:00
|
|
|
: LayerWidget(parent)
|
2017-11-13 15:50:10 +00:00
|
|
|
, _controller(controller)
|
2020-06-22 13:01:41 +00:00
|
|
|
, _userpicButton(
|
|
|
|
this,
|
|
|
|
_controller,
|
|
|
|
_controller->session().user(),
|
|
|
|
Ui::UserpicButton::Role::Custom,
|
|
|
|
st::mainMenuUserpic)
|
2020-06-23 14:55:08 +00:00
|
|
|
, _toggleAccounts(this)
|
2020-06-22 13:01:41 +00:00
|
|
|
, _archiveButton(this, st::mainMenuCloudButton)
|
2020-06-29 05:55:19 +00:00
|
|
|
, _cloudButton(this, st::mainMenuCloudButton)
|
2020-06-22 13:01:41 +00:00
|
|
|
, _scroll(this, st::defaultSolidScroll)
|
|
|
|
, _inner(_scroll->setOwnedWidget(
|
|
|
|
object_ptr<Ui::VerticalLayout>(_scroll.data())))
|
|
|
|
, _accounts(_inner->add(object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
_inner.get(),
|
|
|
|
object_ptr<Ui::VerticalLayout>(_inner.get()))))
|
|
|
|
, _shadow(_inner->add(object_ptr<Ui::SlideWrap<Ui::PlainShadow>>(
|
|
|
|
_inner.get(),
|
|
|
|
object_ptr<Ui::PlainShadow>(_inner.get()))))
|
|
|
|
, _menu(_inner->add(
|
2021-01-12 22:59:55 +00:00
|
|
|
object_ptr<Ui::Menu::Menu>(_inner.get(), st::mainMenu),
|
2020-06-22 13:01:41 +00:00
|
|
|
{ 0, st::mainMenuSkip, 0, 0 }))
|
|
|
|
, _footer(_inner->add(object_ptr<Ui::RpWidget>(_inner.get())))
|
|
|
|
, _telegram(
|
|
|
|
Ui::CreateChild<Ui::FlatLabel>(_footer.get(), st::mainMenuTelegramLabel))
|
|
|
|
, _version(
|
|
|
|
Ui::CreateChild<Ui::FlatLabel>(
|
|
|
|
_footer.get(),
|
|
|
|
st::mainMenuVersionLabel)) {
|
2016-11-11 19:51:59 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
2016-11-16 10:44:06 +00:00
|
|
|
|
2020-06-22 13:01:41 +00:00
|
|
|
setupArchiveButton();
|
2020-06-29 05:55:19 +00:00
|
|
|
setupCloudButton();
|
2020-06-22 13:01:41 +00:00
|
|
|
setupUserpicButton();
|
2020-06-22 14:33:35 +00:00
|
|
|
setupAccountsToggle();
|
2020-06-23 14:55:08 +00:00
|
|
|
setupAccounts();
|
2019-05-16 08:39:45 +00:00
|
|
|
|
2017-06-29 19:09:10 +00:00
|
|
|
_nightThemeSwitch.setCallback([this] {
|
2018-07-19 14:58:40 +00:00
|
|
|
if (const auto action = *_nightThemeAction) {
|
|
|
|
const auto nightMode = Window::Theme::IsNightMode();
|
|
|
|
if (action->isChecked() != nightMode) {
|
|
|
|
Window::Theme::ToggleNightMode();
|
2018-09-26 11:28:16 +00:00
|
|
|
Window::Theme::KeepApplied();
|
2017-06-29 19:09:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-22 13:01:41 +00:00
|
|
|
_footer->heightValue(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_telegram->moveToLeft(st::mainMenuFooterLeft, _footer->height() - st::mainMenuTelegramBottom - _telegram->height());
|
|
|
|
_version->moveToLeft(st::mainMenuFooterLeft, _footer->height() - st::mainMenuVersionBottom - _version->height());
|
|
|
|
}, _footer->lifetime());
|
|
|
|
|
|
|
|
rpl::combine(
|
|
|
|
heightValue(),
|
|
|
|
_inner->heightValue()
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
updateInnerControlsGeometry();
|
|
|
|
}, _inner->lifetime());
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
parentResized();
|
2021-01-12 22:59:55 +00:00
|
|
|
_menu->setTriggeredCallback([](const Ui::Menu::CallbackData &data) {
|
2021-03-03 18:22:42 +00:00
|
|
|
data.action->triggered();
|
2016-11-11 19:51:59 +00:00
|
|
|
});
|
2017-04-28 17:16:14 +00:00
|
|
|
refreshMenu();
|
2019-05-24 18:46:52 +00:00
|
|
|
refreshBackground();
|
2017-04-28 17:16:14 +00:00
|
|
|
|
2019-06-12 20:11:41 +00:00
|
|
|
_telegram->setMarkedText(Ui::Text::Link(
|
|
|
|
qsl("Telegram Desktop"),
|
|
|
|
qsl("https://desktop.telegram.org")));
|
|
|
|
_telegram->setLinksTrusted();
|
2019-06-19 16:39:25 +00:00
|
|
|
_version->setRichText(textcmdLink(1, tr::lng_settings_current_version(tr::now, lt_version, currentVersionText())) + QChar(' ') + QChar(8211) + QChar(' ') + textcmdLink(2, tr::lng_menu_about(tr::now)));
|
2021-02-04 16:42:32 +00:00
|
|
|
_version->setLink(1, std::make_shared<UrlClickHandler>(Core::App().changelogLink()));
|
2017-12-18 09:07:18 +00:00
|
|
|
_version->setLink(2, std::make_shared<LambdaClickHandler>([] { Ui::show(Box<AboutBox>()); }));
|
2017-04-28 17:16:14 +00:00
|
|
|
|
2020-07-01 08:03:34 +00:00
|
|
|
_controller->session().downloaderTaskFinished(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
update();
|
|
|
|
}, lifetime());
|
2020-06-12 12:12:34 +00:00
|
|
|
|
|
|
|
_controller->session().changes().peerUpdates(
|
|
|
|
_controller->session().user(),
|
|
|
|
Data::PeerUpdate::Flag::PhoneNumber
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
updatePhone();
|
|
|
|
}, lifetime());
|
|
|
|
|
2020-06-17 09:36:25 +00:00
|
|
|
_controller->session().serverConfig().phoneCallsEnabled.changes(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
refreshMenu();
|
|
|
|
}, lifetime());
|
|
|
|
|
2017-06-29 19:09:10 +00:00
|
|
|
subscribe(Window::Theme::Background(), [this](const Window::Theme::BackgroundUpdate &update) {
|
|
|
|
if (update.type == Window::Theme::BackgroundUpdate::Type::ApplyingTheme) {
|
2020-06-23 13:29:02 +00:00
|
|
|
if (const auto action = *_nightThemeAction) {
|
|
|
|
const auto nightMode = Window::Theme::IsNightMode();
|
|
|
|
if (action->isChecked() != nightMode) {
|
|
|
|
action->setChecked(nightMode);
|
|
|
|
_menu->finishAnimating();
|
|
|
|
}
|
|
|
|
}
|
2019-05-27 11:43:23 +00:00
|
|
|
}
|
|
|
|
if (update.type == Window::Theme::BackgroundUpdate::Type::New) {
|
2019-05-24 18:46:52 +00:00
|
|
|
refreshBackground();
|
2017-06-29 19:09:10 +00:00
|
|
|
}
|
|
|
|
});
|
2020-06-22 13:01:41 +00:00
|
|
|
updatePhone();
|
|
|
|
initResetScaleButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::setupArchiveButton() {
|
2020-09-16 14:09:04 +00:00
|
|
|
const auto controller = _controller;
|
|
|
|
const auto folder = [=] {
|
|
|
|
return controller->session().data().folderLoaded(Data::Folder::kId);
|
|
|
|
};
|
2020-06-22 13:01:41 +00:00
|
|
|
const auto showArchive = [=] {
|
2020-09-16 14:09:04 +00:00
|
|
|
if (const auto f = folder()) {
|
|
|
|
controller->openFolder(f);
|
2020-06-22 13:01:41 +00:00
|
|
|
Ui::hideSettingsAndLayer();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const auto checkArchive = [=] {
|
2020-09-16 14:09:04 +00:00
|
|
|
const auto f = folder();
|
|
|
|
return f
|
|
|
|
&& !f->chatsList()->empty()
|
|
|
|
&& controller->session().settings().archiveInMainMenu();
|
2020-06-22 13:01:41 +00:00
|
|
|
};
|
|
|
|
_archiveButton->setVisible(checkArchive());
|
|
|
|
_archiveButton->setAcceptBoth(true);
|
|
|
|
_archiveButton->clicks(
|
|
|
|
) | rpl::start_with_next([=](Qt::MouseButton which) {
|
|
|
|
if (which == Qt::LeftButton) {
|
|
|
|
showArchive();
|
|
|
|
return;
|
|
|
|
} else if (which != Qt::RightButton) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_contextMenu = base::make_unique_q<Ui::PopupMenu>(this);
|
2020-09-16 14:09:04 +00:00
|
|
|
const auto addAction = [&](const QString &text, Fn<void()> callback) {
|
|
|
|
return _contextMenu->addAction(text, std::move(callback));
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto hide = [=] {
|
|
|
|
controller->session().settings().setArchiveInMainMenu(false);
|
|
|
|
controller->session().saveSettingsDelayed();
|
2020-06-22 13:01:41 +00:00
|
|
|
Ui::hideSettingsAndLayer();
|
2020-09-16 14:09:04 +00:00
|
|
|
};
|
|
|
|
addAction(tr::lng_context_archive_to_list(tr::now), std::move(hide));
|
|
|
|
|
|
|
|
MenuAddMarkAsReadChatListAction(
|
|
|
|
[f = folder()] { return f->chatsList(); },
|
|
|
|
addAction);
|
|
|
|
|
2020-06-22 13:01:41 +00:00
|
|
|
_contextMenu->popup(QCursor::pos());
|
|
|
|
}, _archiveButton->lifetime());
|
|
|
|
|
2020-09-16 14:09:04 +00:00
|
|
|
controller->session().data().chatsListChanges(
|
2019-05-16 08:39:45 +00:00
|
|
|
) | rpl::filter([](Data::Folder *folder) {
|
|
|
|
return folder && (folder->id() == Data::Folder::kId);
|
|
|
|
}) | rpl::start_with_next([=](Data::Folder *folder) {
|
2020-09-30 11:39:46 +00:00
|
|
|
const auto isArchiveVisible = checkArchive();
|
|
|
|
_archiveButton->setVisible(isArchiveVisible);
|
|
|
|
if (!isArchiveVisible) {
|
|
|
|
_contextMenu = nullptr;
|
|
|
|
}
|
2019-05-16 08:39:45 +00:00
|
|
|
update();
|
|
|
|
}, lifetime());
|
2020-06-22 13:01:41 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 05:55:19 +00:00
|
|
|
void MainMenu::setupCloudButton() {
|
|
|
|
_cloudButton->setClickedCallback([=] {
|
|
|
|
_controller->content()->choosePeer(
|
|
|
|
_controller->session().userPeerId(),
|
|
|
|
ShowAtUnreadMsgId);
|
|
|
|
});
|
|
|
|
_cloudButton->show();
|
|
|
|
}
|
|
|
|
|
2020-06-22 13:01:41 +00:00
|
|
|
void MainMenu::setupUserpicButton() {
|
2020-06-30 07:34:02 +00:00
|
|
|
_userpicButton->setClickedCallback([=] { toggleAccounts(); });
|
2020-06-22 13:01:41 +00:00
|
|
|
_userpicButton->show();
|
|
|
|
}
|
|
|
|
|
2020-06-30 07:34:02 +00:00
|
|
|
void MainMenu::toggleAccounts() {
|
|
|
|
auto &settings = Core::App().settings();
|
|
|
|
const auto shown = !settings.mainMenuAccountsShown();
|
|
|
|
settings.setMainMenuAccountsShown(shown);
|
|
|
|
Core::App().saveSettingsDelayed();
|
|
|
|
}
|
|
|
|
|
2020-06-22 13:01:41 +00:00
|
|
|
void MainMenu::setupAccounts() {
|
|
|
|
const auto inner = _accounts->entity();
|
|
|
|
|
|
|
|
inner->add(object_ptr<Ui::FixedHeightWidget>(inner, st::mainMenuSkip));
|
|
|
|
_addAccount = setupAddAccount(inner);
|
|
|
|
inner->add(object_ptr<Ui::FixedHeightWidget>(inner, st::mainMenuSkip));
|
|
|
|
|
|
|
|
rpl::single(
|
|
|
|
rpl::empty_value()
|
|
|
|
) | rpl::then(Core::App().domain().accountsChanges(
|
|
|
|
)) | rpl::start_with_next([=] {
|
|
|
|
const auto &list = Core::App().domain().accounts();
|
|
|
|
const auto exists = [&](not_null<Main::Account*> account) {
|
|
|
|
for (const auto &[index, existing] : list) {
|
|
|
|
if (account == existing.get()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
for (auto i = _watched.begin(); i != _watched.end();) {
|
|
|
|
if (!exists(i->first)) {
|
|
|
|
i = _watched.erase(i);
|
|
|
|
} else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const auto &[index, account] : list) {
|
|
|
|
if (_watched.emplace(account.get()).second) {
|
|
|
|
account->sessionChanges(
|
|
|
|
) | rpl::start_with_next([=](Main::Session *session) {
|
|
|
|
rebuildAccounts();
|
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rebuildAccounts();
|
|
|
|
}, lifetime());
|
|
|
|
|
|
|
|
_accounts->toggleOn(Core::App().settings().mainMenuAccountsShownValue());
|
|
|
|
_accounts->finishAnimating();
|
|
|
|
|
|
|
|
_shadow->setDuration(0)->toggleOn(_accounts->shownValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::rebuildAccounts() {
|
|
|
|
const auto inner = _accounts->entity();
|
|
|
|
|
|
|
|
auto count = 0;
|
2020-06-23 09:20:38 +00:00
|
|
|
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;
|
2020-06-22 13:01:41 +00:00
|
|
|
if (!account->sessionExists()) {
|
|
|
|
button = nullptr;
|
|
|
|
} else if (!button) {
|
|
|
|
button.reset(inner->insert(
|
|
|
|
++count,
|
|
|
|
object_ptr<AccountButton>(inner, account)));
|
|
|
|
button->setClickedCallback([=] {
|
2020-06-23 09:20:38 +00:00
|
|
|
if (account == &Core::App().domain().active()) {
|
|
|
|
closeLayer();
|
|
|
|
return;
|
|
|
|
}
|
2020-06-22 13:01:41 +00:00
|
|
|
auto activate = [=, guard = _accountSwitchGuard.make_guard()]{
|
|
|
|
if (guard) {
|
2020-12-13 13:08:16 +00:00
|
|
|
Core::App().domain().maybeActivate(account);
|
2020-06-22 13:01:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
base::call_delayed(
|
|
|
|
st::defaultRippleAnimation.hideDuration,
|
|
|
|
account,
|
|
|
|
std::move(activate));
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inner->resizeToWidth(_accounts->width());
|
|
|
|
|
|
|
|
_addAccount->toggle(
|
|
|
|
(count < Main::Domain::kMaxAccounts),
|
|
|
|
anim::type::instant);
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<Ui::SlideWrap<Ui::RippleButton>*> MainMenu::setupAddAccount(
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
|
|
|
const auto result = container->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::RippleButton>>(
|
|
|
|
container.get(),
|
|
|
|
object_ptr<Ui::RippleButton>(
|
|
|
|
container.get(),
|
|
|
|
st::defaultRippleAnimation)))->setDuration(0);
|
|
|
|
const auto st = &st::mainMenu;
|
|
|
|
const auto height = st->itemPadding.top()
|
|
|
|
+ st->itemStyle.font->height
|
|
|
|
+ st->itemPadding.bottom();
|
|
|
|
const auto button = result->entity();
|
|
|
|
button->resize(button->width(), height);
|
|
|
|
|
|
|
|
button->paintRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
auto p = Painter(button);
|
|
|
|
const auto over = button->isOver();
|
|
|
|
p.fillRect(button->rect(), over ? st->itemBgOver : st->itemBg);
|
|
|
|
button->paintRipple(p, 0, 0);
|
|
|
|
const auto &icon = over
|
|
|
|
? st::mainMenuAddAccountOver
|
|
|
|
: st::mainMenuAddAccount;
|
|
|
|
icon.paint(p, st->itemIconPosition, width());
|
|
|
|
p.setPen(over ? st->itemFgOver : st->itemFg);
|
|
|
|
p.setFont(st->itemStyle.font);
|
|
|
|
p.drawTextLeft(
|
|
|
|
st->itemPadding.left(),
|
|
|
|
st->itemPadding.top(),
|
|
|
|
width(),
|
|
|
|
tr::lng_menu_add_account(tr::now));
|
|
|
|
}, button->lifetime());
|
|
|
|
|
|
|
|
const auto add = [=](MTP::Environment environment) {
|
2020-12-13 13:08:16 +00:00
|
|
|
Core::App().preventOrInvoke([=] {
|
|
|
|
Core::App().domain().addActivated(environment);
|
|
|
|
});
|
2020-06-22 13:01:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
button->setAcceptBoth(true);
|
|
|
|
button->clicks(
|
|
|
|
) | rpl::start_with_next([=](Qt::MouseButton which) {
|
|
|
|
if (which == Qt::LeftButton) {
|
|
|
|
add(MTP::Environment::Production);
|
|
|
|
return;
|
|
|
|
} else if (which != Qt::RightButton
|
2020-09-17 14:56:01 +00:00
|
|
|
|| !IsAltShift(button->clickModifiers())) {
|
2020-06-22 13:01:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
_contextMenu = base::make_unique_q<Ui::PopupMenu>(this);
|
|
|
|
_contextMenu->addAction("Production Server", [=] {
|
|
|
|
add(MTP::Environment::Production);
|
|
|
|
});
|
|
|
|
_contextMenu->addAction("Test Server", [=] {
|
|
|
|
add(MTP::Environment::Test);
|
|
|
|
});
|
|
|
|
_contextMenu->popup(QCursor::pos());
|
2020-06-22 14:33:35 +00:00
|
|
|
}, button->lifetime());
|
2020-06-22 13:01:41 +00:00
|
|
|
|
|
|
|
return result;
|
2017-04-28 17:16:14 +00:00
|
|
|
}
|
|
|
|
|
2020-06-22 14:33:35 +00:00
|
|
|
void MainMenu::setupAccountsToggle() {
|
|
|
|
_toggleAccounts->show();
|
2020-06-30 07:34:02 +00:00
|
|
|
_toggleAccounts->setClickedCallback([=] { toggleAccounts(); });
|
2020-06-22 14:33:35 +00:00
|
|
|
}
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
void MainMenu::parentResized() {
|
|
|
|
resize(st::mainMenuWidth, parentWidget()->height());
|
|
|
|
}
|
|
|
|
|
2017-04-28 17:16:14 +00:00
|
|
|
void MainMenu::refreshMenu() {
|
|
|
|
_menu->clearActions();
|
2021-02-03 01:17:03 +00:00
|
|
|
const auto controller = _controller;
|
2019-07-24 11:13:51 +00:00
|
|
|
if (!_controller->session().supportMode()) {
|
2021-02-03 01:17:03 +00:00
|
|
|
_menu->addAction(tr::lng_create_group_title(tr::now), [=] {
|
|
|
|
controller->showNewGroup();
|
2018-10-05 17:08:29 +00:00
|
|
|
}, &st::mainMenuNewGroup, &st::mainMenuNewGroupOver);
|
2021-02-03 01:17:03 +00:00
|
|
|
_menu->addAction(tr::lng_create_channel_title(tr::now), [=] {
|
|
|
|
controller->showNewChannel();
|
2018-10-05 17:08:29 +00:00
|
|
|
}, &st::mainMenuNewChannel, &st::mainMenuNewChannelOver);
|
2019-07-25 18:55:11 +00:00
|
|
|
_menu->addAction(tr::lng_menu_contacts(tr::now), [=] {
|
2020-10-07 17:08:50 +00:00
|
|
|
Ui::show(PrepareContactsBox(controller));
|
2018-10-05 17:08:29 +00:00
|
|
|
}, &st::mainMenuContacts, &st::mainMenuContactsOver);
|
2020-06-17 09:36:25 +00:00
|
|
|
if (_controller->session().serverConfig().phoneCallsEnabled.current()) {
|
2019-07-25 18:55:11 +00:00
|
|
|
_menu->addAction(tr::lng_menu_calls(tr::now), [=] {
|
2021-01-21 15:57:12 +00:00
|
|
|
ShowCallsBox(controller);
|
2018-10-05 17:08:29 +00:00
|
|
|
}, &st::mainMenuCalls, &st::mainMenuCallsOver);
|
|
|
|
}
|
|
|
|
} else {
|
2021-02-03 01:17:03 +00:00
|
|
|
_menu->addAction(tr::lng_profile_add_contact(tr::now), [=] {
|
|
|
|
controller->showAddContact();
|
2018-10-05 17:08:29 +00:00
|
|
|
}, &st::mainMenuContacts, &st::mainMenuContactsOver);
|
2018-10-09 13:32:32 +00:00
|
|
|
|
|
|
|
const auto fix = std::make_shared<QPointer<QAction>>();
|
|
|
|
*fix = _menu->addAction(qsl("Fix chats order"), [=] {
|
|
|
|
(*fix)->setChecked(!(*fix)->isChecked());
|
2019-07-24 11:13:51 +00:00
|
|
|
_controller->session().settings().setSupportFixChatsOrder(
|
|
|
|
(*fix)->isChecked());
|
2020-06-18 12:47:09 +00:00
|
|
|
_controller->session().saveSettings();
|
2018-10-09 13:32:32 +00:00
|
|
|
}, &st::mainMenuFixOrder, &st::mainMenuFixOrderOver);
|
|
|
|
(*fix)->setCheckable(true);
|
2019-07-24 11:13:51 +00:00
|
|
|
(*fix)->setChecked(
|
|
|
|
_controller->session().settings().supportFixChatsOrder());
|
2018-10-09 13:32:32 +00:00
|
|
|
|
|
|
|
_menu->addAction(qsl("Reload templates"), [=] {
|
2019-07-24 11:13:51 +00:00
|
|
|
_controller->session().supportTemplates().reload();
|
2018-10-09 13:32:32 +00:00
|
|
|
}, &st::mainMenuReload, &st::mainMenuReloadOver);
|
2017-04-28 17:16:14 +00:00
|
|
|
}
|
2021-02-03 01:58:27 +00:00
|
|
|
_menu->addAction(tr::lng_menu_settings(tr::now), [=] {
|
|
|
|
controller->showSettings();
|
2016-11-16 10:44:06 +00:00
|
|
|
}, &st::mainMenuSettings, &st::mainMenuSettingsOver);
|
2017-06-29 19:09:10 +00:00
|
|
|
|
2018-10-09 13:32:32 +00:00
|
|
|
_nightThemeAction = std::make_shared<QPointer<QAction>>();
|
2021-01-13 01:10:25 +00:00
|
|
|
|
|
|
|
auto nightCallback = [=] {
|
2020-07-24 06:01:37 +00:00
|
|
|
if (Window::Theme::Background()->editingTheme()) {
|
|
|
|
Ui::show(Box<InformBox>(
|
|
|
|
tr::lng_theme_editor_cant_change_theme(tr::now)));
|
|
|
|
return;
|
|
|
|
}
|
2020-07-22 12:10:17 +00:00
|
|
|
const auto weak = MakeWeak(this);
|
|
|
|
const auto toggle = [=] {
|
|
|
|
if (!weak) {
|
|
|
|
Window::Theme::ToggleNightMode();
|
|
|
|
Window::Theme::KeepApplied();
|
|
|
|
} else if (auto action = *_nightThemeAction) {
|
|
|
|
action->setChecked(!action->isChecked());
|
|
|
|
_nightThemeSwitch.callOnce(st::mainMenu.itemToggle.duration);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Window::Theme::ToggleNightModeWithConfirmation(
|
|
|
|
&_controller->window(),
|
|
|
|
toggle);
|
2021-01-13 01:10:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto item = base::make_unique_q<Ui::Menu::Toggle>(
|
|
|
|
_menu,
|
|
|
|
st::mainMenu,
|
|
|
|
tr::lng_menu_night_mode(tr::now),
|
|
|
|
std::move(nightCallback),
|
|
|
|
&st::mainMenuNightMode,
|
|
|
|
&st::mainMenuNightModeOver);
|
|
|
|
|
|
|
|
auto action = _menu->addAction(std::move(item));
|
2018-07-19 14:58:40 +00:00
|
|
|
*_nightThemeAction = action;
|
|
|
|
action->setCheckable(true);
|
|
|
|
action->setChecked(Window::Theme::IsNightMode());
|
2020-07-14 16:36:55 +00:00
|
|
|
Core::App().settings().systemDarkModeValue(
|
|
|
|
) | rpl::start_with_next([=](std::optional<bool> darkMode) {
|
|
|
|
const auto darkModeEnabled = Core::App().settings().systemDarkModeEnabled();
|
|
|
|
if (darkModeEnabled && darkMode.has_value()) {
|
|
|
|
action->setChecked(*darkMode);
|
|
|
|
}
|
|
|
|
}, lifetime());
|
2018-07-19 14:58:40 +00:00
|
|
|
_menu->finishAnimating();
|
2016-11-11 19:51:59 +00:00
|
|
|
|
2017-05-07 09:00:49 +00:00
|
|
|
updatePhone();
|
2016-11-16 10:44:06 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 18:46:52 +00:00
|
|
|
void MainMenu::refreshBackground() {
|
|
|
|
const auto fill = QRect(0, 0, width(), st::mainMenuCoverHeight);
|
|
|
|
const auto intensityText = IntensityOfColor(st::mainMenuCoverFg->c);
|
|
|
|
QImage backgroundImage(
|
|
|
|
st::mainMenuWidth * cIntRetinaFactor(),
|
|
|
|
st::mainMenuCoverHeight * cIntRetinaFactor(),
|
|
|
|
QImage::Format_ARGB32_Premultiplied);
|
|
|
|
QPainter p(&backgroundImage);
|
|
|
|
|
2019-05-27 11:43:23 +00:00
|
|
|
const auto drawShadow = [](QPainter &p) {
|
|
|
|
st::mainMenuShadow.paint(
|
|
|
|
p,
|
|
|
|
0,
|
|
|
|
st::mainMenuCoverHeight - st::mainMenuShadow.height(),
|
|
|
|
st::mainMenuWidth,
|
|
|
|
IntensityOfColor(st::mainMenuCoverFg->c) < 0.5
|
|
|
|
? Qt::white
|
|
|
|
: Qt::black);
|
|
|
|
};
|
|
|
|
|
2019-05-24 18:46:52 +00:00
|
|
|
// Solid color.
|
|
|
|
if (const auto color = Window::Theme::Background()->colorForFill()) {
|
|
|
|
const auto intensity = IntensityOfColor(*color);
|
|
|
|
p.fillRect(fill, *color);
|
2019-05-27 11:43:23 +00:00
|
|
|
if (std::abs(intensity - intensityText) < kMinDiffIntensity) {
|
|
|
|
drawShadow(p);
|
|
|
|
}
|
2019-05-24 18:46:52 +00:00
|
|
|
_background = backgroundImage;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Background image.
|
|
|
|
const auto &pixmap = Window::Theme::Background()->pixmap();
|
|
|
|
QRect to, from;
|
|
|
|
Window::Theme::ComputeBackgroundRects(fill, pixmap.size(), to, from);
|
|
|
|
|
|
|
|
// Cut off the part of the background that is under text.
|
|
|
|
const QRect underText(
|
|
|
|
st::mainMenuCoverTextLeft,
|
|
|
|
st::mainMenuCoverNameTop,
|
|
|
|
std::max(
|
2019-07-24 11:13:51 +00:00
|
|
|
st::semiboldFont->width(
|
|
|
|
_controller->session().user()->nameText().toString()),
|
2019-05-24 18:46:52 +00:00
|
|
|
st::normalFont->width(_phoneText)),
|
|
|
|
st::semiboldFont->height * 2);
|
|
|
|
|
2019-05-27 11:43:23 +00:00
|
|
|
p.drawPixmap(to, pixmap, from);
|
|
|
|
if (IsShadowShown(backgroundImage, underText, intensityText)) {
|
|
|
|
drawShadow(p);
|
|
|
|
}
|
|
|
|
_background = backgroundImage;
|
2019-05-24 18:46:52 +00:00
|
|
|
}
|
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
void MainMenu::resizeEvent(QResizeEvent *e) {
|
2017-06-29 19:09:10 +00:00
|
|
|
_menu->setForceWidth(width());
|
2020-06-22 13:01:41 +00:00
|
|
|
_inner->resizeToWidth(width());
|
2016-11-16 10:44:06 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::updateControlsGeometry() {
|
2020-06-29 05:55:19 +00:00
|
|
|
_userpicButton->moveToLeft(
|
|
|
|
st::mainMenuUserpicLeft,
|
|
|
|
st::mainMenuUserpicTop);
|
2018-10-20 19:04:10 +00:00
|
|
|
if (_resetScaleButton) {
|
|
|
|
_resetScaleButton->moveToRight(0, 0);
|
2020-06-29 05:55:19 +00:00
|
|
|
_cloudButton->moveToRight(_resetScaleButton->width(), 0);
|
|
|
|
_archiveButton->moveToRight(
|
|
|
|
_resetScaleButton->width() + _cloudButton->width(),
|
|
|
|
0);
|
2020-06-22 13:01:41 +00:00
|
|
|
} else {
|
2020-06-29 05:55:19 +00:00
|
|
|
const auto right = st::mainMenuTogglePosition.x()
|
|
|
|
- (_cloudButton->width() / 2);
|
|
|
|
const auto top = st::mainMenuUserpicTop
|
|
|
|
- (_cloudButton->height() - st::mainMenuCloudSize) / 2;
|
|
|
|
_cloudButton->moveToRight(right, top);
|
|
|
|
_archiveButton->moveToRight(right + _cloudButton->width(), top);
|
2020-06-22 13:01:41 +00:00
|
|
|
}
|
|
|
|
_toggleAccounts->setGeometry(
|
|
|
|
0,
|
|
|
|
st::mainMenuCoverNameTop,
|
|
|
|
width(),
|
|
|
|
st::mainMenuCoverHeight - st::mainMenuCoverNameTop);
|
|
|
|
const auto top = st::mainMenuCoverHeight;
|
|
|
|
_scroll->setGeometry(0, top, width(), height() - top);
|
|
|
|
updateInnerControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::updateInnerControlsGeometry() {
|
|
|
|
const auto contentHeight = _accounts->height()
|
|
|
|
+ _shadow->height()
|
|
|
|
+ st::mainMenuSkip
|
|
|
|
+ _menu->height();
|
|
|
|
const auto available = height() - st::mainMenuCoverHeight - contentHeight;
|
|
|
|
const auto footerHeight = std::max(
|
|
|
|
available,
|
|
|
|
st::mainMenuTelegramBottom + _telegram->height() + st::mainMenuSkip);
|
|
|
|
if (_footer->height() != footerHeight) {
|
|
|
|
_footer->resize(_footer->width(), footerHeight);
|
2018-10-20 19:04:10 +00:00
|
|
|
}
|
2016-11-11 19:51:59 +00:00
|
|
|
}
|
|
|
|
|
2017-05-07 09:00:49 +00:00
|
|
|
void MainMenu::updatePhone() {
|
2019-07-24 11:13:51 +00:00
|
|
|
_phoneText = App::formatPhone(_controller->session().user()->phone());
|
2016-12-03 12:10:35 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
void MainMenu::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
2019-05-17 16:54:24 +00:00
|
|
|
const auto clip = e->rect();
|
2019-05-24 18:46:52 +00:00
|
|
|
const auto cover = QRect(0, 0, width(), st::mainMenuCoverHeight)
|
|
|
|
.intersected(e->rect());
|
2019-05-17 16:54:24 +00:00
|
|
|
|
2020-06-23 13:29:02 +00:00
|
|
|
const auto isFill = IsFilledCover();
|
2019-05-31 17:53:00 +00:00
|
|
|
if (!isFill && !_background.isNull()) {
|
2019-05-17 16:54:24 +00:00
|
|
|
PainterHighQualityEnabler hq(p);
|
2019-05-24 18:46:52 +00:00
|
|
|
p.drawImage(0, 0, _background);
|
2019-05-17 16:54:24 +00:00
|
|
|
}
|
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
if (!cover.isEmpty()) {
|
2020-06-23 13:29:02 +00:00
|
|
|
const auto widthText = width()
|
|
|
|
- st::mainMenuCoverTextLeft
|
|
|
|
- _toggleAccounts->rightSkip();
|
2019-05-31 17:53:00 +00:00
|
|
|
|
|
|
|
if (isFill) {
|
|
|
|
p.fillRect(cover, st::mainMenuCoverBg);
|
|
|
|
}
|
2016-11-11 19:51:59 +00:00
|
|
|
p.setPen(st::mainMenuCoverFg);
|
|
|
|
p.setFont(st::semiboldFont);
|
2019-07-24 11:13:51 +00:00
|
|
|
_controller->session().user()->nameText().drawLeftElided(
|
2018-09-11 12:50:40 +00:00
|
|
|
p,
|
|
|
|
st::mainMenuCoverTextLeft,
|
|
|
|
st::mainMenuCoverNameTop,
|
2019-05-16 08:58:28 +00:00
|
|
|
widthText,
|
2018-09-11 12:50:40 +00:00
|
|
|
width());
|
|
|
|
p.setFont(st::normalFont);
|
|
|
|
p.drawTextLeft(st::mainMenuCoverTextLeft, st::mainMenuCoverStatusTop, width(), _phoneText);
|
2019-05-16 08:39:45 +00:00
|
|
|
|
2020-06-29 05:55:19 +00:00
|
|
|
// Draw Saved Messages button.
|
|
|
|
if (!_cloudButton->isHidden()) {
|
|
|
|
Ui::EmptyUserpic::PaintSavedMessages(
|
|
|
|
p,
|
|
|
|
_cloudButton->x() + (_cloudButton->width() - st::mainMenuCloudSize) / 2,
|
|
|
|
_cloudButton->y() + (_cloudButton->height() - st::mainMenuCloudSize) / 2,
|
|
|
|
width(),
|
|
|
|
st::mainMenuCloudSize,
|
|
|
|
isFill ? st::mainMenuCloudBg : st::msgServiceBg,
|
|
|
|
isFill ? st::mainMenuCloudFg : st::msgServiceFg);
|
|
|
|
}
|
|
|
|
|
2019-05-16 08:39:45 +00:00
|
|
|
// Draw Archive button.
|
|
|
|
if (!_archiveButton->isHidden()) {
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto folder = _controller->session().data().folderLoaded(
|
|
|
|
Data::Folder::kId);
|
|
|
|
if (folder) {
|
2019-05-16 08:39:45 +00:00
|
|
|
folder->paintUserpic(
|
|
|
|
p,
|
|
|
|
_archiveButton->x() + (_archiveButton->width() - st::mainMenuCloudSize) / 2,
|
|
|
|
_archiveButton->y() + (_archiveButton->height() - st::mainMenuCloudSize) / 2,
|
|
|
|
st::mainMenuCloudSize,
|
|
|
|
isFill ? st::mainMenuCloudBg : st::msgServiceBg,
|
|
|
|
isFill ? st::mainMenuCloudFg : st::msgServiceFg);
|
|
|
|
}
|
|
|
|
}
|
2016-11-11 19:51:59 +00:00
|
|
|
}
|
2016-11-17 11:03:49 +00:00
|
|
|
auto other = QRect(0, st::mainMenuCoverHeight, width(), height() - st::mainMenuCoverHeight).intersected(clip);
|
2016-11-11 19:51:59 +00:00
|
|
|
if (!other.isEmpty()) {
|
|
|
|
p.fillRect(other, st::mainMenuBg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-20 19:04:10 +00:00
|
|
|
void MainMenu::initResetScaleButton() {
|
|
|
|
if (!window() || !window()->windowHandle()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto handle = window()->windowHandle();
|
|
|
|
rpl::single(
|
|
|
|
handle->screen()
|
|
|
|
) | rpl::then(
|
2019-09-13 16:45:48 +00:00
|
|
|
base::qt_signal_producer(handle, &QWindow::screenChanged)
|
2019-04-12 13:23:16 +00:00
|
|
|
) | rpl::filter([](QScreen *screen) {
|
|
|
|
return screen != nullptr;
|
|
|
|
}) | rpl::map([](QScreen * screen) {
|
2018-10-20 19:04:10 +00:00
|
|
|
return rpl::single(
|
|
|
|
screen->availableGeometry()
|
|
|
|
) | rpl::then(
|
2018-11-02 16:34:26 +00:00
|
|
|
#ifdef OS_MAC_OLD
|
2019-09-13 16:45:48 +00:00
|
|
|
base::qt_signal_producer(screen, &QScreen::virtualGeometryChanged)
|
2018-11-02 16:34:26 +00:00
|
|
|
#else // OS_MAC_OLD
|
2019-09-13 16:45:48 +00:00
|
|
|
base::qt_signal_producer(screen, &QScreen::availableGeometryChanged)
|
2018-11-02 16:34:26 +00:00
|
|
|
#endif // OS_MAC_OLD
|
2018-10-20 19:04:10 +00:00
|
|
|
);
|
|
|
|
}) | rpl::flatten_latest(
|
|
|
|
) | rpl::map([](QRect available) {
|
|
|
|
return (available.width() >= st::windowMinWidth)
|
|
|
|
&& (available.height() >= st::windowMinHeight);
|
|
|
|
}) | rpl::distinct_until_changed(
|
|
|
|
) | rpl::start_with_next([=](bool good) {
|
|
|
|
if (good) {
|
|
|
|
_resetScaleButton.destroy();
|
|
|
|
} else {
|
|
|
|
_resetScaleButton.create(this);
|
|
|
|
_resetScaleButton->addClickHandler([] {
|
2019-09-13 10:24:06 +00:00
|
|
|
cSetConfigScale(style::kScaleDefault);
|
2018-10-20 19:04:10 +00:00
|
|
|
Local::writeSettings();
|
|
|
|
App::restart();
|
|
|
|
});
|
|
|
|
_resetScaleButton->show();
|
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
}, lifetime());
|
|
|
|
}
|
|
|
|
|
2020-07-24 05:41:51 +00:00
|
|
|
OthersUnreadState OtherAccountsUnreadStateCurrent() {
|
|
|
|
auto &app = Core::App();
|
|
|
|
const auto active = &app.activeAccount();
|
|
|
|
auto allMuted = true;
|
|
|
|
for (const auto &[index, account] : app.domain().accounts()) {
|
|
|
|
if (account.get() == active) {
|
|
|
|
continue;
|
|
|
|
} else if (const auto session = account->maybeSession()) {
|
|
|
|
if (!session->data().unreadBadgeMuted()) {
|
|
|
|
allMuted = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
.count = (app.unreadBadge() - active->session().data().unreadBadge()),
|
|
|
|
.allMuted = allMuted,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
rpl::producer<OthersUnreadState> OtherAccountsUnreadState() {
|
|
|
|
return rpl::single(
|
|
|
|
rpl::empty_value()
|
|
|
|
) | rpl::then(
|
|
|
|
Core::App().unreadBadgeChanges()
|
|
|
|
) | rpl::map(OtherAccountsUnreadStateCurrent);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
} // namespace Window
|