[Option][GUI] Font options
This commit is contained in:
parent
ae7faa1288
commit
aeeec7bea0
11 changed files with 328 additions and 4 deletions
|
|
@ -1023,6 +1023,8 @@ PRIVATE
|
|||
iv/iv_delegate_impl.h
|
||||
iv/iv_instance.cpp
|
||||
iv/iv_instance.h
|
||||
kotato/boxes/kotato_fonts_box.cpp
|
||||
kotato/boxes/kotato_fonts_box.h
|
||||
kotato/boxes/kotato_radio_box.cpp
|
||||
kotato/boxes/kotato_radio_box.h
|
||||
kotato/kotato_lang.cpp
|
||||
|
|
|
|||
|
|
@ -28,6 +28,13 @@
|
|||
"ktg_mac_menu_show": "Show Kotatogram",
|
||||
"ktg_settings_kotato": "Kotatogram Settings",
|
||||
"ktg_settings_chats": "Chats",
|
||||
"ktg_fonts_title": "Fonts",
|
||||
"ktg_settings_fonts": "Change application fonts",
|
||||
"ktg_fonts_reset": "Reset",
|
||||
"ktg_fonts_about": "You will need to restart app to apply and see changes.",
|
||||
"ktg_fonts_semibold_is_bold": "Bold font face",
|
||||
"ktg_fonts_monospaced": "Monospaced font",
|
||||
"ktg_fonts_size": "Font size: {pixels}px",
|
||||
"ktg_settings_network": "Network",
|
||||
"ktg_settings_system": "System",
|
||||
"ktg_settings_other": "Other",
|
||||
|
|
|
|||
|
|
@ -1099,3 +1099,7 @@ moderateBoxDividerLabel: FlatLabel(boxDividerLabel) {
|
|||
selectLinkFg: windowActiveTextFg;
|
||||
}
|
||||
}
|
||||
|
||||
fontsBoxTextStyle: TextStyle(defaultTextStyle) {
|
||||
font: font(13px);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "core/application.h"
|
||||
|
||||
#include "kotato/kotato_lang.h"
|
||||
#include "kotato/kotato_settings.h"
|
||||
#include "data/data_abstract_structure.h"
|
||||
#include "data/data_photo.h"
|
||||
#include "data/data_document.h"
|
||||
|
|
@ -255,6 +256,11 @@ void Application::run() {
|
|||
startLocalStorage();
|
||||
|
||||
style::SetCustomFont(settings().customFontFamily());
|
||||
style::SetCustomFontSettings({
|
||||
::Kotato::JsonSettings::GetString("fonts/monospaced"),
|
||||
::Kotato::JsonSettings::GetInt("fonts/size"),
|
||||
::Kotato::JsonSettings::GetBool("fonts/semibold_is_bold"),
|
||||
});
|
||||
style::internal::StartFonts();
|
||||
|
||||
ValidateScale();
|
||||
|
|
|
|||
|
|
@ -8481,7 +8481,7 @@ void HistoryWidget::paintEvent(QPaintEvent *e) {
|
|||
HistoryView::ServiceMessagePainter::PaintBubble(p, st, tr);
|
||||
|
||||
p.setPen(st->msgServiceFg());
|
||||
p.setFont(st::msgServiceFont->f);
|
||||
p.setFont(st::msgServiceFont);
|
||||
p.drawTextLeft(tr.left() + st::msgPadding.left(), tr.top() + st::msgServicePadding.top(), width(), tr::lng_willbe_history(tr::now));
|
||||
|
||||
//AssertIsDebug();
|
||||
|
|
|
|||
245
Telegram/SourceFiles/kotato/boxes/kotato_fonts_box.cpp
Normal file
245
Telegram/SourceFiles/kotato/boxes/kotato_fonts_box.cpp
Normal file
|
|
@ -0,0 +1,245 @@
|
|||
/*
|
||||
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 "kotato/boxes/kotato_fonts_box.h"
|
||||
|
||||
#include "kotato/kotato_lang.h"
|
||||
#include "kotato/kotato_settings.h"
|
||||
#include "base/platform/base_platform_info.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "ui/wrap/padding_wrap.h"
|
||||
#include "ui/wrap/wrap.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/fields/input_field.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "ui/widgets/continuous_sliders.h"
|
||||
#include "styles/style_layers.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_calls.h"
|
||||
#include "styles/style_settings.h"
|
||||
#include "ui/boxes/confirm_box.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "core/application.h"
|
||||
|
||||
#include <QFontDatabase>
|
||||
#include <QListView>
|
||||
#include <QStringListModel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
class FontListView : public QListView {
|
||||
public:
|
||||
FontListView(QWidget *parent)
|
||||
: QListView(parent) {
|
||||
setModel(new QStringListModel(parent));
|
||||
setEditTriggers(NoEditTriggers);
|
||||
setFont(st::normalFont);
|
||||
}
|
||||
|
||||
inline QStringListModel *model() const {
|
||||
return static_cast<QStringListModel *>(QListView::model());
|
||||
}
|
||||
inline void setCurrentItem(int item) {
|
||||
QListView::setCurrentIndex(static_cast<QAbstractListModel*>(model())->index(item));
|
||||
}
|
||||
inline int currentItem() const {
|
||||
return QListView::currentIndex().row();
|
||||
}
|
||||
inline int count() const {
|
||||
return model()->rowCount();
|
||||
}
|
||||
inline QString currentText() const {
|
||||
int row = QListView::currentIndex().row();
|
||||
return row < 0 ? QString() : model()->stringList().at(row);
|
||||
}
|
||||
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous) override {
|
||||
QListView::currentChanged(current, previous);
|
||||
if (current.isValid())
|
||||
_highlighted.fire_copy(model()->stringList().at(current.row()));
|
||||
}
|
||||
QString text(int i) const {
|
||||
return model()->stringList().at(i);
|
||||
}
|
||||
rpl::producer<QString> highlighted() {
|
||||
return _highlighted.events();
|
||||
}
|
||||
rpl::lifetime &lifetime() {
|
||||
return _lifetime;
|
||||
}
|
||||
|
||||
private:
|
||||
rpl::event_stream<QString> _highlighted;
|
||||
rpl::lifetime _lifetime;
|
||||
};
|
||||
|
||||
class RpFontListView : public Ui::RpWidget {
|
||||
public:
|
||||
RpFontListView(QWidget *parent)
|
||||
: Ui::RpWidget(parent)
|
||||
, _layout(this)
|
||||
, _view(this) {
|
||||
_layout->addWidget(_view);
|
||||
}
|
||||
|
||||
void prepare(
|
||||
Ui::InputField *field,
|
||||
const QStringList &fontList) {
|
||||
_view->model()->setStringList(fontList);
|
||||
resize(0, _view->sizeHintForRow(0) * 10);
|
||||
_view->highlighted(
|
||||
) | rpl::start_with_next([=](QString fontName) {
|
||||
if (!field->hasFocus()) {
|
||||
field->setText(fontName);
|
||||
}
|
||||
}, _view->lifetime());
|
||||
field->changes(
|
||||
) | rpl::start_with_next([=] {
|
||||
if (field->getLastText().isEmpty()) {
|
||||
_view->setCurrentItem(-1);
|
||||
return;
|
||||
}
|
||||
_view->setCurrentItem(
|
||||
std::distance(fontList.begin(), ranges::find_if(
|
||||
fontList,
|
||||
[&](const auto &fontName) {
|
||||
return fontName.startsWith(field->getLastText());
|
||||
})));
|
||||
}, field->lifetime());
|
||||
const auto defaultValue = field->getLastText().trimmed();
|
||||
if (!defaultValue.isEmpty()) {
|
||||
_view->setCurrentItem(fontList.indexOf(defaultValue));
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
object_ptr<QVBoxLayout> _layout;
|
||||
object_ptr<FontListView> _view;
|
||||
};
|
||||
|
||||
FontsBox::FontsBox(QWidget* parent)
|
||||
: _owned(this)
|
||||
, _content(_owned.data())
|
||||
, _fontSize(::Kotato::JsonSettings::GetIntWithPending("fonts/size"))
|
||||
{
|
||||
}
|
||||
|
||||
void FontsBox::prepare() {
|
||||
setTitle(rktr("ktg_fonts_title"));
|
||||
|
||||
addButton(tr::lng_settings_save(), [=] { save(); });
|
||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||
|
||||
addLeftButton(rktr("ktg_fonts_reset"), [=] { resetToDefault(); });
|
||||
|
||||
_semiboldIsBold = _content->add(
|
||||
object_ptr<Ui::Checkbox>(_content,
|
||||
ktr("ktg_fonts_semibold_is_bold"),
|
||||
::Kotato::JsonSettings::GetBoolWithPending("fonts/semibold_is_bold")),
|
||||
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()));
|
||||
_monospacedFontList = _content->add(
|
||||
object_ptr<RpFontListView>(_content),
|
||||
QMargins(
|
||||
st::boxPadding.left(),
|
||||
st::boxPadding.bottom(),
|
||||
st::boxPadding.right(),
|
||||
st::boxPadding.bottom()));
|
||||
_fontSizeLabel = _content->add(
|
||||
object_ptr<Ui::LabelSimple>(
|
||||
_content,
|
||||
st::ktgSettingsSliderLabel),
|
||||
st::groupCallDelayLabelMargin);
|
||||
_fontSizeSlider = _content->add(
|
||||
object_ptr<Ui::MediaSlider>(
|
||||
_content,
|
||||
st::defaultContinuousSlider),
|
||||
st::localStorageLimitMargin);
|
||||
const auto updateFontSizeLabel = [=](int value) {
|
||||
const auto prefix = (value >= 0) ? qsl("+") : QString();
|
||||
const auto pixels = prefix + QString::number(value);
|
||||
_fontSizeLabel->setText(
|
||||
ktr("ktg_fonts_size", { "pixels", pixels }));
|
||||
};
|
||||
const auto updateFontSize = [=](int value) {
|
||||
updateFontSizeLabel(value);
|
||||
_fontSize = value;
|
||||
};
|
||||
_fontSizeSlider->resize(st::defaultContinuousSlider.seekSize);
|
||||
_fontSizeSlider->setPseudoDiscrete(
|
||||
21,
|
||||
[](int val) { return val - 10; },
|
||||
_fontSize,
|
||||
updateFontSize);
|
||||
updateFontSizeLabel(_fontSize);
|
||||
_content->add(
|
||||
object_ptr<Ui::FlatLabel>(_content, rktr("ktg_fonts_about"), st::boxDividerLabel),
|
||||
QMargins(
|
||||
st::boxPadding.left(),
|
||||
0,
|
||||
st::boxPadding.right(),
|
||||
st::boxPadding.bottom()));
|
||||
|
||||
_monospacedFontName->setText(::Kotato::JsonSettings::GetStringWithPending("fonts/monospaced"));
|
||||
|
||||
const auto fontNames = QFontDatabase().families();
|
||||
_monospacedFontList->prepare(_monospacedFontName, fontNames);
|
||||
|
||||
auto wrap = object_ptr<Ui::OverrideMargins>(this, std::move(_owned));
|
||||
setDimensionsToContent(st::boxWidth, wrap.data());
|
||||
setInnerWidget(std::move(wrap));
|
||||
}
|
||||
|
||||
|
||||
void FontsBox::setInnerFocus() {
|
||||
_monospacedFontName->setFocusFast();
|
||||
}
|
||||
|
||||
void FontsBox::save() {
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/monospaced", _monospacedFontName->getLastText().trimmed());
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/semibold_is_bold", _semiboldIsBold->checked());
|
||||
::Kotato::JsonSettings::SetAfterRestart("fonts/size", _fontSize);
|
||||
::Kotato::JsonSettings::Write();
|
||||
|
||||
const auto box = std::make_shared<QPointer<BoxContent>>();
|
||||
|
||||
*box = getDelegate()->show(
|
||||
Ui::MakeConfirmBox({
|
||||
.text = tr::lng_settings_need_restart(),
|
||||
.confirmed = [] { Core::Restart(); },
|
||||
.cancelled = crl::guard(this, [=] { closeBox(); box->data()->closeBox(); }),
|
||||
.confirmText = tr::lng_settings_restart_now(),
|
||||
.cancelText = tr::lng_settings_restart_later(),
|
||||
}));
|
||||
}
|
||||
|
||||
void FontsBox::resetToDefault() {
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/monospaced");
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/semibold_is_bold");
|
||||
::Kotato::JsonSettings::ResetAfterRestart("fonts/size");
|
||||
::Kotato::JsonSettings::Write();
|
||||
|
||||
const auto box = std::make_shared<QPointer<BoxContent>>();
|
||||
|
||||
*box = getDelegate()->show(
|
||||
Ui::MakeConfirmBox({
|
||||
.text = tr::lng_settings_need_restart(),
|
||||
.confirmed = [] { Core::Restart(); },
|
||||
.cancelled = crl::guard(this, [=] { closeBox(); box->data()->closeBox(); }),
|
||||
.confirmText = tr::lng_settings_restart_now(),
|
||||
.cancelText = tr::lng_settings_restart_later(),
|
||||
}));
|
||||
}
|
||||
44
Telegram/SourceFiles/kotato/boxes/kotato_fonts_box.h
Normal file
44
Telegram/SourceFiles/kotato/boxes/kotato_fonts_box.h
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
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 "ui/layers/box_content.h"
|
||||
|
||||
namespace Ui {
|
||||
class VerticalLayout;
|
||||
class Checkbox;
|
||||
class InputField;
|
||||
class LabelSimple;
|
||||
class MediaSlider;
|
||||
} // namespace Ui
|
||||
|
||||
class RpFontListView;
|
||||
|
||||
class FontsBox : public Ui::BoxContent {
|
||||
public:
|
||||
FontsBox(QWidget* parent);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
void setInnerFocus() override;
|
||||
|
||||
private:
|
||||
void save();
|
||||
void resetToDefault();
|
||||
|
||||
object_ptr<Ui::VerticalLayout> _owned;
|
||||
not_null<Ui::VerticalLayout*> _content;
|
||||
|
||||
QPointer<Ui::Checkbox> _semiboldIsBold;
|
||||
QPointer<Ui::InputField> _monospacedFontName;
|
||||
QPointer<RpFontListView> _monospacedFontList;
|
||||
QPointer<Ui::LabelSimple> _fontSizeLabel;
|
||||
QPointer<Ui::MediaSlider> _fontSizeSlider;
|
||||
|
||||
int _fontSize;
|
||||
};
|
||||
|
|
@ -217,6 +217,15 @@ const std::map<QString, Definition, std::greater<QString>> DefinitionMap {
|
|||
.defaultValue = false, }},
|
||||
|
||||
// Stored settings
|
||||
{ "fonts/semibold_is_bold", {
|
||||
.type = SettingType::BoolSetting,
|
||||
.defaultValue = false, }},
|
||||
{ "fonts/monospaced", {
|
||||
.type = SettingType::QStringSetting,
|
||||
.fillerValue = qsl("Consolas"), }},
|
||||
{ "fonts/size", {
|
||||
.type = SettingType::IntSetting,
|
||||
.defaultValue = 0, }},
|
||||
};
|
||||
|
||||
using OldOptionKey = QString;
|
||||
|
|
|
|||
|
|
@ -71,6 +71,14 @@ void SetupKotatoChats(
|
|||
Ui::AddSkip(container);
|
||||
Ui::AddSubsectionTitle(container, rktr("ktg_settings_chats"));
|
||||
|
||||
container->add(object_ptr<Button>(
|
||||
container,
|
||||
rktr("ktg_settings_fonts"),
|
||||
st::settingsButtonNoIcon
|
||||
))->addClickHandler([=] {
|
||||
Ui::show(Box<FontsBox>());
|
||||
});
|
||||
|
||||
|
||||
Ui::AddSkip(container);
|
||||
Ui::AddDivider(container);
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ void PreviewWindowTitle(Painter &p, const style::palette &palette, QRect body, i
|
|||
}
|
||||
|
||||
p.setPen(st::titleFgActive[palette]);
|
||||
p.setFont(font);
|
||||
p.setFont(style::font(font.pixelSize(), 0, font.family()));
|
||||
|
||||
p.drawText(titleRect, u"Kotatogram"_q, style::al_center);
|
||||
|
||||
|
|
|
|||
|
|
@ -282,8 +282,7 @@ void EmptyUserpic::paint(
|
|||
x = style::RightToLeft() ? (outerWidth - x - size) : x;
|
||||
|
||||
const auto fontsize = (size * 13) / 33;
|
||||
auto font = st::historyPeerUserpicFont->f;
|
||||
font.setPixelSize(fontsize);
|
||||
auto font = style::font(fontsize, st::historyPeerUserpicFont->flags(), st::historyPeerUserpicFont->family());
|
||||
|
||||
PainterHighQualityEnabler hq(p);
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue