forked from qt-creator/qt-creator
QmlDesigner: Fix PopupDialog popup location
* Restrict popup location to single screen given by global position * Reintroduce PopupDialog title bar drag * Fix global popup show on linux Change-Id: If1923151cb9d0ec4286f27aeae2baa292e017eb5 Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
committed by
Thomas Hartmann
parent
245bd90a6e
commit
c3f9d43aca
@@ -49,7 +49,7 @@ StudioControls.PopupDialog {
|
||||
root.close()
|
||||
}
|
||||
function onPopupShouldOpen() {
|
||||
root.showGlobal()
|
||||
Qt.callLater(root.showGlobal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -33,9 +33,8 @@ QtObject {
|
||||
|
||||
signal closing(close: var)
|
||||
|
||||
function showGlobal()
|
||||
{
|
||||
var pos = WindowManager.globalCursorPosition();
|
||||
function showGlobal() {
|
||||
var pos = WindowManager.globalCursorPosition()
|
||||
root.__itemGlobal = Qt.rect(pos.x, pos.y, 300, 20)
|
||||
root.chevronVisible = false
|
||||
root.layout()
|
||||
@@ -57,11 +56,8 @@ QtObject {
|
||||
}
|
||||
|
||||
function layout() {
|
||||
// Setup
|
||||
var screen = Qt.rect(0, //Screen.virtualX, // TODO
|
||||
0, //Screen.virtualY, // TODO
|
||||
Screen.desktopAvailableWidth,
|
||||
Screen.desktopAvailableHeight)
|
||||
let position = Qt.point(root.__itemGlobal.x, root.__itemGlobal.y)
|
||||
var screen = WindowManager.getScreenGeometry(position)
|
||||
|
||||
// Collect region information
|
||||
let edges = window.getRegions(screen, root.__itemGlobal)
|
||||
@@ -165,9 +161,18 @@ QtObject {
|
||||
var targetCenter = Qt.point(target.x + (target.width * 0.5),
|
||||
target.y + (target.height * 0.5))
|
||||
|
||||
// Just as a reminder why calculating custom right and bottom:
|
||||
// > Note that for historical reasons this function returns top() + height() - 1;
|
||||
// > use y() + height() to retrieve the true y-coordinate.
|
||||
let sourceRight = source.x + source.width
|
||||
let sourceBottom = source.y + source.height
|
||||
|
||||
// TOP
|
||||
let topAnchor = Qt.point(targetCenter.x, target.y)
|
||||
let topRegion = Qt.rect(source.x, source.y, source.width, Math.max(0, topAnchor.y))
|
||||
let topRegion = Qt.rect(source.x,
|
||||
source.y,
|
||||
source.width,
|
||||
(topAnchor.y < source.top) ? 0 : Math.abs(topAnchor.y - source.top))
|
||||
|
||||
edges[Qt.TopEdge] = {
|
||||
anchor: topAnchor,
|
||||
@@ -180,7 +185,7 @@ QtObject {
|
||||
let rightAnchor = Qt.point(target.x + target.width, targetCenter.y)
|
||||
let rightRegion = Qt.rect(rightAnchor.x,
|
||||
source.y,
|
||||
Math.max(0, source.width - rightAnchor.x),
|
||||
(rightAnchor.x > sourceRight) ? 0 : Math.abs(sourceRight - rightAnchor.x),
|
||||
source.height)
|
||||
|
||||
edges[Qt.RightEdge] = {
|
||||
@@ -195,7 +200,7 @@ QtObject {
|
||||
let bottomRegion = Qt.rect(source.x,
|
||||
bottomAnchor.y,
|
||||
source.width,
|
||||
Math.max(0, source.height - bottomAnchor.y))
|
||||
(bottomAnchor.y > sourceBottom) ? 0 : Math.abs(sourceBottom - bottomAnchor.y))
|
||||
|
||||
edges[Qt.BottomEdge] = {
|
||||
anchor: bottomAnchor,
|
||||
@@ -206,7 +211,10 @@ QtObject {
|
||||
|
||||
// LEFT
|
||||
let leftAnchor = Qt.point(target.x, targetCenter.y)
|
||||
let leftRegion = Qt.rect(source.x, source.y, Math.max(0, leftAnchor.x), source.height)
|
||||
let leftRegion = Qt.rect(source.x,
|
||||
source.y,
|
||||
(leftAnchor.x < source.left) ? 0 : Math.abs(leftAnchor.x - source.left),
|
||||
source.height)
|
||||
|
||||
edges[Qt.LeftEdge] = {
|
||||
anchor: leftAnchor,
|
||||
@@ -392,6 +400,19 @@ QtObject {
|
||||
width: parent.width
|
||||
height: StudioTheme.Values.titleBarHeight
|
||||
|
||||
DragHandler {
|
||||
id: dragHandler
|
||||
|
||||
target: null
|
||||
grabPermissions: PointerHandler.CanTakeOverFromAnything
|
||||
onActiveChanged: {
|
||||
if (dragHandler.active)
|
||||
window.startSystemMove() // QTBUG-102488
|
||||
|
||||
root.chevronVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
id: row
|
||||
anchors.fill: parent
|
||||
|
@@ -8,6 +8,7 @@
|
||||
#include <QCursor>
|
||||
#include <QGuiApplication>
|
||||
#include <QMainWindow>
|
||||
#include <QScreen>
|
||||
#include <QWindow>
|
||||
|
||||
namespace QmlDesignerBase {
|
||||
@@ -43,4 +44,14 @@ QPoint WindowManager::globalCursorPosition()
|
||||
return QCursor::pos();
|
||||
}
|
||||
|
||||
QRect WindowManager::getScreenGeometry(QPoint point)
|
||||
{
|
||||
QScreen *screen = QGuiApplication::screenAt(point);
|
||||
|
||||
if (!screen)
|
||||
return {};
|
||||
|
||||
return screen->geometry();
|
||||
}
|
||||
|
||||
} // namespace QmlDesignerBase
|
||||
|
@@ -25,6 +25,7 @@ public:
|
||||
static void registerDeclarativeType();
|
||||
|
||||
Q_INVOKABLE QPoint globalCursorPosition();
|
||||
Q_INVOKABLE QRect getScreenGeometry(QPoint point);
|
||||
|
||||
signals:
|
||||
void focusWindowChanged(QWindow *window);
|
||||
|
Reference in New Issue
Block a user