2016-08-19 17:26:31 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
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"
|
2016-08-19 17:26:31 +00:00
|
|
|
|
|
|
|
namespace Settings {
|
|
|
|
|
2016-10-26 16:43:13 +00:00
|
|
|
BlockWidget::BlockWidget(QWidget *parent, UserData *self, const QString &title) : TWidget(parent)
|
2016-08-19 17:26:31 +00:00
|
|
|
, _self(self)
|
|
|
|
, _title(title) {
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
for_const (auto &row, _rows) {
|
2016-12-02 19:16:35 +00:00
|
|
|
auto childMargins = row.child->getMargins();
|
2016-08-28 19:16:23 +00:00
|
|
|
row.child->moveToLeft(x + row.margin.left(), result + row.margin.top(), newWidth);
|
|
|
|
auto availRowWidth = availw - row.margin.left() - row.margin.right() - x;
|
2016-08-22 17:16:21 +00:00
|
|
|
auto natural = row.child->naturalWidth();
|
2016-08-28 19:16:23 +00:00
|
|
|
auto rowWidth = (natural < 0) ? availRowWidth : qMin(natural, availRowWidth);
|
2016-12-02 19:16:35 +00:00
|
|
|
if (row.child->widthNoMargins() != rowWidth) {
|
2016-08-22 17:16:21 +00:00
|
|
|
row.child->resizeToWidth(rowWidth);
|
|
|
|
}
|
2016-12-02 19:16:35 +00:00
|
|
|
result += row.margin.top() + row.child->heightNoMargins() + row.margin.bottom();
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
result += st::settingsBlockMarginBottom;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
int titleTop = st::settingsBlockMarginTop + st::settingsBlockTitleTop;
|
|
|
|
p.drawTextLeft(contentLeft(), titleTop, width(), _title);
|
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void BlockWidget::addCreatedRow(TWidget *child, const style::margins &margin) {
|
|
|
|
_rows.push_back({ child, margin });
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockWidget::rowHeightUpdated() {
|
|
|
|
auto newHeight = resizeGetHeight(width());
|
|
|
|
if (newHeight != height()) {
|
|
|
|
resize(width(), newHeight);
|
|
|
|
emit heightUpdated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-07 11:16:37 +00:00
|
|
|
void BlockWidget::createChildRow(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
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void BlockWidget::createChildRow(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
|