diff --git a/Telegram/SourceFiles/kotato/boxes/kotato_fonts_box.cpp b/Telegram/SourceFiles/kotato/boxes/kotato_fonts_box.cpp index 5f31a912e..0515cbffc 100644 --- a/Telegram/SourceFiles/kotato/boxes/kotato_fonts_box.cpp +++ b/Telegram/SourceFiles/kotato/boxes/kotato_fonts_box.cpp @@ -9,6 +9,9 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL #include "kotato/kotato_lang.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/input_fields.h" @@ -20,13 +23,8 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL #include "app.h" FontsBox::FontsBox(QWidget* parent) -: _useSystemFont(this, ktr("ktg_fonts_use_system_font"), cUseSystemFont()) -, _useOriginalMetrics(this, ktr("ktg_fonts_use_original_metrics"), cUseOriginalMetrics()) -, _mainFontName(this, st::defaultInputField, rktr("ktg_fonts_main")) -, _semiboldFontName(this, st::defaultInputField, rktr("ktg_fonts_semibold")) -, _semiboldIsBold(this, ktr("ktg_fonts_semibold_is_bold"), cSemiboldFontIsBold()) -, _monospacedFontName(this, st::defaultInputField, rktr("ktg_fonts_monospaced")) -, _about(st::boxWidth - st::boxPadding.left() * 1.5) +: _owned(this) +, _content(_owned.data()) { } @@ -38,6 +36,56 @@ void FontsBox::prepare() { addLeftButton(rktr("ktg_fonts_reset"), [=] { resetToDefault(); }); + _useSystemFont = _content->add( + object_ptr(_content, ktr("ktg_fonts_use_system_font"), cUseSystemFont()), + QMargins( + st::boxPadding.left(), + 0, + st::boxPadding.right(), + st::boxPadding.bottom())); + _useOriginalMetrics = _content->add( + object_ptr(_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(_content, st::defaultInputField, rktr("ktg_fonts_main")), + QMargins( + st::boxPadding.left(), + 0, + st::boxPadding.right(), + st::boxPadding.bottom())); + _semiboldFontName = _content->add( + object_ptr(_content, st::defaultInputField, rktr("ktg_fonts_semibold")), + QMargins( + st::boxPadding.left(), + 0, + st::boxPadding.right(), + st::boxPadding.bottom())); + _semiboldIsBold = _content->add( + object_ptr(_content, ktr("ktg_fonts_semibold_is_bold"), cSemiboldFontIsBold()), + QMargins( + st::boxPadding.left(), + 0, + st::boxPadding.right(), + st::boxPadding.bottom())); + _monospacedFontName = _content->add( + object_ptr(_content, st::defaultInputField, rktr("ktg_fonts_monospaced")), + QMargins( + st::boxPadding.left(), + 0, + st::boxPadding.right(), + st::boxPadding.bottom())); + _content->add( + object_ptr(_content, rktr("ktg_fonts_about"), st::boxDividerLabel), + QMargins( + st::boxPadding.left(), + 0, + st::boxPadding.right(), + st::boxPadding.bottom())); + if (!cMainFont().isEmpty()) { _mainFontName->setText(cMainFont()); } @@ -50,55 +98,12 @@ void FontsBox::prepare() { _monospacedFontName->setText(cMonospaceFont()); } - _about.setText(st::fontsBoxTextStyle, ktr("ktg_fonts_about")); - _aboutHeight = _about.countHeight(st::boxWidth - st::boxPadding.left() * 1.5); - - setDimensions(st::boxWidth, _useSystemFont->height() - + _useOriginalMetrics->height() - + _mainFontName->height() - + _semiboldFontName->height() - + _semiboldIsBold->height() - + _monospacedFontName->height() - + _aboutHeight - + st::boxLittleSkip * 3); + auto wrap = object_ptr(this, std::move(_owned)); + setDimensionsToContent(st::boxWidth, wrap.data()); + setInnerWidget(std::move(wrap)); } -void FontsBox::paintEvent(QPaintEvent *e) { - BoxContent::paintEvent(e); - - Painter p(this); - int32 w = st::boxWidth - st::boxPadding.left() * 1.5; - int32 abouty = _useSystemFont->height() - + _useOriginalMetrics->height() - + _mainFontName->height() - + _semiboldFontName->height() - + _semiboldIsBold->height() - + _monospacedFontName->height() - + st::boxLittleSkip * 3; - 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(); - _useSystemFont->resize(w, _useSystemFont->height()); - _useSystemFont->moveToLeft(st::boxPadding.left(), 0); - _useOriginalMetrics->resize(w, _useOriginalMetrics->height()); - _useOriginalMetrics->moveToLeft(st::boxPadding.left(), _useSystemFont->y() + _useSystemFont->height() + st::boxLittleSkip); - _mainFontName->resize(w, _mainFontName->height()); - _mainFontName->moveToLeft(st::boxPadding.left(), _useOriginalMetrics->y() + _useOriginalMetrics->height() + st::boxLittleSkip); - _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(); } @@ -156,4 +161,4 @@ void FontsBox::resetToDefault() { tr::lng_settings_restart_now(tr::now), tr::lng_cancel(tr::now), resetFonts)); -} \ No newline at end of file +} diff --git a/Telegram/SourceFiles/kotato/boxes/kotato_fonts_box.h b/Telegram/SourceFiles/kotato/boxes/kotato_fonts_box.h index c518c27e4..3ea8d1e38 100644 --- a/Telegram/SourceFiles/kotato/boxes/kotato_fonts_box.h +++ b/Telegram/SourceFiles/kotato/boxes/kotato_fonts_box.h @@ -7,7 +7,8 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL */ #pragma once -#include "boxes/abstract_box.h" +#include "ui/layers/box_content.h" +#include "ui/wrap/vertical_layout.h" namespace Ui { class Checkbox; @@ -22,19 +23,17 @@ protected: void prepare() override; void setInnerFocus() override; - void paintEvent(QPaintEvent *e) override; - void resizeEvent(QResizeEvent *e) override; private: void save(); void resetToDefault(); - object_ptr _useSystemFont = { nullptr }; - object_ptr _useOriginalMetrics = { nullptr }; - object_ptr _mainFontName = { nullptr }; - object_ptr _semiboldFontName = { nullptr }; - object_ptr _semiboldIsBold = { nullptr }; - object_ptr _monospacedFontName = { nullptr }; - Ui::Text::String _about; + object_ptr _owned; + not_null _content; - int _aboutHeight = 0; -}; \ No newline at end of file + QPointer _useSystemFont; + QPointer _useOriginalMetrics; + QPointer _mainFontName; + QPointer _semiboldFontName; + QPointer _semiboldIsBold; + QPointer _monospacedFontName; +}; diff --git a/Telegram/SourceFiles/kotato/boxes/kotato_radio_box.cpp b/Telegram/SourceFiles/kotato/boxes/kotato_radio_box.cpp index 4b3130123..92f394a64 100644 --- a/Telegram/SourceFiles/kotato/boxes/kotato_radio_box.cpp +++ b/Telegram/SourceFiles/kotato/boxes/kotato_radio_box.cpp @@ -9,6 +9,8 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL #include "lang/lang_keys.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/labels.h" #include "ui/boxes/confirm_box.h" @@ -32,7 +34,9 @@ RadioBox::RadioBox( , _valueCount(valueCount) , _labelGetter(labelGetter) , _saveCallback(std::move(saveCallback)) -, _warnRestart(warnRestart) { +, _warnRestart(warnRestart) +, _owned(this) +, _content(_owned.data()) { } RadioBox::RadioBox( @@ -50,7 +54,9 @@ RadioBox::RadioBox( , _valueCount(valueCount) , _labelGetter(labelGetter) , _saveCallback(std::move(saveCallback)) -, _warnRestart(warnRestart) { +, _warnRestart(warnRestart) +, _owned(this) +, _content(_owned.data()) { } RadioBox::RadioBox( @@ -68,7 +74,9 @@ RadioBox::RadioBox( , _labelGetter(labelGetter) , _descriptionGetter(descriptionGetter) , _saveCallback(std::move(saveCallback)) -, _warnRestart(warnRestart) { +, _warnRestart(warnRestart) +, _owned(this) +, _content(_owned.data()) { } RadioBox::RadioBox( @@ -88,7 +96,9 @@ RadioBox::RadioBox( , _labelGetter(labelGetter) , _descriptionGetter(descriptionGetter) , _saveCallback(std::move(saveCallback)) -, _warnRestart(warnRestart) { +, _warnRestart(warnRestart) +, _owned(this) +, _content(_owned.data()) { } void RadioBox::prepare() { @@ -97,11 +107,9 @@ void RadioBox::prepare() { addButton(tr::lng_settings_save(), [=] { save(); }); addButton(tr::lng_cancel(), [=] { closeBox(); }); - const auto content = Ui::CreateChild(this); - if (!_description.isEmpty()) { - content->add( - object_ptr(this, _description, st::boxDividerLabel), + _content->add( + object_ptr(_content, _description, st::boxDividerLabel), style::margins( st::boxPadding.left(), 0, @@ -116,9 +124,9 @@ void RadioBox::prepare() { ? _descriptionGetter(i) : QString(); - content->add( + _content->add( object_ptr( - this, + _content, _group, i, _labelGetter(i), @@ -129,8 +137,8 @@ void RadioBox::prepare() { st::boxPadding.right(), description.isEmpty() ? st::boxPadding.bottom() : 0)); if (!description.isEmpty()) { - content->add( - object_ptr(this, description, st::boxDividerLabel), + _content->add( + object_ptr(_content, description, st::boxDividerLabel), style::margins( st::boxPadding.left() + st::autolockButton.margin.left() @@ -143,7 +151,9 @@ void RadioBox::prepare() { } } - setDimensionsToContent(st::boxWidth, content); + auto wrap = object_ptr(this, std::move(_owned)); + setDimensionsToContent(st::boxWidth, wrap.data()); + setInnerWidget(std::move(wrap)); } void RadioBox::save() { diff --git a/Telegram/SourceFiles/kotato/boxes/kotato_radio_box.h b/Telegram/SourceFiles/kotato/boxes/kotato_radio_box.h index ab7dc559e..93ded92b7 100644 --- a/Telegram/SourceFiles/kotato/boxes/kotato_radio_box.h +++ b/Telegram/SourceFiles/kotato/boxes/kotato_radio_box.h @@ -13,6 +13,7 @@ namespace Ui { class RadiobuttonGroup; class Radiobutton; class FlatLabel; +class VerticalLayout; } // namespace Ui namespace Kotato { @@ -71,6 +72,9 @@ private: Fn _saveCallback; bool _warnRestart = false; std::shared_ptr _group; + + object_ptr _owned; + not_null _content; }; } // namespace Kotato