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

View File

@ -60,25 +60,6 @@ public:
}; };
Q_DECLARE_FLAGS(StateFlags, QWasmStateFlag) 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 { struct QWasmTitleBarOptions {
QRect rect; QRect rect;
Qt::WindowFlags flags; Qt::WindowFlags flags;
@ -153,7 +134,7 @@ private:
private: private:
struct ResizeState { struct ResizeState {
ResizeMode m_resizeMode; Qt::Edges m_resizeEdges;
QPoint m_originInScreenCoords; QPoint m_originInScreenCoords;
QRect m_initialWindowBounds; QRect m_initialWindowBounds;
const QPoint m_minShrink; const QPoint m_minShrink;

View File

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

View File

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

View File

@ -245,45 +245,24 @@ bool QWasmWindow::isPointOnResizeRegion(QPoint point) const
&& resizeRegion().contains(point); && 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); const QPoint topLeft = window()->frameGeometry().topLeft() - QPoint(5, 5);
QPoint p2 = window()->frameGeometry().bottomRight() + QPoint(5, 5); const QPoint bottomRight = window()->frameGeometry().bottomRight() + QPoint(5, 5);
int corner = 20; const int gripAreaWidth = std::min(20, (bottomRight.y() - topLeft.y()) / 2);
QRect top(p1, QPoint(p2.x(), p1.y() + corner)); const QRect top(topLeft, QPoint(bottomRight.x(), topLeft.y() + gripAreaWidth));
QRect middle(QPoint(p1.x(), p1.y() + corner), QPoint(p2.x(), p2.y() - corner)); const QRect bottom(QPoint(topLeft.x(), bottomRight.y() - gripAreaWidth), bottomRight);
QRect bottom(QPoint(p1.x(), p2.y() - corner), p2); 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())); Q_ASSERT(!top.intersects(bottom));
QRect center(QPoint(p1.x() + corner, p1.y()), QPoint(p2.x() - corner, p2.y())); Q_ASSERT(!left.intersects(right));
QRect right(QPoint(p2.x() - corner, p1.y()), p2);
if (top.contains(point)) { Qt::Edges edges(top.contains(point) ? Qt::Edge::TopEdge : Qt::Edge(0));
// Top edges |= bottom.contains(point) ? Qt::Edge::BottomEdge : Qt::Edge(0);
if (left.contains(point)) edges |= left.contains(point) ? Qt::Edge::LeftEdge : Qt::Edge(0);
return QWasmCompositor::ResizeTopLeft; return edges | (right.contains(point) ? Qt::Edge::RightEdge : Qt::Edge(0));
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;
} }
QRect getSubControlRect(const QWasmWindow *window, QWasmCompositor::SubControls subControl) QRect getSubControlRect(const QWasmWindow *window, QWasmCompositor::SubControls subControl)

View File

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