Use the qt type Qt::Edges instead of wasm-specific

The types essentially do the same job - the one that is more general
should be used, the other - removed, as it is redundant.

Change-Id: Iec09d3311681abce1405fcf8c2cebfb72f3fd51c
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
This commit is contained in:
Mikolaj Boc 2022-08-11 09:35:26 +02:00
parent a4a51f6a64
commit 906dfef22b
6 changed files with 50 additions and 83 deletions

View File

@ -739,23 +739,27 @@ void QWasmCompositor::WindowManipulation::resizeWindow(const QPoint& amount)
{
const auto& minShrink = std::get<ResizeState>(m_state->operationSpecific).m_minShrink;
const auto& maxGrow = std::get<ResizeState>(m_state->operationSpecific).m_maxGrow;
const auto& resizeMode = std::get<ResizeState>(m_state->operationSpecific).m_resizeMode;
const auto &resizeEdges = std::get<ResizeState>(m_state->operationSpecific).m_resizeEdges;
const QPoint cappedGrowVector(
std::min(maxGrow.x(), std::max(minShrink.x(),
(resizeMode & Left) ? -amount.x() : (resizeMode & Right) ? amount.x() : 0)),
std::min(maxGrow.y(), std::max(minShrink.y(),
(resizeMode & Top) ? -amount.y() : (resizeMode & Bottom) ? amount.y() : 0)));
std::min(maxGrow.x(),
std::max(minShrink.x(),
(resizeEdges & Qt::Edge::LeftEdge) ? -amount.x()
: (resizeEdges & Qt::Edge::RightEdge) ? amount.x()
: 0)),
std::min(maxGrow.y(),
std::max(minShrink.y(),
(resizeEdges & Qt::Edge::TopEdge) ? -amount.y()
: (resizeEdges & Qt::Edge::BottomEdge) ? amount.y()
: 0)));
const auto& initialBounds =
std::get<ResizeState>(m_state->operationSpecific).m_initialWindowBounds;
m_state->window->setGeometry(
initialBounds.adjusted(
(resizeMode & Left) ? -cappedGrowVector.x() : 0,
(resizeMode & Top) ? -cappedGrowVector.y() : 0,
(resizeMode & Right) ? cappedGrowVector.x() : 0,
(resizeMode & Bottom) ? cappedGrowVector.y() : 0
));
m_state->window->setGeometry(initialBounds.adjusted(
(resizeEdges & Qt::Edge::LeftEdge) ? -cappedGrowVector.x() : 0,
(resizeEdges & Qt::Edge::TopEdge) ? -cappedGrowVector.y() : 0,
(resizeEdges & Qt::Edge::RightEdge) ? cappedGrowVector.x() : 0,
(resizeEdges & Qt::Edge::BottomEdge) ? cappedGrowVector.y() : 0));
}
void QWasmCompositor::onTopWindowChanged()
@ -866,8 +870,8 @@ bool QWasmCompositor::processPointer(const PointerEvent& event)
const bool isOnResizeRegion = wasmTargetWindow->isPointOnResizeRegion(targetPointInScreenCoords);
if (isTargetWindowResizable && isOnResizeRegion && !isTargetWindowBlocked) {
const QCursor resizingCursor = QWasmEventTranslator::cursorForMode(
wasmTargetWindow->resizeModeAtPoint(targetPointInScreenCoords));
const QCursor resizingCursor = QWasmEventTranslator::cursorForEdges(
wasmTargetWindow->resizeEdgesAtPoint(targetPointInScreenCoords));
if (resizingCursor != targetWindow->cursor()) {
m_isResizeCursorDisplayed = true;
@ -988,7 +992,8 @@ void QWasmCompositor::WindowManipulation::onPointerDown(
});
} else if (asWasmWindow(windowAtPoint)->isPointOnResizeRegion(pointInScreenCoords)) {
operationSpecific = std::make_unique<std::variant<ResizeState, MoveState>>(ResizeState{
.m_resizeMode = asWasmWindow(windowAtPoint)->resizeModeAtPoint(pointInScreenCoords),
.m_resizeEdges =
asWasmWindow(windowAtPoint)->resizeEdgesAtPoint(pointInScreenCoords),
.m_originInScreenCoords = pointInScreenCoords,
.m_initialWindowBounds = windowAtPoint->geometry(),
.m_minShrink =

View File

@ -60,25 +60,6 @@ public:
};
Q_DECLARE_FLAGS(StateFlags, QWasmStateFlag)
enum ResizeDimension {
Left = 1,
Right = 1 << 1,
Top = 1 << 2,
Bottom = 1 << 3
};
enum ResizeMode {
ResizeNone,
ResizeTopLeft = Top | Left,
ResizeTop = Top,
ResizeTopRight = Top | Right,
ResizeRight = Right,
ResizeBottomRight = Bottom | Right,
ResizeBottom = Bottom,
ResizeBottomLeft = Bottom | Left,
ResizeLeft = Left
};
struct QWasmTitleBarOptions {
QRect rect;
Qt::WindowFlags flags;
@ -153,7 +134,7 @@ private:
private:
struct ResizeState {
ResizeMode m_resizeMode;
Qt::Edges m_resizeEdges;
QPoint m_originInScreenCoords;
QRect m_initialWindowBounds;
const QPoint m_minShrink;

View File

@ -283,23 +283,25 @@ QWasmEventTranslator::QWasmEventTranslator() = default;
QWasmEventTranslator::~QWasmEventTranslator() = default;
QCursor QWasmEventTranslator::cursorForMode(QWasmCompositor::ResizeMode m)
QCursor QWasmEventTranslator::cursorForEdges(Qt::Edges edges)
{
switch (m) {
case QWasmCompositor::ResizeTopLeft:
case QWasmCompositor::ResizeBottomRight:
switch (edges) {
case Qt::Edge::LeftEdge | Qt::Edge::TopEdge:
case Qt::Edge::RightEdge | Qt::Edge::BottomEdge:
return Qt::SizeFDiagCursor;
case QWasmCompositor::ResizeBottomLeft:
case QWasmCompositor::ResizeTopRight:
case Qt::Edge::LeftEdge | Qt::Edge::BottomEdge:
case Qt::Edge::RightEdge | Qt::Edge::TopEdge:
return Qt::SizeBDiagCursor;
case QWasmCompositor::ResizeTop:
case QWasmCompositor::ResizeBottom:
case Qt::Edge::TopEdge:
case Qt::Edge::BottomEdge:
return Qt::SizeVerCursor;
case QWasmCompositor::ResizeLeft:
case QWasmCompositor::ResizeRight:
case Qt::Edge::LeftEdge:
case Qt::Edge::RightEdge:
return Qt::SizeHorCursor;
case QWasmCompositor::ResizeNone:
case Qt::Edge(0):
return Qt::ArrowCursor;
default:
Q_ASSERT(false); // Bad edges
}
return Qt::ArrowCursor;
}

View File

@ -33,7 +33,7 @@ public:
explicit QWasmEventTranslator();
~QWasmEventTranslator();
static QCursor cursorForMode(QWasmCompositor::ResizeMode mode);
static QCursor cursorForEdges(Qt::Edges edges);
TranslatedEvent translateKeyEvent(int emEventType, const EmscriptenKeyboardEvent *keyEvent);

View File

@ -245,45 +245,24 @@ bool QWasmWindow::isPointOnResizeRegion(QPoint point) const
&& resizeRegion().contains(point);
}
QWasmCompositor::ResizeMode QWasmWindow::resizeModeAtPoint(QPoint point) const
Qt::Edges QWasmWindow::resizeEdgesAtPoint(QPoint point) const
{
QPoint p1 = window()->frameGeometry().topLeft() - QPoint(5, 5);
QPoint p2 = window()->frameGeometry().bottomRight() + QPoint(5, 5);
int corner = 20;
const QPoint topLeft = window()->frameGeometry().topLeft() - QPoint(5, 5);
const QPoint bottomRight = window()->frameGeometry().bottomRight() + QPoint(5, 5);
const int gripAreaWidth = std::min(20, (bottomRight.y() - topLeft.y()) / 2);
QRect top(p1, QPoint(p2.x(), p1.y() + corner));
QRect middle(QPoint(p1.x(), p1.y() + corner), QPoint(p2.x(), p2.y() - corner));
QRect bottom(QPoint(p1.x(), p2.y() - corner), p2);
const QRect top(topLeft, QPoint(bottomRight.x(), topLeft.y() + gripAreaWidth));
const QRect bottom(QPoint(topLeft.x(), bottomRight.y() - gripAreaWidth), bottomRight);
const QRect left(topLeft, QPoint(topLeft.x() + gripAreaWidth, bottomRight.y()));
const QRect right(QPoint(bottomRight.x() - gripAreaWidth, topLeft.y()), bottomRight);
QRect left(p1, QPoint(p1.x() + corner, p2.y()));
QRect center(QPoint(p1.x() + corner, p1.y()), QPoint(p2.x() - corner, p2.y()));
QRect right(QPoint(p2.x() - corner, p1.y()), p2);
Q_ASSERT(!top.intersects(bottom));
Q_ASSERT(!left.intersects(right));
if (top.contains(point)) {
// Top
if (left.contains(point))
return QWasmCompositor::ResizeTopLeft;
if (center.contains(point))
return QWasmCompositor::ResizeTop;
if (right.contains(point))
return QWasmCompositor::ResizeTopRight;
} else if (middle.contains(point)) {
// Middle
if (left.contains(point))
return QWasmCompositor::ResizeLeft;
if (right.contains(point))
return QWasmCompositor::ResizeRight;
} else if (bottom.contains(point)) {
// Bottom
if (left.contains(point))
return QWasmCompositor::ResizeBottomLeft;
if (center.contains(point))
return QWasmCompositor::ResizeBottom;
if (right.contains(point))
return QWasmCompositor::ResizeBottomRight;
}
return QWasmCompositor::ResizeNone;
Qt::Edges edges(top.contains(point) ? Qt::Edge::TopEdge : Qt::Edge(0));
edges |= bottom.contains(point) ? Qt::Edge::BottomEdge : Qt::Edge(0);
edges |= left.contains(point) ? Qt::Edge::LeftEdge : Qt::Edge(0);
return edges | (right.contains(point) ? Qt::Edge::RightEdge : Qt::Edge(0));
}
QRect getSubControlRect(const QWasmWindow *window, QWasmCompositor::SubControls subControl)

View File

@ -53,7 +53,7 @@ public:
QRegion resizeRegion() const;
bool isPointOnTitle(QPoint point) const;
bool isPointOnResizeRegion(QPoint point) const;
QWasmCompositor::ResizeMode resizeModeAtPoint(QPoint point) const;
Qt::Edges resizeEdgesAtPoint(QPoint point) const;
QRect maxButtonRect() const;
QRect minButtonRect() const;
QRect closeButtonRect() const;