[QGIS Commit] r10776 - trunk/qgis/src/core/composer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed May 13 05:06:03 EDT 2009


Author: mhugent
Date: 2009-05-13 05:06:03 -0400 (Wed, 13 May 2009)
New Revision: 10776

Modified:
   trunk/qgis/src/core/composer/qgscomposeritem.cpp
   trunk/qgis/src/core/composer/qgscomposeritem.h
Log:
Some improvements and bugfixes for moving and resizing composer items

Modified: trunk/qgis/src/core/composer/qgscomposeritem.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposeritem.cpp	2009-05-12 13:38:32 UTC (rev 10775)
+++ trunk/qgis/src/core/composer/qgscomposeritem.cpp	2009-05-13 09:06:03 UTC (rev 10776)
@@ -371,19 +371,21 @@
   bool nearLowerBorder = false;
   bool nearUpperBorder = false;
 
-  if ( itemCoordPos.x() < 5 )
+  double borderTolerance = rectHandlerBorderTolerance();
+
+  if ( itemCoordPos.x() < borderTolerance )
   {
     nearLeftBorder = true;
   }
-  if ( itemCoordPos.y() < 5 )
+  if ( itemCoordPos.y() < borderTolerance )
   {
     nearUpperBorder = true;
   }
-  if ( itemCoordPos.x() > ( rect().width() - 5 ) )
+  if ( itemCoordPos.x() > ( rect().width() - borderTolerance ) )
   {
     nearRightBorder = true;
   }
-  if ( itemCoordPos.y() > ( rect().height() - 5 ) )
+  if ( itemCoordPos.y() > ( rect().height() - borderTolerance ) )
   {
     nearLowerBorder = true;
   }
@@ -431,6 +433,9 @@
     return;
   }
 
+  //test if change item is a composer item. If so, prefer call to  setSceneRect() instead of setTransform() and setRect()
+  QgsComposerItem* changeComposerItem = dynamic_cast<QgsComposerItem*>(changeItem);
+
   double mx = 0.0, my = 0.0, rx = 0.0, ry = 0.0;
   QPointF snappedPosition = mComposition->snapPointToGrid( currentPosition );
   //double diffX = snappedPosition.x() - mouseMoveStartPos.x();
@@ -499,17 +504,34 @@
       double moveRectX = snappedLeftPoint.x() - originalItem->transform().dx();
       double moveRectY = snappedLeftPoint.y() - originalItem->transform().dy();
 
-      QTransform moveTransform;
-      moveTransform.translate( originalItem->transform().dx() + moveRectX, originalItem->transform().dy() + moveRectY );
-      changeItem->setTransform( moveTransform );
+      if(!changeComposerItem)
+      {
+        QTransform moveTransform;
+        moveTransform.translate( originalItem->transform().dx() + moveRectX, originalItem->transform().dy() + moveRectY );
+        changeItem->setTransform( moveTransform );
+      }
+      else  //for composer items, we prefer setSceneRect as subclasses can implement custom behaviour (e.g. item group)
+      {
+        changeComposerItem->setSceneRect(QRectF(originalItem->transform().dx() + moveRectX, \
+                                                originalItem->transform().dy() + moveRectY, \
+                                                originalItem->rect().width(), originalItem->rect().height()));
+      }
       return;
   }
 
-  QTransform itemTransform;
-  itemTransform.translate( originalItem->transform().dx() + mx, originalItem->transform().dy() + my );
-  changeItem->setTransform( itemTransform );
-  QRectF itemRect( 0, 0, originalItem->rect().width() + rx,  originalItem->rect().height() + ry );
-  changeItem->setRect( itemRect );
+  if(!changeComposerItem)
+  {
+    QTransform itemTransform;
+    itemTransform.translate( originalItem->transform().dx() + mx, originalItem->transform().dy() + my );
+    changeItem->setTransform( itemTransform );
+    QRectF itemRect( 0, 0, originalItem->rect().width() + rx,  originalItem->rect().height() + ry );
+    changeItem->setRect( itemRect );
+  }
+  else //for composer items, we prefer setSceneRect as subclasses can implement custom behaviour (e.g. item group)
+  {
+    changeComposerItem->setSceneRect( QRectF(originalItem->transform().dx() + mx, originalItem->transform().dy() + my, \
+      originalItem->rect().width() + rx, originalItem->rect().height() + ry) );
+  }
 }
 
 void QgsComposerItem::drawSelectionBoxes( QPainter* p )
@@ -523,27 +545,9 @@
   {
     //size of symbol boxes depends on zoom level in composer view
     double viewScaleFactor = horizontalViewScaleFactor();
-    double rectHandlerSize = 10.0 / viewScaleFactor;
-    double lockSymbolSize = 20.0 / viewScaleFactor;
+    double rectHandlerSize = rectHandlerBorderTolerance();
+    double sizeLockSymbol = lockSymbolSize();
 
-    //make sure the boxes don't get too large
-    if(rectHandlerSize > (rect().width() / 3))
-    {
-        rectHandlerSize = rect().width() / 3;
-    }
-    if(rectHandlerSize > (rect().height() / 3))
-    {
-        rectHandlerSize = rect().height() / 3;
-    }
-    if(lockSymbolSize > (rect().width() / 3))
-    {
-        lockSymbolSize = rect().width() / 3;
-    }
-    if(lockSymbolSize > (rect().height() / 3))
-    {
-        lockSymbolSize = rect().height() / 3;
-    }
-
     if(mItemPositionLocked)
     {
         //draw lock symbol at upper left edge. Use QImage to be independant of the graphic system
@@ -556,7 +560,7 @@
         QImage lockImage(lockIconPath);
         if(!lockImage.isNull())
         {
-            p->drawImage(QRectF(0, 0, lockSymbolSize, lockSymbolSize), lockImage, QRectF(0, 0, lockImage.width(), lockImage.height()));
+            p->drawImage(QRectF(0, 0, sizeLockSymbol, sizeLockSymbol), lockImage, QRectF(0, 0, lockImage.width(), lockImage.height()));
         }
     }
     else //draw blue squares
@@ -743,6 +747,39 @@
   return result;
 }
 
+double QgsComposerItem::rectHandlerBorderTolerance() const
+{
+     //size of symbol boxes depends on zoom level in composer view
+    double viewScaleFactor = horizontalViewScaleFactor();
+    double rectHandlerSize = 10.0 / viewScaleFactor;
+
+    //make sure the boxes don't get too large
+    if(rectHandlerSize > (rect().width() / 3))
+    {
+        rectHandlerSize = rect().width() / 3;
+    }
+    if(rectHandlerSize > (rect().height() / 3))
+    {
+        rectHandlerSize = rect().height() / 3;
+    }
+    return rectHandlerSize;
+}
+
+double QgsComposerItem::lockSymbolSize() const
+{
+  double lockSymbolSize = 20.0 / horizontalViewScaleFactor();
+
+  if(lockSymbolSize > (rect().width() / 3))
+  {
+    lockSymbolSize = rect().width() / 3;
+  }
+  if(lockSymbolSize > (rect().height() / 3))
+  {
+    lockSymbolSize = rect().height() / 3;
+  }
+  return lockSymbolSize;
+}
+
 void QgsComposerItem::updateCursor(const QPointF& itemPos)
 {
     setCursor( cursorForPosition(itemPos) );

Modified: trunk/qgis/src/core/composer/qgscomposeritem.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposeritem.h	2009-05-12 13:38:32 UTC (rev 10775)
+++ trunk/qgis/src/core/composer/qgscomposeritem.h	2009-05-13 09:06:03 UTC (rev 10776)
@@ -220,8 +220,17 @@
     /**Draw background*/
     virtual void drawBackground( QPainter* p );
 
+    /**Returns the current (zoom level dependent) tolerance to decide if mouse position is close enough to the \
+    item border for resizing*/
+    double rectHandlerBorderTolerance() const;
+
+    /**Returns the size of the lock symbol depending on the composer zoom level and the item size
+    @note: this function was introduced in version 1.2*/
+    double lockSymbolSize() const;
+
     /**Returns the zoom factor of the graphics view. If no
-     graphics view exists, the default 1 is returned*/
+     graphics view exists, the default 1 is returned
+    @note: this function was introduced in version 1.2*/
     double horizontalViewScaleFactor() const;
 };
 



More information about the QGIS-commit mailing list