20 #include <QGraphicsLineItem>
21 #include <QGraphicsScene>
22 #include <QGraphicsSceneMouseEvent>
23 #include <QGraphicsView>
26 #include <QGraphicsEffect>
43 #define FONT_WORKAROUND_SCALE 10 //scale factor for upscaling fontsize and downscaling painter
46 #define M_DEG2RAD 0.0174532925
51 , QGraphicsRectItem( 0 )
52 , mComposition( composition )
53 , mBoundingResizeRectangle( 0 )
54 , mHAlignSnapItem( 0 )
55 , mVAlignSnapItem( 0 )
58 , mBackgroundColor( QColor( 255, 255, 255, 255 ) )
59 , mFrameJoinStyle( Qt::MiterJoin )
60 , mItemPositionLocked( false )
61 , mLastValidViewScaleFactor( -1 )
63 , mBlendMode( QPainter::CompositionMode_SourceOver )
64 , mEffectsEnabled( true )
66 , mLastUsedPositionMode( UpperLeft )
67 , mCurrentExportLayer( -1 )
69 , mUuid( QUuid::createUuid().toString() )
76 , QGraphicsRectItem( 0, 0, width, height, 0 )
77 , mComposition( composition )
78 , mBoundingResizeRectangle( 0 )
79 , mHAlignSnapItem( 0 )
80 , mVAlignSnapItem( 0 )
83 , mBackgroundColor( QColor( 255, 255, 255, 255 ) )
84 , mFrameJoinStyle( Qt::MiterJoin )
85 , mItemPositionLocked( false )
86 , mLastValidViewScaleFactor( -1 )
88 , mBlendMode( QPainter::CompositionMode_SourceOver )
89 , mEffectsEnabled( true )
91 , mLastUsedPositionMode( UpperLeft )
92 , mCurrentExportLayer( -1 )
94 , mUuid( QUuid::createUuid().toString() )
102 setFlag( QGraphicsItem::ItemIsSelectable,
true );
104 setBrush( QBrush( QColor( 255, 255, 255, 255 ) ) );
105 QPen defaultPen( QColor( 0, 0, 0 ) );
106 defaultPen.setWidthF( 0.3 );
108 setPen( defaultPen );
135 QGraphicsRectItem::setSelected( s );
147 if ( itemElem.isNull() )
152 QDomElement composerItemElem = doc.createElement(
"ComposerItem" );
157 composerItemElem.setAttribute(
"frame",
"true" );
161 composerItemElem.setAttribute(
"frame",
"false" );
167 composerItemElem.setAttribute(
"background",
"true" );
171 composerItemElem.setAttribute(
"background",
"false" );
176 composerItemElem.setAttribute(
"x", QString::number( pos().x() ) );
177 composerItemElem.setAttribute(
"y", QString::number( pos().y() ) );
178 composerItemElem.setAttribute(
"page",
page() );
179 composerItemElem.setAttribute(
"pagex", QString::number( pagepos.x() ) );
180 composerItemElem.setAttribute(
"pagey", QString::number( pagepos.y() ) );
181 composerItemElem.setAttribute(
"width", QString::number( rect().width() ) );
182 composerItemElem.setAttribute(
"height", QString::number( rect().height() ) );
184 composerItemElem.setAttribute(
"zValue", QString::number( zValue() ) );
185 composerItemElem.setAttribute(
"outlineWidth", QString::number( pen().widthF() ) );
187 composerItemElem.setAttribute(
"itemRotation", QString::number(
mItemRotation ) );
188 composerItemElem.setAttribute(
"uuid",
mUuid );
189 composerItemElem.setAttribute(
"id",
mId );
193 composerItemElem.setAttribute(
"positionLock",
"true" );
197 composerItemElem.setAttribute(
"positionLock",
"false" );
204 QDomElement frameColorElem = doc.createElement(
"FrameColor" );
205 QColor frameColor = pen().color();
206 frameColorElem.setAttribute(
"red", QString::number( frameColor.red() ) );
207 frameColorElem.setAttribute(
"green", QString::number( frameColor.green() ) );
208 frameColorElem.setAttribute(
"blue", QString::number( frameColor.blue() ) );
209 frameColorElem.setAttribute(
"alpha", QString::number( frameColor.alpha() ) );
210 composerItemElem.appendChild( frameColorElem );
213 QDomElement bgColorElem = doc.createElement(
"BackgroundColor" );
214 QColor bgColor = brush().color();
215 bgColorElem.setAttribute(
"red", QString::number( bgColor.red() ) );
216 bgColorElem.setAttribute(
"green", QString::number( bgColor.green() ) );
217 bgColorElem.setAttribute(
"blue", QString::number( bgColor.blue() ) );
218 bgColorElem.setAttribute(
"alpha", QString::number( bgColor.alpha() ) );
219 composerItemElem.appendChild( bgColorElem );
225 composerItemElem.setAttribute(
"transparency", QString::number(
mTransparency ) );
227 itemElem.appendChild( composerItemElem );
235 if ( itemElem.isNull() )
241 setItemRotation( itemElem.attribute(
"itemRotation",
"0" ).toDouble() );
244 mUuid = itemElem.attribute(
"uuid", QUuid::createUuid().toString() );
250 QString
id = itemElem.attribute(
"id",
"" );
254 QString frame = itemElem.attribute(
"frame" );
255 if ( frame.compare(
"true", Qt::CaseInsensitive ) == 0 )
265 QString background = itemElem.attribute(
"background" );
266 if ( background.compare(
"true", Qt::CaseInsensitive ) == 0 )
276 QString
positionLock = itemElem.attribute(
"positionLock" );
277 if ( positionLock.compare(
"true", Qt::CaseInsensitive ) == 0 )
288 double x, y, pagex, pagey, width, height;
289 bool xOk, yOk, pageOk, pagexOk, pageyOk, widthOk, heightOk, positionModeOK;
291 x = itemElem.attribute(
"x" ).toDouble( &xOk );
292 y = itemElem.attribute(
"y" ).toDouble( &yOk );
293 page = itemElem.attribute(
"page" ).toInt( &pageOk );
294 pagex = itemElem.attribute(
"pagex" ).toDouble( &pagexOk );
295 pagey = itemElem.attribute(
"pagey" ).toDouble( &pageyOk );
296 width = itemElem.attribute(
"width" ).toDouble( &widthOk );
297 height = itemElem.attribute(
"height" ).toDouble( &heightOk );
299 if ( !positionModeOK )
303 if ( pageOk && pagexOk && pageyOk )
311 if ( !xOk || !yOk || !widthOk || !heightOk )
319 setZValue( itemElem.attribute(
"zValue" ).toDouble() );
322 QDomNodeList frameColorList = itemElem.elementsByTagName(
"FrameColor" );
323 if ( frameColorList.size() > 0 )
325 QDomElement frameColorElem = frameColorList.at( 0 ).toElement();
326 bool redOk, greenOk, blueOk, alphaOk, widthOk;
327 int penRed, penGreen, penBlue, penAlpha;
330 penWidth = itemElem.attribute(
"outlineWidth" ).toDouble( &widthOk );
331 penRed = frameColorElem.attribute(
"red" ).toDouble( &redOk );
332 penGreen = frameColorElem.attribute(
"green" ).toDouble( &greenOk );
333 penBlue = frameColorElem.attribute(
"blue" ).toDouble( &blueOk );
334 penAlpha = frameColorElem.attribute(
"alpha" ).toDouble( &alphaOk );
337 if ( redOk && greenOk && blueOk && alphaOk && widthOk )
339 QPen framePen( QColor( penRed, penGreen, penBlue, penAlpha ) );
340 framePen.setWidthF( penWidth );
347 QDomNodeList bgColorList = itemElem.elementsByTagName(
"BackgroundColor" );
348 if ( bgColorList.size() > 0 )
350 QDomElement bgColorElem = bgColorList.at( 0 ).toElement();
351 bool redOk, greenOk, blueOk, alphaOk;
352 int bgRed, bgGreen, bgBlue, bgAlpha;
353 bgRed = bgColorElem.attribute(
"red" ).toDouble( &redOk );
354 bgGreen = bgColorElem.attribute(
"green" ).toDouble( &greenOk );
355 bgBlue = bgColorElem.attribute(
"blue" ).toDouble( &blueOk );
356 bgAlpha = bgColorElem.attribute(
"alpha" ).toDouble( &alphaOk );
357 if ( redOk && greenOk && blueOk && alphaOk )
359 QColor brushColor( bgRed, bgGreen, bgBlue, bgAlpha );
381 QPen itemPen = pen();
387 itemPen.setWidthF( outlineWidth );
401 QPen itemPen = pen();
414 return pen().widthF() / 2.0;
420 return rect().adjusted( -frameBleed, -frameBleed, frameBleed, frameBleed );
463 if ( !QFile::exists( lockIconPath ) )
468 QImage lockImage( lockIconPath );
469 if ( !lockImage.isNull() )
471 p->drawImage( QRectF( 0, 0, sizeLockSymbol, sizeLockSymbol ), lockImage, QRectF( 0, 0, lockImage.width(), lockImage.height() ) );
482 p->setBrush( Qt::NoBrush );
483 p->setRenderHint( QPainter::Antialiasing,
true );
484 p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
495 QRectF newSceneRect( pos().x() + dx, pos().y() + dy, rect().width(), rect().height() );
501 double y = pos().y();
504 while ( y - h >= 0. )
516 p.ry() -= (
page() - 1 ) * h;
522 Q_UNUSED( newPageWidth )
523 QPointF curPagePos =
pagePos();
524 int curPage =
page() - 1;
525 setY( curPage * ( newPageHeight +
composition()->spaceBetweenPages() ) + curPagePos.y() );
531 double width = rect().width();
532 double height = rect().height();
538 double upperLeftX = x;
539 double upperLeftY = y;
544 upperLeftY += ( page - 1 ) * h;
553 upperLeftX -= width / 2.0;
563 upperLeftY -= height / 2.0;
567 upperLeftY -= height;
570 if ( posIncludesFrame )
584 upperLeftX += lineToItemOrigin.x2();
585 upperLeftY += lineToItemOrigin.y2();
592 setSceneRect( QRectF( upperLeftX, upperLeftY, width, height ) );
598 double newWidth = rectangle.width();
599 double newHeight = rectangle.height();
600 double xTranslation = rectangle.x();
601 double yTranslation = rectangle.y();
604 if ( rectangle.width() < 0 )
606 newWidth = - rectangle.width();
607 xTranslation -= newWidth;
610 if ( rectangle.height() < 0 )
612 newHeight = - rectangle.height();
613 yTranslation -= newHeight;
616 QRectF newRect( 0, 0, newWidth, newHeight );
617 QGraphicsRectItem::setRect( newRect );
618 setPos( xTranslation, yTranslation );
627 p->setBrush( brush() );
628 p->setPen( Qt::NoPen );
629 p->setRenderHint( QPainter::Antialiasing,
true );
630 p->drawRect( QRectF( 0, 0, rect().width(), rect().height() ) );
651 setOpacity( 1. - ( transparency / 100. ) );
658 mEffect->setEnabled( effectsEnabled );
666 p->setFont( textFont );
668 p->scale( scaleFactor, scaleFactor );
673 void QgsComposerItem::drawText( QPainter* p,
const QRectF& rect,
const QString& text,
const QFont& font, Qt::AlignmentFlag halignment, Qt::AlignmentFlag valignment,
int flags )
const
681 p->setFont( textFont );
683 p->scale( scaleFactor, scaleFactor );
684 p->drawText( scaledRect, halignment | valignment | flags, text );
693 double angleRad = angle / 180.0 *
M_PI;
694 QPointF middlePoint( x, y );
696 QPointF p1 = QPointF( -arrowHeadWidth / 2.0, arrowHeadWidth );
697 QPointF p2 = QPointF( arrowHeadWidth / 2.0, arrowHeadWidth );
699 QPointF p1Rotated, p2Rotated;
700 p1Rotated.setX( p1.x() * cos( angleRad ) + p1.y() * -sin( angleRad ) );
701 p1Rotated.setY( p1.x() * sin( angleRad ) + p1.y() * cos( angleRad ) );
702 p2Rotated.setX( p2.x() * cos( angleRad ) + p2.y() * -sin( angleRad ) );
703 p2Rotated.setY( p2.x() * sin( angleRad ) + p2.y() * cos( angleRad ) );
705 QPolygonF arrowHeadPoly;
706 arrowHeadPoly << middlePoint;
707 arrowHeadPoly << QPointF( middlePoint.x() + p1Rotated.x(), middlePoint.y() + p1Rotated.y() );
708 arrowHeadPoly << QPointF( middlePoint.x() + p2Rotated.x(), middlePoint.y() + p2Rotated.y() );
712 QPen arrowPen = p->pen();
713 arrowPen.setJoinStyle( Qt::RoundJoin );
714 QBrush arrowBrush = p->brush();
715 arrowBrush.setStyle( Qt::SolidPattern );
716 p->setPen( arrowPen );
717 p->setBrush( arrowBrush );
718 arrowBrush.setStyle( Qt::SolidPattern );
719 p->drawPolygon( arrowHeadPoly );
727 QFontMetricsF fontMetrics( metricsFont );
734 QFontMetricsF fontMetrics( metricsFont );
741 QFontMetricsF fontMetrics( metricsFont );
748 QFontMetricsF fontMetrics( metricsFont );
755 QFontMetricsF fontMetrics( metricsFont );
761 return ( pointSize * 0.3527 );
766 QFont scaledFont = font;
768 scaledFont.setPixelSize( pixelSize );
774 double xDiff = p2.x() - p1.x();
775 double yDiff = p2.y() - p1.y();
776 double length = sqrt( xDiff * xDiff + yDiff * yDiff );
782 double angle = acos(( -yDiff * length ) / ( length * length ) ) * 180 /
M_PI;
785 return ( 360 - angle );
795 QList<QGraphicsView*> viewList = scene()->views();
796 if ( viewList.size() > 0 )
798 QGraphicsView* currentView = viewList.at( 0 );
799 if ( currentView->isVisible() )
801 result = currentView->transform().m11();
813 double rectHandlerSize = 10.0 / viewScaleFactor;
816 if ( rectHandlerSize > ( rect().width() / 3 ) )
818 rectHandlerSize = rect().width() / 3;
820 if ( rectHandlerSize > ( rect().height() / 3 ) )
822 rectHandlerSize = rect().height() / 3;
824 return rectHandlerSize;
831 if ( lockSymbolSize > ( rect().width() / 3 ) )
833 lockSymbolSize = rect().width() / 3;
835 if ( lockSymbolSize > ( rect().height() / 3 ) )
837 lockSymbolSize = rect().height() / 3;
851 if ( adjustPosition )
855 QLineF refLine = QLineF( mapToScene( QPointF( rect().width() / 2.0, rect().height() / 2.0 ) ) , mapToScene( QPointF( 0 , 0 ) ) );
859 QPointF rotatedReferencePoint = refLine.p2();
860 setPos( rotatedReferencePoint );
873 setTransformOriginPoint( 0, 0 );
888 double originalWidth = originalRect.width();
889 double originalHeight = originalRect.height();
890 double boundsWidth = boundsRect.width();
891 double boundsHeight = boundsRect.height();
892 double ratioBoundsRect = boundsWidth / boundsHeight;
894 double clippedRotation = fmod( rotation, 360.0 );
897 if ( clippedRotation == 0 || clippedRotation == 90 || clippedRotation == 180 || clippedRotation == 270 )
900 if ( clippedRotation == 0 || clippedRotation == 180 )
902 rectScale = (( originalWidth / originalHeight ) > ratioBoundsRect ) ? boundsWidth / originalWidth : boundsHeight / originalHeight;
906 rectScale = (( originalHeight / originalWidth ) > ratioBoundsRect ) ? boundsWidth / originalHeight : boundsHeight / originalWidth;
908 double rectScaledWidth = rectScale * originalWidth;
909 double rectScaledHeight = rectScale * originalHeight;
911 if ( clippedRotation == 0 || clippedRotation == 180 )
913 return QRectF(( boundsWidth - rectScaledWidth ) / 2.0, ( boundsHeight - rectScaledHeight ) / 2.0, rectScaledWidth, rectScaledHeight );
917 return QRectF(( boundsWidth - rectScaledHeight ) / 2.0, ( boundsHeight - rectScaledWidth ) / 2.0, rectScaledWidth, rectScaledHeight );
922 double angleRad = -clippedRotation *
M_DEG2RAD;
923 double cosAngle = cos( angleRad );
924 double sinAngle = sin( angleRad );
927 double widthBoundsRotatedRect = originalWidth * fabs( cosAngle ) + originalHeight * fabs( sinAngle );
928 double heightBoundsRotatedRect = originalHeight * fabs( cosAngle ) + originalWidth * fabs( sinAngle );
932 double ratioBoundsRotatedRect = widthBoundsRotatedRect / heightBoundsRotatedRect;
933 double rectScale = ratioBoundsRotatedRect > ratioBoundsRect ? boundsWidth / widthBoundsRotatedRect : boundsHeight / heightBoundsRotatedRect;
934 double rectScaledWidth = rectScale * originalWidth;
935 double rectScaledHeight = rectScale * originalHeight;
939 double currentCornerX = 0;
941 currentCornerX += rectScaledWidth * cosAngle;
942 minX = minX < currentCornerX ? minX : currentCornerX;
943 currentCornerX += rectScaledHeight * sinAngle;
944 minX = minX < currentCornerX ? minX : currentCornerX;
945 currentCornerX -= rectScaledWidth * cosAngle;
946 minX = minX < currentCornerX ? minX : currentCornerX;
948 double currentCornerY = 0;
950 currentCornerY -= rectScaledWidth * sinAngle;
951 minY = minY < currentCornerY ? minY : currentCornerY;
952 currentCornerY += rectScaledHeight * cosAngle;
953 minY = minY < currentCornerY ? minY : currentCornerY;
954 currentCornerY += rectScaledWidth * sinAngle;
955 minY = minY < currentCornerY ? minY : currentCornerY;
958 double offsetX = ratioBoundsRotatedRect > ratioBoundsRect ? 0 : ( boundsWidth - rectScale * widthBoundsRotatedRect ) / 2.0;
959 offsetX += fabs( minX );
960 double offsetY = ratioBoundsRotatedRect > ratioBoundsRect ? ( boundsHeight - rectScale * heightBoundsRotatedRect ) / 2.0 : 0;
961 offsetY += fabs( minY );
963 return QRectF( offsetX, offsetY, rectScaledWidth, rectScaledHeight );
968 if ( qAbs( rotation ) <= 0.0 )
989 double midX = width / 2.0;
990 double midY = height / 2.0;
1011 double distM1 = sqrt(( x1 - midX ) * ( x1 - midX ) + ( y1 - midY ) * ( y1 - midY ) );
1014 if ( p2.x() < width && p2.x() > 0 && p2.y() < height && p2.y() > 0 )
1016 width = sqrt(( p2.x() - x1 ) * ( p2.x() - x1 ) + ( p2.y() - y1 ) * ( p2.y() - y1 ) );
1017 height = sqrt(( x3 - p2.x() ) * ( x3 - p2.x() ) + ( y3 - p2.y() ) * ( y3 - p2.y() ) );
1022 double distM2 = sqrt(( x2 - midX ) * ( x2 - midX ) + ( y2 - midY ) * ( y2 - midY ) );
1025 width = sqrt(( x2 - p1.x() ) * ( x2 - p1.x() ) + ( y2 - p1.y() ) * ( y2 - p1.y() ) );
1026 height = sqrt(( p3.x() - x2 ) * ( p3.x() - x2 ) + ( p3.y() - y2 ) * ( p3.y() - y2 ) );
1039 double rotToRad = rotation *
M_PI / 180.0;
1040 QPointF midpoint( width / 2.0, height / 2.0 );
1041 double xVector = x - midpoint.x();
1042 double yVector = y - midpoint.y();
1045 double xRotated = cos( rotToRad ) * xVector - sin( rotToRad ) * yVector;
1046 double yRotated = sin( rotToRad ) * xVector + cos( rotToRad ) * yVector;
1049 QLineF line( midpoint.x(), midpoint.y(), midpoint.x() + xRotated, midpoint.y() + yRotated );
1052 QList<QLineF> borders;
1053 borders << QLineF( 0, 0, width, 0 );
1054 borders << QLineF( width, 0, width, height );
1055 borders << QLineF( width, height, 0, height );
1056 borders << QLineF( 0, height, 0, 0 );
1058 QList<QLineF>::const_iterator it = borders.constBegin();
1059 QPointF intersectionPoint;
1061 for ( ; it != borders.constEnd(); ++it )
1063 if ( line.intersect( *it, &intersectionPoint ) == QLineF::BoundedIntersection )
1065 x = intersectionPoint.x();
1066 y = intersectionPoint.y();
1081 if ( rotation == 0.0 )
1087 double x1 = -width / 2.0;
1088 double y1 = -height / 2.0;
1089 rotate( rotation, x1, y1 );
1091 double x2 = width / 2.0;
1092 double y2 = -height / 2.0;
1093 rotate( rotation, x2, y2 );
1095 double x3 = width / 2.0;
1096 double y3 = height / 2.0;
1097 rotate( rotation, x3, y3 );
1099 double x4 = -width / 2.0;
1100 double y4 = height / 2.0;
1101 rotate( rotation, x4, y4 );
1104 QPointF midpoint( width / 2.0, height / 2.0 );
1106 QPolygonF rotatedRectPoly;
1107 rotatedRectPoly << QPointF( midpoint.x() + x1, midpoint.y() + y1 );
1108 rotatedRectPoly << QPointF( midpoint.x() + x2, midpoint.y() + y2 );
1109 rotatedRectPoly << QPointF( midpoint.x() + x3, midpoint.y() + y3 );
1110 rotatedRectPoly << QPointF( midpoint.x() + x4, midpoint.y() + y4 );
1111 QRectF boundingRect = rotatedRectPoly.boundingRect();
1112 width = boundingRect.width();
1113 height = boundingRect.height();
1118 double rotToRad = angle *
M_PI / 180.0;
1120 xRot = x * cos( rotToRad ) - y * sin( rotToRad );
1121 yRot = x * sin( rotToRad ) + y * cos( rotToRad );
bool positionLock() const
Returns position lock for mouse drags (true means locked)
bool effectsEnabled() const
Returns true if effects (eg blend modes) are enabled for the item.
bool imageSizeConsideringRotation(double &width, double &height, double rotation) const
Calculates width and hight of the picture (in mm) such that it fits into the item frame with the give...
int mTransparency
Item transparency.
void setEffectsEnabled(bool effectsEnabled)
Sets whether effects (eg blend modes) are enabled for the item.
double fontHeightCharacterMM(const QFont &font, const QChar &c) const
Returns the font height of a character in millimeters.
void itemRotationChanged(double newRotation)
Is emitted on item rotation change.
static const QString activeThemePath()
Returns the path to the currently active theme directory.
double pixelFontSize(double pointSize) const
Calculates font to from point size to pixel size.
void addItemToZList(QgsComposerItem *item)
Adds item to z list.
virtual void setRotation(double r)
Sets the item rotation.
virtual double estimatedFrameBleed() const
Returns the estimated amount the item's frame bleeds outside the item's actual rectangle.
virtual bool removeSettings()
delete settings from project file
double lockSymbolSize() const
Returns the size of the lock symbol depending on the composer zoom level and the item size...
QPointF pagePos() const
Returns the item's position relative to its current page.
void removeItemFromZList(QgsComposerItem *item)
Removes item from z list.
#define FONT_WORKAROUND_SCALE
double mLastValidViewScaleFactor
Backup to restore item appearance if no view scale factor is available.
ItemPositionMode mLastUsedPositionMode
The item's position mode.
virtual void setSelected(bool s)
Set selected, selected item should be highlighted.
virtual void drawFrame(QPainter *p)
Draw black frame around item.
QColor backgroundColor() const
Gets the background color for this item.
QPainter::CompositionMode mBlendMode
Composition blend mode for item.
void setCompositionMode(const QPainter::CompositionMode &compositionMode)
double spaceBetweenPages() const
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
void setItemPosition(double x, double y, ItemPositionMode itemPoint=UpperLeft, int page=-1)
Moves the item to a new position (in canvas coordinates)
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document.
double fontDescentMillimeters(const QFont &font) const
Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCA...
void deleteHAlignSnapItem()
void setTransparency(int transparency)
Sets the item's transparency.
void frameChanged()
Emitted if the item's frame style changes.
double horizontalViewScaleFactor() const
Returns the zoom factor of the graphics view.
void cancelCommand()
Deletes current command.
QFont scaledFontPixelSize(const QFont &font) const
Returns a font where size is in pixel and font size is upscaled with FONT_WORKAROUND_SCALE.
int transparency() const
Returns the item's transparency.
virtual void drawSelectionBoxes(QPainter *p)
Draw selection boxes around item.
double textWidthMillimeters(const QFont &font, const QString &text) const
Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE...
void rotate(double angle, double &x, double &y) const
Rotates a point / vector.
void endCommand()
Saves end state of item and pushes command to the undo history.
QGraphicsRectItem * mBoundingResizeRectangle
Rectangle used during move and resize actions.
QRectF largestRotatedRectWithinBounds(QRectF originalRect, QRectF boundsRect, double rotation) const
Calculates the largest scaled version of originalRect which fits within boundsRect, when it is rotated by a specified amount.
void updatePagePos(double newPageWidth, double newPageHeight)
Moves the item so that it retains its relative position on the page when the paper size changes...
bool mFrame
True if item fram needs to be painted.
void endCommand()
Finish current command and push it onto the undo stack.
static QString encodePenJoinStyle(Qt::PenJoinStyle style)
virtual void setFrameOutlineWidth(double outlineWidth)
Sets frame outline width.
static const QString defaultThemePath()
Returns the path to the default theme directory.
virtual bool writeSettings()
stores state in project
virtual ~QgsComposerItem()
void drawText(QPainter *p, double x, double y, const QString &text, const QFont &font) const
Draws Text.
void beginCommand(const QString &commandText, QgsComposerMergeCommand::Context c=QgsComposerMergeCommand::Unknown)
Starts new composer undo command.
void setFrameJoinStyle(Qt::PenJoinStyle style)
Sets join style used when drawing the item's frame.
QgsComposition * mComposition
Graphics scene for map printing.
virtual void setItemRotation(double r, bool adjustPosition=false)
Sets the item rotation.
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
void setPositionLock(bool lock)
Locks / unlocks the item position for mouse drags.
virtual QRectF rectWithFrame() const
Returns the item's rectangular bounds, including any bleed caused by the item's frame.
QGraphicsLineItem * hAlignSnapItem()
Return horizontal align snap item.
static QPainter::CompositionMode getCompositionMode(const QgsMapRenderer::BlendMode &blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode Added in 1.9.
Qt::PenJoinStyle mFrameJoinStyle
Frame join style.
QColor mBackgroundColor
Background color.
QGraphicsLineItem * mVAlignSnapItem
bool cornerPointOnRotatedAndScaledRect(double &x, double &y, double width, double height, double rotation) const
Calculates corner point after rotation and scaling.
QGraphicsLineItem * mHAlignSnapItem
virtual bool readSettings()
read state from project
void setBackgroundColor(const QColor &backgroundColor)
Sets the background color for this item.
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
bool mItemPositionLocked
True if item position and size cannot be changed with mouse move.
QPainter::CompositionMode blendMode() const
Returns the item's composition blending mode.
virtual void drawBackground(QPainter *p)
Draw background.
void deleteVAlignSnapItem()
bool hasFrame() const
Whether this item has a frame or not.
virtual void setId(const QString &id)
Set item's id (which is not necessarly unique)
double fontHeightMillimeters(const QFont &font) const
Returns the font height in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCAL...
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
double angle(const QPointF &p1, const QPointF &p2) const
Returns angle of the line from p1 to p2 (clockwise, starting at N)
void sizeChanged()
Emitted if the rectangle changes.
const QgsComposition * composition() const
double paperHeight() const
Returns height of paper item.
int page() const
Gets the page the item is currently on.
static Qt::PenJoinStyle decodePenJoinStyle(QString str)
void setBlendMode(QPainter::CompositionMode blendMode)
Sets the item's composition blending mode.
static QgsMapRenderer::BlendMode getBlendModeEnum(const QPainter::CompositionMode &blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode Added in 1.9.
QgsComposerEffect * mEffect
void drawArrowHead(QPainter *p, double x, double y, double angle, double arrowHeadWidth) const
Draws arrowhead.
QgsComposerItem(QgsComposition *composition, bool manageZValue=true)
Constructor.
void init(bool manageZValue)
QgsComposition::PlotStyle plotStyle() const
double rectHandlerBorderTolerance() const
Returns the current (zoom level dependent) tolerance to decide if mouse position is close enough to t...
void setFrameEnabled(bool drawFrame)
Set whether this item has a frame drawn around it or not.
static QPointF pointOnLineWithDistance(const QPointF &startPoint, const QPointF &directionPoint, double distance)
Returns a point on the line from startPoint to directionPoint that is a certain distance away from th...
bool mBackground
True if item background needs to be painted.
void move(double dx, double dy)
Moves item in canvas coordinates.
double mItemRotation
Item rotation in degrees, clockwise.
QGraphicsLineItem * vAlignSnapItem()
Return vertical align snap item.
double fontAscentMillimeters(const QFont &font) const
Returns the font ascent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCAL...
void sizeChangedByRotation(double &width, double &height, double rotation)
Calculates width / height of the bounding box of a rotated rectangle.
void beginCommand(QgsComposerItem *item, const QString &commandText, QgsComposerMergeCommand::Context c=QgsComposerMergeCommand::Unknown)
Allocates new item command and saves initial state in it.
QString id() const
Get item's id (which is not necessarly unique)