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
|
|
|
|
*/
|
|
|
|
#include "boxes/fonts_box.h"
|
|
|
|
|
|
|
|
#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"
|
|
|
|
#include "core/kotato_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())
|
|
|
|
, _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()
|
|
|
|
+ _mainFontName->height()
|
|
|
|
+ _semiboldFontName->height()
|
|
|
|
+ _semiboldIsBold->height()
|
|
|
|
+ _monospacedFontName->height()
|
|
|
|
+ _aboutHeight
|
|
|
|
+ st::boxLittleSkip * 2);
|
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()
|
|
|
|
+ _mainFontName->height()
|
|
|
|
+ _semiboldFontName->height()
|
|
|
|
+ _semiboldIsBold->height()
|
|
|
|
+ _monospacedFontName->height()
|
|
|
|
+ st::boxLittleSkip * 2;
|
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);
|
2019-10-14 02:17:53 +03:00
|
|
|
_mainFontName->resize(w, _mainFontName->height());
|
2020-01-30 11:54:57 +04:00
|
|
|
_mainFontName->moveToLeft(st::boxPadding.left(), _useSystemFont->y() + _useSystemFont->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();
|
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);
|
2019-10-14 07:27:00 +03:00
|
|
|
cSetMainFont(mainFont);
|
|
|
|
cSetSemiboldFont(semiboldFont);
|
|
|
|
cSetSemiboldFontIsBold(semiboldIsBold);
|
|
|
|
cSetMonospaceFont(monospacedFont);
|
|
|
|
KotatoSettings::Write();
|
|
|
|
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>(
|
|
|
|
tr::ktg_fonts_restart_new_fonts(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());
|
|
|
|
KotatoSettings::Write();
|
|
|
|
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>(
|
|
|
|
tr::ktg_fonts_restart_reset(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
|
|
|
}
|