@@ -362,15 +362,28 @@ void QgsComposerMouseHandles::hoverMoveEvent( QGraphicsSceneHoverEvent * event )
362
362
363
363
void QgsComposerMouseHandles::mouseMoveEvent ( QGraphicsSceneMouseEvent* event )
364
364
{
365
+ bool shiftModifier = false ;
366
+ bool controlModifier = false ;
367
+ if ( event->modifiers () & Qt::ShiftModifier )
368
+ {
369
+ // shift key depressed
370
+ shiftModifier = true ;
371
+ }
372
+ if ( event->modifiers () & Qt::ControlModifier )
373
+ {
374
+ // shift key depressed
375
+ controlModifier = true ;
376
+ }
377
+
365
378
if ( mIsDragging )
366
379
{
367
380
// currently dragging a selection
368
- dragMouseMove ( event->lastScenePos () );
381
+ dragMouseMove ( event->lastScenePos (), shiftModifier );
369
382
}
370
383
else if ( mIsResizing )
371
384
{
372
385
// currently resizing a selection
373
- resizeMouseMove ( event->lastScenePos () );
386
+ resizeMouseMove ( event->lastScenePos (), shiftModifier, controlModifier );
374
387
}
375
388
376
389
mLastMouseEventPos = event->lastScenePos ();
@@ -486,7 +499,7 @@ void QgsComposerMouseHandles::mousePressEvent( QGraphicsSceneMouseEvent* event )
486
499
487
500
}
488
501
489
- void QgsComposerMouseHandles::dragMouseMove ( const QPointF& currentPosition )
502
+ void QgsComposerMouseHandles::dragMouseMove ( const QPointF& currentPosition, bool lockMovement )
490
503
{
491
504
if ( !mComposition )
492
505
{
@@ -515,7 +528,7 @@ void QgsComposerMouseHandles::dragMouseMove( const QPointF& currentPosition )
515
528
setTransform ( moveTransform );
516
529
}
517
530
518
- void QgsComposerMouseHandles::resizeMouseMove ( const QPointF& currentPosition )
531
+ void QgsComposerMouseHandles::resizeMouseMove ( const QPointF& currentPosition, bool lockRatio, bool fromCenter )
519
532
{
520
533
521
534
if ( !mComposition )
@@ -529,55 +542,139 @@ void QgsComposerMouseHandles::resizeMouseMove( const QPointF& currentPosition )
529
542
double diffX = 0 ;
530
543
double diffY = 0 ;
531
544
532
- // TODO: shift-resizing should lock aspect ratio
545
+ double ratio = 0 ;
546
+ if ( lockRatio && mBeginHandleHeight != 0 )
547
+ {
548
+ ratio = mBeginHandleWidth / mBeginHandleHeight ;
549
+ }
533
550
534
551
// TODO: resizing eg from top handle to below bottom handle
535
552
switch ( mCurrentMouseMoveAction )
536
553
{
537
554
// vertical resize
538
555
case QgsComposerMouseHandles::ResizeUp:
539
556
diffY = snappedPosition.y () - mBeginHandlePos .y ();
540
- mx = 0 ; my = diffY; rx = 0 ; ry = -diffY;
557
+ if ( ratio )
558
+ {
559
+ diffX = (( mBeginHandleHeight - diffY ) * ratio ) - mBeginHandleWidth ;
560
+ mx = -diffX / 2 ; my = diffY; rx = diffX; ry = -diffY;
561
+ }
562
+ else
563
+ {
564
+ mx = 0 ; my = diffY; rx = 0 ; ry = -diffY;
565
+ }
541
566
break ;
542
567
543
568
case QgsComposerMouseHandles::ResizeDown:
544
569
diffY = snappedPosition.y () - ( mBeginHandlePos .y () + mBeginHandleHeight );
545
- mx = 0 ; my = 0 ; rx = 0 ; ry = diffY;
570
+ if ( ratio )
571
+ {
572
+ diffX = (( mBeginHandleHeight + diffY ) * ratio ) - mBeginHandleWidth ;
573
+ mx = -diffX / 2 ; my = 0 ; rx = diffX; ry = diffY;
574
+ }
575
+ else
576
+ {
577
+ mx = 0 ; my = 0 ; rx = 0 ; ry = diffY;
578
+ }
546
579
break ;
547
580
548
581
// horizontal resize
549
582
case QgsComposerMouseHandles::ResizeLeft:
550
583
diffX = snappedPosition.x () - mBeginHandlePos .x ();
551
- mx = diffX, my = 0 ; rx = -diffX; ry = 0 ;
584
+ if ( ratio )
585
+ {
586
+ diffY = (( mBeginHandleWidth - diffX ) / ratio ) - mBeginHandleHeight ;
587
+ mx = diffX; my = -diffY / 2 ; rx = -diffX; ry = diffY;
588
+ }
589
+ else
590
+ {
591
+ mx = diffX, my = 0 ; rx = -diffX; ry = 0 ;
592
+ }
552
593
break ;
553
594
554
595
case QgsComposerMouseHandles::ResizeRight:
555
596
diffX = snappedPosition.x () - ( mBeginHandlePos .x () + mBeginHandleWidth );
556
- mx = 0 ; my = 0 ; rx = diffX, ry = 0 ;
597
+ if ( ratio )
598
+ {
599
+ diffY = (( mBeginHandleWidth + diffX ) / ratio ) - mBeginHandleHeight ;
600
+ mx = 0 ; my = -diffY / 2 ; rx = diffX; ry = diffY;
601
+ }
602
+ else
603
+ {
604
+ mx = 0 ; my = 0 ; rx = diffX, ry = 0 ;
605
+ }
557
606
break ;
558
607
559
608
// diagonal resize
560
609
case QgsComposerMouseHandles::ResizeLeftUp:
561
610
diffX = snappedPosition.x () - mBeginHandlePos .x ();
562
611
diffY = snappedPosition.y () - mBeginHandlePos .y ();
612
+ if ( ratio )
613
+ {
614
+ // ratio locked resize
615
+ if (( mBeginHandleWidth - diffX ) / ( mBeginHandleHeight - diffY ) > ratio )
616
+ {
617
+ diffX = mBeginHandleWidth - (( mBeginHandleHeight - diffY ) * ratio );
618
+ }
619
+ else
620
+ {
621
+ diffY = mBeginHandleHeight - (( mBeginHandleWidth - diffX ) / ratio );
622
+ }
623
+ }
563
624
mx = diffX, my = diffY; rx = -diffX; ry = -diffY;
564
625
break ;
565
626
566
627
case QgsComposerMouseHandles::ResizeRightDown:
567
628
diffX = snappedPosition.x () - ( mBeginHandlePos .x () + mBeginHandleWidth );
568
629
diffY = snappedPosition.y () - ( mBeginHandlePos .y () + mBeginHandleHeight );
630
+ if ( ratio )
631
+ {
632
+ // ratio locked resize
633
+ if (( mBeginHandleWidth + diffX ) / ( mBeginHandleHeight + diffY ) > ratio )
634
+ {
635
+ diffX = (( mBeginHandleHeight + diffY ) * ratio ) - mBeginHandleWidth ;
636
+ }
637
+ else
638
+ {
639
+ diffY = (( mBeginHandleWidth + diffX ) / ratio ) - mBeginHandleHeight ;
640
+ }
641
+ }
569
642
mx = 0 ; my = 0 ; rx = diffX, ry = diffY;
570
643
break ;
571
644
572
645
case QgsComposerMouseHandles::ResizeRightUp:
573
646
diffX = snappedPosition.x () - ( mBeginHandlePos .x () + mBeginHandleWidth );
574
647
diffY = snappedPosition.y () - mBeginHandlePos .y ();
648
+ if ( ratio )
649
+ {
650
+ // ratio locked resize
651
+ if (( mBeginHandleWidth + diffX ) / ( mBeginHandleHeight - diffY ) > ratio )
652
+ {
653
+ diffX = (( mBeginHandleHeight - diffY ) * ratio ) - mBeginHandleWidth ;
654
+ }
655
+ else
656
+ {
657
+ diffY = mBeginHandleHeight - (( mBeginHandleWidth + diffX ) / ratio );
658
+ }
659
+ }
575
660
mx = 0 ; my = diffY, rx = diffX, ry = -diffY;
576
661
break ;
577
662
578
663
case QgsComposerMouseHandles::ResizeLeftDown:
579
664
diffX = snappedPosition.x () - mBeginHandlePos .x ();
580
665
diffY = snappedPosition.y () - ( mBeginHandlePos .y () + mBeginHandleHeight );
666
+ if ( ratio )
667
+ {
668
+ // ratio locked resize
669
+ if (( mBeginHandleWidth - diffX ) / ( mBeginHandleHeight + diffY ) > ratio )
670
+ {
671
+ diffX = mBeginHandleWidth - (( mBeginHandleHeight + diffY ) * ratio );
672
+ }
673
+ else
674
+ {
675
+ diffY = (( mBeginHandleWidth - diffX ) / ratio ) - mBeginHandleHeight ;
676
+ }
677
+ }
581
678
mx = diffX, my = 0 ; rx = -diffX; ry = diffY;
582
679
break ;
583
680
@@ -587,6 +684,15 @@ void QgsComposerMouseHandles::resizeMouseMove( const QPointF& currentPosition )
587
684
break ;
588
685
}
589
686
687
+ // resizing from center of objects?
688
+ if ( fromCenter )
689
+ {
690
+ my = -ry;
691
+ mx = -rx;
692
+ ry = 2 * ry;
693
+ rx = 2 * rx;
694
+ }
695
+
590
696
// update selection handle rectangle
591
697
QTransform itemTransform;
592
698
itemTransform.translate ( mx, my );
0 commit comments