mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Show a new "Battery and Animations" settings item.
This commit is contained in:
@@ -81,6 +81,7 @@ settingsIconFolders: icon {{ "settings/folders", settingsIconFg }};
|
||||
settingsIconGeneral: icon {{ "settings/advanced", settingsIconFg }};
|
||||
settingsIconLock: icon {{ "settings/lock", settingsIconFg }};
|
||||
settingsIconLanguage: icon {{ "settings/language", settingsIconFg }};
|
||||
settingsIconBattery: icon {{ "settings/battery", settingsIconFg }};
|
||||
settingsIconInterfaceScale: icon {{ "settings/interface_scale", settingsIconFg }};
|
||||
settingsIconFaq: icon {{ "settings/faq", settingsIconFg }};
|
||||
settingsIconCalls: icon {{ "settings/calls", settingsIconFg }};
|
||||
@@ -526,3 +527,13 @@ requestPeerRestriction: FlatLabel(defaultFlatLabel) {
|
||||
lineHeight: 22px;
|
||||
}
|
||||
}
|
||||
|
||||
powerSavingButton: SettingsButton(settingsButton) {
|
||||
style: boxTextStyle;
|
||||
padding: margins(57px, 8px, 22px, 8px);
|
||||
iconLeft: 20px;
|
||||
}
|
||||
powerSavingButtonNoIcon: SettingsButton(powerSavingButton) {
|
||||
padding: margins(22px, 8px, 22px, 8px);
|
||||
}
|
||||
powerSavingSubtitlePadding: margins(0px, 4px, 0px, -2px);
|
||||
|
@@ -664,7 +664,7 @@ void SetupAnimations(
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
AddButton(
|
||||
container,
|
||||
tr::lng_settings_power_title(),
|
||||
tr::lng_settings_power_menu(),
|
||||
st::settingsButtonNoIcon
|
||||
)->setClickedCallback([=] {
|
||||
window->show(Box(PowerSavingBox));
|
||||
|
@@ -60,11 +60,12 @@ base::options::toggle OptionMonoSettingsIcons({
|
||||
const char kOptionMonoSettingsIcons[] = "mono-settings-icons";
|
||||
|
||||
Icon::Icon(IconDescriptor descriptor) : _icon(descriptor.icon) {
|
||||
const auto background = [&] {
|
||||
if (OptionMonoSettingsIcons.value()) {
|
||||
const auto background = [&]() -> const style::color* {
|
||||
if (descriptor.type == IconType::Simple) {
|
||||
return nullptr;
|
||||
} else if (OptionMonoSettingsIcons.value()) {
|
||||
return &st::transparent;
|
||||
}
|
||||
if (descriptor.color > 0) {
|
||||
} else if (descriptor.color > 0) {
|
||||
const auto list = std::array{
|
||||
&st::settingsIconBg1,
|
||||
&st::settingsIconBg2,
|
||||
|
@@ -141,6 +141,7 @@ inline constexpr auto kIconGray = 9;
|
||||
enum class IconType {
|
||||
Rounded,
|
||||
Round,
|
||||
Simple,
|
||||
};
|
||||
|
||||
struct IconDescriptor {
|
||||
|
@@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "settings/settings_advanced.h"
|
||||
#include "settings/settings_folders.h"
|
||||
#include "settings/settings_calls.h"
|
||||
#include "settings/settings_power_saving.h"
|
||||
#include "settings/settings_premium.h"
|
||||
#include "settings/settings_scale_preview.h"
|
||||
#include "boxes/language_box.h"
|
||||
@@ -257,6 +258,19 @@ void Cover::refreshUsernameGeometry(int newWidth) {
|
||||
|
||||
} // namespace
|
||||
|
||||
void SetupPowerSavingButton(
|
||||
not_null<Window::Controller*> window,
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
const auto button = AddButton(
|
||||
container,
|
||||
tr::lng_settings_power_menu(),
|
||||
st::settingsButton,
|
||||
{ &st::settingsIconBattery, kIconDarkOrange });
|
||||
button->setClickedCallback([=] {
|
||||
window->show(Box(PowerSavingBox));
|
||||
});
|
||||
}
|
||||
|
||||
void SetupLanguageButton(
|
||||
not_null<Window::Controller*> window,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
@@ -270,7 +284,7 @@ void SetupLanguageButton(
|
||||
Lang::GetInstance().idChanges()
|
||||
) | rpl::map([] { return Lang::GetInstance().nativeName(); }),
|
||||
icon ? st::settingsButton : st::settingsButtonNoIcon,
|
||||
{ icon ? &st::settingsIconLanguage : nullptr, kIconDarkOrange });
|
||||
{ icon ? &st::settingsIconLanguage : nullptr, kIconLightBlue });
|
||||
const auto guard = Ui::CreateChild<base::binary_guard>(button.get());
|
||||
button->addClickHandler([=] {
|
||||
const auto m = button->clickModifiers();
|
||||
@@ -381,6 +395,7 @@ void SetupSections(
|
||||
Calls::Id(),
|
||||
{ &st::settingsIconCalls, kIconGreen });
|
||||
|
||||
SetupPowerSavingButton(&controller->window(), container);
|
||||
SetupLanguageButton(&controller->window(), container);
|
||||
|
||||
if (controller->session().premiumPossible()) {
|
||||
|
@@ -10,13 +10,31 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "boxes/peers/edit_peer_permissions_box.h"
|
||||
#include "core/application.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "settings/settings_common.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/power_saving.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_settings.h"
|
||||
|
||||
namespace Settings {
|
||||
|
||||
void PowerSavingBox(not_null<Ui::GenericBox*> box) {
|
||||
box->setStyle(st::layerBox);
|
||||
box->setTitle(tr::lng_settings_power_title());
|
||||
box->setWidth(st::boxWideWidth);
|
||||
|
||||
const auto container = box->verticalLayout();
|
||||
|
||||
// Force top shadow visibility.
|
||||
box->setPinnedToTopContent(
|
||||
object_ptr<Ui::FixedHeightWidget>(box, st::lineWidth));
|
||||
|
||||
AddSubsectionTitle(
|
||||
container,
|
||||
tr::lng_settings_power_subtitle(),
|
||||
st::powerSavingSubtitlePadding);
|
||||
|
||||
auto [checkboxes, getResult, changes] = CreateEditPowerSaving(
|
||||
box,
|
||||
@@ -24,6 +42,22 @@ void PowerSavingBox(not_null<Ui::GenericBox*> box) {
|
||||
|
||||
box->addRow(std::move(checkboxes), {});
|
||||
|
||||
auto automatic = (Ui::SettingsButton*)nullptr;
|
||||
const auto hasBattery = true;
|
||||
const auto automaticEnabled = true;
|
||||
if (hasBattery) {
|
||||
AddSkip(container);
|
||||
AddDivider(container);
|
||||
AddSkip(container);
|
||||
AddButton(
|
||||
container,
|
||||
tr::lng_settings_power_auto(),
|
||||
st::powerSavingButtonNoIcon
|
||||
)->toggleOn(rpl::single(automaticEnabled));
|
||||
AddSkip(container);
|
||||
AddDividerText(container, tr::lng_settings_power_auto_about());
|
||||
}
|
||||
|
||||
box->addButton(tr::lng_settings_save(), [=, collect = getResult] {
|
||||
Set(PowerSaving::kAll & ~collect());
|
||||
Core::App().saveSettingsDelayed();
|
||||
@@ -32,35 +66,56 @@ void PowerSavingBox(not_null<Ui::GenericBox*> box) {
|
||||
box->addButton(tr::lng_cancel(), [=] { box->closeBox(); });
|
||||
}
|
||||
|
||||
std::vector<NestedPowerSavingLabels> PowerSavingLabelsList() {
|
||||
EditFlagsDescriptor<PowerSaving::Flags> PowerSavingLabels() {
|
||||
using namespace PowerSaving;
|
||||
using Label = PowerSavingLabel;
|
||||
using Label = EditFlagsLabel<Flags>;
|
||||
|
||||
auto stickers = std::vector<Label>{
|
||||
{ kStickersPanel, tr::lng_settings_power_stickers_panel(tr::now) },
|
||||
{
|
||||
kStickersPanel,
|
||||
tr::lng_settings_power_stickers_panel(tr::now),
|
||||
&st::menuIconStickers,
|
||||
},
|
||||
{ kStickersChat, tr::lng_settings_power_stickers_chat(tr::now) },
|
||||
};
|
||||
auto emoji = std::vector<Label>{
|
||||
{ kEmojiPanel, tr::lng_settings_power_emoji_panel(tr::now) },
|
||||
{
|
||||
kEmojiPanel,
|
||||
tr::lng_settings_power_emoji_panel(tr::now),
|
||||
&st::menuIconEmoji,
|
||||
},
|
||||
{ kEmojiReactions, tr::lng_settings_power_emoji_reactions(tr::now) },
|
||||
{ kEmojiChat, tr::lng_settings_power_emoji_chat(tr::now) },
|
||||
};
|
||||
auto chat = std::vector<Label>{
|
||||
{ kChatBackground, tr::lng_settings_power_chat_background(tr::now) },
|
||||
{
|
||||
kChatBackground,
|
||||
tr::lng_settings_power_chat_background(tr::now),
|
||||
&st::menuIconChatBubble,
|
||||
},
|
||||
{ kChatSpoiler, tr::lng_settings_power_chat_spoiler(tr::now) },
|
||||
};
|
||||
auto calls = std::vector<Label>{
|
||||
{ kCalls, tr::lng_settings_power_calls(tr::now) },
|
||||
{
|
||||
kCalls,
|
||||
tr::lng_settings_power_calls(tr::now),
|
||||
&st::menuIconPhone,
|
||||
},
|
||||
};
|
||||
auto animations = std::vector<Label>{
|
||||
{ kAnimations, tr::lng_settings_power_ui(tr::now) },
|
||||
{
|
||||
kAnimations,
|
||||
tr::lng_settings_power_ui(tr::now),
|
||||
&st::menuIconStartStream,
|
||||
},
|
||||
};
|
||||
return {
|
||||
return { .labels = {
|
||||
{ tr::lng_settings_power_stickers(), std::move(stickers) },
|
||||
{ tr::lng_settings_power_emoji(), std::move(emoji) },
|
||||
{ tr::lng_settings_power_chat(), std::move(chat) },
|
||||
{ std::nullopt, std::move(calls) },
|
||||
{ std::nullopt, std::move(animations) },
|
||||
};
|
||||
{ std::nullopt, std::move(animations), },
|
||||
}, .st = &st::powerSavingButton };
|
||||
}
|
||||
|
||||
} // namespace Settings
|
||||
|
@@ -7,8 +7,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "base/flags.h"
|
||||
|
||||
template <typename Flags>
|
||||
struct EditFlagsDescriptor;
|
||||
|
||||
namespace PowerSaving {
|
||||
enum Flag : uint32;
|
||||
using Flags = base::flags<Flag>;
|
||||
} // namespace PowerSaving
|
||||
|
||||
namespace Ui {
|
||||
@@ -19,16 +25,6 @@ namespace Settings {
|
||||
|
||||
void PowerSavingBox(not_null<Ui::GenericBox*> box);
|
||||
|
||||
struct PowerSavingLabel {
|
||||
PowerSaving::Flag flags;
|
||||
QString label;
|
||||
};
|
||||
|
||||
struct NestedPowerSavingLabels {
|
||||
std::optional<rpl::producer<QString>> nestedLabel;
|
||||
std::vector<PowerSavingLabel> restrictionLabels;
|
||||
};
|
||||
|
||||
[[nodiscard]] std::vector<NestedPowerSavingLabels> PowerSavingLabelsList();
|
||||
[[nodiscard]] EditFlagsDescriptor<PowerSaving::Flags> PowerSavingLabels();
|
||||
|
||||
} // namespace PowerSaving
|
||||
|
Reference in New Issue
Block a user