init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Close stale issues and PRs / stale (push) Successful in 13s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
This commit is contained in:
131
Telegram/SourceFiles/iv/iv_delegate_impl.cpp
Normal file
131
Telegram/SourceFiles/iv/iv_delegate_impl.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
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 "iv/iv_delegate_impl.h"
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/core_settings.h"
|
||||
#include "mainwindow.h"
|
||||
#include "window/main_window.h"
|
||||
#include "window/window_controller.h"
|
||||
#include "styles/style_window.h"
|
||||
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include <QtGui/QScreen>
|
||||
#include <QtGui/QWindow>
|
||||
|
||||
namespace Iv {
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] Core::WindowPosition DefaultPosition() {
|
||||
auto center = qApp->primaryScreen()->geometry().center();
|
||||
const auto moncrc = [&] {
|
||||
if (const auto active = Core::App().activeWindow()) {
|
||||
const auto widget = active->widget();
|
||||
center = widget->geometry().center();
|
||||
if (const auto screen = widget->screen()) {
|
||||
return Platform::ScreenNameChecksum(screen->name());
|
||||
}
|
||||
}
|
||||
return Core::App().settings().windowPosition().moncrc;
|
||||
}();
|
||||
return {
|
||||
.moncrc = moncrc,
|
||||
.scale = cScale(),
|
||||
.x = (center.x() - st::ivWidthDefault / 2),
|
||||
.y = (center.y() - st::ivHeightDefault / 2),
|
||||
.w = st::ivWidthDefault,
|
||||
.h = st::ivHeightDefault,
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void DelegateImpl::ivSetLastSourceWindow(not_null<QWidget*> window) {
|
||||
_lastSourceWindow = window;
|
||||
}
|
||||
|
||||
QRect DelegateImpl::ivGeometry() const {
|
||||
const auto found = _lastSourceWindow
|
||||
? Core::App().findWindow(_lastSourceWindow)
|
||||
: nullptr;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void DelegateImpl::ivSaveGeometry(not_null<Ui::RpWindow*> window) {
|
||||
if (!window->windowHandle()) {
|
||||
return;
|
||||
}
|
||||
const auto state = window->windowHandle()->windowState();
|
||||
if (state == Qt::WindowMinimized) {
|
||||
return;
|
||||
}
|
||||
const auto &savedPosition = Core::App().settings().ivPosition();
|
||||
auto realPosition = savedPosition;
|
||||
if (state == Qt::WindowMaximized) {
|
||||
realPosition.maximized = 1;
|
||||
realPosition.moncrc = 0;
|
||||
DEBUG_LOG(("IV Pos: Saving maximized position."));
|
||||
} else {
|
||||
auto r = window->body()->mapToGlobal(window->body()->rect());
|
||||
realPosition.x = r.x();
|
||||
realPosition.y = r.y();
|
||||
realPosition.w = r.width();
|
||||
realPosition.h = r.height();
|
||||
realPosition.scale = cScale();
|
||||
realPosition.maximized = 0;
|
||||
realPosition.moncrc = 0;
|
||||
DEBUG_LOG(("IV Pos: "
|
||||
"Saving non-maximized position: %1, %2, %3, %4"
|
||||
).arg(realPosition.x
|
||||
).arg(realPosition.y
|
||||
).arg(realPosition.w
|
||||
).arg(realPosition.h));
|
||||
}
|
||||
realPosition = Window::PositionWithScreen(
|
||||
realPosition,
|
||||
window,
|
||||
{ st::ivWidthMin, st::ivHeightMin });
|
||||
if (realPosition.w >= st::ivWidthMin
|
||||
&& realPosition.h >= st::ivHeightMin
|
||||
&& realPosition != savedPosition) {
|
||||
DEBUG_LOG(("IV Pos: "
|
||||
"Writing: %1, %2, %3, %4 (scale %5%, maximized %6)")
|
||||
.arg(realPosition.x)
|
||||
.arg(realPosition.y)
|
||||
.arg(realPosition.w)
|
||||
.arg(realPosition.h)
|
||||
.arg(realPosition.scale)
|
||||
.arg(Logs::b(realPosition.maximized)));
|
||||
Core::App().settings().setIvPosition(realPosition);
|
||||
Core::App().saveSettingsDelayed();
|
||||
}
|
||||
}
|
||||
|
||||
int DelegateImpl::ivZoom() const {
|
||||
return Core::App().settings().ivZoom();
|
||||
}
|
||||
rpl::producer<int> DelegateImpl::ivZoomValue() const {
|
||||
return Core::App().settings().ivZoomValue();
|
||||
}
|
||||
void DelegateImpl::ivSetZoom(int value) {
|
||||
Core::App().settings().setIvZoom(value);
|
||||
Core::App().saveSettingsDelayed();
|
||||
}
|
||||
|
||||
} // namespace Iv
|
||||
Reference in New Issue
Block a user