Added new Adaptive class to replace legacy Adaptive namespace.

Temporarily named class as AdaptiveModern.
This commit is contained in:
23rd 2021-05-27 02:16:12 +03:00
parent d2c8780c0f
commit 2d90a06078
7 changed files with 111 additions and 0 deletions

View File

@ -1086,6 +1086,8 @@ PRIVATE
window/section_memento.h window/section_memento.h
window/section_widget.cpp window/section_widget.cpp
window/section_widget.h window/section_widget.h
window/window_adaptive.cpp
window/window_adaptive.h
window/window_connecting_widget.cpp window/window_connecting_widget.cpp
window/window_connecting_widget.h window/window_connecting_widget.h
window/window_controller.cpp window/window_controller.cpp

View File

@ -0,0 +1,51 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "window/window_adaptive.h"
#include "history/history_item.h"
#include "data/data_media_types.h"
#include "data/data_session.h"
namespace Window {
AdaptiveModern::AdaptiveModern() = default;
void AdaptiveModern::setWindowLayout(WindowLayout value) {
_layout = value;
}
void AdaptiveModern::setChatLayout(ChatLayout value) {
_chatLayout = value;
}
rpl::producer<> AdaptiveModern::changed() const {
return rpl::merge(
_chatLayout.changes() | rpl::to_empty,
_layout.changes() | rpl::to_empty);
}
rpl::producer<bool> AdaptiveModern::oneColumnValue() const {
return _layout.value(
) | rpl::map([=] {
return isOneColumn();
});
}
bool AdaptiveModern::isOneColumn() const {
return _layout.current() == WindowLayout::OneColumn;
}
bool AdaptiveModern::isNormal() const {
return _layout.current() == WindowLayout::Normal;
}
bool AdaptiveModern::isThreeColumn() const {
return _layout.current() == WindowLayout::ThreeColumn;
}
} // namespace Window

View File

@ -0,0 +1,43 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
namespace Window {
class AdaptiveModern {
public:
enum class WindowLayout {
OneColumn,
Normal,
ThreeColumn,
};
enum class ChatLayout {
Normal,
Wide,
};
AdaptiveModern();
void setWindowLayout(WindowLayout value);
void setChatLayout(ChatLayout value);
[[nodiscard]] rpl::producer<> changed() const;
[[nodiscard]] rpl::producer<bool> oneColumnValue() const;
[[nodiscard]] bool isOneColumn() const;
[[nodiscard]] bool isNormal() const;
[[nodiscard]] bool isThreeColumn() const;
private:
rpl::variable<ChatLayout> _chatLayout;
rpl::variable<WindowLayout> _layout;
};
} // namespace Window

View File

@ -41,6 +41,7 @@ namespace Window {
Controller::Controller() Controller::Controller()
: _widget(this) : _widget(this)
, _adaptive(std::make_unique<AdaptiveModern>())
, _isActiveTimer([=] { updateIsActive(); }) { , _isActiveTimer([=] { updateIsActive(); }) {
_widget.init(); _widget.init();
} }
@ -367,4 +368,8 @@ void Controller::showLogoutConfirmation() {
callback)); callback));
} }
Window::AdaptiveModern &Controller::adaptive() const {
return *_adaptive;
}
} // namespace Window } // namespace Window

View File

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once #pragma once
#include "mainwindow.h" #include "mainwindow.h"
#include "window/window_adaptive.h"
#include "ui/layers/layer_widget.h" #include "ui/layers/layer_widget.h"
namespace Main { namespace Main {
@ -39,6 +40,8 @@ public:
} }
[[nodiscard]] bool locked() const; [[nodiscard]] bool locked() const;
[[nodiscard]] AdaptiveModern &adaptive() const;
void finishFirstShow(); void finishFirstShow();
void setupPasscodeLock(); void setupPasscodeLock();
@ -90,6 +93,7 @@ private:
Main::Account *_account = nullptr; Main::Account *_account = nullptr;
::MainWindow _widget; ::MainWindow _widget;
const std::unique_ptr<AdaptiveModern> _adaptive;
std::unique_ptr<SessionController> _sessionController; std::unique_ptr<SessionController> _sessionController;
base::Timer _isActiveTimer; base::Timer _isActiveTimer;
QPointer<Ui::BoxContent> _termsBox; QPointer<Ui::BoxContent> _termsBox;

View File

@ -1205,6 +1205,10 @@ void SessionController::showNewChannel() {
Ui::LayerOption::KeepOther); Ui::LayerOption::KeepOther);
} }
Window::AdaptiveModern &SessionController::adaptive() const {
return _window->adaptive();
}
SessionController::~SessionController() = default; SessionController::~SessionController() = default;
} // namespace Window } // namespace Window

View File

@ -53,6 +53,7 @@ class MainWindow;
class SectionMemento; class SectionMemento;
class Controller; class Controller;
class FiltersMenu; class FiltersMenu;
class AdaptiveModern;
enum class GifPauseReason { enum class GifPauseReason {
Any = 0, Any = 0,
@ -238,6 +239,7 @@ public:
} }
[[nodiscard]] not_null<::MainWindow*> widget() const; [[nodiscard]] not_null<::MainWindow*> widget() const;
[[nodiscard]] not_null<MainWidget*> content() const; [[nodiscard]] not_null<MainWidget*> content() const;
[[nodiscard]] AdaptiveModern &adaptive() const;
// We need access to this from MainWidget::MainWidget, where // We need access to this from MainWidget::MainWidget, where
// we can't call content() yet. // we can't call content() yet.