2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-30 22:16:14 +00:00

Switch MainWindow to Ui::RpWindow

This commit is contained in:
Ilya Fedin
2021-07-26 01:30:56 +04:00
committed by John Preston
parent 4ef2d3b957
commit 1ebf27bfa1
29 changed files with 116 additions and 1933 deletions

View File

@@ -9,9 +9,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/localstorage.h"
#include "platform/platform_specific.h"
#include "ui/platform/ui_platform_window.h"
#include "platform/platform_window_title.h"
#include "base/platform/base_platform_info.h"
#include "ui/platform/ui_platform_utility.h"
#include "history/history.h"
#include "window/window_session_controller.h"
#include "window/window_lock_widgets.h"
@@ -161,9 +161,8 @@ QIcon CreateIcon(Main::Session *session) {
MainWindow::MainWindow(not_null<Controller*> controller)
: _controller(controller)
, _positionUpdatedTimer([=] { savePosition(); })
, _outdated(CreateOutdatedBar(this))
, _body(this)
, _titleText(qsl("Telegram")) {
, _outdated(CreateOutdatedBar(body()))
, _body(body()) {
style::PaletteChanged(
) | rpl::start_with_next([=] {
updatePalette();
@@ -266,8 +265,6 @@ QRect MainWindow::desktopRect() const {
}
void MainWindow::init() {
Expects(!windowHandle());
createWinId();
initHook();
@@ -293,7 +290,7 @@ void MainWindow::init() {
updatePalette();
if (Platform::AllowNativeWindowFrameToggle()) {
if (Ui::Platform::NativeWindowFrameSupported()) {
Core::App().settings().nativeWindowFrameChanges(
) | rpl::start_with_next([=](bool native) {
refreshTitleWidget();
@@ -308,7 +305,6 @@ void MainWindow::init() {
void MainWindow::handleStateChanged(Qt::WindowState state) {
stateChangedHook(state);
updateShadowSize();
updateControlsGeometry();
if (state == Qt::WindowMinimized) {
controller().updateIsActiveBlur();
@@ -381,27 +377,6 @@ void MainWindow::updatePalette() {
setPalette(p);
}
HitTestResult MainWindow::hitTest(const QPoint &p) const {
auto titleResult = _title ? _title->hitTest(p - _title->geometry().topLeft()) : Window::HitTestResult::None;
if (titleResult != Window::HitTestResult::None) {
return titleResult;
} else if (rect().contains(p)) {
return Window::HitTestResult::Client;
}
return Window::HitTestResult::None;
}
bool MainWindow::hasShadow() const {
const auto center = geometry().center();
return Ui::Platform::WindowExtentsSupported()
&& Ui::Platform::TranslucentWindowsSupported(center)
&& _title;
}
QRect MainWindow::inner() const {
return rect().marginsRemoved(_padding);
}
int MainWindow::computeMinWidth() const {
auto result = st::windowMinWidth;
if (const auto session = _controller->sessionController()) {
@@ -412,38 +387,32 @@ int MainWindow::computeMinWidth() const {
if (_rightColumn) {
result += _rightColumn->width();
}
return result + _padding.left() + _padding.right();
return result;
}
int MainWindow::computeMinHeight() const {
const auto title = _title ? _title->height() : 0;
const auto outdated = [&] {
if (!_outdated) {
return 0;
}
_outdated->resizeToWidth(st::windowMinWidth - _padding.left() - _padding.right());
_outdated->resizeToWidth(st::windowMinWidth);
return _outdated->height();
}();
return title + outdated + st::windowMinHeight + _padding.top() + _padding.bottom();
return outdated + st::windowMinHeight;
}
void MainWindow::refreshTitleWidget() {
if (Platform::AllowNativeWindowFrameToggle()
if (Ui::Platform::NativeWindowFrameSupported()
&& Core::App().settings().nativeWindowFrame()) {
_title.destroy();
setNativeFrame(true);
if (Platform::NativeTitleRequiresShadow()) {
_titleShadow.create(this);
_titleShadow->show();
}
} else if ((_title = Platform::CreateTitleWidget(this))) {
_title->show();
_title->init();
} else {
setNativeFrame(false);
_titleShadow.destroy();
}
const auto withShadow = hasShadow();
windowHandle()->setFlag(Qt::NoDropShadowWindowHint, withShadow);
setAttribute(Qt::WA_OpaquePaintEvent, !withShadow);
}
void MainWindow::updateMinimumSize() {
@@ -451,21 +420,13 @@ void MainWindow::updateMinimumSize() {
setMinimumHeight(computeMinHeight());
}
void MainWindow::updateShadowSize() {
_padding = hasShadow() && !isMaximized()
? st::callShadow.extend
: style::margins();
}
void MainWindow::recountGeometryConstraints() {
updateShadowSize();
updateMinimumSize();
updateControlsGeometry();
fixOrder();
}
void MainWindow::initSize() {
updateShadowSize();
updateMinimumSize();
if (initSizeFromSystem()) {
@@ -565,7 +526,6 @@ void MainWindow::initSize() {
}
}
}
geometry += _padding;
DEBUG_LOG(("Window Pos: Setting first %1, %2, %3, %4").arg(geometry.x()).arg(geometry.y()).arg(geometry.width()).arg(geometry.height()));
setGeometry(geometry);
}
@@ -574,18 +534,6 @@ void MainWindow::positionUpdated() {
_positionUpdatedTimer.callOnce(kSaveWindowPositionTimeout);
}
bool MainWindow::titleVisible() const {
return _title && !_title->isHidden();
}
void MainWindow::setTitleVisible(bool visible) {
if (_title && (_title->isHidden() == visible)) {
_title->setVisible(visible);
updateControlsGeometry();
}
titleVisibilityChangedHook();
}
int32 MainWindow::screenNameChecksum(const QString &name) const {
const auto bytes = name.toUtf8();
return base::crc32(bytes.constData(), bytes.size());
@@ -605,15 +553,7 @@ void MainWindow::attachToTrayIcon(not_null<QSystemTrayIcon*> icon) {
});
}
void MainWindow::paintEvent(QPaintEvent *e) {
if (hasShadow() && !isMaximized()) {
QPainter p(this);
Ui::Shadow::paint(p, inner(), width(), st::callShadow);
}
}
void MainWindow::resizeEvent(QResizeEvent *e) {
updateShadowSize();
updateControlsGeometry();
}
@@ -626,14 +566,10 @@ void MainWindow::leaveEventHook(QEvent *e) {
}
void MainWindow::updateControlsGeometry() {
const auto inner = this->inner();
const auto inner = body()->rect();
auto bodyLeft = inner.x();
auto bodyTop = inner.y();
auto bodyWidth = inner.width();
if (_title && !_title->isHidden()) {
_title->setGeometry(inner.x(), bodyTop, inner.width(), _title->height());
bodyTop += _title->height();
}
if (_titleShadow) {
_titleShadow->setGeometry(inner.x(), bodyTop, inner.width(), st::lineWidth);
}
@@ -656,7 +592,7 @@ void MainWindow::updateUnreadCounter() {
}
const auto counter = Core::App().unreadBadge();
_titleText = (counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram");
setTitle((counter > 0) ? qsl("Telegram (%1)").arg(counter) : qsl("Telegram"));
unreadCounterChangedHook();
}
@@ -683,7 +619,7 @@ void MainWindow::savePosition(Qt::WindowState state) {
realPosition.maximized = 1;
DEBUG_LOG(("Window Pos: Saving maximized position."));
} else {
auto r = geometry().marginsRemoved(_padding);
auto r = body()->mapToGlobal(body()->rect());
realPosition.x = r.x();
realPosition.y = r.y();
realPosition.w = r.width() - (_rightColumn ? _rightColumn->width() : 0);
@@ -774,7 +710,7 @@ void MainWindow::showRightColumn(object_ptr<TWidget> widget) {
const auto wasRightWidth = _rightColumn ? _rightColumn->width() : 0;
_rightColumn = std::move(widget);
if (_rightColumn) {
_rightColumn->setParent(this);
_rightColumn->setParent(body());
_rightColumn->show();
_rightColumn->setFocus();
} else {
@@ -799,12 +735,12 @@ void MainWindow::showRightColumn(object_ptr<TWidget> widget) {
int MainWindow::maximalExtendBy() const {
auto desktop = QDesktopWidget().availableGeometry(this);
return std::max(desktop.width() - inner().width(), 0);
return std::max(desktop.width() - body()->width(), 0);
}
bool MainWindow::canExtendNoMove(int extendBy) const {
auto desktop = QDesktopWidget().availableGeometry(this);
auto inner = geometry().marginsRemoved(_padding);
auto inner = body()->mapToGlobal(body()->rect());
auto innerRight = (inner.x() + inner.width() + extendBy);
auto desktopRight = (desktop.x() + desktop.width());
return innerRight <= desktopRight;
@@ -812,7 +748,7 @@ bool MainWindow::canExtendNoMove(int extendBy) const {
int MainWindow::tryToExtendWidthBy(int addToWidth) {
auto desktop = QDesktopWidget().availableGeometry(this);
auto inner = geometry();
auto inner = body()->mapToGlobal(body()->rect());
accumulate_min(
addToWidth,
std::max(desktop.width() - inner.width(), 0));
@@ -821,7 +757,7 @@ int MainWindow::tryToExtendWidthBy(int addToWidth) {
inner.x(),
desktop.x() + desktop.width() - newWidth);
if (inner.x() != newLeft || inner.width() != newWidth) {
setGeometry(newLeft, inner.y(), newWidth, inner.height());
setGeometry(QRect(newLeft, inner.y(), newWidth, inner.height()));
} else {
updateControlsGeometry();
}
@@ -841,8 +777,6 @@ void MainWindow::launchDrag(
}
MainWindow::~MainWindow() {
_title.destroy();
// Otherwise:
// ~QWidget
// QWidgetPrivate::close_helper