feat: add font picker

This commit is contained in:
MaxPlays35 2023-09-26 22:31:57 +03:00
parent b6cf5ebb19
commit eb8331c957
9 changed files with 1396 additions and 10 deletions

View file

@ -138,6 +138,8 @@ PRIVATE
ayu/ui/boxes/edit_deleted_mark.h ayu/ui/boxes/edit_deleted_mark.h
ayu/ui/boxes/edit_edited_mark.cpp ayu/ui/boxes/edit_edited_mark.cpp
ayu/ui/boxes/edit_edited_mark.h ayu/ui/boxes/edit_edited_mark.h
ayu/ui/boxes/font_selector.cpp
ayu/ui/boxes/font_selector.h
ayu/sync/ayu_sync_controller.cpp ayu/sync/ayu_sync_controller.cpp
ayu/sync/ayu_sync_controller.h ayu/sync/ayu_sync_controller.h
ayu/sync/models.h ayu/sync/models.h

View file

@ -11,6 +11,7 @@
#include "ayu/ui/ayu_lottie.h" #include "ayu/ui/ayu_lottie.h"
#include "ayu/database/ayu_database.h" #include "ayu/database/ayu_database.h"
#include "lang/lang_instance.h" #include "lang/lang_instance.h"
#include "ayu/ayu_settings.h"
namespace AyuInfra namespace AyuInfra
{ {
@ -27,18 +28,29 @@ void initLang()
CustomLangPack::currentInstance()->fetchCustomLangPack(langPackId, langPackBaseId); CustomLangPack::currentInstance()->fetchCustomLangPack(langPackId, langPackBaseId);
} }
void initLottie() { void initLottie()
{
AyuUi::setLottieImpl(std::make_shared<AyuUi::AyuLottieImpl>()); AyuUi::setLottieImpl(std::make_shared<AyuUi::AyuLottieImpl>());
} }
void initDatabase() { void initDatabase()
{
AyuDatabase::initialize(); AyuDatabase::initialize();
} }
void initFonts()
{
auto ayuSettings = AyuSettings::getInstance();
AyuFonts::setCommonFont(ayuSettings.commonFont);
AyuFonts::setMonoFont(ayuSettings.monoFont);
}
void init() void init()
{ {
initLang(); initLang();
initLottie(); initLottie();
initFonts();
initDatabase(); initDatabase();
} }

View file

@ -273,6 +273,16 @@ void AyuGramSettings::set_showGhostToggleInDrawer(bool val)
showGhostToggleInDrawer = val; showGhostToggleInDrawer = val;
} }
void AyuGramSettings::set_commonFont(QString val)
{
commonFont = val;
}
void AyuGramSettings::set_monoFont(QString val)
{
monoFont = val;
}
void AyuGramSettings::set_showPeerId(int val) void AyuGramSettings::set_showPeerId(int val)
{ {
showPeerId = val; showPeerId = val;

View file

@ -51,6 +51,8 @@ public:
editedMark = tr::lng_edited(tr::now); editedMark = tr::lng_edited(tr::now);
recentStickersCount = 20; recentStickersCount = 20;
showGhostToggleInDrawer = true; showGhostToggleInDrawer = true;
commonFont = "";
monoFont = "";
/* /*
* showPeerId = 0 means no ID shown * showPeerId = 0 means no ID shown
@ -86,6 +88,8 @@ public:
QString editedMark; QString editedMark;
int recentStickersCount; int recentStickersCount;
bool showGhostToggleInDrawer; bool showGhostToggleInDrawer;
QString commonFont;
QString monoFont;
int showPeerId; int showPeerId;
bool hideAllChatsFolder; bool hideAllChatsFolder;
bool showMessageSeconds; bool showMessageSeconds;
@ -132,6 +136,10 @@ public:
void set_showGhostToggleInDrawer(bool val); void set_showGhostToggleInDrawer(bool val);
void set_commonFont(QString val);
void set_monoFont(QString val);
void set_showPeerId(int val); void set_showPeerId(int val);
void set_showMessageSeconds(bool val); void set_showMessageSeconds(bool val);
@ -165,6 +173,8 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
editedMark, editedMark,
recentStickersCount, recentStickersCount,
showGhostToggleInDrawer, showGhostToggleInDrawer,
commonFont,
monoFont,
showPeerId, showPeerId,
showMessageSeconds, showMessageSeconds,
hideAllChatsFolder, hideAllChatsFolder,

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,73 @@
//
// Created by MaxPlays on 12/09/2023.
//
#ifndef TELEGRAM_FONT_SELECTOR_H
#define TELEGRAM_FONT_SELECTOR_H
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "lang/lang_cloud_manager.h"
#include "boxes/abstract_box.h"
#include "base/binary_guard.h"
struct LanguageId;
struct Font;
namespace Ui
{
class MultiSelect;
struct ScrollToRequest;
class VerticalLayout;
} // namespace Ui
namespace Window
{
class SessionController;
} // namespace Window
namespace AyuUi
{
class FontSelectorBox: public Ui::BoxContent
{
public:
FontSelectorBox(QWidget *, Window::SessionController *controller, Fn<void(QString font)> hook);
void setInnerFocus() override;
static base::binary_guard Show(Window::SessionController *controller, const Fn<void(QString font)> hook);
private:
QString _selectedFont;
protected:
void prepare() override;
void keyPressEvent(QKeyEvent *e) override;
private:
void setupTop(not_null<Ui::VerticalLayout *> container);
[[nodiscard]] int rowsInPage() const;
Window::SessionController *_controller = nullptr;
rpl::event_stream<bool> _translateChatTurnOff;
Fn<void()> _setInnerFocus;
Fn<Ui::ScrollToRequest(int rows)> _jump;
Fn<void(QString font)> _hook;
};
}
#endif //TELEGRAM_FONT_SELECTOR_H

View file

@ -10,6 +10,7 @@
#include "ayu/sync/ayu_sync_controller.h" #include "ayu/sync/ayu_sync_controller.h"
#include "ayu/ui/boxes/edit_deleted_mark.h" #include "ayu/ui/boxes/edit_deleted_mark.h"
#include "ayu/ui/boxes/edit_edited_mark.h" #include "ayu/ui/boxes/edit_edited_mark.h"
#include "ayu/ui/boxes/font_selector.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "lang_auto.h" #include "lang_auto.h"
@ -108,7 +109,7 @@ not_null<Ui::RpWidget *> AddInnerToggle(
[](const auto &v) [](const auto &v)
{ return v->checked(); }); { return v->checked(); });
}; };
for (const auto &innerCheck : state->innerChecks) { for (const auto &innerCheck: state->innerChecks) {
innerCheck->checkedChanges( innerCheck->checkedChanges(
) | rpl::to_empty | start_to_stream( ) | rpl::to_empty | start_to_stream(
state->anyChanges, state->anyChanges,
@ -259,7 +260,7 @@ not_null<Ui::RpWidget *> AddInnerToggle(
{ {
if (!handleLocked()) { if (!handleLocked()) {
const auto checked = !checkView->checked(); const auto checked = !checkView->checked();
for (const auto &innerCheck : state->innerChecks) { for (const auto &innerCheck: state->innerChecks) {
innerCheck->setChecked(checked, anim::type::normal); innerCheck->setChecked(checked, anim::type::normal);
} }
} }
@ -344,7 +345,8 @@ void Ayu::AddPlatformOption(
} }
} }
void Ayu::SetupGhostModeToggle(not_null<Ui::VerticalLayout *> container) { void Ayu::SetupGhostModeToggle(not_null<Ui::VerticalLayout *> container)
{
auto settings = &AyuSettings::getInstance(); auto settings = &AyuSettings::getInstance();
const auto widget = object_ptr<Ui::VerticalLayout>(this); const auto widget = object_ptr<Ui::VerticalLayout>(this);
@ -450,7 +452,7 @@ void Ayu::SetupGhostModeToggle(not_null<Ui::VerticalLayout *> container) {
object_ptr<Ui::VerticalLayout>(container)); object_ptr<Ui::VerticalLayout>(container));
const auto verticalLayout = wrap->entity(); const auto verticalLayout = wrap->entity();
auto innerChecks = std::vector<not_null<Ui::AbstractCheckView *>>(); auto innerChecks = std::vector<not_null<Ui::AbstractCheckView *>>();
for (const auto &entry : checkboxes) { for (const auto &entry: checkboxes) {
const auto c = addCheckbox(verticalLayout, entry.checkboxLabel, entry.initial); const auto c = addCheckbox(verticalLayout, entry.checkboxLabel, entry.initial);
c->checkedValue( c->checkedValue(
) | start_with_next([=](bool enabled) ) | start_with_next([=](bool enabled)
@ -478,7 +480,8 @@ void Ayu::SetupGhostModeToggle(not_null<Ui::VerticalLayout *> container) {
}, raw->lifetime()); }, raw->lifetime());
} }
void Ayu::SetupReadAfterActionToggle(not_null<Ui::VerticalLayout *> container) { void Ayu::SetupReadAfterActionToggle(not_null<Ui::VerticalLayout *> container)
{
auto settings = &AyuSettings::getInstance(); auto settings = &AyuSettings::getInstance();
const auto widget = object_ptr<Ui::VerticalLayout>(this); const auto widget = object_ptr<Ui::VerticalLayout>(this);
@ -570,7 +573,7 @@ void Ayu::SetupReadAfterActionToggle(not_null<Ui::VerticalLayout *> container) {
object_ptr<Ui::VerticalLayout>(container)); object_ptr<Ui::VerticalLayout>(container));
const auto verticalLayout = wrap->entity(); const auto verticalLayout = wrap->entity();
auto innerChecks = std::vector<not_null<Ui::AbstractCheckView *>>(); auto innerChecks = std::vector<not_null<Ui::AbstractCheckView *>>();
for (const auto &entry : checkboxes) { for (const auto &entry: checkboxes) {
const auto c = addCheckbox(verticalLayout, entry.checkboxLabel, entry.initial); const auto c = addCheckbox(verticalLayout, entry.checkboxLabel, entry.initial);
c->checkedValue( c->checkedValue(
) | start_with_next([=](bool enabled) ) | start_with_next([=](bool enabled)
@ -989,6 +992,52 @@ void Ayu::SetupExperimental(not_null<Ui::VerticalLayout *> container,
{ {
AddSubsectionTitle(container, tr::lng_settings_experimental()); AddSubsectionTitle(container, tr::lng_settings_experimental());
AddPlatformOption(controller, container, StreamerMode, rpl::producer<>()); AddPlatformOption(controller, container, StreamerMode, rpl::producer<>());
const auto commonButton = AddButtonWithLabel(
container,
rpl::single(qs("Customise main font")),
rpl::single(
AyuSettings::getInstance().commonFont.isEmpty() ? qs("Default") : AyuSettings::getInstance().commonFont
),
st::settingsButtonNoIcon);
const auto commonGuard = Ui::CreateChild<base::binary_guard>(commonButton.get());
commonButton->addClickHandler([=]
{
const auto m = commonButton->clickModifiers();
*commonGuard = AyuUi::FontSelectorBox::Show(controller, [=](QString font)
{
auto ayuSettings = &AyuSettings::getInstance();
ayuSettings->set_commonFont(std::move(font));
AyuSettings::save();
});
});
const auto monoButton = AddButtonWithLabel(
container,
rpl::single(qs("Customise mono font")),
rpl::single(
AyuSettings::getInstance().monoFont.isEmpty() ? qs("Default")
: AyuSettings::getInstance().monoFont
),
st::settingsButtonNoIcon);
const auto monoGuard = Ui::CreateChild<base::binary_guard>(monoButton.get());
monoButton->addClickHandler([=]
{
const auto m = monoButton->clickModifiers();
*monoGuard = AyuUi::FontSelectorBox::Show(controller, [=](QString font)
{
auto ayuSettings = &AyuSettings::getInstance();
ayuSettings->set_monoFont(std::move(font));
AyuSettings::save();
});
});
AddDividerText(container, rpl::single(qs("Here you can customise fonts for AyuGram")));
} }
void Ayu::SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container, void Ayu::SetupAyuGramSettings(not_null<Ui::VerticalLayout *> container,

View file

@ -24,7 +24,7 @@ extern base::options::toggle StreamerMode;
namespace Settings namespace Settings
{ {
class Ayu : public Section<Ayu> class Ayu: public Section<Ayu>
{ {
public: public:
Ayu(QWidget *parent, not_null<Window::SessionController *> controller); Ayu(QWidget *parent, not_null<Window::SessionController *> controller);

@ -1 +1 @@
Subproject commit ab84152a69c7fe03b3d3353d5a887ee23a354445 Subproject commit a95896165567af0b7d7e511c0d4807a57cc608f6