From c0e20dacf17750d6bdf700557baa64e504a32c96 Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Mon, 14 Oct 2019 02:17:53 +0300 Subject: [PATCH] Added font selection box --- Telegram/Resources/langs/lang.strings | 10 +++ Telegram/Resources/langs/rewrites/ru.json | 10 ++- Telegram/SourceFiles/boxes/boxes.style | 7 ++ Telegram/SourceFiles/boxes/fonts_box.cpp | 85 +++++++++++++++++++ Telegram/SourceFiles/boxes/fonts_box.h | 38 +++++++++ .../SourceFiles/settings/settings_kotato.cpp | 12 ++- .../SourceFiles/settings/settings_kotato.h | 2 + Telegram/gyp/telegram/sources.txt | 2 + 8 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 Telegram/SourceFiles/boxes/fonts_box.cpp create mode 100644 Telegram/SourceFiles/boxes/fonts_box.h diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 9b845e9a0..9b16f53d3 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2258,5 +2258,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "ktg_settings_sticker_height" = "Sticker height: {pixels}px"; "ktg_settings_emoji_outline" = "Big emoji outline"; "ktg_settings_always_show_scheduled" = "Always show scheduled"; +"ktg_settings_fonts" = "Change application fonts"; + +"ktg_fonts_title" = "Fonts"; +"ktg_fonts_reset" = "Reset"; +"ktg_fonts_about" = "If you want to use \"Bold\" font for your semibold, do not put \"Bold\" in font name, use \"Make semibold bold\" option.\n\nYou will need to restart app to apply and see changes."; + +"ktg_fonts_main" = "Main font"; +"ktg_fonts_semibold" = "Semibold font"; +"ktg_fonts_semibold_is_bold" = "Make semibold bold"; +"ktg_fonts_monospaced" = "Monospaced font"; // Keys finished diff --git a/Telegram/Resources/langs/rewrites/ru.json b/Telegram/Resources/langs/rewrites/ru.json index 1e491f531..253e74ccd 100644 --- a/Telegram/Resources/langs/rewrites/ru.json +++ b/Telegram/Resources/langs/rewrites/ru.json @@ -31,5 +31,13 @@ "ktg_settings_chats": "Чаты", "ktg_settings_sticker_height": "Высота стикеров: {pixels} пикс.", "ktg_settings_emoji_outline": "Обводка у больших эмодзи", - "ktg_settings_always_show_scheduled": "Всегда показывать отложенные" + "ktg_settings_always_show_scheduled": "Всегда показывать отложенные", + "ktg_settings_fonts": "Изменить шрифты приложения", + "ktg_fonts_title": "Шрифты", + "ktg_fonts_reset": "Сброс", + "ktg_fonts_about": "Если вы хотите использовать жирное начертание для полужирного шрифта, не пишите «Bold» в названии, используйте настройку «Сделать полужирный жирным».\n\nДля применения и просмотра изменений требуется перезапуск.", + "ktg_fonts_main": "Основной шрифт", + "ktg_fonts_semibold": "Полужирный шрифт", + "ktg_fonts_semibold_is_bold": "Сделать полужирный жирным", + "ktg_fonts_monospaced": "Моноширинный шрифт" } diff --git a/Telegram/SourceFiles/boxes/boxes.style b/Telegram/SourceFiles/boxes/boxes.style index 8cbb512bc..3c49d234d 100644 --- a/Telegram/SourceFiles/boxes/boxes.style +++ b/Telegram/SourceFiles/boxes/boxes.style @@ -1030,3 +1030,10 @@ customBadgeField: InputField(defaultInputField) { heightMin: 32px; } + +fontsBoxTextStyle: TextStyle(defaultTextStyle) { + font: font(13px); + linkFont: font(13px); + linkFontOver: font(13px underline); +} + diff --git a/Telegram/SourceFiles/boxes/fonts_box.cpp b/Telegram/SourceFiles/boxes/fonts_box.cpp new file mode 100644 index 000000000..e56bce7c5 --- /dev/null +++ b/Telegram/SourceFiles/boxes/fonts_box.cpp @@ -0,0 +1,85 @@ +/* +This file is part of Kotatogram Desktop, +the unofficial app based on Telegram Desktop. + +For license and copyright information please follow this link: +https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL +*/ +#include "boxes/fonts_box.h" + +#include "ui/widgets/checkbox.h" +#include "ui/widgets/buttons.h" +#include "ui/widgets/input_fields.h" +#include "styles/style_boxes.h" +#include "lang/lang_keys.h" + +FontsBox::FontsBox(QWidget* parent) +: _mainFontName(this, st::defaultInputField, tr::ktg_fonts_main()) +, _semiboldFontName(this, st::defaultInputField, tr::ktg_fonts_semibold()) +, _semiboldIsBold(this, tr::ktg_fonts_semibold_is_bold(tr::now), cSemiboldFontIsBold()) +, _monospacedFontName(this, st::defaultInputField, tr::ktg_fonts_monospaced()) +, _about(st::boxWidth - st::boxPadding.left() * 1.5) +{ +} + +void FontsBox::prepare() { + setTitle(tr::ktg_fonts_title()); + + addButton(tr::lng_settings_save(), [=] { save(); }); + addButton(tr::lng_cancel(), [=] { closeBox(); }); + + addLeftButton(tr::ktg_fonts_reset(), [=] { resetToDefault(); }); + + if (!cMainFont().isEmpty()) { + _mainFontName->setText(cMainFont()); + } + + if (!cSemiboldFont().isEmpty()) { + _semiboldFontName->setText(cSemiboldFont()); + } + + if (!cMonospaceFont().isEmpty()) { + _monospacedFontName->setText(cMonospaceFont()); + } + + _about.setText(st::fontsBoxTextStyle, tr::ktg_fonts_about(tr::now)); + _aboutHeight = _about.countHeight(st::boxWidth - st::boxPadding.left() * 1.5); + + setDimensions(st::boxWidth, _mainFontName->height() + _semiboldFontName->height() + _semiboldIsBold->height() + _monospacedFontName->height() + _aboutHeight + st::boxLittleSkip * 2); +} + + +void FontsBox::paintEvent(QPaintEvent *e) { + BoxContent::paintEvent(e); + + Painter p(this); + int32 w = st::boxWidth - st::boxPadding.left() * 1.5; + int32 abouty = _mainFontName->height() + _semiboldFontName->height() + _semiboldIsBold->height() + _monospacedFontName->height() + st::boxLittleSkip * 2; + p.setPen(st::windowSubTextFg); + _about.drawLeft(p, st::boxPadding.left(), abouty, w, width()); + +} + +void FontsBox::resizeEvent(QResizeEvent *e) { + BoxContent::resizeEvent(e); + + int32 w = st::boxWidth - st::boxPadding.left() - st::boxPadding.right(); + _mainFontName->resize(w, _mainFontName->height()); + _mainFontName->moveToLeft(st::boxPadding.left(), 0); + _semiboldFontName->resize(w, _semiboldFontName->height()); + _semiboldFontName->moveToLeft(st::boxPadding.left(), _mainFontName->y() + _mainFontName->height()); + _semiboldIsBold->resize(w, _semiboldIsBold->height()); + _semiboldIsBold->moveToLeft(st::boxPadding.left(), _semiboldFontName->y() + _semiboldFontName->height() + st::boxLittleSkip); + _monospacedFontName->resize(w, _monospacedFontName->height()); + _monospacedFontName->moveToLeft(st::boxPadding.left(), _semiboldIsBold->y() + _semiboldIsBold->height()); +} + +void FontsBox::setInnerFocus() { + _mainFontName->setFocusFast(); +} + +void FontsBox::save() { +} + +void FontsBox::resetToDefault() { +} \ No newline at end of file diff --git a/Telegram/SourceFiles/boxes/fonts_box.h b/Telegram/SourceFiles/boxes/fonts_box.h new file mode 100644 index 000000000..22d6111e2 --- /dev/null +++ b/Telegram/SourceFiles/boxes/fonts_box.h @@ -0,0 +1,38 @@ +/* +This file is part of Kotatogram Desktop, +the unofficial app based on Telegram Desktop. + +For license and copyright information please follow this link: +https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL +*/ +#pragma once + +#include "boxes/abstract_box.h" + +namespace Ui { +class Checkbox; +class InputField; +} // namespace Ui + +class FontsBox : public BoxContent { +public: + FontsBox(QWidget* parent); + +protected: + void prepare() override; + void setInnerFocus() override; + + void paintEvent(QPaintEvent *e) override; + void resizeEvent(QResizeEvent *e) override; +private: + void save(); + void resetToDefault(); + + object_ptr _mainFontName = { nullptr }; + object_ptr _semiboldFontName = { nullptr }; + object_ptr _semiboldIsBold = { nullptr }; + object_ptr _monospacedFontName = { nullptr }; + Ui::Text::String _about; + + int _aboutHeight = 0; +}; \ No newline at end of file diff --git a/Telegram/SourceFiles/settings/settings_kotato.cpp b/Telegram/SourceFiles/settings/settings_kotato.cpp index 37e2f33a1..9078b10cd 100644 --- a/Telegram/SourceFiles/settings/settings_kotato.cpp +++ b/Telegram/SourceFiles/settings/settings_kotato.cpp @@ -16,6 +16,7 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL #include "ui/widgets/continuous_sliders.h" #include "ui/text/text_utilities.h" // Ui::Text::ToUpper #include "boxes/connection_box.h" +#include "boxes/fonts_box.h" #include "boxes/about_box.h" #include "boxes/confirm_box.h" #include "info/profile/info_profile_button.h" @@ -95,7 +96,15 @@ void SetupKotatoChats(not_null container) { cSetAlwaysShowScheduled(enabled); Notify::showScheduledButtonChanged(); KotatoSettings::Write(); - }, container->lifetime()); + }, container->lifetime()); + + AddButton( + container, + tr::ktg_settings_fonts(), + st::settingsButton + )->addClickHandler([=] { + Ui::show(Box()); + }); AddSkip(container); } @@ -119,3 +128,4 @@ void Kotato::setupContent(not_null controller) { } } // namespace Settings + diff --git a/Telegram/SourceFiles/settings/settings_kotato.h b/Telegram/SourceFiles/settings/settings_kotato.h index a490c3f2f..fd7ef8092 100644 --- a/Telegram/SourceFiles/settings/settings_kotato.h +++ b/Telegram/SourceFiles/settings/settings_kotato.h @@ -9,6 +9,8 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL #include "settings/settings_common.h" +class BoxContent; + namespace Settings { void SetupKotatoChats(not_null container); diff --git a/Telegram/gyp/telegram/sources.txt b/Telegram/gyp/telegram/sources.txt index a47ea1e61..284fc8ca9 100644 --- a/Telegram/gyp/telegram/sources.txt +++ b/Telegram/gyp/telegram/sources.txt @@ -58,6 +58,8 @@ <(src_loc)/boxes/edit_color_box.h <(src_loc)/boxes/edit_privacy_box.cpp <(src_loc)/boxes/edit_privacy_box.h +<(src_loc)/boxes/fonts_box.cpp +<(src_loc)/boxes/fonts_box.h <(src_loc)/boxes/generic_box.cpp <(src_loc)/boxes/generic_box.h <(src_loc)/boxes/language_box.cpp