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"
|
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"
|
2016-11-11 19:51:59 +00:00
|
|
|
#include "ui/widgets/menu.h"
|
2019-05-16 08:39:45 +00:00
|
|
|
#include "ui/widgets/popup_menu.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"
|
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"
|
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"
|
2017-05-07 09:00:49 +00:00
|
|
|
#include "observer_peer.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.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"
|
2017-04-11 20:03:34 +00:00
|
|
|
#include "mainwidget.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
|
|
|
#include "app.h"
|
2018-10-20 19:04:10 +00:00
|
|
|
#include "styles/style_window.h"
|
|
|
|
#include "styles/style_dialogs.h"
|
|
|
|
#include "styles/style_settings.h"
|
2019-01-11 09:04:28 +00:00
|
|
|
#include "styles/style_boxes.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;
|
|
|
|
|
|
|
|
float64 IntensityOfColor(QColor color) {
|
|
|
|
return (0.299 * color.red()
|
|
|
|
+ 0.587 * color.green()
|
|
|
|
+ 0.114 * color.blue()) / 255.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsShadowShown(const QImage &img, const QRect r, float64 intensityText) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
class MainMenu::ResetScaleButton : public Ui::AbstractButton {
|
|
|
|
public:
|
|
|
|
ResetScaleButton(QWidget *parent);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
static constexpr auto kText = "100%";
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
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)
|
2016-11-16 10:44:06 +00:00
|
|
|
, _menu(this, st::mainMenu)
|
2016-12-23 13:21:01 +00:00
|
|
|
, _telegram(this, st::mainMenuTelegramLabel)
|
|
|
|
, _version(this, st::mainMenuVersionLabel) {
|
2016-11-11 19:51:59 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
2016-11-16 10:44:06 +00:00
|
|
|
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto showSelfChat = [=] {
|
2020-06-10 18:08:17 +00:00
|
|
|
controller->content()->choosePeer(
|
2019-07-24 11:13:51 +00:00
|
|
|
_controller->session().userPeerId(),
|
|
|
|
ShowAtUnreadMsgId);
|
2018-09-11 12:50:40 +00:00
|
|
|
};
|
2019-05-16 08:39:45 +00:00
|
|
|
const auto showArchive = [=] {
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto folder = _controller->session().data().folderLoaded(
|
|
|
|
Data::Folder::kId);
|
|
|
|
if (folder) {
|
2020-06-10 18:08:17 +00:00
|
|
|
controller->openFolder(folder);
|
2019-05-16 08:39:45 +00:00
|
|
|
Ui::hideSettingsAndLayer();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const auto checkArchive = [=] {
|
2019-07-24 11:13:51 +00:00
|
|
|
const auto folder = _controller->session().data().folderLoaded(
|
|
|
|
Data::Folder::kId);
|
2019-05-16 08:39:45 +00:00
|
|
|
return folder
|
|
|
|
&& !folder->chatsList()->empty()
|
|
|
|
&& _controller->session().settings().archiveInMainMenu();
|
|
|
|
};
|
2018-09-11 12:50:40 +00:00
|
|
|
_userpicButton.create(
|
|
|
|
this,
|
|
|
|
_controller,
|
2019-07-24 11:13:51 +00:00
|
|
|
_controller->session().user(),
|
2018-09-11 12:50:40 +00:00
|
|
|
Ui::UserpicButton::Role::Custom,
|
|
|
|
st::mainMenuUserpic);
|
|
|
|
_userpicButton->setClickedCallback(showSelfChat);
|
|
|
|
_userpicButton->show();
|
|
|
|
_cloudButton.create(this, st::mainMenuCloudButton);
|
|
|
|
_cloudButton->setClickedCallback(showSelfChat);
|
|
|
|
_cloudButton->show();
|
2016-11-16 10:44:06 +00:00
|
|
|
|
2019-05-16 08:39:45 +00:00
|
|
|
_archiveButton.create(this, st::mainMenuCloudButton);
|
|
|
|
_archiveButton->setHidden(!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);
|
|
|
|
_contextMenu->addAction(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_context_archive_to_list(tr::now), [=] {
|
2019-05-16 08:39:45 +00:00
|
|
|
_controller->session().settings().setArchiveInMainMenu(false);
|
|
|
|
_controller->session().saveSettingsDelayed();
|
|
|
|
Ui::hideSettingsAndLayer();
|
|
|
|
});
|
|
|
|
_contextMenu->popup(QCursor::pos());
|
|
|
|
}, _archiveButton->lifetime());
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
parentResized();
|
2016-11-11 19:51:59 +00:00
|
|
|
_menu->setTriggeredCallback([](QAction *action, int actionTop, Ui::Menu::TriggeredSource source) {
|
|
|
|
emit action->triggered();
|
|
|
|
});
|
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)));
|
2017-12-18 09:07:18 +00:00
|
|
|
_version->setLink(1, std::make_shared<UrlClickHandler>(qsl("https://desktop.telegram.org/changelog")));
|
|
|
|
_version->setLink(2, std::make_shared<LambdaClickHandler>([] { Ui::show(Box<AboutBox>()); }));
|
2017-04-28 17:16:14 +00:00
|
|
|
|
2019-07-24 11:13:51 +00:00
|
|
|
subscribe(_controller->session().downloaderTaskFinished(), [=] { update(); });
|
2017-04-28 17:16:14 +00:00
|
|
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(Notify::PeerUpdate::Flag::UserPhoneChanged, [this](const Notify::PeerUpdate &update) {
|
|
|
|
if (update.peer->isSelf()) {
|
|
|
|
updatePhone();
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
subscribe(Global::RefPhoneCallsEnabledChanged(), [this] { refreshMenu(); });
|
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) {
|
|
|
|
refreshMenu();
|
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
|
|
|
}
|
|
|
|
});
|
2019-07-24 11:13:51 +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) {
|
|
|
|
_archiveButton->setHidden(!checkArchive());
|
|
|
|
update();
|
|
|
|
}, lifetime());
|
2017-04-28 17:16:14 +00:00
|
|
|
updatePhone();
|
2018-10-20 19:04:10 +00:00
|
|
|
initResetScaleButton();
|
2017-04-28 17:16:14 +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();
|
2019-07-24 11:13:51 +00:00
|
|
|
if (!_controller->session().supportMode()) {
|
2019-07-25 18:55:11 +00:00
|
|
|
const auto controller = _controller;
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_create_group_title(tr::now), [] {
|
2018-10-05 17:08:29 +00:00
|
|
|
App::wnd()->onShowNewGroup();
|
|
|
|
}, &st::mainMenuNewGroup, &st::mainMenuNewGroupOver);
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_create_channel_title(tr::now), [] {
|
2018-10-05 17:08:29 +00:00
|
|
|
App::wnd()->onShowNewChannel();
|
|
|
|
}, &st::mainMenuNewChannel, &st::mainMenuNewChannelOver);
|
2019-07-25 18:55:11 +00:00
|
|
|
_menu->addAction(tr::lng_menu_contacts(tr::now), [=] {
|
|
|
|
Ui::show(Box<PeerListBox>(std::make_unique<ContactsBoxController>(controller), [](not_null<PeerListBox*> box) {
|
2019-06-18 16:53:27 +00:00
|
|
|
box->addButton(tr::lng_close(), [box] { box->closeBox(); });
|
|
|
|
box->addLeftButton(tr::lng_profile_add_contact(), [] { App::wnd()->onShowAddContact(); });
|
2017-06-13 21:08:47 +00:00
|
|
|
}));
|
2018-10-05 17:08:29 +00:00
|
|
|
}, &st::mainMenuContacts, &st::mainMenuContactsOver);
|
|
|
|
if (Global::PhoneCallsEnabled()) {
|
2019-07-25 18:55:11 +00:00
|
|
|
_menu->addAction(tr::lng_menu_calls(tr::now), [=] {
|
|
|
|
Ui::show(Box<PeerListBox>(std::make_unique<Calls::BoxController>(controller), [](not_null<PeerListBox*> box) {
|
2019-06-18 16:53:27 +00:00
|
|
|
box->addButton(tr::lng_close(), [=] {
|
2019-01-11 09:04:28 +00:00
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
box->addTopButton(st::callSettingsButton, [=] {
|
2019-06-06 10:21:40 +00:00
|
|
|
App::wnd()->sessionController()->showSettings(
|
2019-01-11 09:04:28 +00:00
|
|
|
Settings::Type::Calls,
|
|
|
|
Window::SectionShow(anim::type::instant));
|
|
|
|
});
|
2018-10-05 17:08:29 +00:00
|
|
|
}));
|
|
|
|
}, &st::mainMenuCalls, &st::mainMenuCallsOver);
|
|
|
|
}
|
|
|
|
} else {
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_profile_add_contact(tr::now), [] {
|
2018-10-05 17:08:29 +00:00
|
|
|
App::wnd()->onShowAddContact();
|
|
|
|
}, &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-09 16:57:05 +00:00
|
|
|
_controller->session().local().writeSettings();
|
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
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
_menu->addAction(tr::lng_menu_settings(tr::now), [] {
|
2016-11-11 19:51:59 +00:00
|
|
|
App::wnd()->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>>();
|
2019-06-19 15:09:03 +00:00
|
|
|
auto action = _menu->addAction(tr::lng_menu_night_mode(tr::now), [=] {
|
2018-07-19 14:58:40 +00:00
|
|
|
if (auto action = *_nightThemeAction) {
|
|
|
|
action->setChecked(!action->isChecked());
|
|
|
|
_nightThemeSwitch.callOnce(st::mainMenu.itemToggle.duration);
|
|
|
|
}
|
|
|
|
}, &st::mainMenuNightMode, &st::mainMenuNightModeOver);
|
|
|
|
*_nightThemeAction = action;
|
|
|
|
action->setCheckable(true);
|
|
|
|
action->setChecked(Window::Theme::IsNightMode());
|
|
|
|
_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());
|
2016-11-16 10:44:06 +00:00
|
|
|
updateControlsGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainMenu::updateControlsGeometry() {
|
|
|
|
if (_userpicButton) {
|
|
|
|
_userpicButton->moveToLeft(st::mainMenuUserpicLeft, st::mainMenuUserpicTop);
|
|
|
|
}
|
2017-04-05 09:21:38 +00:00
|
|
|
if (_cloudButton) {
|
2019-05-16 08:39:45 +00:00
|
|
|
const auto offset = st::mainMenuCloudSize / 4;
|
|
|
|
const auto y = st::mainMenuCoverHeight
|
|
|
|
- _cloudButton->height()
|
|
|
|
- offset;
|
|
|
|
_cloudButton->moveToRight(offset, y);
|
|
|
|
if (_archiveButton) {
|
|
|
|
_archiveButton->moveToRight(
|
|
|
|
offset,
|
|
|
|
y - _cloudButton->height());
|
|
|
|
}
|
2017-04-05 09:21:38 +00:00
|
|
|
}
|
2018-10-20 19:04:10 +00:00
|
|
|
if (_resetScaleButton) {
|
|
|
|
_resetScaleButton->moveToRight(0, 0);
|
|
|
|
}
|
2017-06-29 19:09:10 +00:00
|
|
|
_menu->moveToLeft(0, st::mainMenuCoverHeight + st::mainMenuSkip);
|
2016-11-11 19:51:59 +00:00
|
|
|
_telegram->moveToLeft(st::mainMenuFooterLeft, height() - st::mainMenuTelegramBottom - _telegram->height());
|
|
|
|
_version->moveToLeft(st::mainMenuFooterLeft, height() - st::mainMenuVersionBottom - _version->height());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-05-31 17:53:00 +00:00
|
|
|
const auto background = Window::Theme::Background();
|
|
|
|
const auto isFill = background->tile()
|
|
|
|
|| background->colorForFill().has_value()
|
|
|
|
|| background->isMonoColorImage()
|
|
|
|
|| background->paper().isPattern()
|
|
|
|
|| Data::IsLegacy1DefaultWallPaper(background->paper());
|
|
|
|
|
|
|
|
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()) {
|
2019-05-16 08:58:28 +00:00
|
|
|
const auto widthText = _cloudButton
|
|
|
|
? _cloudButton->x() - st::mainMenuCloudSize
|
|
|
|
: width() - 2 * st::mainMenuCoverTextLeft;
|
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);
|
2017-04-05 09:21:38 +00:00
|
|
|
if (_cloudButton) {
|
2017-12-05 16:48:03 +00:00
|
|
|
Ui::EmptyUserpic::PaintSavedMessages(
|
|
|
|
p,
|
|
|
|
_cloudButton->x() + (_cloudButton->width() - st::mainMenuCloudSize) / 2,
|
2017-04-05 09:21:38 +00:00
|
|
|
_cloudButton->y() + (_cloudButton->height() - st::mainMenuCloudSize) / 2,
|
2017-12-05 16:48:03 +00:00
|
|
|
width(),
|
|
|
|
st::mainMenuCloudSize,
|
2019-05-31 17:53:00 +00:00
|
|
|
isFill ? st::mainMenuCloudBg : st::msgServiceBg,
|
|
|
|
isFill ? st::mainMenuCloudFg : st::msgServiceFg);
|
2017-04-05 09:21:38 +00:00
|
|
|
}
|
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());
|
|
|
|
}
|
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
} // namespace Window
|