mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-29 09:32:45 +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:
commit
4c11dcdd7d
@ -37,6 +37,7 @@
|
|||||||
#include <components/files/conversion.hpp>
|
#include <components/files/conversion.hpp>
|
||||||
#include <components/misc/helpviewer.hpp>
|
#include <components/misc/helpviewer.hpp>
|
||||||
#include <components/misc/scalableicon.hpp>
|
#include <components/misc/scalableicon.hpp>
|
||||||
|
#include <components/misc/strings/format.hpp>
|
||||||
#include <components/misc/timeconvert.hpp>
|
#include <components/misc/timeconvert.hpp>
|
||||||
#include <components/version/version.hpp>
|
#include <components/version/version.hpp>
|
||||||
|
|
||||||
@ -1112,14 +1113,8 @@ void CSVDoc::View::updateWidth(bool isGrowLimit, int minSubViewWidth)
|
|||||||
QRect rect;
|
QRect rect;
|
||||||
if (isGrowLimit)
|
if (isGrowLimit)
|
||||||
{
|
{
|
||||||
// Widget position can be negative, we should clamp it.
|
QScreen* screen = getWidgetScreen(pos());
|
||||||
QPoint position = pos();
|
rect = screen->geometry();
|
||||||
if (position.x() <= 0)
|
|
||||||
position.setX(0);
|
|
||||||
if (position.y() <= 0)
|
|
||||||
position.setY(0);
|
|
||||||
|
|
||||||
rect = QApplication::screenAt(position)->geometry();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
rect = desktopRect();
|
rect = desktopRect();
|
||||||
@ -1165,3 +1160,27 @@ void CSVDoc::View::onRequestFocus(const std::string& id)
|
|||||||
addSubView(CSMWorld::UniversalId(CSMWorld::UniversalId::Type_Reference, 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;
|
||||||
|
}
|
||||||
|
@ -108,6 +108,8 @@ namespace CSVDoc
|
|||||||
View& operator=(const View&) = delete;
|
View& operator=(const View&) = delete;
|
||||||
~View() override = default;
|
~View() override = default;
|
||||||
|
|
||||||
|
static QScreen* getWidgetScreen(const QPoint& position);
|
||||||
|
|
||||||
const CSMDoc::Document* getDocument() const;
|
const CSMDoc::Document* getDocument() const;
|
||||||
|
|
||||||
CSMDoc::Document* getDocument();
|
CSMDoc::Document* getDocument();
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "../../model/world/tablemimedata.hpp"
|
#include "../../model/world/tablemimedata.hpp"
|
||||||
|
|
||||||
#include "../doc/sizehint.hpp"
|
#include "../doc/sizehint.hpp"
|
||||||
|
#include "../doc/view.hpp"
|
||||||
#include "../filter/filterbox.hpp"
|
#include "../filter/filterbox.hpp"
|
||||||
#include "../filter/filterdata.hpp"
|
#include "../filter/filterdata.hpp"
|
||||||
#include "table.hpp"
|
#include "table.hpp"
|
||||||
@ -81,15 +82,10 @@ CSVWorld::TableSubView::TableSubView(
|
|||||||
|
|
||||||
setWidget(widget);
|
setWidget(widget);
|
||||||
|
|
||||||
// Widget position can be negative, we should clamp it.
|
QScreen* screen = CSVDoc::View::getWidgetScreen(pos());
|
||||||
QPoint position = pos();
|
|
||||||
if (position.x() <= 0)
|
|
||||||
position.setX(0);
|
|
||||||
if (position.y() <= 0)
|
|
||||||
position.setY(0);
|
|
||||||
|
|
||||||
// prefer height of the screen and full width of the table
|
// 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
|
int frameHeight = 40; // set a reasonable default
|
||||||
QWidget* topLevel = QApplication::topLevelAt(pos());
|
QWidget* topLevel = QApplication::topLevelAt(pos());
|
||||||
if (topLevel)
|
if (topLevel)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user