2017-09-13 17:01:23 +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-09-13 17:01:23 +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-09-13 17:01:23 +00:00
|
|
|
*/
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "info/info_layer_widget.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
#include <rpl/mappers.h>
|
|
|
|
#include "info/info_content_widget.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
#include "info/info_top_bar.h"
|
2017-09-30 18:26:45 +00:00
|
|
|
#include "info/info_memento.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2017-09-25 16:06:53 +00:00
|
|
|
#include "ui/focus_persister.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
|
|
|
#include "window/section_widget.h"
|
|
|
|
#include "window/window_controller.h"
|
|
|
|
#include "window/main_window.h"
|
2017-09-19 10:32:34 +00:00
|
|
|
#include "auth_session.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
#include "styles/style_info.h"
|
|
|
|
#include "styles/style_settings.h"
|
|
|
|
#include "styles/style_window.h"
|
|
|
|
#include "styles/style_boxes.h"
|
|
|
|
|
|
|
|
namespace Info {
|
2017-09-19 10:32:34 +00:00
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
LayerWidget::LayerWidget(
|
2017-09-13 17:01:23 +00:00
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
not_null<Memento*> memento)
|
2017-09-15 17:34:41 +00:00
|
|
|
: _controller(controller)
|
2017-09-30 18:26:45 +00:00
|
|
|
, _content(this, controller, Wrap::Layer, memento) {
|
2017-09-15 17:34:41 +00:00
|
|
|
setupHeightConsumers();
|
|
|
|
}
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
LayerWidget::LayerWidget(
|
2017-09-15 17:34:41 +00:00
|
|
|
not_null<Window::Controller*> controller,
|
|
|
|
not_null<MoveMemento*> memento)
|
|
|
|
: _controller(controller)
|
2017-09-30 18:26:45 +00:00
|
|
|
, _content(memento->takeContent(this, Wrap::Layer)) {
|
2017-09-15 17:34:41 +00:00
|
|
|
setupHeightConsumers();
|
|
|
|
}
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
void LayerWidget::setupHeightConsumers() {
|
2017-12-22 07:05:20 +00:00
|
|
|
_content->scrollTillBottomChanges(
|
|
|
|
) | rpl::filter([this] {
|
|
|
|
return !_inResize;
|
|
|
|
}) | rpl::start_with_next([this] {
|
|
|
|
resizeToWidth(width());
|
|
|
|
}, lifetime());
|
|
|
|
_content->desiredHeightValue(
|
|
|
|
) | rpl::start_with_next([this](int height) {
|
|
|
|
accumulate_max(_desiredHeight, height);
|
|
|
|
if (_content && !_inResize) {
|
2017-11-23 12:48:56 +00:00
|
|
|
resizeToWidth(width());
|
2017-12-22 07:05:20 +00:00
|
|
|
}
|
|
|
|
}, lifetime());
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
void LayerWidget::showFinished() {
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
void LayerWidget::parentResized() {
|
2017-09-13 17:01:23 +00:00
|
|
|
auto parentSize = parentWidget()->size();
|
2017-09-19 10:32:34 +00:00
|
|
|
auto parentWidth = parentSize.width();
|
|
|
|
if (parentWidth < MinimalSupportedWidth()) {
|
2017-09-25 16:06:53 +00:00
|
|
|
Ui::FocusPersister persister(this);
|
2017-09-15 17:34:41 +00:00
|
|
|
auto localCopy = _controller;
|
2017-09-30 18:26:45 +00:00
|
|
|
auto memento = MoveMemento(std::move(_content));
|
2017-09-20 10:23:57 +00:00
|
|
|
localCopy->hideSpecialLayer(anim::type::instant);
|
|
|
|
localCopy->showSection(
|
|
|
|
std::move(memento),
|
2017-10-03 13:05:58 +00:00
|
|
|
Window::SectionShow(
|
|
|
|
Window::SectionShow::Way::Forward,
|
|
|
|
anim::type::instant,
|
|
|
|
anim::activation::background));
|
2017-12-06 07:05:18 +00:00
|
|
|
//
|
|
|
|
// There was a layout logic which caused layer info to become a
|
|
|
|
// third column info if the window size allows, but it was decided
|
|
|
|
// to keep layer info and third column info separated.
|
|
|
|
//
|
2017-12-04 07:33:33 +00:00
|
|
|
//} else if (_controller->canShowThirdSectionWithoutResize()) {
|
|
|
|
// takeToThirdSection();
|
2017-09-15 17:34:41 +00:00
|
|
|
} else {
|
|
|
|
auto newWidth = qMin(
|
2017-09-19 10:32:34 +00:00
|
|
|
parentWidth - 2 * st::infoMinimalLayerMargin,
|
2017-09-15 17:34:41 +00:00
|
|
|
st::infoDesiredWidth);
|
|
|
|
resizeToWidth(newWidth);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
bool LayerWidget::takeToThirdSection() {
|
2017-12-04 07:33:33 +00:00
|
|
|
return false;
|
2017-12-06 07:05:18 +00:00
|
|
|
//
|
|
|
|
// There was a layout logic which caused layer info to become a
|
|
|
|
// third column info if the window size allows, but it was decided
|
|
|
|
// to keep layer info and third column info separated.
|
|
|
|
//
|
2017-12-04 07:33:33 +00:00
|
|
|
//Ui::FocusPersister persister(this);
|
|
|
|
//auto localCopy = _controller;
|
|
|
|
//auto memento = MoveMemento(std::move(_content));
|
|
|
|
//localCopy->hideSpecialLayer(anim::type::instant);
|
|
|
|
|
|
|
|
//// When creating third section in response to the window
|
|
|
|
//// size allowing it to fit without window resize we want
|
|
|
|
//// to save that we didn't extend the window while showing
|
|
|
|
//// the third section, so that when we close it we won't
|
|
|
|
//// shrink the window size.
|
|
|
|
////
|
|
|
|
//// See https://github.com/telegramdesktop/tdesktop/issues/4091
|
2018-01-04 10:22:53 +00:00
|
|
|
//Auth().settings().setThirdSectionExtendedBy(0);
|
2017-12-04 07:33:33 +00:00
|
|
|
|
2018-01-04 10:22:53 +00:00
|
|
|
//Auth().settings().setThirdSectionInfoEnabled(true);
|
|
|
|
//Auth().saveSettingsDelayed();
|
2017-12-04 07:33:33 +00:00
|
|
|
//localCopy->showSection(
|
|
|
|
// std::move(memento),
|
|
|
|
// Window::SectionShow(
|
|
|
|
// Window::SectionShow::Way::ClearStack,
|
|
|
|
// anim::type::instant,
|
|
|
|
// anim::activation::background));
|
|
|
|
//return true;
|
2017-09-19 10:32:34 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
bool LayerWidget::showSectionInternal(
|
|
|
|
not_null<Window::SectionMemento*> memento,
|
|
|
|
const Window::SectionShow ¶ms) {
|
2017-11-16 07:45:55 +00:00
|
|
|
if (_content->showInternal(memento, params)) {
|
|
|
|
if (params.activation != anim::activation::background) {
|
|
|
|
Ui::hideLayer();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-10-03 13:05:58 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
int LayerWidget::MinimalSupportedWidth() {
|
2017-09-15 17:34:41 +00:00
|
|
|
auto minimalMargins = 2 * st::infoMinimalLayerMargin;
|
|
|
|
return st::infoMinimalWidth + minimalMargins;
|
|
|
|
}
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
int LayerWidget::resizeGetHeight(int newWidth) {
|
2017-09-19 10:32:34 +00:00
|
|
|
if (!parentWidget() || !_content) {
|
2017-09-15 17:34:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-11-23 12:48:56 +00:00
|
|
|
_inResize = true;
|
|
|
|
auto guard = gsl::finally([&] { _inResize = false; });
|
2017-09-13 17:01:23 +00:00
|
|
|
|
|
|
|
auto parentSize = parentWidget()->size();
|
|
|
|
auto windowWidth = parentSize.width();
|
|
|
|
auto windowHeight = parentSize.height();
|
2017-11-23 12:48:56 +00:00
|
|
|
auto newLeft = (windowWidth - newWidth) / 2;
|
2017-11-22 09:56:00 +00:00
|
|
|
auto newTop = snap(
|
2017-11-19 11:37:15 +00:00
|
|
|
windowHeight / 24,
|
|
|
|
st::infoLayerTopMinimal,
|
|
|
|
st::infoLayerTopMaximal);
|
2017-11-23 12:48:56 +00:00
|
|
|
auto newBottom = newTop;
|
|
|
|
auto desiredHeight = st::boxRadius + _desiredHeight + st::boxRadius;
|
|
|
|
accumulate_min(desiredHeight, windowHeight - newTop - newBottom);
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
// First resize content to new width and get the new desired height.
|
2017-11-23 12:48:56 +00:00
|
|
|
auto contentLeft = 0;
|
2017-09-30 18:26:45 +00:00
|
|
|
auto contentTop = st::boxRadius;
|
2017-11-23 12:48:56 +00:00
|
|
|
auto contentBottom = st::boxRadius;
|
|
|
|
auto contentWidth = newWidth;
|
|
|
|
auto contentHeight = desiredHeight - contentTop - contentBottom;
|
|
|
|
auto scrollTillBottom = _content->scrollTillBottom(contentHeight);
|
|
|
|
auto additionalScroll = std::min(scrollTillBottom, newBottom);
|
|
|
|
|
|
|
|
desiredHeight += additionalScroll;
|
|
|
|
contentHeight += additionalScroll;
|
|
|
|
_tillBottom = (newTop + desiredHeight >= windowHeight);
|
|
|
|
if (_tillBottom) {
|
|
|
|
contentHeight += contentBottom;
|
|
|
|
additionalScroll += contentBottom;
|
|
|
|
}
|
|
|
|
_content->updateGeometry({
|
|
|
|
contentLeft,
|
|
|
|
contentTop,
|
|
|
|
contentWidth,
|
|
|
|
contentHeight }, additionalScroll);
|
|
|
|
|
|
|
|
auto newGeometry = QRect(newLeft, newTop, newWidth, desiredHeight);
|
|
|
|
if (newGeometry != geometry()) {
|
|
|
|
_content->forceContentRepaint();
|
|
|
|
}
|
|
|
|
if (newGeometry.topLeft() != geometry().topLeft()) {
|
|
|
|
move(newGeometry.topLeft());
|
2017-09-30 18:26:45 +00:00
|
|
|
}
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2017-11-23 12:48:56 +00:00
|
|
|
return desiredHeight;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
void LayerWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
2017-11-19 11:37:15 +00:00
|
|
|
|
|
|
|
auto clip = e->rect();
|
|
|
|
auto r = st::boxRadius;
|
|
|
|
auto parts = RectPart::None | 0;
|
|
|
|
if (clip.intersects({ 0, 0, width(), r })) {
|
|
|
|
parts |= RectPart::FullTop;
|
|
|
|
}
|
2017-11-23 12:48:56 +00:00
|
|
|
if (!_tillBottom) {
|
2017-09-13 17:01:23 +00:00
|
|
|
if (clip.intersects({ 0, height() - r, width(), r })) {
|
|
|
|
parts |= RectPart::FullBottom;
|
|
|
|
}
|
2017-11-19 11:37:15 +00:00
|
|
|
}
|
|
|
|
if (parts) {
|
|
|
|
App::roundRect(
|
|
|
|
p,
|
|
|
|
rect(),
|
|
|
|
st::boxBg,
|
|
|
|
BoxCorners,
|
|
|
|
nullptr,
|
|
|
|
parts);
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Info
|