mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-30 14:17:45 +00:00
Rework custom boxes to support scrolling
This commit is contained in:
parent
310a81b482
commit
8ceccc2bcb
@ -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<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()) {
|
||||
_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<Ui::OverrideMargins>(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));
|
||||
}
|
||||
}
|
||||
|
@ -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<Ui::Checkbox> _useSystemFont = { nullptr };
|
||||
object_ptr<Ui::Checkbox> _useOriginalMetrics = { nullptr };
|
||||
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;
|
||||
object_ptr<Ui::VerticalLayout> _owned;
|
||||
not_null<Ui::VerticalLayout*> _content;
|
||||
|
||||
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;
|
||||
};
|
||||
|
@ -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<Ui::VerticalLayout>(this);
|
||||
|
||||
if (!_description.isEmpty()) {
|
||||
content->add(
|
||||
object_ptr<Ui::FlatLabel>(this, _description, st::boxDividerLabel),
|
||||
_content->add(
|
||||
object_ptr<Ui::FlatLabel>(_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<Ui::Radiobutton>(
|
||||
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<Ui::FlatLabel>(this, description, st::boxDividerLabel),
|
||||
_content->add(
|
||||
object_ptr<Ui::FlatLabel>(_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<Ui::OverrideMargins>(this, std::move(_owned));
|
||||
setDimensionsToContent(st::boxWidth, wrap.data());
|
||||
setInnerWidget(std::move(wrap));
|
||||
}
|
||||
|
||||
void RadioBox::save() {
|
||||
|
@ -13,6 +13,7 @@ namespace Ui {
|
||||
class RadiobuttonGroup;
|
||||
class Radiobutton;
|
||||
class FlatLabel;
|
||||
class VerticalLayout;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Kotato {
|
||||
@ -71,6 +72,9 @@ private:
|
||||
Fn<void(int)> _saveCallback;
|
||||
bool _warnRestart = false;
|
||||
std::shared_ptr<Ui::RadiobuttonGroup> _group;
|
||||
|
||||
object_ptr<Ui::VerticalLayout> _owned;
|
||||
not_null<Ui::VerticalLayout*> _content;
|
||||
};
|
||||
|
||||
} // namespace Kotato
|
||||
|
Loading…
x
Reference in New Issue
Block a user