2016-08-19 17:26:31 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-08-19 17:26:31 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-08-19 17:26:31 +00:00
|
|
|
*/
|
|
|
|
#include "settings/settings_block_widget.h"
|
|
|
|
|
|
|
|
#include "styles/style_settings.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
2017-09-13 16:57:44 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2016-08-19 17:26:31 +00:00
|
|
|
|
|
|
|
namespace Settings {
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
BlockWidget::BlockWidget(QWidget *parent, UserData *self, const QString &title) : RpWidget(parent)
|
2017-09-18 17:04:45 +00:00
|
|
|
, _content(this)
|
2016-08-19 17:26:31 +00:00
|
|
|
, _self(self)
|
2017-09-18 17:04:45 +00:00
|
|
|
, _title(title) {
|
2017-12-22 07:05:20 +00:00
|
|
|
_content->heightValue(
|
|
|
|
) | rpl::start_with_next([this](int contentHeight) {
|
|
|
|
resize(
|
|
|
|
width(),
|
|
|
|
contentTop()
|
|
|
|
+ contentHeight
|
|
|
|
+ st::settingsBlockMarginBottom);
|
|
|
|
}, lifetime());
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BlockWidget::setContentLeft(int contentLeft) {
|
|
|
|
_contentLeft = contentLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BlockWidget::contentTop() const {
|
|
|
|
return emptyTitle() ? 0 : (st::settingsBlockMarginTop + st::settingsBlockTitleHeight);
|
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
int BlockWidget::resizeGetHeight(int newWidth) {
|
|
|
|
int x = contentLeft(), result = contentTop();
|
|
|
|
int availw = newWidth - x;
|
2017-09-13 16:57:44 +00:00
|
|
|
|
|
|
|
auto margins = getMargins();
|
|
|
|
|
|
|
|
_content->resizeToWidth(availw);
|
|
|
|
_content->moveToLeft(margins.left() + x, margins.top() + result, newWidth);
|
|
|
|
result += _content->heightNoMargins() + st::settingsBlockMarginBottom;
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
QMargins BlockWidget::getMargins() const {
|
|
|
|
auto result = _content->getMargins();
|
|
|
|
return QMargins(
|
|
|
|
result.left(),
|
|
|
|
qMax(result.top() - contentTop(), 0),
|
|
|
|
result.right(),
|
|
|
|
qMax(result.bottom() - st::settingsBlockMarginBottom, 0));
|
|
|
|
}
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
void BlockWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
|
|
|
paintTitle(p);
|
|
|
|
paintContents(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockWidget::paintTitle(Painter &p) {
|
|
|
|
if (emptyTitle()) return;
|
|
|
|
|
|
|
|
p.setFont(st::settingsBlockTitleFont);
|
|
|
|
p.setPen(st::settingsBlockTitleFg);
|
2017-09-13 16:57:44 +00:00
|
|
|
auto margins = getMargins();
|
|
|
|
auto titleTop = st::settingsBlockMarginTop + st::settingsBlockTitleTop;
|
|
|
|
p.drawTextLeft(
|
|
|
|
margins.left() + contentLeft(),
|
|
|
|
margins.top() + titleTop,
|
|
|
|
width(),
|
|
|
|
_title);
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
Ui::RpWidget *BlockWidget::addCreatedRow(
|
|
|
|
object_ptr<RpWidget> row,
|
|
|
|
const style::margins &margin) {
|
|
|
|
return _content->add(std::move(row), margin);
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
void BlockWidget::createChildWidget(
|
|
|
|
object_ptr<Ui::Checkbox> &child,
|
|
|
|
style::margins &margin,
|
|
|
|
const QString &text,
|
|
|
|
base::lambda<void(bool checked)> callback,
|
|
|
|
bool checked) {
|
2016-11-11 13:46:04 +00:00
|
|
|
child.create(this, text, checked, st::defaultBoxCheckbox);
|
2017-07-07 11:16:37 +00:00
|
|
|
subscribe(child->checkedChanged, std::move(callback));
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
void BlockWidget::createChildWidget(
|
|
|
|
object_ptr<Ui::LinkButton> &child,
|
|
|
|
style::margins &margin,
|
|
|
|
const QString &text,
|
|
|
|
const char *slot,
|
|
|
|
const style::LinkButton &st) {
|
2017-03-18 21:06:10 +00:00
|
|
|
child.create(this, text, st);
|
2016-08-27 04:49:18 +00:00
|
|
|
connect(child, SIGNAL(clicked()), this, slot);
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
} // namespace Settings
|