Move info between Layer and Narrow wrap.

This commit is contained in:
John Preston 2017-09-15 20:34:41 +03:00
parent 088d23d557
commit f162462111
51 changed files with 758 additions and 323 deletions

View file

@ -355,7 +355,13 @@ void GroupInfoBox::setupPhotoButton() {
if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) {
return;
}
auto box = Ui::show(Box<PhotoCropBox>(img, (_creating == CreatingGroupChannel) ? peerFromChannel(0) : peerFromChat(0)), KeepOtherLayers);
auto box = Ui::show(
Box<PhotoCropBox>(
img,
(_creating == CreatingGroupChannel)
? peerFromChannel(0)
: peerFromChat(0)),
LayerOption::KeepOther);
connect(box, SIGNAL(ready(const QImage&)), this, SLOT(onPhotoReady(const QImage&)));
}));
}));
@ -445,9 +451,14 @@ void GroupInfoBox::createGroup(not_null<PeerListBox*> selectUsersBox, const QStr
}
} else if (error.type() == qstr("USERS_TOO_FEW")) {
} else if (error.type() == qstr("PEER_FLOOD")) {
Ui::show(Box<InformBox>(PeerFloodErrorText(PeerFloodType::InviteGroup)), KeepOtherLayers);
Ui::show(
Box<InformBox>(
PeerFloodErrorText(PeerFloodType::InviteGroup)),
LayerOption::KeepOther);
} else if (error.type() == qstr("USER_RESTRICTED")) {
Ui::show(Box<InformBox>(lang(lng_cant_do_this)), KeepOtherLayers);
Ui::show(
Box<InformBox>(lang(lng_cant_do_this)),
LayerOption::KeepOther);
}
}).send();
}
@ -476,7 +487,12 @@ void GroupInfoBox::onNext() {
});
box->addButton(langFactory(lng_cancel), [box] { box->closeBox(); });
};
Ui::show(Box<PeerListBox>(std::make_unique<AddParticipantsBoxController>(nullptr), std::move(initBox)), KeepOtherLayers);
Ui::show(
Box<PeerListBox>(
std::make_unique<AddParticipantsBoxController>(
nullptr),
std::move(initBox)),
LayerOption::KeepOther);
}
}
@ -792,7 +808,7 @@ void SetupChannelBox::privacyChanged(Privacy value) {
_tooMuchUsernames = false;
_privacyGroup->setValue(Privacy::Public);
onCheck();
})), KeepOtherLayers);
})), LayerOption::KeepOther);
return;
}
_link->show();
@ -883,8 +899,10 @@ bool SetupChannelBox::onCheckFail(const RPCError &error) {
void SetupChannelBox::showRevokePublicLinkBoxForEdit() {
closeBox();
Ui::show(Box<RevokePublicLinkBox>([channel = _channel, existing = _existing]() {
Ui::show(Box<SetupChannelBox>(channel, existing), KeepOtherLayers);
}), KeepOtherLayers);
Ui::show(
Box<SetupChannelBox>(channel, existing),
LayerOption::KeepOther);
}), LayerOption::KeepOther);
}
bool SetupChannelBox::onFirstCheckFail(const RPCError &error) {
@ -1278,7 +1296,9 @@ void EditChannelBox::onSave() {
}
void EditChannelBox::onPublicLink() {
Ui::show(Box<SetupChannelBox>(_channel, true), KeepOtherLayers);
Ui::show(
Box<SetupChannelBox>(_channel, true),
LayerOption::KeepOther);
}
void EditChannelBox::saveDescription() {
@ -1473,7 +1493,7 @@ void RevokePublicLinkBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
_revokeCallback();
}
}).send();
})), KeepOtherLayers);
})), LayerOption::KeepOther);
}
}

View file

@ -169,7 +169,13 @@ void ChangePhoneBox::EnterPhone::sendPhoneDone(const QString &phoneNumber, const
if (data.has_next_type() && data.vnext_type.type() == mtpc_auth_codeTypeCall) {
callTimeout = data.has_timeout() ? data.vtimeout.v : 60;
}
Ui::show(Box<EnterCode>(phoneNumber, phoneCodeHash, codeLength, callTimeout), KeepOtherLayers);
Ui::show(
Box<EnterCode>(
phoneNumber,
phoneCodeHash,
codeLength,
callTimeout),
LayerOption::KeepOther);
}
bool ChangePhoneBox::EnterPhone::sendPhoneFail(const QString &phoneNumber, const RPCError &error) {

View file

@ -51,7 +51,7 @@ void ConnectionBox::ShowApplyProxyConfirmation(const QMap<QString, QString> &fie
reinitLocationManager();
reinitWebLoadManager();
if (*weakBox) (*weakBox)->closeBox();
}), KeepOtherLayers);
}), LayerOption::KeepOther);
*weakBox = box;
}
}

View file

@ -400,7 +400,14 @@ void EditRestrictedBox::showRestrictUntil() {
auto tomorrow = QDate::currentDate().addDays(1);
auto highlighted = isUntilForever() ? tomorrow : date(getRealUntilValue()).date();
auto month = highlighted;
_restrictUntilBox = Ui::show(Box<CalendarBox>(month, highlighted, [this](const QDate &date) { setRestrictUntil(static_cast<int>(QDateTime(date).toTime_t())); }), KeepOtherLayers);
_restrictUntilBox = Ui::show(
Box<CalendarBox>(
month,
highlighted,
[this](const QDate &date) {
setRestrictUntil(static_cast<int>(QDateTime(date).toTime_t()));
}),
LayerOption::KeepOther);
_restrictUntilBox->setMaxDate(QDate::currentDate().addDays(kMaxRestrictDelayDays));
_restrictUntilBox->setMinDate(tomorrow);
_restrictUntilBox->addLeftButton(langFactory(lng_rights_chat_banned_forever), [this] { setRestrictUntil(0); });

View file

@ -205,7 +205,9 @@ void EditPrivacyBox::editExceptionUsers(Exception exception) {
}));
box->addButton(langFactory(lng_cancel), [box] { box->closeBox(); });
};
Ui::show(Box<PeerListBox>(std::move(controller), std::move(initBox)), KeepOtherLayers);
Ui::show(
Box<PeerListBox>(std::move(controller), std::move(initBox)),
LayerOption::KeepOther);
}
QString EditPrivacyBox::exceptionLinkText(Exception exception) {

View file

@ -320,7 +320,7 @@ void PasscodeBox::onSave(bool force) {
_skipEmailWarning = true;
_replacedBy = Ui::show(Box<ConfirmBox>(lang(lng_cloud_password_about_recover), lang(lng_cloud_password_skip_email), st::attentionBoxButton, base::lambda_guarded(this, [this] {
onSave(true);
})), KeepOtherLayers);
})), LayerOption::KeepOther);
} else {
QByteArray newPasswordData = pwd.isEmpty() ? QByteArray() : (_newSalt + pwd.toUtf8() + _newSalt);
QByteArray newPasswordHash = pwd.isEmpty() ? QByteArray() : QByteArray(32, Qt::Uninitialized);
@ -401,7 +401,9 @@ void PasscodeBox::onRecoverExpired() {
void PasscodeBox::recover() {
if (_pattern == "-") return;
_replacedBy = Ui::show(Box<RecoverBox>(_pattern), KeepOtherLayers);
_replacedBy = Ui::show(
Box<RecoverBox>(_pattern),
LayerOption::KeepOther);
connect(_replacedBy, SIGNAL(reloadPassword()), this, SIGNAL(reloadPassword()));
connect(_replacedBy, SIGNAL(recoveryExpired()), this, SLOT(onRecoverExpired()));
}

View file

@ -377,10 +377,14 @@ void AddParticipantsBoxController::rowClicked(not_null<PeerListRow*> row) {
updateTitle();
} else if (auto channel = _peer ? _peer->asChannel() : nullptr) {
if (!_peer->isMegagroup()) {
Ui::show(Box<MaxInviteBox>(_peer->asChannel()), KeepOtherLayers);
Ui::show(
Box<MaxInviteBox>(_peer->asChannel()),
LayerOption::KeepOther);
}
} else if (count >= Global::ChatSizeMax() && count < Global::MegagroupSizeMax()) {
Ui::show(Box<InformBox>(lng_profile_add_more_after_upgrade(lt_count, Global::MegagroupSizeMax())), KeepOtherLayers);
Ui::show(
Box<InformBox>(lng_profile_add_more_after_upgrade(lt_count, Global::MegagroupSizeMax())),
LayerOption::KeepOther);
}
}
@ -744,13 +748,17 @@ void AddBotToGroupBoxController::shareBotGame(not_null<PeerData*> chat) {
}
return lng_bot_sure_share_game_group(lt_group, chat->name);
};
Ui::show(Box<ConfirmBox>(confirmText(), send), KeepOtherLayers);
Ui::show(
Box<ConfirmBox>(confirmText(), send),
LayerOption::KeepOther);
}
void AddBotToGroupBoxController::addBotToGroup(not_null<PeerData*> chat) {
if (auto megagroup = chat->asMegagroup()) {
if (!megagroup->canAddMembers()) {
Ui::show(Box<InformBox>(lang(lng_error_cant_add_member)), KeepOtherLayers);
Ui::show(
Box<InformBox>(lang(lng_error_cant_add_member)),
LayerOption::KeepOther);
return;
}
}
@ -786,7 +794,9 @@ void AddBotToGroupBoxController::addBotToGroup(not_null<PeerData*> chat) {
Ui::showPeerHistory(chat, ShowAtUnreadMsgId);
};
auto confirmText = lng_bot_sure_invite(lt_group, chat->name);
Ui::show(Box<ConfirmBox>(confirmText, send), KeepOtherLayers);
Ui::show(
Box<ConfirmBox>(confirmText, send),
LayerOption::KeepOther);
}
std::unique_ptr<ChatsListBoxController::Row> AddBotToGroupBoxController::createRow(not_null<History*> history) {

View file

@ -317,7 +317,7 @@ void SessionsBox::Inner::onTerminate() {
i.value()->clearState();
i.value()->hide();
}
})), KeepOtherLayers);
})), LayerOption::KeepOther);
}
}
}
@ -331,7 +331,7 @@ void SessionsBox::Inner::onTerminateAll() {
}
MTP::send(MTPauth_ResetAuthorizations(), rpcDone(&Inner::terminateAllDone), rpcFail(&Inner::terminateAllFail));
emit terminateAll();
})), KeepOtherLayers);
})), LayerOption::KeepOther);
}
void SessionsBox::Inner::terminateDone(uint64 hash, const MTPBool &result) {

View file

@ -436,7 +436,9 @@ QString StickerSetBox::Inner::shortName() const {
void StickerSetBox::Inner::install() {
if (isMasksSet()) {
Ui::show(Box<InformBox>(lang(lng_stickers_masks_pack)), KeepOtherLayers);
Ui::show(
Box<InformBox>(lang(lng_stickers_masks_pack)),
LayerOption::KeepOther);
return;
}
if (_installRequest) return;

View file

@ -1077,7 +1077,9 @@ void StickersBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
setMegagroupSelectedSet(MTP_inputStickerSetID(MTP_long(it->id), MTP_long(it->access)));
} else {
setSelected(-1);
Ui::show(Box<StickerSetBox>(Stickers::inputSetId(*it)), KeepOtherLayers);
Ui::show(
Box<StickerSetBox>(Stickers::inputSetId(*it)),
LayerOption::KeepOther);
}
}
}

View file

@ -86,7 +86,7 @@ void ApplyArchivedResult(const MTPDmessages_stickerSetInstallResultArchive &d) {
toast.maxWidth = st::stickersToastMaxWidth;
toast.padding = st::stickersToastPadding;
Ui::Toast::Show(toast);
// Ui::show(Box<StickersBox>(archived), KeepOtherLayers);
// Ui::show(Box<StickersBox>(archived), LayerOption::KeepOther);
Auth().data().stickersUpdated().notify(true);
}
@ -169,7 +169,9 @@ void UndoInstallLocally(uint64 setId) {
Local::writeInstalledStickers();
Auth().data().stickersUpdated().notify(true);
Ui::show(Box<InformBox>(lang(lng_stickers_not_found)), KeepOtherLayers);
Ui::show(
Box<InformBox>(lang(lng_stickers_not_found)),
LayerOption::KeepOther);
}
void MarkFeaturedAsRead(uint64 setId) {

View file

@ -1637,7 +1637,9 @@ void StickersListWidget::displaySet(uint64 setId) {
auto it = sets.constFind(setId);
if (it != sets.cend()) {
_displayingSetId = setId;
auto box = Ui::show(Box<StickerSetBox>(Stickers::inputSetId(*it)), KeepOtherLayers);
auto box = Ui::show(
Box<StickerSetBox>(Stickers::inputSetId(*it)),
LayerOption::KeepOther);
connect(box, &QObject::destroyed, this, [this] {
_displayingSetId = 0;
emit checkForHide();

View file

@ -559,17 +559,6 @@ enum ForwardWhatMessages {
ForwardPressedLinkMessage
};
enum ShowLayerOption {
CloseOtherLayers = (1 << 0),
KeepOtherLayers = (1 << 1),
ShowAfterOtherLayers = (1 << 2),
AnimatedShowLayer = (1 << 3),
ForceFastShowLayer = (1 << 4),
};
using ShowLayerOptions = base::flags<ShowLayerOption>;
inline constexpr auto is_flag_type(ShowLayerOption) { return true; };
static int32 FullArcLength = 360 * 16;
static int32 QuarterArcLength = (FullArcLength / 4);
static int32 MinArcLength = (FullArcLength / 360);

View file

@ -42,7 +42,7 @@ void ShowSearchFromBox(PeerData *peer, base::lambda<void(not_null<UserData*>)> c
auto subscription = std::make_shared<base::Subscription>();
auto box = Ui::show(Box<PeerListBox>(std::move(controller), [subscription](not_null<PeerListBox*> box) {
box->addButton(langFactory(lng_cancel), [box, subscription] { box->closeBox(); });
}), KeepOtherLayers);
}), LayerOption::KeepOther);
*subscription = box->boxClosing.add_subscription(std::move(closedCallback));
}
}

View file

@ -24,6 +24,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "info/info_memento.h"
#include "core/click_handler_types.h"
#include "media/media_clip_reader.h"
#include "window/window_controller.h"
#include "observer_peer.h"
#include "mainwindow.h"
#include "mainwidget.h"
@ -201,7 +202,7 @@ void logOutDelayed() {
namespace Ui {
namespace internal {
void showBox(object_ptr<BoxContent> content, ShowLayerOptions options) {
void showBox(object_ptr<BoxContent> content, LayerOptions options) {
if (auto w = App::wnd()) {
w->ui_showBox(std::move(content), options);
}
@ -229,13 +230,17 @@ void hideMediaPreview() {
void hideLayer(bool fast) {
if (auto w = App::wnd()) {
w->ui_showBox({ nullptr }, CloseOtherLayers | (fast ? ForceFastShowLayer : AnimatedShowLayer));
w->ui_showBox(
{ nullptr },
LayerOption::CloseOther | (fast ? LayerOption::ForceFast : LayerOption::Animated));
}
}
void hideSettingsAndLayer(bool fast) {
if (auto w = App::wnd()) {
w->ui_hideSettingsAndLayer(fast ? ForceFastShowLayer : AnimatedShowLayer);
w->ui_hideSettingsAndLayer(fast
? LayerOption::ForceFast
: LayerOption::Animated);
}
}
@ -264,7 +269,7 @@ void showPeerProfile(const PeerId &peer) {
if (auto window = App::wnd()) {
auto memento = Info::Memento(peer);
if (auto layer = memento.createLayer(window->controller())) {
window->showSpecialLayer(std::move(layer));
window->controller()->showSpecialLayer(std::move(layer));
} else {
App::main()->showWideSection(std::move(memento));
}

View file

@ -82,10 +82,22 @@ void logOutDelayed();
} // namespace App
enum class LayerOption {
CloseOther = (1 << 0),
KeepOther = (1 << 1),
ShowAfterOther = (1 << 2),
Animated = (1 << 3),
ForceFast = (1 << 4),
};
using LayerOptions = base::flags<LayerOption>;
inline constexpr auto is_flag_type(LayerOption) { return true; };
namespace Ui {
namespace internal {
void showBox(object_ptr<BoxContent> content, ShowLayerOptions options);
void showBox(object_ptr<BoxContent> content, LayerOptions options);
} // namespace internal
@ -94,7 +106,9 @@ void showMediaPreview(PhotoData *photo);
void hideMediaPreview();
template <typename BoxType>
QPointer<BoxType> show(object_ptr<BoxType> content, ShowLayerOptions options = CloseOtherLayers) {
QPointer<BoxType> show(
object_ptr<BoxType> content,
LayerOptions options = LayerOption::CloseOther) {
auto result = QPointer<BoxType>(content.data());
internal::showBox(std::move(content), options);
return result;

View file

@ -1033,7 +1033,9 @@ void InnerWidget::suggestRestrictUser(not_null<UserData*> user) {
(*weakBox)->closeBox();
}
});
*weakBox = Ui::show(std::move(box), KeepOtherLayers);
*weakBox = Ui::show(
std::move(box),
LayerOption::KeepOther);
};
if (base::contains(_admins, user)) {
editRestrictions(true, MTP_channelBannedRights(MTP_flags(0), MTP_int(0)));

View file

@ -236,7 +236,9 @@ void FastShareMessage(not_null<HistoryItem*> item) {
restrictedEverywhere = false;
}
if (restrictedEverywhere) {
Ui::show(Box<InformBox>(firstError), KeepOtherLayers);
Ui::show(
Box<InformBox>(firstError),
LayerOption::KeepOther);
return;
}

View file

@ -5304,7 +5304,9 @@ void HistoryWidget::onFieldTabbed() {
bool HistoryWidget::onStickerSend(DocumentData *sticker) {
if (auto megagroup = _peer ? _peer->asMegagroup() : nullptr) {
if (megagroup->restrictedRights().is_send_stickers()) {
Ui::show(Box<InformBox>(lang(lng_restricted_send_stickers)), KeepOtherLayers);
Ui::show(
Box<InformBox>(lang(lng_restricted_send_stickers)),
LayerOption::KeepOther);
return false;
}
}
@ -5314,7 +5316,9 @@ bool HistoryWidget::onStickerSend(DocumentData *sticker) {
void HistoryWidget::onPhotoSend(PhotoData *photo) {
if (auto megagroup = _peer ? _peer->asMegagroup() : nullptr) {
if (megagroup->restrictedRights().is_send_media()) {
Ui::show(Box<InformBox>(lang(lng_restricted_send_media)), KeepOtherLayers);
Ui::show(
Box<InformBox>(lang(lng_restricted_send_media)),
LayerOption::KeepOther);
return;
}
}

View file

@ -37,6 +37,7 @@ infoTopBarBack: IconButton(defaultIconButton) {
icon: infoTopBarBackIcon;
iconOver: infoTopBarBackIconOver;
iconPosition: point(10px, -1px);
rippleAreaPosition: point(6px, 6px);
rippleAreaSize: 44px;

View file

@ -25,7 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace Info {
namespace CommonGroups {
object_ptr<ContentWidget> Memento::createWidget(
QWidget *parent,
Wrap wrap,
@ -45,7 +45,7 @@ Widget::Widget(
Wrap wrap,
not_null<Window::Controller*> controller,
not_null<UserData*> user)
: ContentWidget(parent, wrap, controller) {
: ContentWidget(parent, wrap, controller, user) {
_inner = setInnerWidget(object_ptr<InnerWidget>(this, user));
}
@ -53,6 +53,10 @@ not_null<UserData*> Widget::user() const {
return _inner->user();
}
Section Widget::section() const {
return Section(Section::Type::CommonGroups);
}
bool Widget::showInternal(not_null<ContentMemento*> memento) {
if (auto groupsMemento = dynamic_cast<Memento*>(memento.get())) {
if (groupsMemento->userId() == user()->bareId()) {

View file

@ -57,6 +57,7 @@ public:
not_null<UserData*> user);
not_null<UserData*> user() const;
Section section() const override;
bool showInternal(
not_null<ContentMemento*> memento) override;

View file

@ -37,28 +37,52 @@ namespace Info {
LayerWrap::LayerWrap(
not_null<Window::Controller*> controller,
not_null<Memento*> memento)
: _topBar(createTopBar(controller, memento))
, _content(createContent(controller, memento)) {
: _controller(controller)
, _content(createContent(controller, memento))
, _topBar(createTopBar()) {
setupHeightConsumers();
}
LayerWrap::LayerWrap(
not_null<Window::Controller*> controller,
not_null<MoveMemento*> memento)
: _controller(controller)
, _content(memento->content(this, Wrap::Layer))
, _topBar(createTopBar()) {
setupHeightConsumers();
}
void LayerWrap::setupHeightConsumers() {
_content->desiredHeightValue()
| rpl::on_next([this](int height) {
_desiredHeight = height;
resizeToDesiredHeight();
resizeToWidth(width());
})
| rpl::start(lifetime());
heightValue()
| rpl::on_next([this](int height) {
_content->resize(
width(),
height - _topBar->bottomNoMargins() - st::boxRadius);
})
| rpl::start(lifetime());
}
object_ptr<TopBar> LayerWrap::createTopBar(
not_null<Window::Controller*> controller,
not_null<Memento*> memento) {
object_ptr<TopBar> LayerWrap::createTopBar() {
auto result = object_ptr<TopBar>(
this,
st::infoLayerTopBar);
result->addButton(object_ptr<Ui::IconButton>(
auto close = result->addButton(object_ptr<Ui::IconButton>(
result.data(),
st::infoLayerTopBarClose));
close->clicks()
| rpl::on_next([this](auto&&) {
_controller->hideSpecialLayer();
})
| rpl::start(close->lifetime());
result->setTitle(TitleValue(
memento->section(),
App::peer(memento->peerId())));
_content->section(),
_content->peer()));
return result;
}
@ -69,7 +93,7 @@ object_ptr<ContentWidget> LayerWrap::createContent(
this,
Wrap::Layer,
controller,
controller->window()->rect());
QRect());
}
void LayerWrap::showFinished() {
@ -78,58 +102,55 @@ void LayerWrap::showFinished() {
void LayerWrap::parentResized() {
auto parentSize = parentWidget()->size();
auto windowWidth = parentSize.width();
auto newWidth = st::settingsMaxWidth;
auto newContentLeft = st::settingsMaxPadding;
if (windowWidth <= st::settingsMaxWidth) {
newWidth = windowWidth;
newContentLeft = st::settingsMinPadding;
if (windowWidth > st::windowMinWidth) {
// Width changes from st::windowMinWidth to st::settingsMaxWidth.
// Padding changes from st::settingsMinPadding to st::settingsMaxPadding.
newContentLeft += ((newWidth - st::windowMinWidth) * (st::settingsMaxPadding - st::settingsMinPadding)) / (st::settingsMaxWidth - st::windowMinWidth);
}
} else if (windowWidth < st::settingsMaxWidth + 2 * st::settingsMargin) {
newWidth = windowWidth - 2 * st::settingsMargin;
newContentLeft = st::settingsMinPadding;
if (windowWidth > st::windowMinWidth) {
// Width changes from st::windowMinWidth to st::settingsMaxWidth.
// Padding changes from st::settingsMinPadding to st::settingsMaxPadding.
newContentLeft += ((newWidth - st::windowMinWidth) * (st::settingsMaxPadding - st::settingsMinPadding)) / (st::settingsMaxWidth - st::windowMinWidth);
}
if (windowWidth < MinimalSupportedWidth()) {
hide();
setParent(nullptr);
auto localCopy = _controller;
localCopy->showWideSection(
MoveMemento(std::move(_content), Wrap::Narrow));
localCopy->hideSpecialLayer(LayerOption::ForceFast);
} else {
auto newWidth = qMin(
windowWidth - 2 * st::infoMinimalLayerMargin,
st::infoDesiredWidth);
resizeToWidth(newWidth);
}
resizeToWidth(newWidth, newContentLeft);
}
void LayerWrap::resizeToWidth(int newWidth, int newContentLeft) {
resize(newWidth, height());
int LayerWrap::MinimalSupportedWidth() {
auto minimalMargins = 2 * st::infoMinimalLayerMargin;
return st::infoMinimalWidth + minimalMargins;
}
int LayerWrap::resizeGetHeight(int newWidth) {
if (!parentWidget()) {
return 0;
}
// First resize content to new width and get the new desired height.
_topBar->resizeToWidth(newWidth);
_topBar->moveToLeft(0, 0, newWidth);
// Widget height depends on content height, so we
// resize it here, not in the resizeEvent() handler.
_topBar->moveToLeft(0, st::boxRadius, newWidth);
_content->resizeToWidth(newWidth);
_content->moveToLeft(0, _topBar->height(), newWidth);
resizeToDesiredHeight();
}
void LayerWrap::resizeToDesiredHeight() {
if (!parentWidget()) return;
_content->moveToLeft(0, _topBar->bottomNoMargins(), newWidth);
auto parentSize = parentWidget()->size();
auto windowWidth = parentSize.width();
auto windowHeight = parentSize.height();
auto maxHeight = _topBar->height() + _desiredHeight;
auto newHeight = maxHeight + st::boxRadius;
if (newHeight > windowHeight || width() >= windowWidth) {
auto newHeight = st::boxRadius + maxHeight + st::boxRadius;
if (newHeight > windowHeight || newWidth >= windowWidth) {
newHeight = windowHeight;
}
setRoundedCorners(newHeight < windowHeight);
setGeometry((windowWidth - width()) / 2, (windowHeight - newHeight) / 2, width(), newHeight);
moveToLeft((windowWidth - newWidth) / 2, (windowHeight - newHeight) / 2);
_topBar->update();
_content->update();
update();
return newHeight;
}
void LayerWrap::setRoundedCorners(bool rounded) {

View file

@ -29,6 +29,7 @@ class Controller;
namespace Info {
class Memento;
class MoveMemento;
class ContentWidget;
class TopBar;
@ -37,28 +38,33 @@ public:
LayerWrap(
not_null<Window::Controller*> controller,
not_null<Memento*> memento);
LayerWrap(
not_null<Window::Controller*> controller,
not_null<MoveMemento*> memento);
void showFinished() override;
void parentResized() override;
static int MinimalSupportedWidth();
protected:
int resizeGetHeight(int newWidth) override;
void paintEvent(QPaintEvent *e) override;
void setRoundedCorners(bool roundedCorners);
private:
object_ptr<TopBar> createTopBar(
not_null<Window::Controller*> controller,
not_null<Memento*> memento);
void setupHeightConsumers();
object_ptr<ContentWidget> createContent(
not_null<Window::Controller*> controller,
not_null<Memento*> memento);
object_ptr<TopBar> createTopBar();
void resizeToWidth(int newWidth, int newContentLeft);
void resizeToDesiredHeight();
void setRoundedCorners(bool roundedCorners);
object_ptr<TopBar> _topBar;
not_null<Window::Controller*> _controller;
object_ptr<ContentWidget> _content;
object_ptr<TopBar> _topBar;
int _desiredHeight = 0;
bool _roundedCorners = false;

View file

@ -25,7 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace Info {
namespace Media {
object_ptr<ContentWidget> Memento::createWidget(
QWidget *parent,
Wrap wrap,
@ -47,12 +47,12 @@ Widget::Widget(
not_null<Window::Controller*> controller,
not_null<PeerData*> peer,
Type type)
: ContentWidget(parent, wrap, controller) {
: ContentWidget(parent, wrap, controller, peer) {
_inner = setInnerWidget(object_ptr<InnerWidget>(this, peer, type));
}
not_null<PeerData*> Widget::peer() const {
return _inner->peer();
Section Widget::section() const {
return Section(type());
}
Widget::Type Widget::type() const {

View file

@ -68,8 +68,8 @@ public:
not_null<PeerData*> peer,
Type type);
not_null<PeerData*> peer() const;
Type type() const;
Section section() const override;
bool showInternal(
not_null<ContentMemento*> memento) override;

View file

@ -38,14 +38,24 @@ namespace Info {
ContentWidget::ContentWidget(
QWidget *parent,
Wrap wrap,
not_null<Window::Controller*> controller)
not_null<Window::Controller*> controller,
not_null<PeerData*> peer)
: RpWidget(parent)
, _controller(controller)
, _peer(peer)
, _wrap(wrap)
, _scroll(this, st::infoScroll) {
setAttribute(Qt::WA_OpaquePaintEvent);
}
void ContentWidget::setWrap(Wrap wrap) {
if (_wrap != wrap) {
_wrap = wrap;
wrapUpdatedHook();
update();
}
}
void ContentWidget::resizeEvent(QResizeEvent *e) {
auto newScrollTop = _scroll->scrollTop() + _topDelta;
auto scrollGeometry = rect().marginsRemoved(
@ -118,11 +128,6 @@ rpl::producer<int> ContentWidget::scrollTopValue() const {
return _scroll->scrollTopValue();
}
void ContentWidget::setWrap(Wrap wrap) {
_wrap = wrap;
update();
}
int ContentWidget::scrollTopSave() const {
return _scroll->scrollTop();
}
@ -178,6 +183,52 @@ object_ptr<LayerWidget> Memento::createLayer(
return object_ptr<LayerWrap>(controller, this);
}
MoveMemento::MoveMemento(
object_ptr<ContentWidget> content,
Wrap wrap)
: _content(std::move(content))
, _wrap(wrap) {
}
object_ptr<Window::SectionWidget> MoveMemento::createWidget(
QWidget *parent,
not_null<Window::Controller*> controller,
const QRect &geometry) {
if (_wrap == Wrap::Narrow) {
auto result = object_ptr<NarrowWrap>(
parent,
controller,
this);
result->setGeometry(geometry);
return result;
}
auto result = object_ptr<SideWrap>(
parent,
controller,
this);
result->setGeometry(geometry);
return result;
}
object_ptr<LayerWidget> MoveMemento::createLayer(
not_null<Window::Controller*> controller) {
if (_wrap == Wrap::Layer) {
auto result = object_ptr<LayerWrap>(
controller,
this);
return result;
}
return nullptr;
}
object_ptr<ContentWidget> MoveMemento::content(
QWidget *parent,
Wrap wrap) {
Ui::AttachParentChild(parent, _content);
_content->setWrap(wrap);
return std::move(_content);
}
rpl::producer<QString> TitleValue(
const Section &section,
not_null<PeerData*> peer) {

View file

@ -77,15 +77,20 @@ public:
ContentWidget(
QWidget *parent,
Wrap wrap,
not_null<Window::Controller*> controller);
not_null<Window::Controller*> controller,
not_null<PeerData*> peer);
virtual bool showInternal(
not_null<ContentMemento*> memento) = 0;
virtual std::unique_ptr<ContentMemento> createMemento() = 0;
virtual rpl::producer<Section> sectionRequest() const;
virtual void setWrap(Wrap wrap);
void setWrap(Wrap wrap);
virtual Section section() const = 0;
not_null<PeerData*> peer() const {
return _peer;
}
rpl::producer<int> desiredHeightValue() const override;
@ -127,12 +132,16 @@ protected:
int scrollTopSave() const;
void scrollTopRestore(int scrollTop);
virtual void wrapUpdatedHook() {
}
private:
RpWidget *doSetInnerWidget(
object_ptr<RpWidget> inner,
int scrollTopSkip);
not_null<Window::Controller*> _controller;
const not_null<Window::Controller*> _controller;
const not_null<PeerData*> _peer;
Wrap _wrap = Wrap::Layer;
int _scrollTopSkip = 0;
@ -216,6 +225,32 @@ private:
};
class MoveMemento final : public Window::SectionMemento {
public:
MoveMemento(object_ptr<ContentWidget> content, Wrap wrap);
object_ptr<Window::SectionWidget> createWidget(
QWidget *parent,
not_null<Window::Controller*> controller,
const QRect &geometry) override;
object_ptr<LayerWidget> createLayer(
not_null<Window::Controller*> controller) override;
bool instant() const override {
return true;
}
object_ptr<ContentWidget> content(
QWidget *parent,
Wrap wrap);
private:
object_ptr<ContentWidget> _content;
Wrap _wrap = Wrap::Layer;
};
rpl::producer<QString> TitleValue(
const Section &section,
not_null<PeerData*> peer);

View file

@ -21,12 +21,20 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "info/info_narrow_wrap.h"
#include <rpl/flatten_latest.h>
#include <rpl/filter.h>
#include "info/info_profile_widget.h"
#include "info/info_media_widget.h"
#include "info/info_memento.h"
#include "info/info_top_bar.h"
#include "info/info_layer_wrap.h"
#include "ui/widgets/discrete_sliders.h"
#include "ui/widgets/shadow.h"
#include "ui/widgets/buttons.h"
#include "window/window_controller.h"
#include "window/main_window.h"
#include "mainwindow.h"
#include "lang/lang_keys.h"
#include "mainwidget.h"
#include "styles/style_info.h"
#include "styles/style_profile.h"
@ -36,52 +44,73 @@ NarrowWrap::NarrowWrap(
QWidget *parent,
not_null<Window::Controller*> controller,
not_null<Memento*> memento)
: Window::SectionWidget(parent, controller)
, _peer(App::peer(memento->peerId())) {
: Window::SectionWidget(parent, controller) {
setInternalState(geometry(), memento);
}
void NarrowWrap::showInner(object_ptr<ContentWidget> inner) {
_inner = std::move(inner);
_inner->setGeometry(innerGeometry());
_inner->show();
_desiredHeights.fire(desiredHeightForInner());
NarrowWrap::NarrowWrap(
QWidget *parent,
not_null<Window::Controller*> controller,
not_null<MoveMemento*> memento)
: Window::SectionWidget(parent, controller) {
restoreState(memento);
}
rpl::producer<int> NarrowWrap::desiredHeightForInner() const {
return _inner->desiredHeightValue();
object_ptr<LayerWidget> NarrowWrap::moveContentToLayer(
int availableWidth) {
if (width() < LayerWrap::MinimalSupportedWidth()) {
return nullptr;
}
return MoveMemento(
std::move(_content),
Wrap::Layer
).createLayer(controller());
}
object_ptr<Profile::Widget> NarrowWrap::createProfileWidget() {
auto result = object_ptr<Profile::Widget>(
not_null<PeerData*> NarrowWrap::peer() const {
return _content->peer();
}
void NarrowWrap::showContent(object_ptr<ContentWidget> content) {
_content = std::move(content);
_content->setGeometry(contentGeometry());
_content->show();
_topBar = createTopBar();
_desiredHeights.fire(desiredHeightForContent());
}
object_ptr<TopBar> NarrowWrap::createTopBar() {
auto result = object_ptr<TopBar>(
this,
Wrap::Narrow,
controller(),
_peer);
st::infoLayerTopBar);
result->enableBackButton(true);
result->backRequest()
| rpl::on_next([this](auto&&) {
controller()->showBackFromStack();
})
| rpl::start(result->lifetime());
result->setTitle(TitleValue(
_content->section(),
_content->peer()));
return result;
}
object_ptr<Media::Widget> NarrowWrap::createMediaWidget() {
auto result = object_ptr<Media::Widget>(
this,
Wrap::Narrow,
controller(),
_peer,
Media::Widget::Type::Photo);
return result;
rpl::producer<int> NarrowWrap::desiredHeightForContent() const {
return _content->desiredHeightValue();
}
QPixmap NarrowWrap::grabForShowAnimation(
const Window::SectionSlideParams &params) {
// if (params.withTopBarShadow) _tabsShadow->hide();
// if (params.withTopBarShadow) _topShadow->hide();
auto result = myGrab(this);
// if (params.withTopBarShadow) _tabsShadow->show();
// if (params.withTopBarShadow) _topShadow->show();
return result;
}
void NarrowWrap::doSetInnerFocus() {
_inner->setInnerFocus();
// _content->setInnerFocus();
}
bool NarrowWrap::showInternal(
@ -110,30 +139,39 @@ std::unique_ptr<Window::SectionMemento> NarrowWrap::createMemento() {
rpl::producer<int> NarrowWrap::desiredHeight() const {
return
rpl::single(desiredHeightForInner())
rpl::single(desiredHeightForContent())
| rpl::then(_desiredHeights.events())
| rpl::flatten_latest();
}
void NarrowWrap::saveState(not_null<Memento*> memento) {
memento->setInner(_inner->createMemento());
memento->setInner(_content->createMemento());
}
QRect NarrowWrap::innerGeometry() const {
return rect();
QRect NarrowWrap::contentGeometry() const {
return rect().marginsRemoved(
QMargins(0, _topBar ? _topBar->bottomNoMargins() : 0, 0, 0));
}
void NarrowWrap::restoreState(not_null<Memento*> memento) {
showInner(memento->content()->createWidget(
showContent(memento->content()->createWidget(
this,
Wrap::Narrow,
controller(),
innerGeometry()));
contentGeometry()));
}
void NarrowWrap::restoreState(not_null<MoveMemento*> memento) {
showContent(memento->content(this, Wrap::Narrow));
}
void NarrowWrap::resizeEvent(QResizeEvent *e) {
if (_inner) {
_inner->setGeometry(innerGeometry());
if (_topBar) {
_topBar->resizeToWidth(width());
_topBar->moveToLeft(0, 0);
}
if (_content) {
_content->setGeometry(contentGeometry());
}
}
@ -146,13 +184,13 @@ bool NarrowWrap::wheelEventFromFloatPlayer(
QEvent *e,
Window::Column myColumn,
Window::Column playerColumn) {
return _inner->wheelEventFromFloatPlayer(e);
return _content->wheelEventFromFloatPlayer(e);
}
QRect NarrowWrap::rectForFloatPlayer(
Window::Column myColumn,
Window::Column playerColumn) const {
return _inner->rectForFloatPlayer();
return _content->rectForFloatPlayer();
}
} // namespace Info

View file

@ -38,7 +38,9 @@ class Widget;
} // namespace Media
class Memento;
class MoveMemento;
class ContentWidget;
class TopBar;
class NarrowWrap final : public Window::SectionWidget {
public:
@ -46,12 +48,14 @@ public:
QWidget *parent,
not_null<Window::Controller*> controller,
not_null<Memento*> memento);
NarrowWrap(
QWidget *parent,
not_null<Window::Controller*> controller,
not_null<MoveMemento*> memento);
not_null<PeerData*> peer() const {
return _peer;
}
not_null<PeerData*> peer() const;
PeerData *peerForDialogs() const override {
return _peer;
return peer();
}
bool hasTopBarShadow() const override {
@ -67,6 +71,9 @@ public:
rpl::producer<int> desiredHeight() const override;
object_ptr<LayerWidget> moveContentToLayer(
int availableWidth) override;
void setInternalState(
const QRect &geometry,
not_null<Memento*> memento);
@ -89,19 +96,17 @@ protected:
private:
void saveState(not_null<Memento*> memento);
void restoreState(not_null<Memento*> memento);
void restoreState(not_null<MoveMemento*> memento);
QRect innerGeometry() const;
rpl::producer<int> desiredHeightForInner() const;
QRect contentGeometry() const;
rpl::producer<int> desiredHeightForContent() const;
void showInner(object_ptr<ContentWidget> inner);
void showContent(object_ptr<ContentWidget> content);
object_ptr<TopBar> createTopBar();
object_ptr<Profile::Widget> createProfileWidget();
object_ptr<Media::Widget> createMediaWidget();
not_null<PeerData*> _peer;
object_ptr<Ui::PlainShadow> _tabsShadow = { nullptr };
object_ptr<ContentWidget> _inner = { nullptr };
object_ptr<Ui::PlainShadow> _topShadow = { nullptr };
object_ptr<ContentWidget> _content = { nullptr };
object_ptr<TopBar> _topBar = { nullptr };
rpl::event_stream<rpl::producer<int>> _desiredHeights;

View file

@ -25,6 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "mainwidget.h"
#include "info/info_profile_widget.h"
#include "info/info_profile_lines.h"
#include "window/window_controller.h"
#include "lang/lang_keys.h"
#include "styles/style_info.h"
#include "ui/widgets/buttons.h"
@ -33,8 +34,12 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace Info {
namespace Profile {
InnerWidget::InnerWidget(QWidget *parent, not_null<PeerData*> peer)
InnerWidget::InnerWidget(
QWidget *parent,
not_null<Window::Controller*> controller,
not_null<PeerData*> peer)
: RpWidget(parent)
, _controller(controller)
, _peer(peer)
, _content(this) {
setupContent();
@ -121,10 +126,9 @@ void InnerWidget::setupMainUserButtons(
Lang::Viewer(lng_profile_send_message) | ToUpperValue(),
st::infoMainButton));
sendMessage->clicks()
| rpl::on_next([user](auto&&) {
Ui::showPeerHistory(
| rpl::on_next([this, user](auto&&) {
_controller->showPeerHistory(
user,
ShowAtUnreadMsgId,
Ui::ShowWay::Forward);
})
| rpl::start(sendMessage->lifetime());

View file

@ -24,6 +24,10 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "ui/rp_widget.h"
#include "ui/wrap/vertical_layout.h"
namespace Window {
class Controller;
} // namespace Window
namespace Info {
namespace Profile {
@ -31,7 +35,10 @@ class Memento;
class InnerWidget final : public Ui::RpWidget {
public:
InnerWidget(QWidget *parent, not_null<PeerData*> peer);
InnerWidget(
QWidget *parent,
not_null<Window::Controller*> controller,
not_null<PeerData*> peer);
not_null<PeerData*> peer() const {
return _peer;
@ -60,6 +67,7 @@ private:
Ui::VerticalLayout *wrap,
not_null<UserData*> user) const;
not_null<Window::Controller*> _controller;
not_null<PeerData*> _peer;
int _visibleTop = 0;

View file

@ -25,7 +25,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
namespace Info {
namespace Profile {
object_ptr<ContentWidget> Memento::createWidget(
QWidget *parent,
Wrap wrap,
@ -45,13 +45,16 @@ Widget::Widget(
Wrap wrap,
not_null<Window::Controller*> controller,
not_null<PeerData*> peer)
: ContentWidget(parent, wrap, controller) {
_inner = setInnerWidget(object_ptr<InnerWidget>(this, peer));
: ContentWidget(parent, wrap, controller, peer) {
_inner = setInnerWidget(object_ptr<InnerWidget>(
this,
controller,
peer));
_inner->move(0, 0);
}
not_null<PeerData*> Widget::peer() const {
return _inner->peer();
Section Widget::section() const {
return Section(Section::Type::Profile);
}
void Widget::setInnerFocus() {

View file

@ -64,7 +64,7 @@ public:
not_null<Window::Controller*> controller,
not_null<PeerData*> peer);
not_null<PeerData*> peer() const;
Section section() const override;
bool showInternal(
not_null<ContentMemento*> memento) override;

View file

@ -35,9 +35,21 @@ namespace Info {
SideWrap::SideWrap(
QWidget *parent,
not_null<Window::Controller*> controller,
not_null<PeerData*> peer)
: Window::SectionWidget(parent, controller)
, _peer(peer) {
not_null<Memento*> memento)
: Window::SectionWidget(parent, controller) {
setInternalState(geometry(), memento);
}
SideWrap::SideWrap(
QWidget *parent,
not_null<Window::Controller*> controller,
not_null<MoveMemento*> memento)
: Window::SectionWidget(parent, controller) {
restoreState(memento);
}
not_null<PeerData*> SideWrap::peer() const {
return _content->peer();
}
void SideWrap::setupTabs() {
@ -65,19 +77,41 @@ void SideWrap::setupTabs() {
}
void SideWrap::showTab(Tab tab) {
showInner(createInner(tab));
showContent(createContent(tab));
}
void SideWrap::showInner(object_ptr<ContentWidget> inner) {
_inner = std::move(inner);
_inner->setGeometry(innerGeometry());
_inner->show();
void SideWrap::showContent(object_ptr<ContentWidget> content) {
auto section = content->section();
switch (section.type()) {
case Section::Type::Profile:
setCurrentTab(Tab::Profile);
break;
case Section::Type::Media:
switch (section.mediaType()) {
case Section::MediaType::Photo:
case Section::MediaType::Video:
case Section::MediaType::File:
setCurrentTab(Tab::Media);
break;
default:
setCurrentTab(Tab::None);
break;
}
break;
case Section::Type::CommonGroups:
setCurrentTab(Tab::None);
break;
}
_desiredHeights.fire(desiredHeightForInner());
_content = std::move(content);
_content->setGeometry(contentGeometry());
_content->show();
_desiredHeights.fire(desiredHeightForContent());
}
rpl::producer<int> SideWrap::desiredHeightForInner() const {
auto result = _inner->desiredHeightValue();
rpl::producer<int> SideWrap::desiredHeightForContent() const {
auto result = _content->desiredHeightValue();
if (_tabs) {
result = std::move(result)
| rpl::map(func::add(_tabs->height()));
@ -85,7 +119,7 @@ rpl::producer<int> SideWrap::desiredHeightForInner() const {
return result;
}
object_ptr<ContentWidget> SideWrap::createInner(Tab tab) {
object_ptr<ContentWidget> SideWrap::createContent(Tab tab) {
switch (tab) {
case Tab::Profile: return createProfileWidget();
case Tab::Media: return createMediaWidget();
@ -98,7 +132,7 @@ object_ptr<Profile::Widget> SideWrap::createProfileWidget() {
this,
Wrap::Side,
controller(),
_peer);
_content->peer());
return result;
}
@ -107,7 +141,7 @@ object_ptr<Media::Widget> SideWrap::createMediaWidget() {
this,
Wrap::Side,
controller(),
_peer,
_content->peer(),
Media::Widget::Type::Photo);
return result;
}
@ -121,7 +155,7 @@ QPixmap SideWrap::grabForShowAnimation(
}
void SideWrap::doSetInnerFocus() {
_inner->setInnerFocus();
_content->setInnerFocus();
}
bool SideWrap::showInternal(
@ -153,45 +187,31 @@ std::unique_ptr<Window::SectionMemento> SideWrap::createMemento() {
rpl::producer<int> SideWrap::desiredHeightValue() const {
return
rpl::single(desiredHeightForInner())
rpl::single(desiredHeightForContent())
| rpl::then(_desiredHeights.events())
| rpl::flatten_latest();
}
void SideWrap::saveState(not_null<Memento*> memento) {
memento->setInner(_inner->createMemento());
memento->setInner(_content->createMemento());
}
QRect SideWrap::innerGeometry() const {
QRect SideWrap::contentGeometry() const {
return (_tab == Tab::None)
? rect()
: rect().marginsRemoved({ 0, _tabs->height(), 0, 0 });
}
void SideWrap::restoreState(not_null<Memento*> memento) {
switch (memento->section().type()) {
case Section::Type::Profile:
setCurrentTab(Tab::Profile);
break;
case Section::Type::Media:
switch (memento->section().mediaType()) {
case Section::MediaType::Photo:
case Section::MediaType::Video:
case Section::MediaType::File:
setCurrentTab(Tab::Media);
break;
default:
setCurrentTab(Tab::None);
break;
}
break;
}
showInner(memento->content()->createWidget(
showContent(memento->content()->createWidget(
this,
Wrap::Side,
controller(),
innerGeometry()));
contentGeometry()));
}
void SideWrap::restoreState(not_null<MoveMemento*> memento) {
showContent(memento->content(this, Wrap::Side));
}
void SideWrap::setCurrentTab(Tab tab) {
@ -209,8 +229,8 @@ void SideWrap::resizeEvent(QResizeEvent *e) {
if (_tabs) {
_tabs->resizeToWidth(width());
}
if (_inner) {
_inner->setGeometry(innerGeometry());
if (_content) {
_content->setGeometry(contentGeometry());
}
}
@ -223,13 +243,13 @@ bool SideWrap::wheelEventFromFloatPlayer(
QEvent *e,
Window::Column myColumn,
Window::Column playerColumn) {
return _inner->wheelEventFromFloatPlayer(e);
return _content->wheelEventFromFloatPlayer(e);
}
QRect SideWrap::rectForFloatPlayer(
Window::Column myColumn,
Window::Column playerColumn) const {
return _inner->rectForFloatPlayer();
return _content->rectForFloatPlayer();
}
} // namespace Info

View file

@ -38,6 +38,7 @@ class Widget;
} // namespace Media
class Memento;
class MoveMemento;
class ContentWidget;
class SideWrap final : public Window::SectionWidget {
@ -45,13 +46,15 @@ public:
SideWrap(
QWidget *parent,
not_null<Window::Controller*> controller,
not_null<PeerData*> peer);
not_null<Memento*> memento);
SideWrap(
QWidget *parent,
not_null<Window::Controller*> controller,
not_null<MoveMemento*> memento);
not_null<PeerData*> peer() const {
return _peer;
}
not_null<PeerData*> peer() const;
PeerData *peerForDialogs() const override {
return _peer;
return peer();
}
bool hasTopBarShadow() const override {
@ -94,23 +97,22 @@ private:
};
void saveState(not_null<Memento*> memento);
void restoreState(not_null<Memento*> memento);
void restoreState(not_null<MoveMemento*> memento);
QRect innerGeometry() const;
rpl::producer<int> desiredHeightForInner() const;
QRect contentGeometry() const;
rpl::producer<int> desiredHeightForContent() const;
void setupTabs();
void showTab(Tab tab);
void setCurrentTab(Tab tab);
void showInner(object_ptr<ContentWidget> inner);
object_ptr<ContentWidget> createInner(Tab tab);
void showContent(object_ptr<ContentWidget> content);
object_ptr<ContentWidget> createContent(Tab tab);
object_ptr<Profile::Widget> createProfileWidget();
object_ptr<Media::Widget> createMediaWidget();
not_null<PeerData*> _peer;
object_ptr<Ui::PlainShadow> _tabsShadow = { nullptr };
object_ptr<Ui::SettingsSlider> _tabs = { nullptr };
object_ptr<ContentWidget> _inner = { nullptr };
object_ptr<ContentWidget> _content = { nullptr };
Tab _tab = Tab::Profile;
rpl::event_stream<rpl::producer<int>> _desiredHeights;

View file

@ -20,6 +20,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
*/
#include "info/info_top_bar.h"
#include "styles/style_info.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
@ -33,6 +34,10 @@ TopBar::TopBar(QWidget *parent, const style::InfoTopBar &st)
void TopBar::setTitle(rpl::producer<QString> &&title) {
_title.create(this, std::move(title), _st.title);
if (_back) {
_title->setAttribute(Qt::WA_TransparentForMouseEvents);
}
updateControlsGeometry(width());
}
void TopBar::enableBackButton(bool enable) {
@ -72,7 +77,18 @@ void TopBar::updateControlsGeometry(int newWidth) {
right += button->width();
}
if (_back) {
_back->setGeometryToLeft(0, 0, newWidth - right, _back->height(), newWidth);
_back->setGeometryToLeft(
0,
0,
newWidth - right,
_back->height(),
newWidth);
}
if (_title) {
_title->moveToLeft(
_back ? _st.back.width : _st.titlePosition.x(),
_st.titlePosition.y(),
newWidth);
}
}

View file

@ -177,7 +177,7 @@ bool CloudManager::showOfferSwitchBox() {
Ui::hideLayer();
changeIdAndReInitConnection(DefaultLanguageId());
Local::writeLangPack();
}), KeepOtherLayers);
}), LayerOption::KeepOther);
return true;
}
@ -236,7 +236,7 @@ void CloudManager::switchToLanguage(QString id) {
auto cancel = getValue(lng_cancel);
Ui::show(Box<ConfirmBox>(text, save, cancel, [this, id] {
performSwitchAndRestart(id);
}), KeepOtherLayers);
}), LayerOption::KeepOther);
}).send();
}
}
@ -267,10 +267,12 @@ void CloudManager::performSwitchToCustom() {
Ui::show(Box<ConfirmBox>(text, save, cancel, [weak, filePath] {
weak->_langpack.switchToCustomFile(filePath);
App::restart();
}), KeepOtherLayers);
}), LayerOption::KeepOther);
}
} else {
Ui::show(Box<InformBox>("Custom lang failed :(\n\nError: " + loader.errors()), KeepOtherLayers);
Ui::show(
Box<InformBox>("Custom lang failed :(\n\nError: " + loader.errors()),
LayerOption::KeepOther);
}
});
}

View file

@ -2498,10 +2498,12 @@ void MainWidget::ui_showPeerHistory(quint64 peerId, qint32 showAtMsgId, Ui::Show
return false;
}
}
if (back || way == Ui::ShowWay::Forward) {
return true;
if (_history->isHidden()) {
return (_wideSection != nullptr)
|| (_overview != nullptr)
|| (Adaptive::OneColumn() && !_dialogs->isHidden());
}
if (_history->isHidden() && (_wideSection || _overview || Adaptive::OneColumn())) {
if (back || way == Ui::ShowWay::Forward) {
return true;
}
return false;
@ -2828,16 +2830,16 @@ void MainWidget::showNewWideSection(Window::SectionMemento &&memento, bool back,
auto sectionTop = getSectionTop();
auto newWideGeometry = QRect(_history->x(), sectionTop, _history->width(), height() - sectionTop);
auto newWideSection = memento.createWidget(this, _controller, newWideGeometry);
auto animatedShow = [this] {
if (_a_show.animating() || App::passcoded()) {
auto animatedShow = [&] {
if (_a_show.animating() || App::passcoded() || memento.instant()) {
return false;
}
if (Adaptive::OneColumn() || isSectionShown()) {
return true;
}
return false;
};
auto animationParams = animatedShow() ? prepareWideSectionAnimation(newWideSection) : Window::SectionSlideParams();
}();
auto animationParams = animatedShow ? prepareWideSectionAnimation(newWideSection) : Window::SectionSlideParams();
setFocus(); // otherwise dialogs widget could be focused.
@ -2858,6 +2860,7 @@ void MainWidget::showNewWideSection(Window::SectionMemento &&memento, bool back,
_wideSection = nullptr;
}
_wideSection = std::move(newWideSection);
updateControlsGeometry();
_history->finishAnimation();
_history->showHistory(0, 0);
@ -2875,6 +2878,26 @@ void MainWidget::showNewWideSection(Window::SectionMemento &&memento, bool back,
orderWidgets();
}
void MainWidget::checkWideSectionToLayer() {
if (!_wideSection) {
return;
}
if (auto layer = _wideSection->moveContentToLayer(width())) {
dropWideSection(_wideSection);
_controller->showSpecialLayer(
std::move(layer),
LayerOption::ForceFast);
}
}
void MainWidget::dropWideSection(Window::SectionWidget *widget) {
if (_wideSection != widget) {
return;
}
_wideSection.destroy();
showBackFromStack();
}
bool MainWidget::isSectionShown() const {
return _wideSection || _overview || _history->peer();
}
@ -3142,7 +3165,7 @@ void MainWidget::showAll() {
if (_hider) _hider->offerPeer(0);
}), base::lambda_guarded(this, [this] {
if (_hider && _forwardConfirm) _hider->offerPeer(0);
})), ForceFastShowLayer);
})), LayerOption::ForceFast);
}
}
if (selectingPeer()) {

View file

@ -219,6 +219,7 @@ public:
void orderWidgets();
QRect historyRect() const;
QPixmap grabForShowAnimation(const Window::SectionSlideParams &params);
void checkWideSectionToLayer();
void onSendFileConfirm(const FileLoadResultPtr &file);
bool onSendSticker(DocumentData *sticker);
@ -524,6 +525,7 @@ private:
Window::SectionSlideParams prepareShowAnimation(bool willHaveTopBarShadow, bool willHaveTabbedSection);
void showNewWideSection(Window::SectionMemento &&memento, bool back, bool saveInStack);
void dropWideSection(Window::SectionWidget *widget);
// All this methods use the prepareShowAnimation().
Window::SectionSlideParams prepareWideSectionAnimation(Window::SectionWidget *section);

View file

@ -320,14 +320,19 @@ void MainWindow::setupMain(const MTPUser *self) {
void MainWindow::showSettings() {
if (isHidden()) showFromTray();
showSpecialLayer(Box<Settings::Widget>());
controller()->showSpecialLayer(Box<Settings::Widget>());
}
void MainWindow::showSpecialLayer(object_ptr<LayerWidget> layer) {
void MainWindow::showSpecialLayer(
object_ptr<LayerWidget> layer,
LayerOptions options) {
if (_passcode) return;
ensureLayerCreated();
_layerBg->showSpecialLayer(std::move(layer));
if (options & LayerOption::ForceFast) {
_layerBg->finishAnimation();
}
}
void MainWindow::showMainMenu() {
@ -357,10 +362,10 @@ void MainWindow::destroyLayerDelayed() {
}
}
void MainWindow::ui_hideSettingsAndLayer(ShowLayerOptions options) {
void MainWindow::ui_hideSettingsAndLayer(LayerOptions options) {
if (_layerBg) {
_layerBg->hideAll();
if (options & ForceFastShowLayer) {
if (options & LayerOption::ForceFast) {
destroyLayerDelayed();
}
}
@ -396,11 +401,13 @@ PasscodeWidget *MainWindow::passcodeWidget() {
return _passcode;
}
void MainWindow::ui_showBox(object_ptr<BoxContent> box, ShowLayerOptions options) {
void MainWindow::ui_showBox(
object_ptr<BoxContent> box,
LayerOptions options) {
if (box) {
ensureLayerCreated();
if (options & KeepOtherLayers) {
if (options & ShowAfterOtherLayers) {
if (options & LayerOption::KeepOther) {
if (options & LayerOption::ShowAfterOther) {
_layerBg->prependBox(std::move(box));
} else {
_layerBg->appendBox(std::move(box));
@ -408,13 +415,13 @@ void MainWindow::ui_showBox(object_ptr<BoxContent> box, ShowLayerOptions options
} else {
_layerBg->showBox(std::move(box));
}
if (options & ForceFastShowLayer) {
if (options & LayerOption::ForceFast) {
_layerBg->finishAnimation();
}
} else {
if (_layerBg) {
_layerBg->hideTopLayer();
if ((options & ForceFastShowLayer) && !_layerBg->layerShown()) {
if ((options & LayerOption::ForceFast) && !_layerBg->layerShown()) {
destroyLayerDelayed();
}
}
@ -638,7 +645,7 @@ void MainWindow::onShowAddContact() {
if (isHidden()) showFromTray();
if (App::self()) {
Ui::show(Box<AddContactBox>(), KeepOtherLayers);
Ui::show(Box<AddContactBox>(), LayerOption::KeepOther);
}
}
@ -646,14 +653,20 @@ void MainWindow::onShowNewGroup() {
if (isHidden()) showFromTray();
if (App::self()) {
Ui::show(Box<GroupInfoBox>(CreatingGroupGroup, false), KeepOtherLayers);
Ui::show(
Box<GroupInfoBox>(CreatingGroupGroup, false),
LayerOption::KeepOther);
}
}
void MainWindow::onShowNewChannel() {
if (isHidden()) showFromTray();
if (_main) Ui::show(Box<GroupInfoBox>(CreatingGroupChannel, false), KeepOtherLayers);
if (_main) {
Ui::show(
Box<GroupInfoBox>(CreatingGroupChannel, false),
LayerOption::KeepOther);
}
}
void MainWindow::onLogout() {
@ -798,6 +811,8 @@ void MainWindow::updateControlsGeometry() {
if (_mediaPreview) _mediaPreview->setGeometry(body);
if (_connecting) _connecting->moveToLeft(0, body.height() - _connecting->height());
if (_testingThemeWarning) _testingThemeWarning->setGeometry(body);
if (_main) _main->checkWideSectionToLayer();
}
MainWindow::TempDirState MainWindow::tempDirState() {

View file

@ -89,6 +89,10 @@ public:
void mtpStateChanged(int32 dc, int32 state);
MainWidget *chatsWidget() {
return mainWidget();
}
MainWidget *mainWidget();
PasscodeWidget *passcodeWidget();
@ -129,10 +133,14 @@ public:
void showMainMenu();
void updateTrayMenu(bool force = false) override;
void showSpecialLayer(object_ptr<LayerWidget> layer);
void showSpecialLayer(
object_ptr<LayerWidget> layer,
LayerOptions options);
void ui_showBox(object_ptr<BoxContent> box, ShowLayerOptions options);
void ui_hideSettingsAndLayer(ShowLayerOptions options);
void ui_showBox(
object_ptr<BoxContent> box,
LayerOptions options);
void ui_hideSettingsAndLayer(LayerOptions options);
bool ui_isLayerShown();
void ui_showMediaPreview(DocumentData *document);
void ui_showMediaPreview(PhotoData *photo);

View file

@ -80,13 +80,17 @@ void ParticipantsBoxController::Start(not_null<ChannelData*> channel, Role role)
box->addLeftButton(addNewItemText(), [controller] { controller->addNewItem(); });
}
};
Ui::show(Box<PeerListBox>(std::move(controller), std::move(initBox)), KeepOtherLayers);
Ui::show(
Box<PeerListBox>(std::move(controller), std::move(initBox)),
LayerOption::KeepOther);
}
void ParticipantsBoxController::addNewItem() {
if (_role == Role::Members) {
if (_channel->membersCount() >= Global::ChatSizeMax()) {
Ui::show(Box<MaxInviteBox>(_channel), KeepOtherLayers);
Ui::show(
Box<MaxInviteBox>(_channel),
LayerOption::KeepOther);
} else {
auto already = std::vector<not_null<UserData*>>();
already.reserve(delegate()->peerListFullRowsCount());
@ -108,7 +112,7 @@ void ParticipantsBoxController::addNewItem() {
}
}), [](not_null<PeerListBox*> box) {
box->addButton(langFactory(lng_cancel), [box] { box->closeBox(); });
}), KeepOtherLayers);
}), LayerOption::KeepOther);
}
void ParticipantsBoxController::peerListSearchAddRow(not_null<PeerData*> peer) {
@ -351,7 +355,7 @@ void ParticipantsBoxController::showAdmin(not_null<UserData*> user) {
}));
});
}
_editBox = Ui::show(std::move(box), KeepOtherLayers);
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
}
void ParticipantsBoxController::editAdminDone(not_null<UserData*> user, const MTPChannelAdminRights &rights) {
@ -405,7 +409,7 @@ void ParticipantsBoxController::showRestricted(not_null<UserData*> user) {
}));
});
}
_editBox = Ui::show(std::move(box), KeepOtherLayers);
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
}
void ParticipantsBoxController::editRestrictedDone(not_null<UserData*> user, const MTPChannelBannedRights &rights) {
@ -457,7 +461,7 @@ void ParticipantsBoxController::kickMember(not_null<UserData*> user) {
if (weak) {
weak->kickMemberSure(user);
}
}), KeepOtherLayers);
}), LayerOption::KeepOther);
}
void ParticipantsBoxController::kickMemberSure(not_null<UserData*> user) {
@ -820,15 +824,19 @@ void AddParticipantBoxController::showAdmin(not_null<UserData*> user, bool sure)
if (weak) {
weak->showAdmin(user, true);
}
}), KeepOtherLayers);
}), LayerOption::KeepOther);
return;
}
} else {
Ui::show(Box<InformBox>(lang(lng_error_cant_add_admin_unban)), KeepOtherLayers);
Ui::show(Box<InformBox>(
lang(lng_error_cant_add_admin_unban)),
LayerOption::KeepOther);
return;
}
} else {
Ui::show(Box<InformBox>(lang(lng_error_cant_add_admin_invite)), KeepOtherLayers);
Ui::show(Box<InformBox>(
lang(lng_error_cant_add_admin_invite)),
LayerOption::KeepOther);
return;
}
} else if (_additional.restrictedRights.find(user) != _additional.restrictedRights.end()) {
@ -839,11 +847,13 @@ void AddParticipantBoxController::showAdmin(not_null<UserData*> user, bool sure)
if (weak) {
weak->showAdmin(user, true);
}
}), KeepOtherLayers);
}), LayerOption::KeepOther);
return;
}
} else {
Ui::show(Box<InformBox>(lang(lng_error_cant_add_admin_unban)), KeepOtherLayers);
Ui::show(Box<InformBox>(
lang(lng_error_cant_add_admin_unban)),
LayerOption::KeepOther);
return;
}
} else if (_additional.external.find(user) != _additional.external.end()) {
@ -854,11 +864,13 @@ void AddParticipantBoxController::showAdmin(not_null<UserData*> user, bool sure)
if (weak) {
weak->showAdmin(user, true);
}
}), KeepOtherLayers);
}), LayerOption::KeepOther);
return;
}
} else {
Ui::show(Box<InformBox>(lang(lng_error_cant_add_admin_invite)), KeepOtherLayers);
Ui::show(
Box<InformBox>(lang(lng_error_cant_add_admin_invite)),
LayerOption::KeepOther);
return;
}
}
@ -881,9 +893,16 @@ void AddParticipantBoxController::showAdmin(not_null<UserData*> user, bool sure)
return false;
}
if (error.type() == qstr("USER_NOT_MUTUAL_CONTACT")) {
Ui::show(Box<InformBox>(PeerFloodErrorText(channel->isMegagroup() ? PeerFloodType::InviteGroup : PeerFloodType::InviteChannel)), KeepOtherLayers);
Ui::show(
Box<InformBox>(PeerFloodErrorText(
channel->isMegagroup()
? PeerFloodType::InviteGroup
: PeerFloodType::InviteChannel)),
LayerOption::KeepOther);
} else if (error.type() == qstr("BOT_GROUPS_BLOCKED")) {
Ui::show(Box<InformBox>(lang(lng_error_cant_add_bot)), KeepOtherLayers);
Ui::show(
Box<InformBox>(lang(lng_error_cant_add_bot)),
LayerOption::KeepOther);
}
if (weak && weak->_editBox) {
weak->_editBox->closeBox();
@ -892,7 +911,7 @@ void AddParticipantBoxController::showAdmin(not_null<UserData*> user, bool sure)
}));
});
}
_editBox = Ui::show(std::move(box), KeepOtherLayers);
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
}
void AddParticipantBoxController::editAdminDone(not_null<UserData*> user, const MTPChannelAdminRights &rights) {
@ -945,11 +964,13 @@ void AddParticipantBoxController::showRestricted(not_null<UserData*> user, bool
if (weak) {
weak->showRestricted(user, true);
}
}), KeepOtherLayers);
}), LayerOption::KeepOther);
return;
}
} else {
Ui::show(Box<InformBox>(lang(lng_error_cant_ban_admin)), KeepOtherLayers);
Ui::show(
Box<InformBox>(lang(lng_error_cant_ban_admin)),
LayerOption::KeepOther);
return;
}
}
@ -961,7 +982,7 @@ void AddParticipantBoxController::showRestricted(not_null<UserData*> user, bool
weak->restrictUserSure(user, oldRights, newRights);
}
});
_editBox = Ui::show(std::move(box), KeepOtherLayers);
_editBox = Ui::show(std::move(box), LayerOption::KeepOther);
}
void AddParticipantBoxController::restrictUserSure(not_null<UserData*> user, const MTPChannelBannedRights &oldRights, const MTPChannelBannedRights &newRights) {
@ -1013,11 +1034,13 @@ void AddParticipantBoxController::kickUser(not_null<UserData*> user, bool sure)
if (weak) {
weak->kickUser(user, true);
}
}), KeepOtherLayers);
}), LayerOption::KeepOther);
return;
}
} else {
Ui::show(Box<InformBox>(lang(lng_error_cant_ban_admin)), KeepOtherLayers);
Ui::show(
Box<InformBox>(lang(lng_error_cant_ban_admin)),
LayerOption::KeepOther);
return;
}
}
@ -1029,7 +1052,7 @@ void AddParticipantBoxController::kickUser(not_null<UserData*> user, bool sure)
if (weak) {
weak->kickUser(user, true);
}
}), KeepOtherLayers);
}), LayerOption::KeepOther);
return;
}
auto currentRights = MTP_channelBannedRights(MTP_flags(0), MTP_int(0));

View file

@ -194,7 +194,9 @@ void BlockedBoxController::BlockNewUser() {
});
box->addButton(langFactory(lng_cancel), [box] { box->closeBox(); });
};
Ui::show(Box<PeerListBox>(std::move(controller), std::move(initBox)), KeepOtherLayers);
Ui::show(
Box<PeerListBox>(std::move(controller), std::move(initBox)),
LayerOption::KeepOther);
}
bool BlockedBoxController::appendRow(UserData *user) {
@ -276,7 +278,7 @@ void LastSeenPrivacyController::confirmSave(bool someAreDisallowed, base::lambda
Local::writeUserSettings();
};
auto box = Box<ConfirmBox>(lang(lng_edit_privacy_lastseen_warning), lang(lng_continue), lang(lng_cancel), std::move(callback));
*weakBox = Ui::show(std::move(box), KeepOtherLayers);
*weakBox = Ui::show(std::move(box), LayerOption::KeepOther);
} else {
saveCallback();
}

View file

@ -574,11 +574,21 @@ void FileLoadTask::process() {
void FileLoadTask::finish() {
if (!_result || !_result->filesize) {
Ui::show(Box<InformBox>(lng_send_image_empty(lt_name, _filepath)), KeepOtherLayers);
Ui::show(
Box<InformBox>(lng_send_image_empty(lt_name, _filepath)),
LayerOption::KeepOther);
} else if (_result->filesize == -1) { // dir
Ui::show(Box<InformBox>(lng_send_folder(lt_name, QFileInfo(_filepath).dir().dirName())), KeepOtherLayers);
Ui::show(
Box<InformBox>(
lng_send_folder(
lt_name,
QFileInfo(_filepath).dir().dirName())),
LayerOption::KeepOther);
} else if (_result->filesize > App::kFileSizeLimit) {
Ui::show(Box<InformBox>(lng_send_image_too_large(lt_name, _filepath)), KeepOtherLayers);
Ui::show(
Box<InformBox>(
lng_send_image_too_large(lt_name, _filepath)),
LayerOption::KeepOther);
} else if (App::main()) {
App::main()->onSendFileConfirm(_result);
}

View file

@ -33,7 +33,7 @@ public:
}
rpl::producer<QRect> geometryValue() const {
auto &stream = eventFilter().geometry;
auto &stream = eventStreams().geometry;
return stream.events_starting_with_copy(geometry());
}
rpl::producer<QSize> sizeValue() const {
@ -71,57 +71,61 @@ public:
}
rpl::producer<QRect> paintRequest() const {
return eventFilter().paint.events();
return eventStreams().paint.events();
}
rpl::producer<> alive() const {
return eventFilter().alive.events();
return eventStreams().alive.events();
}
rpl::lifetime &lifetime() {
return _lifetime;
}
private:
class EventFilter : public QObject {
public:
EventFilter(RpWidget *parent) : QObject(parent) {
parent->installEventFilter(this);
protected:
bool event(QEvent *event) override {
switch (event->type()) {
case QEvent::Move:
case QEvent::Resize:
if (auto streams = _eventStreams.get()) {
auto that = weak(this);
streams->geometry.fire_copy(geometry());
if (!that) {
return true;
}
}
break;
case QEvent::Paint:
if (auto streams = _eventStreams.get()) {
auto that = weak(this);
streams->paint.fire_copy(
static_cast<QPaintEvent*>(event)->rect());
if (!that) {
return true;
}
}
break;
}
return TWidget::event(event);
}
private:
struct EventStreams {
rpl::event_stream<QRect> geometry;
rpl::event_stream<QRect> paint;
rpl::event_stream<> alive;
protected:
bool eventFilter(QObject *object, QEvent *event) {
auto widget = static_cast<RpWidget*>(parent());
switch (event->type()) {
case QEvent::Move:
case QEvent::Resize:
geometry.fire_copy(widget->geometry());
break;
case QEvent::Paint:
paint.fire_copy(
static_cast<QPaintEvent*>(event)->rect());
break;
}
return QObject::eventFilter(object, event);
}
};
EventFilter &eventFilter() const {
if (!_eventFilter) {
auto that = const_cast<RpWidget*>(this);
that->_eventFilter = std::make_unique<EventFilter>(that);
EventStreams &eventStreams() const {
if (!_eventStreams) {
_eventStreams = std::make_unique<EventStreams>();
}
return *_eventFilter;
return *_eventStreams;
}
std::unique_ptr<EventFilter> _eventFilter;
mutable std::unique_ptr<EventStreams> _eventStreams;
rpl::lifetime _lifetime;

View file

@ -38,6 +38,9 @@ public:
not_null<Window::Controller*> controller) {
return nullptr;
}
virtual bool instant() const {
return false;
}
virtual ~SectionMemento() = default;

View file

@ -37,7 +37,11 @@ void SectionWidget::setGeometryWithTopMoved(
_topDelta = topDelta;
bool willBeResized = (size() != newGeometry.size());
if (geometry() != newGeometry) {
auto that = weak(this);
setGeometry(newGeometry);
if (!that) {
return;
}
}
if (!willBeResized) {
resizeEvent(nullptr);

View file

@ -117,6 +117,12 @@ public:
virtual rpl::producer<int> desiredHeight() const;
// Some sections convert to layers on some geometry sizes.
virtual object_ptr<LayerWidget> moveContentToLayer(
int availableWidth) {
return nullptr;
}
// Global shortcut handler. For now that ugly :(
virtual bool cmd_search() {
return false;

View file

@ -22,6 +22,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "window/main_window.h"
#include "mainwidget.h"
#include "mainwindow.h"
#include "styles/style_window.h"
#include "styles/style_dialogs.h"
#include "boxes/calendar_box.h"
@ -183,4 +184,33 @@ void Controller::showJumpToDate(not_null<PeerData*> peer, QDate requestedDate) {
Ui::show(std::move(box));
}
void Controller::showPeerHistory(
not_null<PeerData*> peer,
Ui::ShowWay way,
MsgId msgId) {
Ui::showPeerHistory(peer, msgId, way);
}
void Controller::showWideSection(SectionMemento &&memento) {
App::main()->showWideSection(std::move(memento));
}
void Controller::showBackFromStack() {
chats()->showBackFromStack();
}
void Controller::showSpecialLayer(
object_ptr<LayerWidget> &&layer,
LayerOptions options) {
App::wnd()->showSpecialLayer(std::move(layer), options);
}
void Controller::hideSpecialLayer(LayerOptions options) {
Ui::hideSettingsAndLayer(options & LayerOption::ForceFast);
}
not_null<MainWidget*> Controller::chats() const {
return App::wnd()->chatsWidget();
}
} // namespace Window

View file

@ -22,6 +22,8 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "base/flags.h"
class MainWidget;
namespace Window {
enum class GifPauseReason {
@ -36,6 +38,7 @@ using GifPauseReasons = base::flags<GifPauseReason>;
inline constexpr bool is_flag_type(GifPauseReason) { return true; };
class MainWindow;
class SectionMemento;
class Controller {
public:
@ -103,7 +106,21 @@ public:
return _dialogsListDisplayForced;
}
void showPeerHistory(
not_null<PeerData*> peer,
Ui::ShowWay way = Ui::ShowWay::ClearStack,
MsgId msgId = ShowAtUnreadMsgId);
void showWideSection(SectionMemento &&memento);
void showBackFromStack();
void showSpecialLayer(
object_ptr<LayerWidget> &&layer,
LayerOptions options = LayerOption::Animated);
void hideSpecialLayer(
LayerOptions options = LayerOption::Animated);
private:
not_null<MainWidget*> chats() const;
not_null<MainWindow*> _window;
base::Observable<PeerData*> _searchInPeerChanged;