4 #include <QDragEnterEvent>
5 #include <QGraphicsLineItem>
19 mScaleMinPixelsWidth( 0 )
21 setMouseTracking(
true );
87 double startX = t.map( QPointF( 0, 0 ) ).x();
88 double endX = t.map( QPointF( width(), 0 ) ).x();
91 double markerPos = ( floor( startX / mmDisplay ) + 1 ) * mmDisplay;
96 while ( markerPos <= endX )
98 double pixelCoord =
mTransform.map( QPointF( markerPos, 0 ) ).x();
107 markerPos += mmDisplay;
117 double startY = t.map( QPointF( 0, 0 ) ).y();
118 double endY = t.map( QPointF( 0, height() ) ).y();
127 double beforePageCoord = -mmDisplay;
128 double firstPageY =
mTransform.map( QPointF( 0, 0 ) ).y();
131 while ( beforePageCoord > startY )
133 double pixelCoord =
mTransform.map( QPointF( 0, beforePageCoord ) ).y();
136 QString label = QString::number( beforePageCoord );
140 if ( pixelCoord + labelSize + 8 < firstPageY )
148 beforePageCoord -= mmDisplay;
152 drawSmallDivisions( &p, beforePageCoord + mmDisplay, numSmallDivisions, -mmDisplay, startY );
161 double nextPageStartPos = 0;
162 int nextPageStartPixel = 0;
164 for (
int i = startPage; i <= endPage; ++i )
166 double pageCoord = 0;
175 nextPageStartPixel =
mTransform.map( QPointF( 0, nextPageStartPos ) ).y();
180 nextPageStartPos = 0;
181 nextPageStartPixel = 0;
184 while (( totalCoord < nextPageStartPos ) || (( nextPageStartPos == 0 ) && ( totalCoord <= endY ) ) )
186 double pixelCoord =
mTransform.map( QPointF( 0, totalCoord ) ).y();
189 QString label = QString::number( pageCoord );
193 if (( pixelCoord + labelSize + 8 < nextPageStartPixel )
194 || ( nextPageStartPixel == 0 ) )
202 pageCoord += mmDisplay;
203 totalCoord += mmDisplay;
215 painter->setPen( QColor( Qt::red ) );
229 painter->translate( pos.x(), pos.y() );
230 painter->rotate( 270 );
231 painter->drawText( 0, 0, text );
238 double smallMarkerPos = startPos;
239 double smallDivisionSpacing = rulerScale / numDivisions;
244 for (
int i = 0; i < numDivisions; ++i )
246 smallMarkerPos += smallDivisionSpacing;
248 if ( maxPos > 0 && smallMarkerPos > maxPos )
257 pixelCoord =
mTransform.map( QPointF( smallMarkerPos, 0 ) ).x();
261 pixelCoord =
mTransform.map( QPointF( 0, smallMarkerPos ) ).y();
266 if (( numDivisions == 10 && i == 4 ) || ( numDivisions == 4 && i == 1 ) )
279 painter->drawLine( pixelCoord, lineSize, pixelCoord,
mRulerMinSize );
283 painter->drawLine( lineSize, pixelCoord,
mRulerMinSize, pixelCoord );
293 for (
unsigned int magnitudeCandidate = 0; magnitudeCandidate <
COUNT_VALID_MAGNITUDES; ++magnitudeCandidate )
295 for (
unsigned int multipleCandidate = 0; multipleCandidate <
COUNT_VALID_MULTIPLES; ++multipleCandidate )
299 double pixelDiff =
mTransform.map( QPointF( candidateScale, 0 ) ).x() -
mTransform.map( QPointF( 0, 0 ) ).x();
300 if ( pixelDiff > minPixelDiff )
303 magnitude = validScaleMagnitudes[magnitudeCandidate];
305 return candidateScale;
316 double largeDivisionSize =
mTransform.map( QPointF( rulerScale, 0 ) ).x() -
mTransform.map( QPointF( 0, 0 ) ).x();
319 QList<int> validSmallDivisions;
320 switch ( scaleMultiple )
325 validSmallDivisions << 10 << 5 << 2;
330 validSmallDivisions << 10 << 4 << 2;
335 validSmallDivisions << 10 << 5;
340 QList<int>::iterator divisions_it;
341 for ( divisions_it = validSmallDivisions.begin(); divisions_it != validSmallDivisions.end(); ++divisions_it )
344 double candidateSize = largeDivisionSize / ( *divisions_it );
349 return ( *divisions_it );
360 QString debug = QString::number( transform.dx() ) +
"," + QString::number( transform.dy() ) +
","
361 + QString::number( transform.m11() ) +
"," + QString::number( transform.m22() );
373 QPointF displayPos =
mTransform.inverted().map( event->posF() );
377 displayPos.setY( 0 );
382 displayPos.setX( 0 );
392 QPointF pos =
mTransform.inverted().map( event->pos() );
393 bool removeItem =
false;
396 removeItem = pos.x() < 0 ?
true :
false;
400 removeItem = pos.y() < 0 ?
true :
false;
417 x =
mTransform.inverted().map( event->pos() ).x();
421 y =
mTransform.inverted().map( event->pos() ).y();
444 QPointF transformedPt =
mTransform.inverted().map( pos );
453 mLineSnapItem->setLine( QLineF( transformedPt.x(), 0, transformedPt.x(), lineHeight ) );
461 QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode > >::iterator itemIt =
mSnappedItems.begin();