1
1
#include " qgscomposerruler.h"
2
2
#include < QPainter>
3
+ #include < cmath>
3
4
4
5
const int RULER_MIN_SIZE = 20 ;
5
6
@@ -19,8 +20,41 @@ QSize QgsComposerRuler::minimumSizeHint() const
19
20
void QgsComposerRuler::paintEvent ( QPaintEvent* event )
20
21
{
21
22
Q_UNUSED ( event );
22
-
23
- // draw blue rectangle for a test
24
23
QPainter p ( this );
25
- p.fillRect ( rect (), QColor ( 0 , 0 , 255 ) );
24
+
25
+ QTransform t = mTransform .inverted ();
26
+
27
+ if ( mDirection == Horizontal )
28
+ {
29
+ // start x-coordinate
30
+ double startX = t.map ( QPointF ( 0 , 0 ) ).x ();// -mTransform.dx() / mTransform.m11();
31
+ double endX = t.map ( QPointF ( width (), 0 ) ).x ();// ( -mTransform.dx() + width() ) / mTransform.m11();
32
+
33
+ double markerPos = ( floor ( startX / 10.0 ) + 1 ) * 10.0 - RULER_MIN_SIZE; // marker position in mm
34
+ while ( markerPos <= endX )
35
+ {
36
+ if ( markerPos >= 0 && markerPos <= 296 ) // todo: need to know paper size
37
+ {
38
+ double pixelCoord = mTransform .map ( QPointF ( markerPos, 0 ) ).x ();
39
+ p.drawLine ( pixelCoord, 0 , pixelCoord, RULER_MIN_SIZE );
40
+ }
41
+ markerPos += 10.0 ;
42
+ }
43
+
44
+ qWarning ( QString::number ( startX ).toLocal8Bit ().data () );
45
+ qWarning ( QString::number ( endX ).toLocal8Bit ().data () );
46
+ }
47
+ else // vertical
48
+ {
49
+ // p.fillRect( rect(), QColor( 0, 0, 255 ) );
50
+ }
51
+ }
52
+
53
+ void QgsComposerRuler::setSceneTransform ( const QTransform& transform )
54
+ {
55
+ QString debug = QString::number ( transform.dx () ) + " ," + QString::number ( transform.dy () ) + " ,"
56
+ + QString::number ( transform.m11 () ) + " ," + QString::number ( transform.m22 () );
57
+ qWarning ( debug.toLocal8Bit ().data () );
58
+ mTransform = transform;
59
+ update ();
26
60
}
0 commit comments