tdesktop/Telegram/SourceFiles/info/profile/info_profile_inner_widget.cpp

268 lines
8.1 KiB
C++
Raw Normal View History

/*
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
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
2017-09-24 15:46:37 +00:00
#include "info/profile/info_profile_inner_widget.h"
#include <rpl/combine.h>
2017-10-20 17:54:51 +00:00
#include <rpl/combine_previous.h>
2017-09-26 19:42:58 +00:00
#include <rpl/flatten_latest.h>
#include "info/info_memento.h"
#include "info/info_controller.h"
#include "info/info_top_bar_override.h"
#include "info/profile/info_profile_button.h"
#include "info/profile/info_profile_widget.h"
#include "info/profile/info_profile_text.h"
#include "info/profile/info_profile_values.h"
#include "info/profile/info_profile_cover.h"
#include "info/profile/info_profile_icon.h"
2017-09-25 16:06:53 +00:00
#include "info/profile/info_profile_members.h"
2017-11-07 11:53:05 +00:00
#include "info/profile/info_profile_actions.h"
#include "info/media/info_media_buttons.h"
#include "boxes/abstract_box.h"
#include "boxes/add_contact_box.h"
2017-09-26 19:42:58 +00:00
#include "boxes/confirm_box.h"
#include "boxes/report_box.h"
#include "mainwidget.h"
2017-09-26 19:42:58 +00:00
#include "auth_session.h"
#include "apiwrap.h"
#include "window/main_window.h"
#include "window/window_controller.h"
#include "storage/storage_shared_media.h"
#include "lang/lang_keys.h"
#include "styles/style_info.h"
2017-09-26 19:42:58 +00:00
#include "styles/style_boxes.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/checkbox.h"
#include "ui/widgets/scroll_area.h"
#include "ui/widgets/shadow.h"
#include "ui/wrap/slide_wrap.h"
#include "ui/wrap/vertical_layout.h"
#include "data/data_shared_media.h"
namespace Info {
namespace Profile {
InnerWidget::InnerWidget(
QWidget *parent,
not_null<Controller*> controller)
: RpWidget(parent)
, _controller(controller)
, _peer(_controller->peer())
, _migrated(_controller->migrated())
, _content(setupContent(this)) {
_content->heightValue()
| rpl::start_with_next([this](int height) {
resizeToWidth(width());
_desiredHeight.fire(countDesiredHeight());
}, lifetime());
}
bool InnerWidget::canHideDetailsEver() const {
return (_peer->isChat() || _peer->isMegagroup());
}
rpl::producer<bool> InnerWidget::canHideDetails() const {
using namespace rpl::mappers;
return MembersCountValue(_peer)
| rpl::map($1 > 0);
}
object_ptr<Ui::RpWidget> InnerWidget::setupContent(
2017-11-07 11:53:05 +00:00
not_null<RpWidget*> parent) {
auto result = object_ptr<Ui::VerticalLayout>(parent);
_cover = result->add(object_ptr<Cover>(
result,
_peer));
_cover->setOnlineCount(rpl::single(0));
2017-11-07 11:53:05 +00:00
auto details = SetupDetails(_controller, parent, _peer);
if (canHideDetailsEver()) {
_cover->setToggleShown(canHideDetails());
_infoWrap = result->add(object_ptr<Ui::SlideWrap<>>(
result,
std::move(details))
)->toggleOn(_cover->toggledValue());
} else {
result->add(std::move(details));
}
2017-11-07 11:53:05 +00:00
result->add(setupSharedMedia(result.data()));
if (auto members = SetupChannelMembers(_controller, result.data(), _peer)) {
result->add(std::move(members));
}
result->add(object_ptr<BoxContentDivider>(result));
2017-11-07 11:53:05 +00:00
if (auto actions = SetupActions(_controller, result.data(), _peer)) {
result->add(std::move(actions));
}
2017-11-07 11:53:05 +00:00
2017-09-25 16:06:53 +00:00
if (_peer->isChat() || _peer->isMegagroup()) {
_members = result->add(object_ptr<Members>(
2017-09-25 16:06:53 +00:00
result,
_controller,
_peer)
);
_members->scrollToRequests()
| rpl::start_with_next([this](Ui::ScrollToRequest request) {
auto min = (request.ymin < 0)
? request.ymin
: mapFromGlobal(_members->mapToGlobal({ 0, request.ymin })).y();
auto max = (request.ymin < 0)
? mapFromGlobal(_members->mapToGlobal({ 0, 0 })).y()
: (request.ymax < 0)
? request.ymax
: mapFromGlobal(_members->mapToGlobal({ 0, request.ymax })).y();
_scrollToRequests.fire({ min, max });
}, _members->lifetime());
_cover->setOnlineCount(_members->onlineCountValue());
2017-09-25 16:06:53 +00:00
}
return std::move(result);
}
object_ptr<Ui::RpWidget> InnerWidget::setupSharedMedia(
2017-11-07 11:53:05 +00:00
not_null<RpWidget*> parent) {
using namespace rpl::mappers;
using MediaType = Media::Type;
auto content = object_ptr<Ui::VerticalLayout>(parent);
auto tracker = Ui::MultiSlideTracker();
2017-10-20 17:54:51 +00:00
auto addMediaButton = [&](
MediaType type,
const style::icon &icon) {
auto result = Media::AddButton(
content,
_controller->window(),
_peer,
_migrated,
type,
tracker);
2017-10-20 17:54:51 +00:00
object_ptr<Profile::FloatingIcon>(
result,
icon,
st::infoSharedMediaButtonIconPosition);
};
2017-10-20 17:54:51 +00:00
auto addCommonGroupsButton = [&](
not_null<UserData*> user,
const style::icon &icon) {
auto result = Media::AddCommonGroupsButton(
content,
_controller->window(),
user,
tracker);
2017-10-20 17:54:51 +00:00
object_ptr<Profile::FloatingIcon>(
result,
icon,
st::infoSharedMediaButtonIconPosition);
};
2017-10-20 17:54:51 +00:00
addMediaButton(MediaType::Photo, st::infoIconMediaPhoto);
addMediaButton(MediaType::Video, st::infoIconMediaVideo);
addMediaButton(MediaType::File, st::infoIconMediaFile);
addMediaButton(MediaType::MusicFile, st::infoIconMediaAudio);
addMediaButton(MediaType::Link, st::infoIconMediaLink);
if (auto user = _peer->asUser()) {
2017-10-20 17:54:51 +00:00
addCommonGroupsButton(user, st::infoIconMediaGroup);
}
2017-10-20 17:54:51 +00:00
addMediaButton(MediaType::VoiceFile, st::infoIconMediaVoice);
// addMediaButton(MediaType::RoundFile, st::infoIconMediaRound);
auto result = object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
parent,
object_ptr<Ui::VerticalLayout>(parent)
);
2017-10-20 17:54:51 +00:00
using ToggledData = std::tuple<bool, Wrap, bool>;
rpl::combine(
tracker.atLeastOneShownValue(),
_controller->wrapValue(),
2017-11-06 08:09:58 +00:00
_isStackBottom.value())
2017-10-20 17:54:51 +00:00
| rpl::combine_previous(ToggledData())
| rpl::start_with_next([wrap = result.data()](
const ToggledData &was,
const ToggledData &now) {
bool wasOneShown, wasStackBottom, nowOneShown, nowStackBottom;
Wrap wasWrap, nowWrap;
std::tie(wasOneShown, wasWrap, wasStackBottom) = was;
std::tie(nowOneShown, nowWrap, nowStackBottom) = now;
// MSVC Internal Compiler Error
//auto [wasOneShown, wasWrap, wasStackBottom] = was;
//auto [nowOneShown, nowWrap, nowStackBottom] = now;
wrap->toggle(
nowOneShown && (nowWrap != Wrap::Side || !nowStackBottom),
2017-11-06 08:09:58 +00:00
(wasStackBottom == nowStackBottom && wasWrap == nowWrap)
2017-10-20 17:54:51 +00:00
? anim::type::normal
: anim::type::instant);
}, result->lifetime());
auto layout = result->entity();
layout->add(object_ptr<BoxContentDivider>(layout));
layout->add(object_ptr<Ui::FixedHeightWidget>(
layout,
st::infoSharedMediaBottomSkip)
)->setAttribute(Qt::WA_TransparentForMouseEvents);
2017-10-20 17:54:51 +00:00
layout->add(std::move(content));
layout->add(object_ptr<Ui::FixedHeightWidget>(
layout,
st::infoSharedMediaBottomSkip)
)->setAttribute(Qt::WA_TransparentForMouseEvents);
_sharedMediaWrap = result;
return std::move(result);
}
int InnerWidget::countDesiredHeight() const {
return _content->height() + (_members
? (_members->desiredHeight() - _members->height())
: 0);
}
void InnerWidget::visibleTopBottomUpdated(
int visibleTop,
int visibleBottom) {
2017-09-25 16:06:53 +00:00
setChildVisibleTopBottom(_content, visibleTop, visibleBottom);
}
void InnerWidget::saveState(not_null<Memento*> memento) {
memento->setInfoExpanded(_cover->toggled());
if (_members) {
_members->saveState(memento);
}
}
void InnerWidget::restoreState(not_null<Memento*> memento) {
_cover->toggle(memento->infoExpanded(), anim::type::instant);
if (_members) {
_members->restoreState(memento);
}
if (_infoWrap) {
_infoWrap->finishAnimating();
}
if (_sharedMediaWrap) {
_sharedMediaWrap->finishAnimating();
}
}
int InnerWidget::resizeGetHeight(int newWidth) {
_content->resizeToWidth(newWidth);
2017-09-21 10:28:34 +00:00
_content->moveToLeft(0, 0);
return _content->heightNoMargins();
}
} // namespace Profile
} // namespace Info