mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Decompose countInitialGeomety from MainWindow
This commit is contained in:
@@ -177,22 +177,20 @@ QRect Panel::panelGeometry() const {
|
||||
const auto center = Core::App().getPointForCallPanelCenter();
|
||||
const auto simple = QRect(0, 0, st::callWidth, st::callHeight);
|
||||
const auto initial = simple.translated(center - simple.center());
|
||||
auto result = initial;
|
||||
if (const auto window = Core::App().activeWindow()) {
|
||||
const auto initialPosition = Core::WindowPosition{
|
||||
.moncrc = 0,
|
||||
.scale = cScale(),
|
||||
.x = initial.x(),
|
||||
.y = initial.y(),
|
||||
.w = initial.width(),
|
||||
.h = initial.height(),
|
||||
};
|
||||
result = window->widget()->countInitialGeometry(
|
||||
adjusted,
|
||||
initialPosition,
|
||||
{ st::callWidthMin, st::callHeightMin });
|
||||
}
|
||||
return result;
|
||||
const auto initialPosition = Core::WindowPosition{
|
||||
.moncrc = 0,
|
||||
.scale = cScale(),
|
||||
.x = initial.x(),
|
||||
.y = initial.y(),
|
||||
.w = initial.width(),
|
||||
.h = initial.height(),
|
||||
};
|
||||
return ::Window::CountInitialGeometry(
|
||||
window(),
|
||||
adjusted,
|
||||
initialPosition,
|
||||
{ st::callWidthMin, st::callHeightMin },
|
||||
u"Call"_q);
|
||||
}
|
||||
|
||||
ConferencePanelMigration Panel::migrationInfo() const {
|
||||
|
||||
@@ -615,7 +615,7 @@ void Controller::createWindow() {
|
||||
updateTitleGeometry(width);
|
||||
}, _subtitle->lifetime());
|
||||
|
||||
window->setGeometry(_delegate->ivGeometry());
|
||||
window->setGeometry(_delegate->ivGeometry(window));
|
||||
window->setMinimumSize({ st::windowMinWidth, st::windowMinHeight });
|
||||
|
||||
window->geometryValue(
|
||||
|
||||
@@ -15,8 +15,7 @@ namespace Iv {
|
||||
|
||||
class Delegate {
|
||||
public:
|
||||
virtual void ivSetLastSourceWindow(not_null<QWidget*> window) = 0;
|
||||
[[nodiscard]] virtual QRect ivGeometry() const = 0;
|
||||
[[nodiscard]] virtual QRect ivGeometry(not_null<Ui::RpWindow*> window) const = 0;
|
||||
virtual void ivSaveGeometry(not_null<Ui::RpWindow*> window) = 0;
|
||||
|
||||
[[nodiscard]] virtual int ivZoom() const = 0;
|
||||
|
||||
@@ -45,26 +45,16 @@ namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
void DelegateImpl::ivSetLastSourceWindow(not_null<QWidget*> window) {
|
||||
_lastSourceWindow = window;
|
||||
}
|
||||
|
||||
QRect DelegateImpl::ivGeometry() const {
|
||||
const auto found = _lastSourceWindow
|
||||
? Core::App().findWindow(_lastSourceWindow)
|
||||
: nullptr;
|
||||
|
||||
QRect DelegateImpl::ivGeometry(not_null<Ui::RpWindow*> window) const {
|
||||
const auto saved = Core::App().settings().ivPosition();
|
||||
const auto adjusted = Core::AdjustToScale(saved, u"IV"_q);
|
||||
const auto initial = DefaultPosition();
|
||||
auto result = initial.rect();
|
||||
if (const auto window = found ? found : Core::App().activeWindow()) {
|
||||
result = window->widget()->countInitialGeometry(
|
||||
adjusted,
|
||||
initial,
|
||||
{ st::ivWidthMin, st::ivHeightMin });
|
||||
}
|
||||
return result;
|
||||
return Window::CountInitialGeometry(
|
||||
window,
|
||||
adjusted,
|
||||
initial,
|
||||
{ st::ivWidthMin, st::ivHeightMin },
|
||||
u"IV"_q);
|
||||
}
|
||||
|
||||
void DelegateImpl::ivSaveGeometry(not_null<Ui::RpWindow*> window) {
|
||||
|
||||
@@ -15,17 +15,13 @@ class DelegateImpl final : public Delegate {
|
||||
public:
|
||||
DelegateImpl() = default;
|
||||
|
||||
void ivSetLastSourceWindow(not_null<QWidget*> window) override;
|
||||
[[nodiscard]] QRect ivGeometry() const override;
|
||||
[[nodiscard]] QRect ivGeometry(not_null<Ui::RpWindow*> window) const override;
|
||||
void ivSaveGeometry(not_null<Ui::RpWindow*> window) override;
|
||||
|
||||
[[nodiscard]] int ivZoom() const override;
|
||||
[[nodiscard]] rpl::producer<int> ivZoomValue() const override;
|
||||
void ivSetZoom(int value) override;
|
||||
|
||||
private:
|
||||
QPointer<QWidget> _lastSourceWindow;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Iv
|
||||
|
||||
@@ -829,7 +829,6 @@ void Instance::show(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Data*> data,
|
||||
QString hash) {
|
||||
_delegate->ivSetLastSourceWindow(controller->widget());
|
||||
show(controller->uiShow(), data, hash);
|
||||
}
|
||||
|
||||
|
||||
@@ -958,13 +958,12 @@ void OverlayWidget::initNormalGeometry() {
|
||||
const auto saved = Core::App().settings().mediaViewPosition();
|
||||
const auto adjusted = Core::AdjustToScale(saved, u"Viewer"_q);
|
||||
const auto initial = DefaultPosition();
|
||||
_normalGeometry = initial.rect();
|
||||
if (const auto active = Core::App().activeWindow()) {
|
||||
_normalGeometry = active->widget()->countInitialGeometry(
|
||||
adjusted,
|
||||
initial,
|
||||
{ st::mediaviewMinWidth, st::mediaviewMinHeight });
|
||||
}
|
||||
_normalGeometry = Window::CountInitialGeometry(
|
||||
_window,
|
||||
adjusted,
|
||||
initial,
|
||||
{ st::mediaviewMinWidth, st::mediaviewMinHeight },
|
||||
u"Viewer"_q);
|
||||
}
|
||||
|
||||
void OverlayWidget::savePosition() {
|
||||
|
||||
@@ -700,115 +700,12 @@ QRect MainWindow::countInitialGeometry(WindowPosition position) {
|
||||
.w = initialWidth,
|
||||
.h = initialHeight,
|
||||
};
|
||||
return countInitialGeometry(
|
||||
return CountInitialGeometry(
|
||||
this,
|
||||
position,
|
||||
initial,
|
||||
{ st::windowMinWidth, st::windowMinHeight });
|
||||
}
|
||||
|
||||
QRect MainWindow::countInitialGeometry(
|
||||
WindowPosition position,
|
||||
WindowPosition initial,
|
||||
QSize minSize) const {
|
||||
if (!position.w || !position.h) {
|
||||
return initial.rect();
|
||||
}
|
||||
const auto screen = [&]() -> QScreen* {
|
||||
for (const auto screen : QGuiApplication::screens()) {
|
||||
const auto sum = Platform::ScreenNameChecksum(screen->name());
|
||||
if (position.moncrc == sum) {
|
||||
return screen;
|
||||
}
|
||||
}
|
||||
return QGuiApplication::screenAt(position.rect().center());
|
||||
}();
|
||||
if (!screen) {
|
||||
return initial.rect();
|
||||
}
|
||||
const auto frame = frameMargins();
|
||||
const auto screenGeometry = screen->geometry();
|
||||
const auto availableGeometry = screen->availableGeometry();
|
||||
const auto spaceForInner = availableGeometry.marginsRemoved(frame);
|
||||
DEBUG_LOG(("Window Pos: "
|
||||
"Screen found, screen geometry: %1, %2, %3, %4, "
|
||||
"available: %5, %6, %7, %8"
|
||||
).arg(screenGeometry.x()
|
||||
).arg(screenGeometry.y()
|
||||
).arg(screenGeometry.width()
|
||||
).arg(screenGeometry.height()
|
||||
).arg(availableGeometry.x()
|
||||
).arg(availableGeometry.y()
|
||||
).arg(availableGeometry.width()
|
||||
).arg(availableGeometry.height()));
|
||||
DEBUG_LOG(("Window Pos: "
|
||||
"Window frame margins: %1, %2, %3, %4, "
|
||||
"available space for inner geometry: %5, %6, %7, %8"
|
||||
).arg(frame.left()
|
||||
).arg(frame.top()
|
||||
).arg(frame.right()
|
||||
).arg(frame.bottom()
|
||||
).arg(spaceForInner.x()
|
||||
).arg(spaceForInner.y()
|
||||
).arg(spaceForInner.width()
|
||||
).arg(spaceForInner.height()));
|
||||
|
||||
const auto x = spaceForInner.x()
|
||||
- (position.moncrc ? screenGeometry.x() : 0);
|
||||
const auto y = spaceForInner.y()
|
||||
- (position.moncrc ? screenGeometry.y() : 0);
|
||||
const auto w = spaceForInner.width();
|
||||
const auto h = spaceForInner.height();
|
||||
if (w < st::windowMinWidth || h < st::windowMinHeight) {
|
||||
return initial.rect();
|
||||
}
|
||||
if (position.x < x) position.x = x;
|
||||
if (position.y < y) position.y = y;
|
||||
if (position.w > w) position.w = w;
|
||||
if (position.h > h) position.h = h;
|
||||
const auto rightPoint = position.x + position.w;
|
||||
const auto screenRightPoint = x + w;
|
||||
if (rightPoint > screenRightPoint) {
|
||||
const auto distance = rightPoint - screenRightPoint;
|
||||
const auto newXPos = position.x - distance;
|
||||
if (newXPos >= x) {
|
||||
position.x = newXPos;
|
||||
} else {
|
||||
position.x = x;
|
||||
const auto newRightPoint = position.x + position.w;
|
||||
const auto newDistance = newRightPoint - screenRightPoint;
|
||||
position.w -= newDistance;
|
||||
}
|
||||
}
|
||||
const auto bottomPoint = position.y + position.h;
|
||||
const auto screenBottomPoint = y + h;
|
||||
if (bottomPoint > screenBottomPoint) {
|
||||
const auto distance = bottomPoint - screenBottomPoint;
|
||||
const auto newYPos = position.y - distance;
|
||||
if (newYPos >= y) {
|
||||
position.y = newYPos;
|
||||
} else {
|
||||
position.y = y;
|
||||
const auto newBottomPoint = position.y + position.h;
|
||||
const auto newDistance = newBottomPoint - screenBottomPoint;
|
||||
position.h -= newDistance;
|
||||
}
|
||||
}
|
||||
if (position.moncrc) {
|
||||
position.x += screenGeometry.x();
|
||||
position.y += screenGeometry.y();
|
||||
}
|
||||
if ((position.x + st::windowMinWidth
|
||||
> screenGeometry.x() + screenGeometry.width())
|
||||
|| (position.y + st::windowMinHeight
|
||||
> screenGeometry.y() + screenGeometry.height())) {
|
||||
return initial.rect();
|
||||
}
|
||||
DEBUG_LOG(("Window Pos: Resulting geometry is %1, %2, %3, %4"
|
||||
).arg(position.x
|
||||
).arg(position.y
|
||||
).arg(position.w
|
||||
).arg(position.h));
|
||||
return position.rect();
|
||||
{ st::windowMinWidth, st::windowMinHeight },
|
||||
u"Window"_q);
|
||||
}
|
||||
|
||||
void MainWindow::firstShow() {
|
||||
@@ -1136,4 +1033,114 @@ WindowPosition PositionWithScreen(
|
||||
name);
|
||||
}
|
||||
|
||||
QRect CountInitialGeometry(
|
||||
not_null<const Ui::RpWindow*> widget,
|
||||
WindowPosition position,
|
||||
WindowPosition initial,
|
||||
QSize minSize,
|
||||
const QString &name) {
|
||||
if (!position.w || !position.h) {
|
||||
return initial.rect();
|
||||
}
|
||||
const auto screen = [&]() -> QScreen* {
|
||||
for (const auto screen : QGuiApplication::screens()) {
|
||||
const auto sum = Platform::ScreenNameChecksum(screen->name());
|
||||
if (position.moncrc == sum) {
|
||||
return screen;
|
||||
}
|
||||
}
|
||||
return QGuiApplication::screenAt(position.rect().center());
|
||||
}();
|
||||
if (!screen) {
|
||||
return initial.rect();
|
||||
}
|
||||
const auto frame = widget->frameMargins();
|
||||
const auto screenGeometry = screen->geometry();
|
||||
const auto availableGeometry = screen->availableGeometry();
|
||||
const auto spaceForInner = availableGeometry.marginsRemoved(frame);
|
||||
DEBUG_LOG(("%1 Pos: "
|
||||
"Screen found, screen geometry: %2, %3, %4, %5, "
|
||||
"available: %6, %7, %8, %9"
|
||||
).arg(name
|
||||
).arg(screenGeometry.x()
|
||||
).arg(screenGeometry.y()
|
||||
).arg(screenGeometry.width()
|
||||
).arg(screenGeometry.height()
|
||||
).arg(availableGeometry.x()
|
||||
).arg(availableGeometry.y()
|
||||
).arg(availableGeometry.width()
|
||||
).arg(availableGeometry.height()));
|
||||
DEBUG_LOG(("%1 Pos: "
|
||||
"Window frame margins: %2, %3, %4, %5, "
|
||||
"available space for inner geometry: %6, %7, %8, %9"
|
||||
).arg(name
|
||||
).arg(frame.left()
|
||||
).arg(frame.top()
|
||||
).arg(frame.right()
|
||||
).arg(frame.bottom()
|
||||
).arg(spaceForInner.x()
|
||||
).arg(spaceForInner.y()
|
||||
).arg(spaceForInner.width()
|
||||
).arg(spaceForInner.height()));
|
||||
|
||||
const auto x = spaceForInner.x()
|
||||
- (position.moncrc ? screenGeometry.x() : 0);
|
||||
const auto y = spaceForInner.y()
|
||||
- (position.moncrc ? screenGeometry.y() : 0);
|
||||
const auto w = spaceForInner.width();
|
||||
const auto h = spaceForInner.height();
|
||||
if (w < st::windowMinWidth || h < st::windowMinHeight) {
|
||||
return initial.rect();
|
||||
}
|
||||
if (position.x < x) position.x = x;
|
||||
if (position.y < y) position.y = y;
|
||||
if (position.w > w) position.w = w;
|
||||
if (position.h > h) position.h = h;
|
||||
const auto rightPoint = position.x + position.w;
|
||||
const auto screenRightPoint = x + w;
|
||||
if (rightPoint > screenRightPoint) {
|
||||
const auto distance = rightPoint - screenRightPoint;
|
||||
const auto newXPos = position.x - distance;
|
||||
if (newXPos >= x) {
|
||||
position.x = newXPos;
|
||||
} else {
|
||||
position.x = x;
|
||||
const auto newRightPoint = position.x + position.w;
|
||||
const auto newDistance = newRightPoint - screenRightPoint;
|
||||
position.w -= newDistance;
|
||||
}
|
||||
}
|
||||
const auto bottomPoint = position.y + position.h;
|
||||
const auto screenBottomPoint = y + h;
|
||||
if (bottomPoint > screenBottomPoint) {
|
||||
const auto distance = bottomPoint - screenBottomPoint;
|
||||
const auto newYPos = position.y - distance;
|
||||
if (newYPos >= y) {
|
||||
position.y = newYPos;
|
||||
} else {
|
||||
position.y = y;
|
||||
const auto newBottomPoint = position.y + position.h;
|
||||
const auto newDistance = newBottomPoint - screenBottomPoint;
|
||||
position.h -= newDistance;
|
||||
}
|
||||
}
|
||||
if (position.moncrc) {
|
||||
position.x += screenGeometry.x();
|
||||
position.y += screenGeometry.y();
|
||||
}
|
||||
if ((position.x + st::windowMinWidth
|
||||
> screenGeometry.x() + screenGeometry.width())
|
||||
|| (position.y + st::windowMinHeight
|
||||
> screenGeometry.y() + screenGeometry.height())) {
|
||||
return initial.rect();
|
||||
}
|
||||
DEBUG_LOG(("%1 Pos: Resulting geometry is %2, %3, %4, %5"
|
||||
).arg(name
|
||||
).arg(position.x
|
||||
).arg(position.y
|
||||
).arg(position.w
|
||||
).arg(position.h));
|
||||
return position.rect();
|
||||
}
|
||||
|
||||
} // namespace Window
|
||||
|
||||
@@ -139,11 +139,6 @@ public:
|
||||
updateGlobalMenuHook();
|
||||
}
|
||||
|
||||
[[nodiscard]] QRect countInitialGeometry(
|
||||
Core::WindowPosition position,
|
||||
Core::WindowPosition initial,
|
||||
QSize minSize) const;
|
||||
|
||||
[[nodiscard]] virtual rpl::producer<QPoint> globalForceClicks() {
|
||||
return rpl::never<QPoint>();
|
||||
}
|
||||
@@ -237,10 +232,19 @@ private:
|
||||
[[nodiscard]] Core::WindowPosition PositionWithScreen(
|
||||
Core::WindowPosition position,
|
||||
const QScreen *chosen,
|
||||
QSize minimal);
|
||||
QSize minimal,
|
||||
const QString &name);
|
||||
[[nodiscard]] Core::WindowPosition PositionWithScreen(
|
||||
Core::WindowPosition position,
|
||||
not_null<const QWidget*> widget,
|
||||
QSize minimal);
|
||||
QSize minimal,
|
||||
const QString &name);
|
||||
|
||||
[[nodiscard]] QRect CountInitialGeometry(
|
||||
not_null<const Ui::RpWindow*> widget,
|
||||
Core::WindowPosition position,
|
||||
Core::WindowPosition initial,
|
||||
QSize minSize,
|
||||
const QString &name);
|
||||
|
||||
} // namespace Window
|
||||
|
||||
Reference in New Issue
Block a user