pr comments

This commit is contained in:
Alex Okonechnikov 2025-12-31 07:46:38 -05:00
parent 02c6d0bf47
commit 4af15ab532
2 changed files with 41 additions and 18 deletions

View file

@ -257,9 +257,24 @@ void ZoneViewWidget::stopWindowDrag()
ungrabMouse();
}
QPointF ZoneViewWidget::draggedWindowPos(const QPoint &screenPos,
const QPointF &scenePos,
const QPointF &buttonDownScenePos) const
QGraphicsView *ZoneViewWidget::findDragView(QWidget *eventWidget) const
{
QWidget *current = eventWidget;
while (current) {
if (auto *view = qobject_cast<QGraphicsView *>(current))
return view;
current = current->parentWidget();
}
if (scene() && !scene()->views().isEmpty())
return scene()->views().constFirst();
return nullptr;
}
QPointF ZoneViewWidget::calcDraggedWindowPos(const QPoint &screenPos,
const QPointF &scenePos,
const QPointF &buttonDownScenePos) const
{
if (dragView && dragView->viewport()) {
const QPoint vpStart = dragView->viewport()->mapFromGlobal(dragStartScreenPos);
@ -285,6 +300,7 @@ bool ZoneViewWidget::windowFrameEvent(QEvent *event)
if (me->button() == Qt::LeftButton && section == Qt::TitleBarArea) {
// avoid drag on close button
const QRectF frameRectF = windowFrameRect();
// square at right end of the title bar is the close button
const QRectF closeRect(frameRectF.right() - kTitleBarHeight, frameRectF.top(), kTitleBarHeight,
kTitleBarHeight);
if (closeRect.contains(me->pos())) {
@ -297,17 +313,7 @@ bool ZoneViewWidget::windowFrameEvent(QEvent *event)
dragStartItemPos = pos();
dragStartScreenPos = me->screenPos();
dragView = nullptr;
if (me->widget()) {
QWidget *current = me->widget();
while (current && !dragView) {
dragView = qobject_cast<QGraphicsView *>(current);
current = current->parentWidget();
}
}
if (!dragView && scene() && !scene()->views().isEmpty()) {
dragView = scene()->views().constFirst();
}
dragView = findDragView(me->widget());
// need to grab mouse to receive events and not miss initial movement
grabMouse();
@ -326,7 +332,7 @@ bool ZoneViewWidget::windowFrameEvent(QEvent *event)
return true;
}
setPos(draggedWindowPos(me->screenPos(), me->scenePos(), me->buttonDownScenePos(Qt::LeftButton)));
setPos(calcDraggedWindowPos(me->screenPos(), me->scenePos(), me->buttonDownScenePos(Qt::LeftButton)));
me->accept();
return true;
}
@ -352,7 +358,7 @@ void ZoneViewWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
// move if the scene routes moves while dragging
if (draggingWindow && (event->buttons() & Qt::LeftButton)) {
setPos(draggedWindowPos(event->screenPos(), event->scenePos(), event->buttonDownScenePos(Qt::LeftButton)));
setPos(calcDraggedWindowPos(event->screenPos(), event->scenePos(), event->buttonDownScenePos(Qt::LeftButton)));
event->accept();
return;
}

View file

@ -3,7 +3,6 @@
* @ingroup GameGraphicsZones
* @brief TODO: Document this.
*/
#ifndef ZONEVIEWWIDGET_H
#define ZONEVIEWWIDGET_H
@ -30,6 +29,7 @@ class QGraphicsSceneMouseEvent;
class QGraphicsSceneWheelEvent;
class QStyleOption;
class QGraphicsView;
class QWidget;
class ScrollableGraphicsProxyWidget : public QGraphicsProxyWidget
{
@ -74,7 +74,24 @@ private:
QPointer<QGraphicsView> dragView;
void stopWindowDrag();
QPointF draggedWindowPos(const QPoint &screenPos, const QPointF &scenePos, const QPointF &buttonDownScenePos) const;
/**
* @brief Resolves the QGraphicsView to use for drag coordinate mapping
*
* @param eventWidget QWidget that originated the mouse event
* @return The resolved QGraphicsView
*/
QGraphicsView *findDragView(QWidget *eventWidget) const;
/**
* @brief Calculates the desired widget position while dragging
*
* @param screenPos Global screen coordinates of the current mouse position
* @param scenePos Scene coordinates of the current mouse position
* @param buttonDownScenePos Scene coordinates of the initial mouse press position
*
* @return The new widget position in scene coordinates
*/
QPointF
calcDraggedWindowPos(const QPoint &screenPos, const QPointF &scenePos, const QPointF &buttonDownScenePos) const;
void resizeScrollbar(qreal newZoneHeight);
signals: