2019-10-14 02:17:53 +03:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
*/
|
2021-08-25 01:09:37 +03:00
|
|
|
#include "kotato/boxes/kotato_fonts_box.h"
|
2019-10-14 02:17:53 +03:00
|
|
|
|
2021-08-24 14:01:27 +03:00
|
|
|
#include "kotato/kotato_lang.h"
|
2020-12-26 05:03:59 +04:00
|
|
|
#include "base/platform/base_platform_info.h"
|
2021-12-27 09:41:55 +03:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
|
|
|
#include "ui/wrap/padding_wrap.h"
|
|
|
|
#include "ui/wrap/wrap.h"
|
2019-10-14 02:17:53 +03:00
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "ui/widgets/input_fields.h"
|
2019-11-06 16:22:25 +03:00
|
|
|
#include "styles/style_layers.h"
|
2019-10-14 02:17:53 +03:00
|
|
|
#include "styles/style_boxes.h"
|
2021-12-07 09:25:44 +03:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2020-04-21 06:20:14 +03:00
|
|
|
#include "kotato/json_settings.h"
|
2019-10-14 02:17:53 +03:00
|
|
|
#include "lang/lang_keys.h"
|
2019-10-14 07:27:00 +03:00
|
|
|
#include "app.h"
|
2019-10-14 02:17:53 +03:00
|
|
|
|
|
|
|
FontsBox::FontsBox(QWidget* parent)
|
2021-12-27 09:41:55 +03:00
|
|
|
: _owned(this)
|
|
|
|
, _content(_owned.data())
|
2019-10-14 02:17:53 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void FontsBox::prepare() {
|
2021-08-24 14:01:27 +03:00
|
|
|
setTitle(rktr("ktg_fonts_title"));
|
2019-10-14 02:17:53 +03:00
|
|
|
|
|
|
|
addButton(tr::lng_settings_save(), [=] { save(); });
|
|
|
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
|
|
|
|
2021-08-24 14:01:27 +03:00
|
|
|
addLeftButton(rktr("ktg_fonts_reset"), [=] { resetToDefault(); });
|
2019-10-14 02:17:53 +03:00
|
|
|
|
2021-12-27 09:41:55 +03:00
|
|
|
_useSystemFont = _content->add(
|
|
|
|
object_ptr<Ui::Checkbox>(_content, ktr("ktg_fonts_use_system_font"), cUseSystemFont()),
|
|
|
|
QMargins(
|
|
|
|
st::boxPadding.left(),
|
|
|
|
0,
|
|
|
|
st::boxPadding.right(),
|
|
|
|
st::boxPadding.bottom()));
|
|
|
|
_useOriginalMetrics = _content->add(
|
|
|
|
object_ptr<Ui::Checkbox>(_content, ktr("ktg_fonts_use_original_metrics"), cUseOriginalMetrics()),
|
|
|
|
QMargins(
|
|
|
|
st::boxPadding.left(),
|
|
|
|
st::boxPadding.bottom(),
|
|
|
|
st::boxPadding.right(),
|
|
|
|
st::boxPadding.bottom()));
|
|
|
|
_mainFontName = _content->add(
|
|
|
|
object_ptr<Ui::InputField>(_content, st::defaultInputField, rktr("ktg_fonts_main")),
|
|
|
|
QMargins(
|
|
|
|
st::boxPadding.left(),
|
|
|
|
0,
|
|
|
|
st::boxPadding.right(),
|
|
|
|
st::boxPadding.bottom()));
|
|
|
|
_semiboldFontName = _content->add(
|
|
|
|
object_ptr<Ui::InputField>(_content, st::defaultInputField, rktr("ktg_fonts_semibold")),
|
|
|
|
QMargins(
|
|
|
|
st::boxPadding.left(),
|
|
|
|
0,
|
|
|
|
st::boxPadding.right(),
|
|
|
|
st::boxPadding.bottom()));
|
|
|
|
_semiboldIsBold = _content->add(
|
|
|
|
object_ptr<Ui::Checkbox>(_content, ktr("ktg_fonts_semibold_is_bold"), cSemiboldFontIsBold()),
|
|
|
|
QMargins(
|
|
|
|
st::boxPadding.left(),
|
|
|
|
0,
|
|
|
|
st::boxPadding.right(),
|
|
|
|
st::boxPadding.bottom()));
|
|
|
|
_monospacedFontName = _content->add(
|
|
|
|
object_ptr<Ui::InputField>(_content, st::defaultInputField, rktr("ktg_fonts_monospaced")),
|
|
|
|
QMargins(
|
|
|
|
st::boxPadding.left(),
|
|
|
|
0,
|
|
|
|
st::boxPadding.right(),
|
|
|
|
st::boxPadding.bottom()));
|
|
|
|
_content->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(_content, rktr("ktg_fonts_about"), st::boxDividerLabel),
|
|
|
|
QMargins(
|
|
|
|
st::boxPadding.left(),
|
|
|
|
0,
|
|
|
|
st::boxPadding.right(),
|
|
|
|
st::boxPadding.bottom()));
|
|
|
|
|
2019-10-14 02:17:53 +03:00
|
|
|
if (!cMainFont().isEmpty()) {
|
|
|
|
_mainFontName->setText(cMainFont());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cSemiboldFont().isEmpty()) {
|
|
|
|
_semiboldFontName->setText(cSemiboldFont());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cMonospaceFont().isEmpty()) {
|
|
|
|
_monospacedFontName->setText(cMonospaceFont());
|
|
|
|
}
|
|
|
|
|
2021-12-27 09:41:55 +03:00
|
|
|
auto wrap = object_ptr<Ui::OverrideMargins>(this, std::move(_owned));
|
|
|
|
setDimensionsToContent(st::boxWidth, wrap.data());
|
|
|
|
setInnerWidget(std::move(wrap));
|
2019-10-14 02:17:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FontsBox::setInnerFocus() {
|
|
|
|
_mainFontName->setFocusFast();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FontsBox::save() {
|
2020-01-30 11:54:57 +04:00
|
|
|
const auto useSystemFont = _useSystemFont->checked();
|
2020-02-05 21:27:25 +03:00
|
|
|
const auto useOriginalMetrics = _useOriginalMetrics->checked();
|
2019-10-14 07:27:00 +03:00
|
|
|
const auto mainFont = _mainFontName->getLastText().trimmed();
|
|
|
|
const auto semiboldFont = _semiboldFontName->getLastText().trimmed();
|
|
|
|
const auto semiboldIsBold = _semiboldIsBold->checked();
|
|
|
|
const auto monospacedFont = _monospacedFontName->getLastText().trimmed();
|
|
|
|
|
|
|
|
const auto changeFonts = [=] {
|
2020-01-30 11:54:57 +04:00
|
|
|
cSetUseSystemFont(useSystemFont);
|
2020-02-05 21:27:25 +03:00
|
|
|
cSetUseOriginalMetrics(useOriginalMetrics);
|
2019-10-14 07:27:00 +03:00
|
|
|
cSetMainFont(mainFont);
|
|
|
|
cSetSemiboldFont(semiboldFont);
|
|
|
|
cSetSemiboldFontIsBold(semiboldIsBold);
|
|
|
|
cSetMonospaceFont(monospacedFont);
|
2020-04-21 06:20:14 +03:00
|
|
|
Kotato::JsonSettings::Write();
|
2019-10-14 07:27:00 +03:00
|
|
|
App::restart();
|
|
|
|
};
|
|
|
|
|
2019-10-14 07:34:55 +03:00
|
|
|
const auto box = std::make_shared<QPointer<BoxContent>>();
|
|
|
|
|
|
|
|
*box = getDelegate()->show(
|
2021-12-07 09:25:44 +03:00
|
|
|
Box<Ui::ConfirmBox>(
|
2020-04-23 17:42:48 +03:00
|
|
|
tr::lng_settings_need_restart(tr::now),
|
2020-01-30 18:38:59 +03:00
|
|
|
tr::lng_settings_restart_now(tr::now),
|
2019-10-14 07:27:00 +03:00
|
|
|
tr::lng_cancel(tr::now),
|
|
|
|
changeFonts));
|
2019-10-14 02:17:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void FontsBox::resetToDefault() {
|
2019-10-14 07:27:00 +03:00
|
|
|
const auto resetFonts = [=] {
|
|
|
|
cSetMainFont(QString());
|
|
|
|
cSetSemiboldFont(QString());
|
|
|
|
cSetSemiboldFontIsBold(false);
|
|
|
|
cSetMonospaceFont(QString());
|
2020-04-17 16:04:36 +03:00
|
|
|
#ifdef DESKTOP_APP_USE_PACKAGED_FONTS
|
|
|
|
cSetUseSystemFont(true);
|
|
|
|
#else
|
2020-12-26 05:03:59 +04:00
|
|
|
cSetUseSystemFont(Platform::IsLinux());
|
2020-04-17 16:04:36 +03:00
|
|
|
#endif
|
|
|
|
cSetUseOriginalMetrics(false);
|
2020-04-21 06:20:14 +03:00
|
|
|
Kotato::JsonSettings::Write();
|
2019-10-14 07:27:00 +03:00
|
|
|
App::restart();
|
|
|
|
};
|
|
|
|
|
2019-10-14 07:34:55 +03:00
|
|
|
const auto box = std::make_shared<QPointer<BoxContent>>();
|
|
|
|
|
|
|
|
*box = getDelegate()->show(
|
2021-12-07 09:25:44 +03:00
|
|
|
Box<Ui::ConfirmBox>(
|
2020-04-23 17:42:48 +03:00
|
|
|
tr::lng_settings_need_restart(tr::now),
|
2020-01-30 18:38:59 +03:00
|
|
|
tr::lng_settings_restart_now(tr::now),
|
2019-10-14 07:27:00 +03:00
|
|
|
tr::lng_cancel(tr::now),
|
|
|
|
resetFonts));
|
2021-12-27 09:41:55 +03:00
|
|
|
}
|