QGIS API Documentation  2.4.0-Chugiak
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposeritem.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposeritem.h
3  -------------------
4  begin : January 2005
5  copyright : (C) 2005 by Radim Blazek
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #ifndef QGSCOMPOSERITEM_H
18 #define QGSCOMPOSERITEM_H
19 
20 #include "qgscomposeritemcommand.h"
21 #include "qgscomposereffect.h"
22 #include "qgsmaprenderer.h" // for blend mode functions & enums
23 #include <QGraphicsRectItem>
24 #include <QObject>
25 
26 class QgsComposition;
27 class QWidget;
28 class QDomDocument;
29 class QDomElement;
30 class QGraphicsLineItem;
32 
36 class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
37 {
38  Q_OBJECT
39  public:
40 
41  enum ItemType
42  {
43  // base class for the items
44  ComposerItem = UserType + 100,
45 
46  // derived classes
52  ComposerPaper, // QgsPaperItem
59  ComposerFrame
60  };
61 
64  {
74  NoAction
75  };
76 
78  {
87  LowerRight
88  };
89 
93  QgsComposerItem( QgsComposition* composition, bool manageZValue = true );
101  QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition, bool manageZValue = true );
102  virtual ~QgsComposerItem();
103 
105  virtual int type() const { return ComposerItem; }
106 
108  virtual void setSelected( bool s );
109 
111  virtual bool selected() const {return QGraphicsRectItem::isSelected();};
112 
114  virtual bool writeSettings();
115 
117  virtual bool readSettings();
118 
120  virtual bool removeSettings();
121 
123  void move( double dx, double dy );
124 
128  virtual void moveContent( double dx, double dy ) { Q_UNUSED( dx ); Q_UNUSED( dy ); }
129 
134  virtual void zoomContent( int delta, double x, double y ) { Q_UNUSED( delta ); Q_UNUSED( x ); Q_UNUSED( y ); }
135 
142  int page() const;
143 
150  QPointF pagePos() const;
151 
160  void updatePagePos( double newPageWidth, double newPageHeight );
161 
163  void setItemPosition( double x, double y, ItemPositionMode itemPoint = UpperLeft, int page = -1 );
164 
174  void setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint = UpperLeft, bool posIncludesFrame = false, int page = -1 );
175 
179  ItemPositionMode lastUsedPositionMode() { return mLastUsedPositionMode; }
180 
183  virtual void setSceneRect( const QRectF& rectangle );
184 
189  virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) const = 0;
190 
192  bool _writeXML( QDomElement& itemElem, QDomDocument& doc ) const;
193 
198  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) = 0;
199 
201  bool _readXML( const QDomElement& itemElem, const QDomDocument& doc );
202 
208  bool hasFrame() const {return mFrame;}
209 
216  void setFrameEnabled( bool drawFrame );
217 
224  virtual void setFrameOutlineWidth( double outlineWidth );
225 
232  double frameOutlineWidth() const { return pen().widthF(); }
233 
240  Qt::PenJoinStyle frameJoinStyle() const { return mFrameJoinStyle; }
248  void setFrameJoinStyle( Qt::PenJoinStyle style );
249 
256  virtual double estimatedFrameBleed() const;
257 
266  virtual QRectF rectWithFrame() const;
267 
273  bool hasBackground() const {return mBackground;}
274 
281  void setBackgroundEnabled( bool drawBackground ) { mBackground = drawBackground; }
282 
287  QColor backgroundColor() const { return mBackgroundColor; }
288 
294  void setBackgroundColor( const QColor& backgroundColor );
295 
297  QPainter::CompositionMode blendMode() const { return mBlendMode; }
298 
300  void setBlendMode( QPainter::CompositionMode blendMode );
301 
303  int transparency() const { return mTransparency; }
305  void setTransparency( int transparency );
306 
310  bool effectsEnabled() const { return mEffectsEnabled; }
314  void setEffectsEnabled( bool effectsEnabled );
315 
317  virtual void addItem( QgsComposerItem* item ) { Q_UNUSED( item ); }
318  virtual void removeItems() {}
319 
320  const QgsComposition* composition() const { return mComposition; }
321  QgsComposition* composition() {return mComposition;}
322 
323  virtual void beginItemCommand( const QString& text ) { beginCommand( text ); }
324 
328  void beginCommand( const QString& commandText, QgsComposerMergeCommand::Context c = QgsComposerMergeCommand::Unknown );
329 
330  virtual void endItemCommand() { endCommand(); }
332  void endCommand();
333  void cancelCommand();
334 
335  //functions that encapsulate the workaround for the Qt font bug (that is to scale the font size up and then scale the
336  //painter down by the same factor for drawing
337 
340  void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font ) const;
341 
351  void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignment = Qt::AlignLeft, Qt::AlignmentFlag valignment = Qt::AlignTop, int flags = Qt::TextWordWrap ) const;
352 
354  double textWidthMillimeters( const QFont& font, const QString& text ) const;
355 
358  double fontHeightCharacterMM( const QFont& font, const QChar& c ) const;
359 
361  double fontAscentMillimeters( const QFont& font ) const;
362 
364  double fontDescentMillimeters( const QFont& font ) const;
365 
370  double fontHeightMillimeters( const QFont& font ) const;
371 
373  double pixelFontSize( double pointSize ) const;
374 
376  QFont scaledFontPixelSize( const QFont& font ) const;
377 
380  void setPositionLock( bool lock );
381 
384  bool positionLock() const { return mItemPositionLocked; }
385 
388  double itemRotation() const { return mItemRotation; }
389 
394  Q_DECL_DEPRECATED double rotation() const { return mItemRotation; }
395 
397  virtual void updateItem() { QGraphicsRectItem::update(); }
398 
401  QString id() const { return mId; }
402 
405  virtual void setId( const QString& id );
406 
410  QString uuid() const { return mUuid; }
411 
417  virtual int numberExportLayers() const { return 0; }
418 
423  virtual void setCurrentExportLayer( int layerIdx = -1 ) { mCurrentExportLayer = layerIdx; }
424 
425  public slots:
429  virtual void setRotation( double r );
430 
437  virtual void setItemRotation( double r, bool adjustPosition = false );
438 
439  void repaint();
440 
441  protected:
442 
444 
450 
452  QGraphicsRectItem* mBoundingResizeRectangle;
453  QGraphicsLineItem* mHAlignSnapItem;
454  QGraphicsLineItem* mVAlignSnapItem;
455 
457  bool mFrame;
463  Qt::PenJoinStyle mFrameJoinStyle;
464 
468 
471 
474 
476  QPainter::CompositionMode mBlendMode;
479 
482 
486 
491 
493  virtual void drawSelectionBoxes( QPainter* p );
494 
496  virtual void drawFrame( QPainter* p );
497 
499  virtual void drawBackground( QPainter* p );
500 
502  void drawArrowHead( QPainter* p, double x, double y, double angle, double arrowHeadWidth ) const;
503 
505  double angle( const QPointF& p1, const QPointF& p2 ) const;
506 
509  double rectHandlerBorderTolerance() const;
510 
513  double lockSymbolSize() const;
514 
518  double horizontalViewScaleFactor() const;
519 
520  //some utility functions
521 
523  bool imageSizeConsideringRotation( double& width, double& height, double rotation ) const;
528  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height ) const;
529 
536  QRectF largestRotatedRectWithinBounds( QRectF originalRect, QRectF boundsRect, double rotation ) const;
537 
539  bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height, double rotation ) const;
544  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
545 
547  void sizeChangedByRotation( double& width, double& height, double rotation );
552  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height );
553 
558  void rotate( double angle, double& x, double& y ) const;
559 
561  QGraphicsLineItem* hAlignSnapItem();
562  void deleteHAlignSnapItem();
564  QGraphicsLineItem* vAlignSnapItem();
565  void deleteVAlignSnapItem();
566  void deleteAlignItems();
567 
568  signals:
570  void itemRotationChanged( double newRotation );
572  void itemChanged();
574  void sizeChanged();
578  void frameChanged();
579  private:
580  // id (not unique)
581  QString mId;
582  // name (unique)
583  QString mUuid;
584  // name (temporary when loaded from template)
585  QString mTemplateUuid;
586 
587  void init( bool manageZValue );
588 
589  friend class QgsComposerItemGroup; // to access mTemplateUuid
590 };
591 
592 #endif
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.
double outlineWidth
Definition: qgssvgcache.cpp:78
int mTransparency
Item transparency.
QPointF mLastMouseEventPos
Position of the last mouse move event (in scene coordinates)
virtual void beginItemCommand(const QString &text)
ItemPositionMode lastUsedPositionMode()
Returns item's last used position mode.
virtual bool selected() const
Is selected.
virtual void removeItems()
Qt::PenJoinStyle frameJoinStyle() const
Returns the join style used for drawing the item's frame.
A item that forms part of a map composition.
QgsComposerItem::MouseMoveAction mCurrentMouseMoveAction
double mLastValidViewScaleFactor
Backup to restore item appearance if no view scale factor is available.
ItemPositionMode mLastUsedPositionMode
The item's position mode.
A container for grouping several QgsComposerItems.
QColor backgroundColor() const
Gets the background color for this item.
QPainter::CompositionMode mBlendMode
Composition blend mode for item.
virtual void setCurrentExportLayer(int layerIdx=-1)
Sets the current layer to draw for exporting.
QgsComposition * composition()
double frameOutlineWidth() const
Returns the frame's outline width.
virtual int type() const
return correct graphics item type.
virtual void moveContent(double dx, double dy)
Move Content of item.
QString uuid() const
Get item identification name.
void setBackgroundEnabled(bool drawBackground)
Set whether this item has a Background drawn around it or not.
int transparency() const
Returns the item's transparency.
virtual void updateItem()
Updates item, with the possibility to do custom update for subclasses.
QGraphicsRectItem * mBoundingResizeRectangle
Rectangle used during move and resize actions.
bool mFrame
True if item fram needs to be painted.
double itemRotation() const
Returns the rotation for the composer item.
MouseMoveAction
Describes the action (move or resize in different directon) to be done during mouse move...
virtual int numberExportLayers() const
Get the number of layers that this item requires for exporting as layers.
QPointF mMouseMoveStartPos
Start point of the last mouse move action (in scene coordinates)
QgsComposition * mComposition
Graphics scene for map printing.
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)
virtual void zoomContent(int delta, double x, double y)
Zoom content of item.
Q_DECL_DEPRECATED double rotation() const
Returns the rotation for the composer item.
Qt::PenJoinStyle mFrameJoinStyle
Frame join style.
QColor mBackgroundColor
Background color.
QGraphicsLineItem * mVAlignSnapItem
QGraphicsLineItem * mHAlignSnapItem
int mCurrentExportLayer
The layer that needs to be exported.
virtual void endItemCommand()
virtual void addItem(QgsComposerItem *item)
Composite operations for item groups do nothing per default.
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.
bool hasFrame() const
Whether this item has a frame or not.
const QgsComposition * composition() const
bool hasBackground() const
Whether this item has a Background or not.
QgsComposerEffect * mEffect
bool mBackground
True if item background needs to be painted.
double mItemRotation
Item rotation in degrees, clockwise.
QString id() const
Get item's id (which is not necessarly unique)