Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 : blazek@itc.it
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 "qgscomposition.h"
21 #include <QGraphicsRectItem>
22 #include <QObject>
23 
24 class QWidget;
25 class QDomDocument;
26 class QDomElement;
27 
28 class QqsComposition;
29 
33 class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem
34 {
35  Q_OBJECT
36  public:
37 
38  enum ItemType
39  {
40  // base class for the items
41  ComposerItem = UserType + 100,
42 
43  // derived classes
49  ComposerPaper, // QgsPaperItem
55  ComposerTextTable
56  };
57 
60  {
70  NoAction
71  };
72 
74  {
83  LowerRight
84  };
85 
89  QgsComposerItem( QgsComposition* composition, bool manageZValue = true );
97  QgsComposerItem( qreal x, qreal y, qreal width, qreal height, QgsComposition* composition, bool manageZValue = true );
98  virtual ~QgsComposerItem();
99 
101  virtual int type() const { return ComposerItem; }
102 
104  virtual void setSelected( bool s );
105 
107  virtual bool selected( void ) {return QGraphicsRectItem::isSelected();}
108 
110  virtual bool writeSettings( void );
111 
113  virtual bool readSettings( void );
114 
116  virtual bool removeSettings( void );
117 
119  void move( double dx, double dy );
120 
124  virtual void moveContent( double dx, double dy ) { Q_UNUSED( dx ); Q_UNUSED( dy ); }
125 
130  virtual void zoomContent( int delta, double x, double y ) { Q_UNUSED( delta ); Q_UNUSED( x ); Q_UNUSED( y ); }
131 
133  void setItemPosition( double x, double y, ItemPositionMode itemPoint = UpperLeft );
134 
137  void setItemPosition( double x, double y, double width, double height, ItemPositionMode itemPoint = UpperLeft );
138 
141  virtual void setSceneRect( const QRectF& rectangle );
142 
147  virtual bool writeXML( QDomElement& elem, QDomDocument & doc ) const = 0;
148 
150  bool _writeXML( QDomElement& itemElem, QDomDocument& doc ) const;
151 
156  virtual bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) = 0;
157 
159  bool _readXML( const QDomElement& itemElem, const QDomDocument& doc );
160 
161 
162 
163  bool frame() const {return mFrame;}
164  void setFrame( bool drawFrame ) {mFrame = drawFrame;}
165 
167  virtual void addItem( QgsComposerItem* item ) { Q_UNUSED( item ); }
168  virtual void removeItems() {}
169 
170  const QgsComposition* composition() const {return mComposition;}
171 
175  void beginCommand( const QString& commandText, QgsComposerMergeCommand::Context c = QgsComposerMergeCommand::Unknown );
177  void endCommand();
178  void cancelCommand();
179 
180  //functions that encapsulate the workaround for the Qt font bug (that is to scale the font size up and then scale the
181  //painter down by the same factor for drawing
182 
185  void drawText( QPainter* p, double x, double y, const QString& text, const QFont& font ) const;
186 
188  void drawText( QPainter* p, const QRectF& rect, const QString& text, const QFont& font, Qt::AlignmentFlag halignement = Qt::AlignLeft, Qt::AlignmentFlag valignement = Qt::AlignTop ) const;
189 
191  double textWidthMillimeters( const QFont& font, const QString& text ) const;
192 
195  double fontHeightCharacterMM( const QFont& font, const QChar& c ) const;
196 
198  double fontAscentMillimeters( const QFont& font ) const;
199 
201  double pixelFontSize( double pointSize ) const;
202 
204  QFont scaledFontPixelSize( const QFont& font ) const;
205 
208  void setPositionLock( bool lock ) {mItemPositionLocked = lock;}
209 
212  bool positionLock() const {return mItemPositionLocked;}
213 
216  void updateCursor( const QPointF& itemPos );
217 
218  double rotation() const {return mRotation;}
219 
220  public slots:
221  virtual void setRotation( double r );
222  void repaint();
223 
224  protected:
225 
227 
233 
235  QGraphicsRectItem* mBoundingResizeRectangle;
236 
238  bool mFrame;
239 
243 
246 
248  double mRotation;
249 
250  //event handlers
251  virtual void mouseMoveEvent( QGraphicsSceneMouseEvent * event );
252  virtual void mousePressEvent( QGraphicsSceneMouseEvent * event );
253  virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent * event );
254 
255  virtual void hoverMoveEvent( QGraphicsSceneHoverEvent * event );
256 
258  Qt::CursorShape cursorForPosition( const QPointF& itemCoordPos );
259 
261  QgsComposerItem::MouseMoveAction mouseMoveActionForPosition( const QPointF& itemCoordPos );
262 
271  void changeItemRectangle( const QPointF& currentPosition, const QPointF& mouseMoveStartPos, const QGraphicsRectItem* originalItem, double dx, double dy, QGraphicsRectItem* changeItem );
272 
274  virtual void drawSelectionBoxes( QPainter* p );
275 
277  virtual void drawFrame( QPainter* p );
278 
280  virtual void drawBackground( QPainter* p );
281 
283  void drawArrowHead( QPainter* p, double x, double y, double angle, double arrowHeadWidth ) const;
284 
286  double angle( const QPointF& p1, const QPointF& p2 ) const;
287 
290  double rectHandlerBorderTolerance() const;
291 
294  double lockSymbolSize() const;
295 
299  double horizontalViewScaleFactor() const;
300 
301  //some utility functions
302 
304  bool imageSizeConsideringRotation( double& width, double& height ) const;
306  bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
308  QPointF pointOnLineWithDistance( const QPointF& startPoint, const QPointF& directionPoint, double distance ) const;
310  void sizeChangedByRotation( double& width, double& height );
315  void rotate( double angle, double& x, double& y ) const;
316 
317  signals:
319  void rotationChanged( double newRotation );
321  void itemChanged();
322 };
323 
324 #endif