QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposerruler.h
Go to the documentation of this file.
1 #ifndef QGSCOMPOSERRULER_H
2 #define QGSCOMPOSERRULER_H
3 
4 #include "qgscomposeritem.h"
5 #include <QWidget>
6 class QgsComposition;
7 class QGraphicsLineItem;
8 
10 class GUI_EXPORT QgsComposerRuler: public QWidget
11 {
12  Q_OBJECT
13 
14  public:
15  enum Direction
16  {
17  Horizontal = 0,
18  Vertical
19  };
20 
23 
24  QSize minimumSizeHint() const override;
25 
26  void setSceneTransform( const QTransform& transform );
27  void updateMarker( const QPointF& pos ) { mMarkerPos = pos; repaint(); }
28 
29  void setComposition( QgsComposition* c ) { mComposition = c; }
30  QgsComposition* composition() { return mComposition; }
31 
32  int rulerSize() { return mRulerMinSize; }
33 
34  protected:
35  void paintEvent( QPaintEvent* event ) override;
36  void mouseMoveEvent( QMouseEvent* event ) override;
37  void mouseReleaseEvent( QMouseEvent* event ) override;
38  void mousePressEvent( QMouseEvent* event ) override;
39 
40  private:
41  static const int validScaleMultiples[];
42  static const int validScaleMagnitudes[];
43 
44  Direction mDirection;
45  QTransform mTransform;
46  QPointF mMarkerPos;
47  QgsComposition* mComposition; //reference to composition for paper size, nPages
48  QGraphicsLineItem* mLineSnapItem;
49  //items snapped to the current snap line
50  QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode > > mSnappedItems;
51 
52  QFont * mRulerFont;
53  QFontMetrics * mRulerFontMetrics;
54  double mScaleMinPixelsWidth;
55  int mRulerMinSize;
56  int mMinPixelsPerDivision;
57  int mPixelsBetweenLineAndText;
58  int mTextBaseline;
59  int mMinSpacingVerticalLabels;
60 
61  void setSnapLinePosition( const QPointF& pos );
62 
63  //calculate optimum labeled units for ruler so that labels are a good distance apart
64  int optimumScale( double minPixelDiff, int &magnitude, int &multiple );
65  //calculate number of small divisions for each ruler unit, ensuring that they
66  //are sufficiently spaced
67  int optimumNumberDivisions( double rulerScale, int scaleMultiple );
68 
69  //draws vertical text on a painter
70  void drawRotatedText( QPainter *painter, QPointF pos, const QString &text );
71 
72  /* Draws small ruler divisions
73  * Starting at startPos in mm, for numDivisions divisions, with major division spacing of rulerScale (in mm)
74  * Stop drawing if position exceeds maxPos
75  */
76  void drawSmallDivisions( QPainter *painter, double startPos, int numDivisions, double rulerScale, double maxPos = 0 );
77 
78  //draw current marker pos on ruler
79  void drawMarkerPos( QPainter *painter );
80 
81  signals:
83  void cursorPosChanged( QPointF );
84 
85 };
86 
87 #endif // QGSCOMPOSERRULER_H