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
|
|
|
|
*/
|
2020-05-16 20:07:05 +03:00
|
|
|
#include "kotato/customboxes/fonts_box.h"
|
2019-10-14 02:17:53 +03:00
|
|
|
|
2020-12-26 05:03:59 +04:00
|
|
|
#include "base/platform/base_platform_info.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"
|
2019-10-14 07:27:00 +03:00
|
|
|
#include "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)
|
2020-01-30 11:54:57 +04:00
|
|
|
: _useSystemFont(this, tr::ktg_fonts_use_system_font(tr::now), cUseSystemFont())
|
2020-02-05 21:27:25 +03:00
|
|
|
, _useOriginalMetrics(this, tr::ktg_fonts_use_original_metrics(tr::now), cUseOriginalMetrics())
|
2020-01-30 11:54:57 +04:00
|
|
|
, _mainFontName(this, st::defaultInputField, tr::ktg_fonts_main())
|
2019-10-14 02:17:53 +03:00
|
|
|
, _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);
|
2020-01-20 22:34:01 +00:00
|
|
|
|
2020-01-30 11:54:57 +04:00
|
|
|
setDimensions(st::boxWidth, _useSystemFont->height()
|
2020-02-05 21:27:25 +03:00
|
|
|
+ _useOriginalMetrics->height()
|
2020-01-30 11:54:57 +04:00
|
|
|
+ _mainFontName->height()
|
|
|
|
+ _semiboldFontName->height()
|
|
|
|
+ _semiboldIsBold->height()
|
|
|
|
+ _monospacedFontName->height()
|
|
|
|
+ _aboutHeight
|
2020-02-05 21:27:25 +03:00
|
|
|
+ st::boxLittleSkip * 3);
|
2019-10-14 02:17:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FontsBox::paintEvent(QPaintEvent *e) {
|
|
|
|
BoxContent::paintEvent(e);
|
|
|
|
|
|
|
|
Painter p(this);
|
|
|
|
int32 w = st::boxWidth - st::boxPadding.left() * 1.5;
|
2020-01-30 11:54:57 +04:00
|
|
|
int32 abouty = _useSystemFont->height()
|
2020-02-05 21:27:25 +03:00
|
|
|
+ _useOriginalMetrics->height()
|
2020-01-30 11:54:57 +04:00
|
|
|
+ _mainFontName->height()
|
|
|
|
+ _semiboldFontName->height()
|
|
|
|
+ _semiboldIsBold->height()
|
|
|
|
+ _monospacedFontName->height()
|
2020-02-05 21:27:25 +03:00
|
|
|
+ st::boxLittleSkip * 3;
|
2019-10-14 02:17:53 +03:00
|
|
|
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();
|
2020-01-30 11:54:57 +04:00
|
|
|
_useSystemFont->resize(w, _useSystemFont->height());
|
|
|
|
_useSystemFont->moveToLeft(st::boxPadding.left(), 0);
|
2020-02-05 21:27:25 +03:00
|
|
|
_useOriginalMetrics->resize(w, _useOriginalMetrics->height());
|
|
|
|
_useOriginalMetrics->moveToLeft(st::boxPadding.left(), _useSystemFont->y() + _useSystemFont->height() + st::boxLittleSkip);
|
2019-10-14 02:17:53 +03:00
|
|
|
_mainFontName->resize(w, _mainFontName->height());
|
2020-02-05 21:27:25 +03:00
|
|
|
_mainFontName->moveToLeft(st::boxPadding.left(), _useOriginalMetrics->y() + _useOriginalMetrics->height() + st::boxLittleSkip);
|
2019-10-14 02:17:53 +03:00
|
|
|
_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() {
|
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(
|
2019-10-14 07:27:00 +03:00
|
|
|
Box<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(
|
2019-10-14 07:27:00 +03:00
|
|
|
Box<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));
|
2019-10-14 02:17:53 +03:00
|
|
|
}
|