Implement a system that resizes the ghost widget appropriately to avoid undefined behavior due to it being moved into the gap between screens caused by scaling.
Signed-off-by: Danilo Aimini <82231674+AMZN-daimini@users.noreply.github.com>
This commit is contained in:
@@ -1615,14 +1615,16 @@ namespace AzQtComponents
|
||||
}
|
||||
|
||||
// Handle snapping to the screen edges/other floating windows while dragging
|
||||
QScreen* screen = Utilities::ScreenAtPoint(globalPos);
|
||||
QScreen* screen = QApplication::screenAt(globalPos);
|
||||
|
||||
AdjustForSnapping(placeholder, screen);
|
||||
if (screen)
|
||||
{
|
||||
AdjustForSnapping(placeholder, screen);
|
||||
m_state.setPlaceholder(placeholder, screen);
|
||||
|
||||
m_state.setPlaceholder(placeholder, screen);
|
||||
|
||||
m_ghostWidget->Enable();
|
||||
RepaintFloatingIndicators();
|
||||
m_ghostWidget->Enable();
|
||||
RepaintFloatingIndicators();
|
||||
}
|
||||
}
|
||||
|
||||
return m_dropZoneState.dragging();
|
||||
|
||||
+48
-2
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <AzQtComponents/Components/FancyDockingGhostWidget.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QCloseEvent>
|
||||
#include <QScreen>
|
||||
@@ -76,7 +77,32 @@ namespace AzQtComponents
|
||||
window->setScreen(screen);
|
||||
}
|
||||
|
||||
setGeometry(targetRect);
|
||||
QPoint midPoint = targetRect.topLeft() + QPoint(targetRect.width() / 2, targetRect.height() / 2);
|
||||
QScreen* pointScreen = QApplication::screenAt(midPoint);
|
||||
QRect rect(targetRect);
|
||||
|
||||
if (!pointScreen || pointScreen != screen)
|
||||
{
|
||||
if (midPoint.x() >= QCursor::pos().x())
|
||||
{
|
||||
rect.setLeft(rect.left() - rect.width());
|
||||
rect.setTop(rect.top() - rect.height());
|
||||
m_paintMode = PaintMode::BOTTOMRIGHT;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect.setRight(rect.right() + rect.width());
|
||||
rect.setTop(rect.top() - rect.height());
|
||||
m_paintMode = PaintMode::BOTTOMLEFT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_paintMode = PaintMode::FULL;
|
||||
}
|
||||
|
||||
setGeometry(rect);
|
||||
|
||||
setPixmapVisible(true);
|
||||
if (needsRepaint)
|
||||
{
|
||||
@@ -135,7 +161,27 @@ namespace AzQtComponents
|
||||
yOffset = widgetSize.height() - aspectRatioHeight;
|
||||
}
|
||||
|
||||
painter.drawPixmap(QRect(0, yOffset, widgetSize.width(), aspectRatioHeight), m_pixmap);
|
||||
switch (m_paintMode)
|
||||
{
|
||||
case PaintMode::FULL:
|
||||
{
|
||||
painter.drawPixmap(QRect(0, yOffset, widgetSize.width(), aspectRatioHeight), m_pixmap);
|
||||
}
|
||||
break;
|
||||
|
||||
case PaintMode::BOTTOMLEFT:
|
||||
{
|
||||
painter.drawPixmap(QRect(0, (widgetSize.height() + yOffset) / 2, widgetSize.width() / 2, aspectRatioHeight / 2), m_pixmap);
|
||||
}
|
||||
break;
|
||||
|
||||
case PaintMode::BOTTOMRIGHT:
|
||||
{
|
||||
painter.drawPixmap(QRect(widgetSize.width() / 2, (widgetSize.height() + yOffset) / 2, widgetSize.width() / 2, aspectRatioHeight / 2), m_pixmap);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_clipToWidgets)
|
||||
{
|
||||
painter.restore();
|
||||
|
||||
@@ -45,5 +45,14 @@ namespace AzQtComponents
|
||||
QPixmap m_pixmap;
|
||||
bool m_visible = false; // maintain our own flag, so that we're always ready to render ignoring Qt's widget caching system
|
||||
bool m_clipToWidgets = false;
|
||||
|
||||
enum class PaintMode
|
||||
{
|
||||
FULL = 0,
|
||||
BOTTOMLEFT,
|
||||
BOTTOMRIGHT
|
||||
};
|
||||
|
||||
PaintMode m_paintMode = PaintMode::FULL;
|
||||
};
|
||||
} // namespace AzQtComponents
|
||||
|
||||
Reference in New Issue
Block a user