2016-05-12 16:05:20 +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-05-12 16:05:20 +00:00
|
|
|
*/
|
|
|
|
#include "profile/profile_widget.h"
|
|
|
|
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "styles/style_settings.h"
|
2016-05-14 16:57:06 +00:00
|
|
|
#include "profile/profile_fixed_bar.h"
|
2016-05-12 16:05:20 +00:00
|
|
|
#include "profile/profile_inner_widget.h"
|
2016-05-19 12:03:51 +00:00
|
|
|
#include "profile/profile_section_memento.h"
|
2016-05-12 16:05:20 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "application.h"
|
2016-12-13 17:07:56 +00:00
|
|
|
#include "ui/effects/widget_fade_wrap.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2016-12-08 14:08:54 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
2016-05-12 16:05:20 +00:00
|
|
|
|
|
|
|
namespace Profile {
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
Widget::Widget(QWidget *parent, not_null<Window::Controller*> controller, PeerData *peer) : Window::SectionWidget(parent, controller)
|
2016-11-16 10:44:06 +00:00
|
|
|
, _scroll(this, st::settingsScroll)
|
2016-06-06 11:35:49 +00:00
|
|
|
, _fixedBar(this, peer)
|
2016-12-21 15:05:58 +00:00
|
|
|
, _fixedBarShadow(this, object_ptr<Ui::PlainShadow>(this, st::shadowFg)) {
|
2016-05-14 16:57:06 +00:00
|
|
|
_fixedBar->move(0, 0);
|
|
|
|
_fixedBar->resizeToWidth(width());
|
|
|
|
_fixedBar->show();
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
_fixedBarShadow->hideFast();
|
2016-05-19 12:03:51 +00:00
|
|
|
_fixedBarShadow->raise();
|
|
|
|
updateAdaptiveLayout();
|
2016-08-27 04:49:18 +00:00
|
|
|
subscribe(Adaptive::Changed(), [this]() { updateAdaptiveLayout(); });
|
2016-05-19 12:03:51 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
_inner = _scroll->setOwnedWidget(object_ptr<InnerWidget>(this, peer));
|
2016-05-14 16:57:06 +00:00
|
|
|
_scroll->move(0, _fixedBar->height());
|
2016-05-12 16:05:20 +00:00
|
|
|
_scroll->show();
|
|
|
|
|
|
|
|
connect(_scroll, SIGNAL(scrolled()), this, SLOT(onScroll()));
|
2016-05-25 17:59:21 +00:00
|
|
|
connect(_inner, SIGNAL(cancelled()), _fixedBar, SLOT(onBack()));
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
void Widget::updateAdaptiveLayout() {
|
|
|
|
_fixedBarShadow->moveToLeft(Adaptive::OneColumn() ? 0 : st::lineWidth, _fixedBar->height());
|
|
|
|
}
|
|
|
|
|
2016-05-12 16:05:20 +00:00
|
|
|
PeerData *Widget::peer() const {
|
|
|
|
return _inner->peer();
|
|
|
|
}
|
|
|
|
|
2016-12-08 14:08:54 +00:00
|
|
|
bool Widget::hasTopBarShadow() const {
|
2016-12-13 17:07:56 +00:00
|
|
|
return !_fixedBarShadow->isHidden() && !_fixedBarShadow->animating();
|
2016-12-08 14:08:54 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
QPixmap Widget::grabForShowAnimation(const Window::SectionSlideParams ¶ms) {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (params.withTopBarShadow || !_scroll->scrollTop()) _fixedBarShadow->hide();
|
2016-05-19 12:03:51 +00:00
|
|
|
auto result = myGrab(this);
|
|
|
|
if (params.withTopBarShadow) _fixedBarShadow->show();
|
|
|
|
return result;
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
2017-01-14 18:50:16 +00:00
|
|
|
void Widget::doSetInnerFocus() {
|
2016-05-19 12:03:51 +00:00
|
|
|
_inner->setFocus();
|
|
|
|
}
|
2016-05-14 16:57:06 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
bool Widget::showInternal(not_null<Window::SectionMemento*> memento) {
|
2017-06-24 17:05:32 +00:00
|
|
|
if (auto profileMemento = dynamic_cast<SectionMemento*>(memento.get())) {
|
2016-10-23 21:03:10 +00:00
|
|
|
if (profileMemento->getPeer() == peer()) {
|
|
|
|
restoreState(profileMemento);
|
2016-05-19 12:03:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2016-05-14 16:57:06 +00:00
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void Widget::setInternalState(const QRect &geometry, not_null<SectionMemento*> memento) {
|
2016-10-23 21:03:10 +00:00
|
|
|
setGeometry(geometry);
|
2016-05-19 12:03:51 +00:00
|
|
|
myEnsureResized(this);
|
2016-10-23 21:03:10 +00:00
|
|
|
restoreState(memento);
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
2017-06-24 17:05:32 +00:00
|
|
|
std::unique_ptr<Window::SectionMemento> Widget::createMemento() {
|
2017-02-21 13:45:56 +00:00
|
|
|
auto result = std::make_unique<SectionMemento>(peer());
|
2016-10-23 21:03:10 +00:00
|
|
|
saveState(result.get());
|
2017-02-21 13:45:56 +00:00
|
|
|
return std::move(result);
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void Widget::saveState(not_null<SectionMemento*> memento) {
|
2016-10-23 21:03:10 +00:00
|
|
|
memento->setScrollTop(_scroll->scrollTop());
|
|
|
|
_inner->saveState(memento);
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
void Widget::restoreState(not_null<SectionMemento*> memento) {
|
2016-10-23 21:03:10 +00:00
|
|
|
_inner->restoreState(memento);
|
|
|
|
auto scrollTop = memento->getScrollTop();
|
|
|
|
_scroll->scrollToY(scrollTop);
|
2016-12-13 17:07:56 +00:00
|
|
|
updateScrollState();
|
|
|
|
_fixedBarShadow->finishAnimation();
|
2016-10-23 21:03:10 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 16:05:20 +00:00
|
|
|
void Widget::resizeEvent(QResizeEvent *e) {
|
2016-05-19 12:03:51 +00:00
|
|
|
if (!width() || !height()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int newScrollTop = _scroll->scrollTop() + topDelta();
|
2016-05-14 16:57:06 +00:00
|
|
|
_fixedBar->resizeToWidth(width());
|
2016-12-13 17:07:56 +00:00
|
|
|
_fixedBarShadow->entity()->resize(width(), st::lineWidth);
|
2016-05-14 16:57:06 +00:00
|
|
|
|
|
|
|
QSize scrollSize(width(), height() - _fixedBar->height());
|
|
|
|
if (_scroll->size() != scrollSize) {
|
|
|
|
_scroll->resize(scrollSize);
|
2016-08-17 15:14:08 +00:00
|
|
|
_inner->resizeToWidth(scrollSize.width(), _scroll->height());
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
2016-05-27 15:45:35 +00:00
|
|
|
_fixedBar->setHideShareContactButton(_inner->shareContactButtonShown());
|
2016-05-27 13:56:35 +00:00
|
|
|
|
2016-05-12 16:05:20 +00:00
|
|
|
if (!_scroll->isHidden()) {
|
2016-05-19 12:03:51 +00:00
|
|
|
if (topDelta()) {
|
2016-05-12 16:05:20 +00:00
|
|
|
_scroll->scrollToY(newScrollTop);
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
updateScrollState();
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void Widget::updateScrollState() {
|
|
|
|
auto scrollTop = _scroll->scrollTop();
|
2016-05-14 16:57:06 +00:00
|
|
|
_inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height());
|
2016-12-13 17:07:56 +00:00
|
|
|
if (scrollTop > 0) {
|
|
|
|
_fixedBarShadow->showAnimated();
|
|
|
|
} else {
|
|
|
|
_fixedBarShadow->hideAnimated();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::onScroll() {
|
|
|
|
updateScrollState();
|
2016-05-14 16:57:06 +00:00
|
|
|
}
|
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
void Widget::showAnimatedHook() {
|
|
|
|
_fixedBar->setAnimatingMode(true);
|
|
|
|
}
|
2016-05-14 16:57:06 +00:00
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
void Widget::showFinishedHook() {
|
2016-05-14 16:57:06 +00:00
|
|
|
_fixedBar->setAnimatingMode(false);
|
2016-12-13 17:07:56 +00:00
|
|
|
if (!_scroll->scrollTop()) {
|
|
|
|
_fixedBarShadow->hide();
|
|
|
|
}
|
2016-05-27 10:57:11 +00:00
|
|
|
_inner->showFinished();
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 16:53:41 +00:00
|
|
|
bool Widget::wheelEventFromFloatPlayer(QEvent *e) {
|
2017-05-22 15:25:49 +00:00
|
|
|
return _scroll->viewportEvent(e);
|
|
|
|
}
|
|
|
|
|
2017-09-16 16:53:41 +00:00
|
|
|
QRect Widget::rectForFloatPlayer() const {
|
2017-05-22 15:25:49 +00:00
|
|
|
return mapToGlobal(_scroll->geometry());
|
|
|
|
}
|
|
|
|
|
2016-05-12 16:05:20 +00:00
|
|
|
} // namespace Profile
|