mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Lock rotation handle UI/UX behind an enabled boolean
This commit is contained in:
parent
ae463d8b75
commit
1f6c1277dd
@ -44,6 +44,8 @@ QgsLayoutMouseHandles::QgsLayoutMouseHandles( QgsLayout *layout, QgsLayoutView *
|
|||||||
, mLayout( layout )
|
, mLayout( layout )
|
||||||
, mView( view )
|
, mView( view )
|
||||||
{
|
{
|
||||||
|
setRotationEnabled( true );
|
||||||
|
|
||||||
//listen for selection changes, and update handles accordingly
|
//listen for selection changes, and update handles accordingly
|
||||||
connect( mLayout, &QGraphicsScene::selectionChanged, this, &QgsLayoutMouseHandles::selectionChanged );
|
connect( mLayout, &QGraphicsScene::selectionChanged, this, &QgsLayoutMouseHandles::selectionChanged );
|
||||||
|
|
||||||
|
@ -47,6 +47,17 @@ QgsGraphicsViewMouseHandles::QgsGraphicsViewMouseHandles( QGraphicsView *view )
|
|||||||
mRotationHandlePath.lineTo( 0, 14 );
|
mRotationHandlePath.lineTo( 0, 14 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsGraphicsViewMouseHandles::setRotationEnabled( bool enable )
|
||||||
|
{
|
||||||
|
if ( mRotationEnabled == enable )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mRotationEnabled = enable;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
void QgsGraphicsViewMouseHandles::paintInternal( QPainter *painter, bool showHandles, bool showStaticBoundingBoxes, bool showTemporaryBoundingBoxes, const QStyleOptionGraphicsItem *, QWidget * )
|
void QgsGraphicsViewMouseHandles::paintInternal( QPainter *painter, bool showHandles, bool showStaticBoundingBoxes, bool showTemporaryBoundingBoxes, const QStyleOptionGraphicsItem *, QWidget * )
|
||||||
{
|
{
|
||||||
if ( !showHandles )
|
if ( !showHandles )
|
||||||
@ -142,58 +153,61 @@ void QgsGraphicsViewMouseHandles::drawHandles( QPainter *painter, double rectHan
|
|||||||
//bottom right
|
//bottom right
|
||||||
painter->drawRect( QRectF( rect().width() - rectHandlerSize, rect().height() - rectHandlerSize, rectHandlerSize, rectHandlerSize ) );
|
painter->drawRect( QRectF( rect().width() - rectHandlerSize, rect().height() - rectHandlerSize, rectHandlerSize, rectHandlerSize ) );
|
||||||
|
|
||||||
//draw rotate handles
|
if ( isRotationEnabled() )
|
||||||
const double scale = rectHandlerSize / mHandleSize;
|
|
||||||
const bool drawBottomRotationHandles = ( rectHandlerSize * 2 ) + ( mRotationHandleSize * scale * 2 ) < rect().height();
|
|
||||||
const bool drawRightRotationHandles = ( rectHandlerSize * 2 ) + ( mRotationHandleSize * scale * 2 ) < rect().width();
|
|
||||||
QTransform transform;
|
|
||||||
|
|
||||||
//top left
|
|
||||||
transform.reset();
|
|
||||||
transform.translate( rectHandlerSize, rectHandlerSize );
|
|
||||||
transform.scale( scale, scale );
|
|
||||||
painter->save();
|
|
||||||
painter->setTransform( transform, true );
|
|
||||||
painter->drawPath( mRotationHandlePath );
|
|
||||||
painter->restore();
|
|
||||||
|
|
||||||
//top right
|
|
||||||
if ( drawRightRotationHandles )
|
|
||||||
{
|
{
|
||||||
|
//draw rotate handles
|
||||||
|
const double scale = rectHandlerSize / mHandleSize;
|
||||||
|
const bool drawBottomRotationHandles = ( rectHandlerSize * 2 ) + ( mRotationHandleSize * scale * 2 ) < rect().height();
|
||||||
|
const bool drawRightRotationHandles = ( rectHandlerSize * 2 ) + ( mRotationHandleSize * scale * 2 ) < rect().width();
|
||||||
|
QTransform transform;
|
||||||
|
|
||||||
|
//top left
|
||||||
transform.reset();
|
transform.reset();
|
||||||
transform.translate( rect().width() - rectHandlerSize, rectHandlerSize );
|
transform.translate( rectHandlerSize, rectHandlerSize );
|
||||||
transform.rotate( 90 );
|
|
||||||
transform.scale( scale, scale );
|
|
||||||
painter->save();
|
|
||||||
painter->setTransform( transform, true );
|
|
||||||
painter->drawPath( mRotationHandlePath );
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( drawBottomRotationHandles )
|
|
||||||
{
|
|
||||||
//bottom left
|
|
||||||
transform.reset();
|
|
||||||
transform.translate( rectHandlerSize, rect().height() - rectHandlerSize );
|
|
||||||
transform.rotate( 270 );
|
|
||||||
transform.scale( scale, scale );
|
|
||||||
painter->save();
|
|
||||||
painter->setTransform( transform, true );
|
|
||||||
painter->drawPath( mRotationHandlePath );
|
|
||||||
painter->restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( drawBottomRotationHandles && drawRightRotationHandles )
|
|
||||||
{
|
|
||||||
//bottom right
|
|
||||||
transform.reset();
|
|
||||||
transform.translate( rect().width() - rectHandlerSize, rect().height() - rectHandlerSize );
|
|
||||||
transform.rotate( 180 );
|
|
||||||
transform.scale( scale, scale );
|
transform.scale( scale, scale );
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setTransform( transform, true );
|
painter->setTransform( transform, true );
|
||||||
painter->drawPath( mRotationHandlePath );
|
painter->drawPath( mRotationHandlePath );
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
|
//top right
|
||||||
|
if ( drawRightRotationHandles )
|
||||||
|
{
|
||||||
|
transform.reset();
|
||||||
|
transform.translate( rect().width() - rectHandlerSize, rectHandlerSize );
|
||||||
|
transform.rotate( 90 );
|
||||||
|
transform.scale( scale, scale );
|
||||||
|
painter->save();
|
||||||
|
painter->setTransform( transform, true );
|
||||||
|
painter->drawPath( mRotationHandlePath );
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( drawBottomRotationHandles )
|
||||||
|
{
|
||||||
|
//bottom left
|
||||||
|
transform.reset();
|
||||||
|
transform.translate( rectHandlerSize, rect().height() - rectHandlerSize );
|
||||||
|
transform.rotate( 270 );
|
||||||
|
transform.scale( scale, scale );
|
||||||
|
painter->save();
|
||||||
|
painter->setTransform( transform, true );
|
||||||
|
painter->drawPath( mRotationHandlePath );
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( drawBottomRotationHandles && drawRightRotationHandles )
|
||||||
|
{
|
||||||
|
//bottom right
|
||||||
|
transform.reset();
|
||||||
|
transform.translate( rect().width() - rectHandlerSize, rect().height() - rectHandlerSize );
|
||||||
|
transform.rotate( 180 );
|
||||||
|
transform.scale( scale, scale );
|
||||||
|
painter->save();
|
||||||
|
painter->setTransform( transform, true );
|
||||||
|
painter->drawPath( mRotationHandlePath );
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,7 +448,7 @@ Qgis::MouseHandlesAction QgsGraphicsViewMouseHandles::mouseActionForPosition( QP
|
|||||||
{
|
{
|
||||||
nearLeftBorder = true;
|
nearLeftBorder = true;
|
||||||
}
|
}
|
||||||
else if ( itemCoordPos.x() >= borderTolerance && itemCoordPos.x() < ( borderTolerance + innerTolerance ) )
|
else if ( isRotationEnabled() && itemCoordPos.x() >= borderTolerance && itemCoordPos.x() < ( borderTolerance + innerTolerance ) )
|
||||||
{
|
{
|
||||||
nearLeftInner = true;
|
nearLeftInner = true;
|
||||||
}
|
}
|
||||||
@ -442,7 +456,7 @@ Qgis::MouseHandlesAction QgsGraphicsViewMouseHandles::mouseActionForPosition( QP
|
|||||||
{
|
{
|
||||||
nearUpperBorder = true;
|
nearUpperBorder = true;
|
||||||
}
|
}
|
||||||
else if ( itemCoordPos.y() >= borderTolerance && itemCoordPos.y() < ( borderTolerance + innerTolerance ) )
|
else if ( isRotationEnabled() && itemCoordPos.y() >= borderTolerance && itemCoordPos.y() < ( borderTolerance + innerTolerance ) )
|
||||||
{
|
{
|
||||||
nearUpperInner = true;
|
nearUpperInner = true;
|
||||||
}
|
}
|
||||||
@ -450,7 +464,7 @@ Qgis::MouseHandlesAction QgsGraphicsViewMouseHandles::mouseActionForPosition( QP
|
|||||||
{
|
{
|
||||||
nearRightBorder = true;
|
nearRightBorder = true;
|
||||||
}
|
}
|
||||||
else if ( itemCoordPos.x() <= ( rect().width() - borderTolerance ) && itemCoordPos.x() > ( rect().width() - borderTolerance - innerTolerance ) )
|
else if ( isRotationEnabled() && itemCoordPos.x() <= ( rect().width() - borderTolerance ) && itemCoordPos.x() > ( rect().width() - borderTolerance - innerTolerance ) )
|
||||||
{
|
{
|
||||||
nearRightInner = true;
|
nearRightInner = true;
|
||||||
}
|
}
|
||||||
@ -458,7 +472,7 @@ Qgis::MouseHandlesAction QgsGraphicsViewMouseHandles::mouseActionForPosition( QP
|
|||||||
{
|
{
|
||||||
nearLowerBorder = true;
|
nearLowerBorder = true;
|
||||||
}
|
}
|
||||||
else if ( itemCoordPos.y() <= ( rect().height() - borderTolerance ) && itemCoordPos.y() > ( rect().height() - borderTolerance - innerTolerance ) )
|
else if ( isRotationEnabled() && itemCoordPos.y() <= ( rect().height() - borderTolerance ) && itemCoordPos.y() > ( rect().height() - borderTolerance - innerTolerance ) )
|
||||||
{
|
{
|
||||||
nearLowerInner = true;
|
nearLowerInner = true;
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,12 @@ class GUI_EXPORT QgsGraphicsViewMouseHandles : public QObject, public QGraphicsR
|
|||||||
//! Initializes a drag operation \since QGIS 3.34
|
//! Initializes a drag operation \since QGIS 3.34
|
||||||
void startMove( QPointF sceneCoordPos );
|
void startMove( QPointF sceneCoordPos );
|
||||||
|
|
||||||
|
//! Returns TRUE if rotation functionality is enabled
|
||||||
|
bool isRotationEnabled() const { return mRotationEnabled; }
|
||||||
|
|
||||||
|
//! Sets whether rotation functionality is enabled
|
||||||
|
void setRotationEnabled( bool enable );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
//! Redraws handles when selected item size changes
|
//! Redraws handles when selected item size changes
|
||||||
@ -214,10 +220,14 @@ class GUI_EXPORT QgsGraphicsViewMouseHandles : public QObject, public QGraphicsR
|
|||||||
|
|
||||||
QRectF mResizeRect;
|
QRectF mResizeRect;
|
||||||
|
|
||||||
|
bool mRotationEnabled = false;
|
||||||
//! Center point around which rotation occurs
|
//! Center point around which rotation occurs
|
||||||
QPointF mRotationCenter;
|
QPointF mRotationCenter;
|
||||||
|
//! The starting rotation angle from center point
|
||||||
double mRotationBegin = 0.0;
|
double mRotationBegin = 0.0;
|
||||||
|
//! The current rotation angle from center point
|
||||||
double mRotationCurrent = 0.0;
|
double mRotationCurrent = 0.0;
|
||||||
|
//! The rotation angle delta to be applied (can be snapped to common angle)
|
||||||
double mRotationDelta = 0.0;
|
double mRotationDelta = 0.0;
|
||||||
|
|
||||||
//! Start point of the last mouse move action (in scene coordinates)
|
//! Start point of the last mouse move action (in scene coordinates)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user