1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2024-12-29 03:19:44 +00:00

Merge branch 'display_fix' into 'master'

Improve screen detection for editor's widgets

Closes #8146

See merge request OpenMW/openmw!4364
This commit is contained in:
Evil Eye 2024-10-29 16:51:37 +00:00
commit 4c11dcdd7d
3 changed files with 32 additions and 15 deletions

View File

@ -37,6 +37,7 @@
#include <components/files/conversion.hpp>
#include <components/misc/helpviewer.hpp>
#include <components/misc/scalableicon.hpp>
#include <components/misc/strings/format.hpp>
#include <components/misc/timeconvert.hpp>
#include <components/version/version.hpp>
@ -1112,14 +1113,8 @@ void CSVDoc::View::updateWidth(bool isGrowLimit, int minSubViewWidth)
QRect rect;
if (isGrowLimit)
{
// Widget position can be negative, we should clamp it.
QPoint position = pos();
if (position.x() <= 0)
position.setX(0);
if (position.y() <= 0)
position.setY(0);
rect = QApplication::screenAt(position)->geometry();
QScreen* screen = getWidgetScreen(pos());
rect = screen->geometry();
}
else
rect = desktopRect();
@ -1165,3 +1160,27 @@ void CSVDoc::View::onRequestFocus(const std::string& id)
addSubView(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Reference, id));
}
}
QScreen* CSVDoc::View::getWidgetScreen(const QPoint& position)
{
QScreen* screen = QApplication::screenAt(position);
if (screen == nullptr)
{
QPoint clampedPosition = position;
// If we failed to find the screen,
// clamp negative positions and try again
if (clampedPosition.x() <= 0)
clampedPosition.setX(0);
if (clampedPosition.y() <= 0)
clampedPosition.setY(0);
screen = QApplication::screenAt(clampedPosition);
}
if (screen == nullptr)
throw std::runtime_error(
Misc::StringUtils::format("Can not detect the screen for position [%d, %d]", position.x(), position.y()));
return screen;
}

View File

@ -108,6 +108,8 @@ namespace CSVDoc
View& operator=(const View&) = delete;
~View() override = default;
static QScreen* getWidgetScreen(const QPoint& position);
const CSMDoc::Document* getDocument() const;
CSMDoc::Document* getDocument();

View File

@ -23,6 +23,7 @@
#include "../../model/world/tablemimedata.hpp"
#include "../doc/sizehint.hpp"
#include "../doc/view.hpp"
#include "../filter/filterbox.hpp"
#include "../filter/filterdata.hpp"
#include "table.hpp"
@ -81,15 +82,10 @@ CSVWorld::TableSubView::TableSubView(
setWidget(widget);
// Widget position can be negative, we should clamp it.
QPoint position = pos();
if (position.x() <= 0)
position.setX(0);
if (position.y() <= 0)
position.setY(0);
QScreen* screen = CSVDoc::View::getWidgetScreen(pos());
// prefer height of the screen and full width of the table
const QRect rect = QApplication::screenAt(position)->geometry();
const QRect rect = screen->geometry();
int frameHeight = 40; // set a reasonable default
QWidget* topLevel = QApplication::topLevelAt(pos());
if (topLevel)