QGIS API Documentation  2.15.0-Master (972fc9f)
qgscomposerruler.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerruler.h
3  ---------------------
4  begin : January 2013
5  copyright : (C) 2013 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSCOMPOSERRULER_H
16 #define QGSCOMPOSERRULER_H
17 
18 #include "qgscomposeritem.h"
19 #include <QWidget>
20 class QgsComposition;
21 class QGraphicsLineItem;
22 
24 class GUI_EXPORT QgsComposerRuler: public QWidget
25 {
26  Q_OBJECT
27 
28  public:
29  enum Direction
30  {
31  Horizontal = 0,
32  Vertical
33  };
34 
37 
38  QSize minimumSizeHint() const override;
39 
40  void setSceneTransform( const QTransform& transform );
41  void updateMarker( QPointF pos ) { mMarkerPos = pos; repaint(); }
42 
43  void setComposition( QgsComposition* c ) { mComposition = c; }
44  QgsComposition* composition() { return mComposition; }
45 
46  int rulerSize() { return mRulerMinSize; }
47 
48  protected:
49  void paintEvent( QPaintEvent* event ) override;
50  void mouseMoveEvent( QMouseEvent* event ) override;
51  void mouseReleaseEvent( QMouseEvent* event ) override;
52  void mousePressEvent( QMouseEvent* event ) override;
53 
54  private:
55  static const int validScaleMultiples[];
56  static const int validScaleMagnitudes[];
57 
58  Direction mDirection;
59  QTransform mTransform;
60  QPointF mMarkerPos;
61  QgsComposition* mComposition; //reference to composition for paper size, nPages
62  QGraphicsLineItem* mLineSnapItem;
63  //items snapped to the current snap line
65 
66  QFont * mRulerFont;
67  QFontMetrics * mRulerFontMetrics;
68  double mScaleMinPixelsWidth;
69  int mRulerMinSize;
70  int mMinPixelsPerDivision;
71  int mPixelsBetweenLineAndText;
72  int mTextBaseline;
73  int mMinSpacingVerticalLabels;
74 
75  void setSnapLinePosition( QPointF pos );
76 
77  //calculate optimum labeled units for ruler so that labels are a good distance apart
78  int optimumScale( double minPixelDiff, int &magnitude, int &multiple );
79  //calculate number of small divisions for each ruler unit, ensuring that they
80  //are sufficiently spaced
81  int optimumNumberDivisions( double rulerScale, int scaleMultiple );
82 
83  //draws vertical text on a painter
84  void drawRotatedText( QPainter *painter, QPointF pos, const QString &text );
85 
86  /* Draws small ruler divisions
87  * Starting at startPos in mm, for numDivisions divisions, with major division spacing of rulerScale (in mm)
88  * Stop drawing if position exceeds maxPos
89  */
90  void drawSmallDivisions( QPainter *painter, double startPos, int numDivisions, double rulerScale, double maxPos = 0 );
91 
92  //draw current marker pos on ruler
93  void drawMarkerPos( QPainter *painter );
94 
95  signals:
97  void cursorPosChanged( QPointF );
98 
99 };
100 
101 #endif // QGSCOMPOSERRULER_H
virtual QSize minimumSizeHint() const
void setComposition(QgsComposition *c)
virtual void mouseReleaseEvent(QMouseEvent *event)
virtual void paintEvent(QPaintEvent *event)
virtual void mousePressEvent(QMouseEvent *event)
virtual void mouseMoveEvent(QMouseEvent *event)
QPoint pos() const
Graphics scene for map printing.
A class to show paper scale and the current cursor position.
void repaint()
void updateMarker(QPointF pos)
QgsComposition * composition()