Skip to content
Permalink
Browse files
Store reference to composition in ruler to get page info
  • Loading branch information
mhugent committed Feb 17, 2013
1 parent 5f8e9e1 commit 466280272a3b095458ab06074c7c63a4d3ee5a41
Showing with 22 additions and 4 deletions.
  1. +9 −4 src/gui/qgscomposerruler.cpp
  2. +5 −0 src/gui/qgscomposerruler.h
  3. +8 −0 src/gui/qgscomposerview.cpp
@@ -1,11 +1,12 @@
#include "qgscomposerruler.h"
#include "qgscomposition.h"
#include "qgis.h"
#include <QPainter>
#include <cmath>

const int RULER_MIN_SIZE = 20;

QgsComposerRuler::QgsComposerRuler( QgsComposerRuler::Direction d ): QWidget( 0 ), mDirection( d )
QgsComposerRuler::QgsComposerRuler( QgsComposerRuler::Direction d ): QWidget( 0 ), mDirection( d ), mComposition( 0 )
{
}

@@ -21,6 +22,11 @@ QSize QgsComposerRuler::minimumSizeHint() const
void QgsComposerRuler::paintEvent( QPaintEvent* event )
{
Q_UNUSED( event );
if ( !mComposition )
{
return;
}

QPainter p( this );

QTransform t = mTransform.inverted();
@@ -39,7 +45,7 @@ void QgsComposerRuler::paintEvent( QPaintEvent* event )
double markerPos = ( floor( startX / 10.0 ) + 1 ) * 10.0; //marker position in mm
while ( markerPos <= endX )
{
if ( markerPos >= 0 && markerPos <= 297 ) //todo: need to know paper size
if ( markerPos >= 0 && markerPos <= mComposition->paperWidth() ) //todo: need to know paper size
{
double pixelCoord = mTransform.map( QPointF( markerPos, 0 ) ).x();
p.drawLine( pixelCoord, 0, pixelCoord, RULER_MIN_SIZE );
@@ -64,7 +70,7 @@ void QgsComposerRuler::paintEvent( QPaintEvent* event )
double markerPos = ( floor( startY / 10.0 ) + 1 ) * 10.0; //marker position in mm
while ( markerPos <= endY )
{
if ( markerPos >= 0 && markerPos <= 210 )
if ( markerPos >= 0 && markerPos <= mComposition->paperHeight() )
{
double pixelCoord = mTransform.map( QPointF( 0, markerPos ) ).y();
p.drawLine( 0, pixelCoord, RULER_MIN_SIZE, pixelCoord );
@@ -82,7 +88,6 @@ void QgsComposerRuler::setSceneTransform( const QTransform& transform )
{
QString debug = QString::number( transform.dx() ) + "," + QString::number( transform.dy() ) + ","
+ QString::number( transform.m11() ) + "," + QString::number( transform.m22() );
qWarning( debug.toLocal8Bit().data() );
mTransform = transform;
update();
}
@@ -2,6 +2,7 @@
#define QGSCOMPOSERRULER_H

#include <QWidget>
class QgsComposition;

/**A class to show paper scale and the current cursor position*/
class QgsComposerRuler: public QWidget
@@ -21,13 +22,17 @@ class QgsComposerRuler: public QWidget
void setSceneTransform( const QTransform& transform );
void updateMarker( const QPointF& pos ) { mMarkerPos = pos; repaint(); }

void setComposition( const QgsComposition* c ) { mComposition = c; }
const QgsComposition* composition() const { return mComposition; }

protected:
void paintEvent( QPaintEvent* event );

private:
Direction mDirection;
QTransform mTransform;
QPointF mMarkerPos;
const QgsComposition* mComposition; //reference to composition for paper size, nPages
};

#endif // QGSCOMPOSERRULER_H
@@ -651,6 +651,14 @@ void QgsComposerView::scrollContentsBy( int dx, int dy )
void QgsComposerView::setComposition( QgsComposition* c )
{
setScene( c );
if ( mHorizontalRuler )
{
mHorizontalRuler->setComposition( c );
}
if ( mVerticalRuler )
{
mVerticalRuler->setComposition( c );
}
}

QgsComposition* QgsComposerView::composition()

0 comments on commit 4662802

Please sign in to comment.