2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-30 22:25:12 +00:00

Rework custom boxes to support scrolling

This commit is contained in:
RadRussianRus
2021-12-27 09:41:55 +03:00
parent 310a81b482
commit 8ceccc2bcb
4 changed files with 97 additions and 79 deletions

View File

@@ -9,6 +9,9 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL
#include "kotato/kotato_lang.h" #include "kotato/kotato_lang.h"
#include "base/platform/base_platform_info.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/checkbox.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/input_fields.h" #include "ui/widgets/input_fields.h"
@@ -20,13 +23,8 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL
#include "app.h" #include "app.h"
FontsBox::FontsBox(QWidget* parent) FontsBox::FontsBox(QWidget* parent)
: _useSystemFont(this, ktr("ktg_fonts_use_system_font"), cUseSystemFont()) : _owned(this)
, _useOriginalMetrics(this, ktr("ktg_fonts_use_original_metrics"), cUseOriginalMetrics()) , _content(_owned.data())
, _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)
{ {
} }
@@ -38,6 +36,56 @@ void FontsBox::prepare() {
addLeftButton(rktr("ktg_fonts_reset"), [=] { resetToDefault(); }); addLeftButton(rktr("ktg_fonts_reset"), [=] { resetToDefault(); });
_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()));
if (!cMainFont().isEmpty()) { if (!cMainFont().isEmpty()) {
_mainFontName->setText(cMainFont()); _mainFontName->setText(cMainFont());
} }
@@ -50,55 +98,12 @@ void FontsBox::prepare() {
_monospacedFontName->setText(cMonospaceFont()); _monospacedFontName->setText(cMonospaceFont());
} }
_about.setText(st::fontsBoxTextStyle, ktr("ktg_fonts_about")); auto wrap = object_ptr<Ui::OverrideMargins>(this, std::move(_owned));
_aboutHeight = _about.countHeight(st::boxWidth - st::boxPadding.left() * 1.5); setDimensionsToContent(st::boxWidth, wrap.data());
setInnerWidget(std::move(wrap));
setDimensions(st::boxWidth, _useSystemFont->height()
+ _useOriginalMetrics->height()
+ _mainFontName->height()
+ _semiboldFontName->height()
+ _semiboldIsBold->height()
+ _monospacedFontName->height()
+ _aboutHeight
+ st::boxLittleSkip * 3);
} }
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() { void FontsBox::setInnerFocus() {
_mainFontName->setFocusFast(); _mainFontName->setFocusFast();
} }
@@ -156,4 +161,4 @@ void FontsBox::resetToDefault() {
tr::lng_settings_restart_now(tr::now), tr::lng_settings_restart_now(tr::now),
tr::lng_cancel(tr::now), tr::lng_cancel(tr::now),
resetFonts)); resetFonts));
} }

View File

@@ -7,7 +7,8 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL
*/ */
#pragma once #pragma once
#include "boxes/abstract_box.h" #include "ui/layers/box_content.h"
#include "ui/wrap/vertical_layout.h"
namespace Ui { namespace Ui {
class Checkbox; class Checkbox;
@@ -22,19 +23,17 @@ protected:
void prepare() override; void prepare() override;
void setInnerFocus() override; void setInnerFocus() override;
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
private: private:
void save(); void save();
void resetToDefault(); void resetToDefault();
object_ptr<Ui::Checkbox> _useSystemFont = { nullptr }; object_ptr<Ui::VerticalLayout> _owned;
object_ptr<Ui::Checkbox> _useOriginalMetrics = { nullptr }; not_null<Ui::VerticalLayout*> _content;
object_ptr<Ui::InputField> _mainFontName = { nullptr };
object_ptr<Ui::InputField> _semiboldFontName = { nullptr };
object_ptr<Ui::Checkbox> _semiboldIsBold = { nullptr };
object_ptr<Ui::InputField> _monospacedFontName = { nullptr };
Ui::Text::String _about;
int _aboutHeight = 0; QPointer<Ui::Checkbox> _useSystemFont;
}; QPointer<Ui::Checkbox> _useOriginalMetrics;
QPointer<Ui::InputField> _mainFontName;
QPointer<Ui::InputField> _semiboldFontName;
QPointer<Ui::Checkbox> _semiboldIsBold;
QPointer<Ui::InputField> _monospacedFontName;
};

View File

@@ -9,6 +9,8 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "ui/wrap/vertical_layout.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/checkbox.h"
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
#include "ui/boxes/confirm_box.h" #include "ui/boxes/confirm_box.h"
@@ -32,7 +34,9 @@ RadioBox::RadioBox(
, _valueCount(valueCount) , _valueCount(valueCount)
, _labelGetter(labelGetter) , _labelGetter(labelGetter)
, _saveCallback(std::move(saveCallback)) , _saveCallback(std::move(saveCallback))
, _warnRestart(warnRestart) { , _warnRestart(warnRestart)
, _owned(this)
, _content(_owned.data()) {
} }
RadioBox::RadioBox( RadioBox::RadioBox(
@@ -50,7 +54,9 @@ RadioBox::RadioBox(
, _valueCount(valueCount) , _valueCount(valueCount)
, _labelGetter(labelGetter) , _labelGetter(labelGetter)
, _saveCallback(std::move(saveCallback)) , _saveCallback(std::move(saveCallback))
, _warnRestart(warnRestart) { , _warnRestart(warnRestart)
, _owned(this)
, _content(_owned.data()) {
} }
RadioBox::RadioBox( RadioBox::RadioBox(
@@ -68,7 +74,9 @@ RadioBox::RadioBox(
, _labelGetter(labelGetter) , _labelGetter(labelGetter)
, _descriptionGetter(descriptionGetter) , _descriptionGetter(descriptionGetter)
, _saveCallback(std::move(saveCallback)) , _saveCallback(std::move(saveCallback))
, _warnRestart(warnRestart) { , _warnRestart(warnRestart)
, _owned(this)
, _content(_owned.data()) {
} }
RadioBox::RadioBox( RadioBox::RadioBox(
@@ -88,7 +96,9 @@ RadioBox::RadioBox(
, _labelGetter(labelGetter) , _labelGetter(labelGetter)
, _descriptionGetter(descriptionGetter) , _descriptionGetter(descriptionGetter)
, _saveCallback(std::move(saveCallback)) , _saveCallback(std::move(saveCallback))
, _warnRestart(warnRestart) { , _warnRestart(warnRestart)
, _owned(this)
, _content(_owned.data()) {
} }
void RadioBox::prepare() { void RadioBox::prepare() {
@@ -97,11 +107,9 @@ void RadioBox::prepare() {
addButton(tr::lng_settings_save(), [=] { save(); }); addButton(tr::lng_settings_save(), [=] { save(); });
addButton(tr::lng_cancel(), [=] { closeBox(); }); addButton(tr::lng_cancel(), [=] { closeBox(); });
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
if (!_description.isEmpty()) { if (!_description.isEmpty()) {
content->add( _content->add(
object_ptr<Ui::FlatLabel>(this, _description, st::boxDividerLabel), object_ptr<Ui::FlatLabel>(_content, _description, st::boxDividerLabel),
style::margins( style::margins(
st::boxPadding.left(), st::boxPadding.left(),
0, 0,
@@ -116,9 +124,9 @@ void RadioBox::prepare() {
? _descriptionGetter(i) ? _descriptionGetter(i)
: QString(); : QString();
content->add( _content->add(
object_ptr<Ui::Radiobutton>( object_ptr<Ui::Radiobutton>(
this, _content,
_group, _group,
i, i,
_labelGetter(i), _labelGetter(i),
@@ -129,8 +137,8 @@ void RadioBox::prepare() {
st::boxPadding.right(), st::boxPadding.right(),
description.isEmpty() ? st::boxPadding.bottom() : 0)); description.isEmpty() ? st::boxPadding.bottom() : 0));
if (!description.isEmpty()) { if (!description.isEmpty()) {
content->add( _content->add(
object_ptr<Ui::FlatLabel>(this, description, st::boxDividerLabel), object_ptr<Ui::FlatLabel>(_content, description, st::boxDividerLabel),
style::margins( style::margins(
st::boxPadding.left() st::boxPadding.left()
+ st::autolockButton.margin.left() + st::autolockButton.margin.left()
@@ -143,7 +151,9 @@ void RadioBox::prepare() {
} }
} }
setDimensionsToContent(st::boxWidth, content); auto wrap = object_ptr<Ui::OverrideMargins>(this, std::move(_owned));
setDimensionsToContent(st::boxWidth, wrap.data());
setInnerWidget(std::move(wrap));
} }
void RadioBox::save() { void RadioBox::save() {

View File

@@ -13,6 +13,7 @@ namespace Ui {
class RadiobuttonGroup; class RadiobuttonGroup;
class Radiobutton; class Radiobutton;
class FlatLabel; class FlatLabel;
class VerticalLayout;
} // namespace Ui } // namespace Ui
namespace Kotato { namespace Kotato {
@@ -71,6 +72,9 @@ private:
Fn<void(int)> _saveCallback; Fn<void(int)> _saveCallback;
bool _warnRestart = false; bool _warnRestart = false;
std::shared_ptr<Ui::RadiobuttonGroup> _group; std::shared_ptr<Ui::RadiobuttonGroup> _group;
object_ptr<Ui::VerticalLayout> _owned;
not_null<Ui::VerticalLayout*> _content;
}; };
} // namespace Kotato } // namespace Kotato