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"
|
2022-02-20 11:00:36 +00:00
|
|
|
#include "window/window_controller.h"
|
2021-08-26 15:02:21 +00:00
|
|
|
#include "ui/chat/chat_theme.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"
|
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"
|
2022-01-31 16:06:40 +00:00
|
|
|
#include "ui/wrap/vertical_layout_reorder.h"
|
2021-07-26 06:32:16 +00:00
|
|
|
#include "ui/text/format_values.h" // Ui::FormatPhone
|
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"
|
2021-10-01 10:48:52 +00:00
|
|
|
#include "dialogs/ui/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"
|
2022-04-01 11:53:23 +00:00
|
|
|
#include "settings/settings_calls.h"
|
2022-03-15 11:12:49 +00:00
|
|
|
#include "settings/settings_information.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"
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/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"
|
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"
|
2021-12-09 17:56:24 +00:00
|
|
|
#include "styles/style_menu_icons.h"
|
2016-11-11 19:51:59 +00:00
|
|
|
|
2019-09-04 07:19:15 +00:00
|
|
|
#include <QtGui/QWindow>
|
|
|
|
#include <QtGui/QScreen>
|
|
|
|
|
2022-04-28 14:29:31 +00:00
|
|
|
#include <QtGui/QGuiApplication>
|
|
|
|
#include <QtGui/QClipboard>
|
|
|
|
|
2022-02-10 11:03:07 +00:00
|
|
|
namespace Window {
|
2019-05-24 18:46:52 +00:00
|
|
|
namespace {
|
|
|
|
|
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([=] {
|
2021-12-10 12:10:14 +00:00
|
|
|
*menu = base::make_unique_q<Ui::PopupMenu>(
|
|
|
|
menuButton,
|
|
|
|
st::popupMenuWithIcons);
|
2021-01-21 15:57:12 +00:00
|
|
|
const auto showSettings = [=] {
|
|
|
|
window->showSettings(
|
2022-04-01 11:53:23 +00:00
|
|
|
Settings::Calls::Id(),
|
2021-01-21 15:57:12 +00:00
|
|
|
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),
|
2021-12-10 12:10:14 +00:00
|
|
|
showSettings,
|
|
|
|
&st::menuIconSettings);
|
2021-01-26 10:28:25 +00:00
|
|
|
if (controller->delegate()->peerListFullRowsCount() > 0) {
|
|
|
|
(*menu)->addAction(
|
|
|
|
tr::lng_call_box_clear_all(tr::now),
|
2021-12-10 12:10:14 +00:00
|
|
|
clearAll,
|
|
|
|
&st::menuIconDelete);
|
2021-01-26 10:28:25 +00:00
|
|
|
}
|
2021-01-21 15:57:12 +00:00
|
|
|
(*menu)->popup(QCursor::pos());
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
};
|
2021-06-13 07:37:52 +00:00
|
|
|
window->show(Box<PeerListBox>(std::move(controller), initBox));
|
2021-01-21 15:57:12 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 11:03:07 +00:00
|
|
|
} // namespace
|
|
|
|
|
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 {
|
2022-02-10 11:03:07 +00:00
|
|
|
return _rightSkip;
|
2020-06-22 14:33:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
2022-02-10 11:03:07 +00:00
|
|
|
void paintUnreadBadge(Painter &p);
|
2020-06-23 13:29:02 +00:00
|
|
|
|
|
|
|
void validateUnreadBadge();
|
|
|
|
[[nodiscard]] QString computeUnreadBadge() const;
|
2020-06-22 14:33:35 +00:00
|
|
|
|
2022-02-10 11:03:07 +00:00
|
|
|
int _rightSkip = 0;
|
2020-06-22 14:33:35 +00:00
|
|
|
Ui::Animations::Simple _toggledAnimation;
|
|
|
|
bool _toggled = false;
|
|
|
|
|
2020-06-23 13:29:02 +00:00
|
|
|
QString _unreadBadge;
|
|
|
|
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-23 14:55:08 +00:00
|
|
|
MainMenu::ToggleAccountsButton::ToggleAccountsButton(QWidget *parent)
|
2020-06-22 14:33:35 +00:00
|
|
|
: AbstractButton(parent) {
|
2022-03-11 05:55:21 +00:00
|
|
|
rpl::single(rpl::empty) | rpl::then(
|
2020-06-23 13:29:02 +00:00
|
|
|
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;
|
|
|
|
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);
|
2022-02-10 11:03:07 +00:00
|
|
|
p.fillPath(path, st::windowSubTextFg);
|
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
|
|
|
}
|
|
|
|
|
2022-02-10 11:03:07 +00:00
|
|
|
void MainMenu::ToggleAccountsButton::paintUnreadBadge(Painter &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;
|
|
|
|
}
|
|
|
|
|
2022-03-15 11:12:49 +00:00
|
|
|
auto st = Settings::BadgeStyle();
|
2022-02-10 11:03:07 +00:00
|
|
|
const auto right = width()
|
|
|
|
- st::mainMenuTogglePosition.x()
|
|
|
|
- st::mainMenuToggleSize * 3;
|
|
|
|
const auto top = height()
|
|
|
|
- st::mainMenuTogglePosition.y()
|
|
|
|
- st::mainMenuBadgeSize / 2;
|
|
|
|
p.setOpacity(progress);
|
|
|
|
Dialogs::Ui::PaintUnreadBadge(p, _unreadBadge, right, top, st);
|
2020-06-23 13:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::ToggleAccountsButton::validateUnreadBadge() {
|
|
|
|
const auto base = st::mainMenuTogglePosition.x()
|
|
|
|
+ 2 * st::mainMenuToggleSize;
|
|
|
|
if (_toggled) {
|
|
|
|
_rightSkip = base;
|
|
|
|
return;
|
|
|
|
} else if (!_unreadBadgeStale) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_unreadBadge = computeUnreadBadge();
|
|
|
|
|
2022-03-16 07:23:37 +00:00
|
|
|
_rightSkip = base;
|
|
|
|
if (!_unreadBadge.isEmpty()) {
|
|
|
|
const auto st = Settings::BadgeStyle();
|
|
|
|
_rightSkip += 2 * st::mainMenuToggleSize
|
|
|
|
+ Dialogs::Ui::CountUnreadBadgeSize(_unreadBadge, st).width();
|
|
|
|
}
|
2020-06-23 13:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString MainMenu::ToggleAccountsButton::computeUnreadBadge() const {
|
2020-07-24 05:41:51 +00:00
|
|
|
const auto state = OtherAccountsUnreadStateCurrent();
|
|
|
|
return state.allMuted
|
|
|
|
? QString()
|
|
|
|
: (state.count > 0)
|
2022-02-10 10:08:39 +00:00
|
|
|
? Lang::FormatCountToShort(state.count).string
|
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
|
|
|
, _scroll(this, st::defaultSolidScroll)
|
|
|
|
, _inner(_scroll->setOwnedWidget(
|
|
|
|
object_ptr<Ui::VerticalLayout>(_scroll.data())))
|
2022-02-10 11:03:07 +00:00
|
|
|
, _topShadowSkip(_inner->add(
|
|
|
|
object_ptr<Ui::FixedHeightWidget>(_inner.get(), st::lineWidth)))
|
2020-06-22 13:01:41 +00:00
|
|
|
, _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(
|
2022-02-09 13:54:16 +00:00
|
|
|
object_ptr<Ui::VerticalLayout>(_inner.get()),
|
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
|
|
|
setupUserpicButton();
|
2020-06-22 14:33:35 +00:00
|
|
|
setupAccountsToggle();
|
2020-06-23 14:55:08 +00:00
|
|
|
setupAccounts();
|
2022-02-09 14:52:20 +00:00
|
|
|
setupArchive();
|
2022-02-09 13:54:16 +00:00
|
|
|
setupMenu();
|
2019-05-16 08:39:45 +00:00
|
|
|
|
2022-02-10 11:03:07 +00:00
|
|
|
const auto shadow = Ui::CreateChild<Ui::PlainShadow>(this);
|
|
|
|
widthValue(
|
|
|
|
) | rpl::start_with_next([=](int width) {
|
|
|
|
const auto line = st::lineWidth;
|
|
|
|
shadow->setGeometry(0, st::mainMenuCoverHeight - line, width, line);
|
|
|
|
}, shadow->lifetime());
|
|
|
|
|
2017-06-29 19:09:10 +00:00
|
|
|
_nightThemeSwitch.setCallback([this] {
|
2022-02-09 13:54:16 +00:00
|
|
|
Expects(_nightThemeToggle != nullptr);
|
|
|
|
|
|
|
|
const auto nightMode = Window::Theme::IsNightMode();
|
|
|
|
if (_nightThemeToggle->toggled() != nightMode) {
|
|
|
|
Window::Theme::ToggleNightMode();
|
|
|
|
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();
|
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();
|
2021-12-26 17:49:27 +00:00
|
|
|
_version->setMarkedText(
|
|
|
|
Ui::Text::Link(
|
|
|
|
tr::lng_settings_current_version(
|
|
|
|
tr::now,
|
|
|
|
lt_version,
|
|
|
|
currentVersionText()),
|
2022-02-03 20:37:55 +00:00
|
|
|
1) // Link 1.
|
2021-12-26 17:49:27 +00:00
|
|
|
.append(QChar(' '))
|
|
|
|
.append(QChar(8211))
|
|
|
|
.append(QChar(' '))
|
2022-02-03 20:37:55 +00:00
|
|
|
.append(Ui::Text::Link(tr::lng_menu_about(tr::now), 2))); // Link 2.
|
2021-12-26 17:49:27 +00:00
|
|
|
_version->setLink(
|
|
|
|
1,
|
|
|
|
std::make_shared<UrlClickHandler>(Core::App().changelogLink()));
|
2021-06-13 07:37:52 +00:00
|
|
|
_version->setLink(
|
|
|
|
2,
|
|
|
|
std::make_shared<LambdaClickHandler>([=] {
|
|
|
|
controller->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-22 13:01:41 +00:00
|
|
|
updatePhone();
|
|
|
|
initResetScaleButton();
|
|
|
|
}
|
|
|
|
|
2022-02-09 14:52:20 +00:00
|
|
|
void MainMenu::setupArchive() {
|
|
|
|
using namespace Settings;
|
|
|
|
|
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);
|
2022-02-20 11:00:36 +00:00
|
|
|
controller->window().hideSettingsAndLayer();
|
2020-06-22 13:01:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
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
|
|
|
};
|
2022-02-09 14:52:20 +00:00
|
|
|
|
|
|
|
const auto wrap = _menu->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
|
|
|
_menu,
|
|
|
|
object_ptr<Ui::VerticalLayout>(_menu)));
|
|
|
|
const auto inner = wrap->entity();
|
|
|
|
wrap->toggle(checkArchive(), anim::type::instant);
|
|
|
|
|
|
|
|
const auto button = AddButton(
|
|
|
|
inner,
|
|
|
|
tr::lng_archived_name(),
|
|
|
|
st::mainMenuButton,
|
|
|
|
{ &st::settingsIconArchive, kIconGray });
|
|
|
|
inner->add(
|
|
|
|
object_ptr<Ui::PlainShadow>(inner),
|
|
|
|
{ 0, st::mainMenuSkip, 0, st::mainMenuSkip });
|
|
|
|
button->setAcceptBoth(true);
|
|
|
|
button->clicks(
|
2020-06-22 13:01:41 +00:00
|
|
|
) | rpl::start_with_next([=](Qt::MouseButton which) {
|
|
|
|
if (which == Qt::LeftButton) {
|
|
|
|
showArchive();
|
|
|
|
return;
|
|
|
|
} else if (which != Qt::RightButton) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-09 17:56:24 +00:00
|
|
|
_contextMenu = base::make_unique_q<Ui::PopupMenu>(
|
|
|
|
this,
|
|
|
|
st::popupMenuWithIcons);
|
2022-03-28 12:30:40 +00:00
|
|
|
const auto addAction = PeerMenuCallback([&](
|
|
|
|
PeerMenuCallback::Args a) {
|
2021-12-09 17:56:24 +00:00
|
|
|
return _contextMenu->addAction(
|
2022-03-28 12:30:40 +00:00
|
|
|
a.text,
|
|
|
|
std::move(a.handler),
|
|
|
|
a.icon);
|
|
|
|
});
|
2020-09-16 14:09:04 +00:00
|
|
|
|
|
|
|
const auto hide = [=] {
|
|
|
|
controller->session().settings().setArchiveInMainMenu(false);
|
|
|
|
controller->session().saveSettingsDelayed();
|
2022-02-20 11:00:36 +00:00
|
|
|
controller->window().hideSettingsAndLayer();
|
2020-09-16 14:09:04 +00:00
|
|
|
};
|
2021-12-09 17:56:24 +00:00
|
|
|
addAction(
|
|
|
|
tr::lng_context_archive_to_list(tr::now),
|
|
|
|
std::move(hide),
|
|
|
|
&st::menuIconFromMainMenu);
|
2020-09-16 14:09:04 +00:00
|
|
|
|
|
|
|
MenuAddMarkAsReadChatListAction(
|
2022-02-21 01:17:19 +00:00
|
|
|
controller,
|
2020-09-16 14:09:04 +00:00
|
|
|
[f = folder()] { return f->chatsList(); },
|
|
|
|
addAction);
|
|
|
|
|
2020-06-22 13:01:41 +00:00
|
|
|
_contextMenu->popup(QCursor::pos());
|
2022-02-09 14:52:20 +00:00
|
|
|
}, button->lifetime());
|
2020-06-22 13:01:41 +00:00
|
|
|
|
2022-02-10 09:57:22 +00:00
|
|
|
const auto now = folder();
|
|
|
|
auto folderValue = now
|
|
|
|
? (rpl::single(now) | rpl::type_erased())
|
|
|
|
: controller->session().data().chatsListChanges(
|
|
|
|
) | rpl::filter([](Data::Folder *folder) {
|
|
|
|
return folder && (folder->id() == Data::Folder::kId);
|
|
|
|
}) | rpl::take(1);
|
|
|
|
|
2022-03-15 11:12:49 +00:00
|
|
|
using namespace Settings;
|
2022-03-11 05:55:21 +00:00
|
|
|
AddUnreadBadge(button, rpl::single(rpl::empty) | rpl::then(std::move(
|
2022-02-10 09:57:22 +00:00
|
|
|
folderValue
|
|
|
|
) | rpl::map([=](not_null<Data::Folder*> folder) {
|
|
|
|
return folder->owner().chatsList(folder)->unreadStateChanges();
|
|
|
|
}) | rpl::flatten_latest() | rpl::to_empty) | rpl::map([=] {
|
|
|
|
const auto loaded = folder();
|
|
|
|
return UnreadBadge{
|
|
|
|
loaded ? loaded->chatListUnreadCount() : 0,
|
|
|
|
true,
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
|
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);
|
2022-02-10 09:57:22 +00:00
|
|
|
}) | rpl::start_with_next([=] {
|
2020-09-30 11:39:46 +00:00
|
|
|
const auto isArchiveVisible = checkArchive();
|
2022-02-09 14:52:20 +00:00
|
|
|
wrap->toggle(isArchiveVisible, anim::type::normal);
|
2020-09-30 11:39:46 +00:00
|
|
|
if (!isArchiveVisible) {
|
|
|
|
_contextMenu = nullptr;
|
|
|
|
}
|
2019-05-16 08:39:45 +00:00
|
|
|
update();
|
|
|
|
}, lifetime());
|
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));
|
2022-03-15 11:12:49 +00:00
|
|
|
auto events = Settings::SetupAccounts(inner, _controller);
|
2020-06-22 13:01:41 +00:00
|
|
|
inner->add(object_ptr<Ui::FixedHeightWidget>(inner, st::mainMenuSkip));
|
|
|
|
|
2022-03-15 11:12:49 +00:00
|
|
|
std::move(
|
|
|
|
events.currentAccountActivations
|
2022-03-11 05:55:21 +00:00
|
|
|
) | rpl::start_with_next([=] {
|
2022-03-15 11:12:49 +00:00
|
|
|
closeLayer();
|
|
|
|
}, inner->lifetime());
|
2020-06-22 13:01:41 +00:00
|
|
|
|
|
|
|
_accounts->toggleOn(Core::App().settings().mainMenuAccountsShownValue());
|
|
|
|
_accounts->finishAnimating();
|
|
|
|
|
|
|
|
_shadow->setDuration(0)->toggleOn(_accounts->shownValue());
|
|
|
|
}
|
|
|
|
|
2020-06-22 14:33:35 +00:00
|
|
|
void MainMenu::setupAccountsToggle() {
|
|
|
|
_toggleAccounts->show();
|
2022-04-28 14:29:31 +00:00
|
|
|
_toggleAccounts->setAcceptBoth();
|
|
|
|
_toggleAccounts->addClickHandler([=](Qt::MouseButton button) {
|
|
|
|
if (button == Qt::LeftButton) {
|
|
|
|
toggleAccounts();
|
|
|
|
} else if (button == Qt::RightButton) {
|
|
|
|
const auto menu = Ui::CreateChild<Ui::PopupMenu>(
|
|
|
|
_toggleAccounts.data());
|
|
|
|
|
|
|
|
menu->addAction(tr::lng_profile_copy_phone(tr::now), [=] {
|
|
|
|
QGuiApplication::clipboard()->setText(_phoneText);
|
|
|
|
});
|
|
|
|
menu->popup(QCursor::pos());
|
|
|
|
}
|
|
|
|
});
|
2020-06-22 14:33:35 +00:00
|
|
|
}
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
void MainMenu::parentResized() {
|
|
|
|
resize(st::mainMenuWidth, parentWidget()->height());
|
|
|
|
}
|
|
|
|
|
2022-02-09 13:54:16 +00:00
|
|
|
void MainMenu::setupMenu() {
|
|
|
|
using namespace Settings;
|
|
|
|
|
2021-02-03 01:17:03 +00:00
|
|
|
const auto controller = _controller;
|
2022-02-09 13:54:16 +00:00
|
|
|
const auto addAction = [&](
|
|
|
|
rpl::producer<QString> text,
|
|
|
|
IconDescriptor &&descriptor) {
|
|
|
|
return AddButton(
|
|
|
|
_menu,
|
|
|
|
std::move(text),
|
|
|
|
st::mainMenuButton,
|
|
|
|
std::move(descriptor));
|
|
|
|
};
|
2019-07-24 11:13:51 +00:00
|
|
|
if (!_controller->session().supportMode()) {
|
2022-02-09 13:54:16 +00:00
|
|
|
addAction(
|
|
|
|
tr::lng_create_group_title(),
|
2022-02-13 13:30:43 +00:00
|
|
|
{ &st::settingsIconGroup, kIconLightBlue }
|
2022-02-09 13:54:16 +00:00
|
|
|
)->setClickedCallback([=] {
|
2021-02-03 01:17:03 +00:00
|
|
|
controller->showNewGroup();
|
2022-02-09 13:54:16 +00:00
|
|
|
});
|
|
|
|
addAction(
|
|
|
|
tr::lng_create_channel_title(),
|
2022-02-13 13:30:43 +00:00
|
|
|
{ &st::settingsIconChannel, kIconLightOrange }
|
2022-02-09 13:54:16 +00:00
|
|
|
)->setClickedCallback([=] {
|
2021-02-03 01:17:03 +00:00
|
|
|
controller->showNewChannel();
|
2022-02-09 13:54:16 +00:00
|
|
|
});
|
|
|
|
addAction(
|
|
|
|
tr::lng_menu_contacts(),
|
2022-02-18 16:26:57 +00:00
|
|
|
{ &st::settingsIconUser, kIconRed }
|
2022-02-09 13:54:16 +00:00
|
|
|
)->setClickedCallback([=] {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller->show(PrepareContactsBox(controller));
|
2022-02-09 13:54:16 +00:00
|
|
|
});
|
|
|
|
addAction(
|
|
|
|
tr::lng_menu_calls(),
|
|
|
|
{ &st::settingsIconCalls, kIconGreen }
|
|
|
|
)->setClickedCallback([=] {
|
|
|
|
ShowCallsBox(controller);
|
|
|
|
});
|
|
|
|
addAction(
|
|
|
|
tr::lng_saved_messages(),
|
|
|
|
{ &st::settingsIconSavedMessages, kIconLightBlue }
|
|
|
|
)->setClickedCallback([=] {
|
|
|
|
controller->content()->choosePeer(
|
|
|
|
controller->session().userPeerId(),
|
|
|
|
ShowAtUnreadMsgId);
|
|
|
|
});
|
2018-10-05 17:08:29 +00:00
|
|
|
} else {
|
2022-02-09 13:54:16 +00:00
|
|
|
addAction(
|
|
|
|
tr::lng_profile_add_contact(),
|
2022-02-18 16:26:57 +00:00
|
|
|
{ &st::settingsIconUser, kIconRed }
|
2022-02-09 13:54:16 +00:00
|
|
|
)->setClickedCallback([=] {
|
2021-02-03 01:17:03 +00:00
|
|
|
controller->showAddContact();
|
2022-02-09 13:54:16 +00:00
|
|
|
});
|
|
|
|
addAction(
|
|
|
|
rpl::single(u"Fix chats order"_q),
|
2022-03-01 11:28:08 +00:00
|
|
|
{ &st::settingsIconPin, kIconGreen }
|
2022-02-09 13:54:16 +00:00
|
|
|
)->toggleOn(rpl::single(
|
|
|
|
_controller->session().settings().supportFixChatsOrder()
|
|
|
|
))->toggledChanges(
|
|
|
|
) | rpl::start_with_next([=](bool fix) {
|
|
|
|
_controller->session().settings().setSupportFixChatsOrder(fix);
|
2020-06-18 12:47:09 +00:00
|
|
|
_controller->session().saveSettings();
|
2022-02-09 13:54:16 +00:00
|
|
|
}, _menu->lifetime());
|
|
|
|
addAction(
|
|
|
|
rpl::single(u"Reload templates"_q),
|
|
|
|
{ &st::settingsIconReload, kIconLightBlue }
|
|
|
|
)->setClickedCallback([=] {
|
2019-07-24 11:13:51 +00:00
|
|
|
_controller->session().supportTemplates().reload();
|
2022-02-09 13:54:16 +00:00
|
|
|
});
|
2017-04-28 17:16:14 +00:00
|
|
|
}
|
2022-02-09 13:54:16 +00:00
|
|
|
addAction(
|
|
|
|
tr::lng_menu_settings(),
|
|
|
|
{ &st::settingsIconSettings, kIconPurple }
|
|
|
|
)->setClickedCallback([=] {
|
2021-02-03 01:58:27 +00:00
|
|
|
controller->showSettings();
|
2022-02-09 13:54:16 +00:00
|
|
|
});
|
2021-01-13 01:10:25 +00:00
|
|
|
|
2022-02-09 13:54:16 +00:00
|
|
|
_nightThemeToggle = addAction(
|
|
|
|
tr::lng_menu_night_mode(),
|
|
|
|
{ &st::settingsIconNight, kIconDarkBlue }
|
|
|
|
)->toggleOn(_nightThemeSwitches.events_starting_with(
|
|
|
|
Window::Theme::IsNightMode()
|
|
|
|
));
|
|
|
|
_nightThemeToggle->toggledChanges(
|
|
|
|
) | rpl::filter([=](bool night) {
|
|
|
|
return (night != Window::Theme::IsNightMode());
|
|
|
|
}) | rpl::start_with_next([=](bool night) {
|
2020-07-24 06:01:37 +00:00
|
|
|
if (Window::Theme::Background()->editingTheme()) {
|
2022-02-09 13:54:16 +00:00
|
|
|
_nightThemeSwitches.fire(!night);
|
2022-02-27 08:23:20 +00:00
|
|
|
controller->show(Ui::MakeInformBox(
|
|
|
|
tr::lng_theme_editor_cant_change_theme()));
|
2020-07-24 06:01:37 +00:00
|
|
|
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();
|
2022-02-09 13:54:16 +00:00
|
|
|
} else {
|
2020-07-22 12:10:17 +00:00
|
|
|
_nightThemeSwitch.callOnce(st::mainMenu.itemToggle.duration);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Window::Theme::ToggleNightModeWithConfirmation(
|
|
|
|
&_controller->window(),
|
|
|
|
toggle);
|
2022-02-09 13:54:16 +00:00
|
|
|
}, _nightThemeToggle->lifetime());
|
2021-01-13 01:10:25 +00:00
|
|
|
|
2020-07-14 16:36:55 +00:00
|
|
|
Core::App().settings().systemDarkModeValue(
|
|
|
|
) | rpl::start_with_next([=](std::optional<bool> darkMode) {
|
2022-02-09 13:54:16 +00:00
|
|
|
const auto darkModeEnabled
|
|
|
|
= Core::App().settings().systemDarkModeEnabled();
|
2020-07-14 16:36:55 +00:00
|
|
|
if (darkModeEnabled && darkMode.has_value()) {
|
2022-02-09 13:54:16 +00:00
|
|
|
_nightThemeSwitches.fire_copy(*darkMode);
|
2020-07-14 16:36:55 +00:00
|
|
|
}
|
2022-02-09 13:54:16 +00:00
|
|
|
}, _nightThemeToggle->lifetime());
|
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
|
|
|
}
|
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
void MainMenu::resizeEvent(QResizeEvent *e) {
|
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-22 13:01:41 +00:00
|
|
|
}
|
|
|
|
_toggleAccounts->setGeometry(
|
|
|
|
0,
|
|
|
|
st::mainMenuCoverNameTop,
|
|
|
|
width(),
|
|
|
|
st::mainMenuCoverHeight - st::mainMenuCoverNameTop);
|
2022-02-10 11:03:07 +00:00
|
|
|
// Allow cover shadow over the scrolled content.
|
|
|
|
const auto top = st::mainMenuCoverHeight - st::lineWidth;
|
2020-06-22 13:01:41 +00:00
|
|
|
_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,
|
2022-02-15 15:29:01 +00:00
|
|
|
st::mainMenuFooterHeightMin);
|
2020-06-22 13:01:41 +00:00
|
|
|
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() {
|
2021-07-26 06:32:16 +00:00
|
|
|
_phoneText = Ui::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();
|
2022-02-10 11:03:07 +00:00
|
|
|
const auto cover = QRect(0, 0, width(), st::mainMenuCoverHeight);
|
2019-05-17 16:54:24 +00:00
|
|
|
|
2022-02-10 11:03:07 +00:00
|
|
|
p.fillRect(clip, st::mainMenuBg);
|
|
|
|
if (cover.intersects(clip)) {
|
2020-06-23 13:29:02 +00:00
|
|
|
const auto widthText = width()
|
2022-02-09 13:54:16 +00:00
|
|
|
- st::mainMenuCoverNameLeft
|
2020-06-23 13:29:02 +00:00
|
|
|
- _toggleAccounts->rightSkip();
|
2019-05-31 17:53:00 +00:00
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
p.setFont(st::semiboldFont);
|
2022-02-10 11:03:07 +00:00
|
|
|
p.setPen(st::windowBoldFg);
|
2019-07-24 11:13:51 +00:00
|
|
|
_controller->session().user()->nameText().drawLeftElided(
|
2018-09-11 12:50:40 +00:00
|
|
|
p,
|
2022-02-09 13:54:16 +00:00
|
|
|
st::mainMenuCoverNameLeft,
|
2018-09-11 12:50:40 +00:00
|
|
|
st::mainMenuCoverNameTop,
|
2019-05-16 08:58:28 +00:00
|
|
|
widthText,
|
2018-09-11 12:50:40 +00:00
|
|
|
width());
|
2022-02-24 15:03:54 +00:00
|
|
|
p.setFont(st::mainMenuPhoneFont);
|
2022-02-10 11:03:07 +00:00
|
|
|
p.setPen(st::windowSubTextFg);
|
2022-02-09 13:54:16 +00:00
|
|
|
p.drawTextLeft(
|
|
|
|
st::mainMenuCoverStatusLeft,
|
|
|
|
st::mainMenuCoverStatusTop,
|
|
|
|
width(),
|
|
|
|
_phoneText);
|
2016-11-11 19:51:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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(
|
2019-09-13 16:45:48 +00:00
|
|
|
base::qt_signal_producer(screen, &QScreen::availableGeometryChanged)
|
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();
|
2022-01-27 12:48:51 +00:00
|
|
|
Core::Restart();
|
2018-10-20 19:04:10 +00:00
|
|
|
});
|
|
|
|
_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() {
|
2022-03-11 05:55:21 +00:00
|
|
|
return rpl::single(rpl::empty) | rpl::then(
|
2020-07-24 05:41:51 +00:00
|
|
|
Core::App().unreadBadgeChanges()
|
|
|
|
) | rpl::map(OtherAccountsUnreadStateCurrent);
|
|
|
|
}
|
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
} // namespace Window
|