2017-02-03 20:07:26 +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.
|
2017-02-03 20:07:26 +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
|
2017-02-03 20:07:26 +00:00
|
|
|
*/
|
|
|
|
#include "settings/settings_layer.h"
|
|
|
|
|
2017-09-30 19:20:40 +00:00
|
|
|
#include <rpl/mappers.h>
|
2017-02-03 20:07:26 +00:00
|
|
|
#include "settings/settings_inner_widget.h"
|
|
|
|
#include "settings/settings_fixed_bar.h"
|
|
|
|
#include "styles/style_settings.h"
|
|
|
|
#include "styles/style_window.h"
|
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
#include "ui/widgets/scroll_area.h"
|
|
|
|
#include "ui/widgets/buttons.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
|
|
|
#include "ui/wrap/fade_wrap.h"
|
2017-02-03 20:07:26 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "mainwidget.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
2017-02-03 20:07:26 +00:00
|
|
|
#include "application.h"
|
2017-02-28 14:05:30 +00:00
|
|
|
#include "core/file_utilities.h"
|
2017-02-03 20:07:26 +00:00
|
|
|
#include "window/themes/window_theme.h"
|
|
|
|
|
|
|
|
namespace Settings {
|
|
|
|
|
|
|
|
Layer::Layer()
|
|
|
|
: _scroll(this, st::settingsScroll)
|
|
|
|
, _fixedBar(this)
|
|
|
|
, _fixedBarClose(this, st::settingsFixedBarClose)
|
2017-09-30 18:26:45 +00:00
|
|
|
, _fixedBarShadow(this) {
|
2017-02-03 20:07:26 +00:00
|
|
|
_fixedBar->moveToLeft(0, st::boxRadius);
|
|
|
|
_fixedBarClose->moveToRight(0, 0);
|
|
|
|
_fixedBarShadow->entity()->resize(width(), st::lineWidth);
|
|
|
|
_fixedBarShadow->moveToLeft(0, _fixedBar->y() + _fixedBar->height());
|
2017-09-30 19:20:40 +00:00
|
|
|
_fixedBarShadow->hide(anim::type::instant);
|
2017-02-03 20:07:26 +00:00
|
|
|
_scroll->moveToLeft(0, st::settingsFixedBarHeight);
|
|
|
|
|
2017-09-30 19:20:40 +00:00
|
|
|
using namespace rpl::mappers;
|
|
|
|
_fixedBarShadow->toggleOn(_scroll->scrollTopValue()
|
2017-11-20 12:32:55 +00:00
|
|
|
| rpl::map(_1 > 0));
|
2017-02-03 20:07:26 +00:00
|
|
|
}
|
|
|
|
|
2017-02-26 11:32:13 +00:00
|
|
|
void Layer::setCloseClickHandler(base::lambda<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_fixedBarClose->setClickedCallback(std::move(callback));
|
2017-02-03 20:07:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::resizeToWidth(int newWidth, int newContentLeft) {
|
|
|
|
// Widget height depends on InnerWidget height, so we
|
|
|
|
// resize it here, not in the resizeEvent() handler.
|
|
|
|
_inner->resizeToWidth(newWidth, newContentLeft);
|
|
|
|
|
|
|
|
resizeUsingInnerHeight(newWidth, _inner->height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::doSetInnerWidget(object_ptr<LayerInner> widget) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_inner = _scroll->setOwnedWidget(std::move(widget));
|
2017-12-22 07:05:20 +00:00
|
|
|
_inner->heightValue(
|
|
|
|
) | rpl::start_with_next([this](int innerHeight) {
|
|
|
|
resizeUsingInnerHeight(width(), innerHeight);
|
|
|
|
}, lifetime());
|
2017-02-03 20:07:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
auto clip = e->rect();
|
|
|
|
if (_roundedCorners) {
|
|
|
|
auto paintTopRounded = clip.intersects(QRect(0, 0, width(), st::boxRadius));
|
|
|
|
auto paintBottomRounded = clip.intersects(QRect(0, height() - st::boxRadius, width(), st::boxRadius));
|
|
|
|
if (paintTopRounded || paintBottomRounded) {
|
2017-08-31 16:28:58 +00:00
|
|
|
auto parts = RectPart::None | 0;
|
2017-05-24 12:20:50 +00:00
|
|
|
if (paintTopRounded) parts |= RectPart::FullTop;
|
|
|
|
if (paintBottomRounded) parts |= RectPart::FullBottom;
|
2017-02-03 20:07:26 +00:00
|
|
|
App::roundRect(p, rect(), st::boxBg, BoxCorners, nullptr, parts);
|
|
|
|
}
|
|
|
|
auto other = clip.intersected(QRect(0, st::boxRadius, width(), height() - 2 * st::boxRadius));
|
|
|
|
if (!other.isEmpty()) {
|
|
|
|
p.fillRect(other, st::boxBg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
p.fillRect(e->rect(), st::boxBg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::resizeEvent(QResizeEvent *e) {
|
|
|
|
LayerWidget::resizeEvent(e);
|
|
|
|
if (!width() || !height()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_fixedBar->resizeToWidth(width());
|
|
|
|
_fixedBar->moveToLeft(0, st::boxRadius);
|
2017-09-30 18:26:45 +00:00
|
|
|
_fixedBar->update();
|
2017-02-03 20:07:26 +00:00
|
|
|
_fixedBarClose->moveToRight(0, 0);
|
|
|
|
auto shadowTop = _fixedBar->y() + _fixedBar->height();
|
|
|
|
_fixedBarShadow->entity()->resize(width(), st::lineWidth);
|
|
|
|
_fixedBarShadow->moveToLeft(0, shadowTop);
|
|
|
|
|
|
|
|
auto scrollSize = QSize(width(), height() - shadowTop - (_roundedCorners ? st::boxRadius : 0));
|
|
|
|
if (_scroll->size() != scrollSize) {
|
|
|
|
_scroll->resize(scrollSize);
|
|
|
|
}
|
|
|
|
if (!_scroll->isHidden()) {
|
|
|
|
auto scrollTop = _scroll->scrollTop();
|
|
|
|
_inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layer::setTitle(const QString &title) {
|
|
|
|
_fixedBar->setText(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Settings
|