mirror of
https://github.com/huderlem/porymap.git
synced 2026-03-21 17:45:44 -05:00
Take screen boundaries into account
This commit is contained in:
parent
e710e105c5
commit
ac8a79a7cc
|
|
@ -602,11 +602,7 @@ void MainWindow::loadUserSettings() {
|
|||
void MainWindow::restoreWindowState() {
|
||||
QMap<QString, QByteArray> geometry = porymapConfig.getMainGeometry();
|
||||
const QByteArray mainWindowGeometry = geometry.value("main_window_geometry");
|
||||
if (mainWindowGeometry.isEmpty()) {
|
||||
// If there's no saved geometry for the main window (i.e., first show) then we show it maximized.
|
||||
// This simplifies the problem of picking a good window size depending on the screen.
|
||||
setWindowState(Qt::WindowMaximized | Qt::WindowActive);
|
||||
} else {
|
||||
if (!mainWindowGeometry.isEmpty()) {
|
||||
logInfo("Restoring main window geometry from previous session.");
|
||||
restoreGeometry(mainWindowGeometry);
|
||||
restoreState(geometry.value("main_window_state"));
|
||||
|
|
@ -614,6 +610,22 @@ void MainWindow::restoreWindowState() {
|
|||
ui->splitter_main->restoreState(geometry.value("main_splitter_state"));
|
||||
ui->splitter_Metatiles->restoreState(geometry.value("metatiles_splitter_state"));
|
||||
}
|
||||
|
||||
// Resize the window if it exceeds the available screen size.
|
||||
auto screen = windowHandle() ? windowHandle()->screen() : QGuiApplication::primaryScreen();
|
||||
if (!screen) return;
|
||||
const QRect screenGeometry = screen->availableGeometry();
|
||||
if (this->width() > screenGeometry.width() || this->height() > screenGeometry.height()) {
|
||||
auto pixelRatio = screen->devicePixelRatio();
|
||||
logInfo(QString("Resizing main window. Dimensions of %1x%2 exceed available screen size of %3x%4")
|
||||
.arg(qRound(this->width() * pixelRatio))
|
||||
.arg(qRound(this->height() * pixelRatio))
|
||||
.arg(qRound(screenGeometry.width() * pixelRatio))
|
||||
.arg(qRound(screenGeometry.height() * pixelRatio)));
|
||||
resize(qMin(this->width(), screenGeometry.width()),
|
||||
qMin(this->height(), screenGeometry.height()));
|
||||
move(screenGeometry.center() - this->rect().center());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::setTheme(QString theme) {
|
||||
|
|
|
|||
|
|
@ -43,11 +43,11 @@ ColorPicker::~ColorPicker()
|
|||
void ColorPicker::hover(const QPoint &pos) {
|
||||
QScreen *screen = QGuiApplication::screenAt(pos);
|
||||
if (!screen) {
|
||||
// Try the screen the color picker is on, or the primary screen.
|
||||
const QWindow *window = windowHandle();
|
||||
if (window) screen = window->screen();
|
||||
screen = (window && window->screen()) ? window->screen() : QGuiApplication::primaryScreen();
|
||||
if (!screen) return;
|
||||
}
|
||||
if (!screen)
|
||||
return;
|
||||
|
||||
// 15 X 15 box with 8x magnification = 120px square)
|
||||
QPixmap grab = screen->grabWindow(0, pos.x() - zoom_box_dimensions / 2, pos.y() - zoom_box_dimensions / 2, zoom_box_dimensions, zoom_box_dimensions);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user