16
16
#include " qgslayout.h"
17
17
#include " qgis.h"
18
18
#include " qgslayoutview.h"
19
+ #include " qgslogger.h"
19
20
#include < QDragEnterEvent>
20
21
#include < QGraphicsLineItem>
21
22
#include < QPainter>
@@ -52,6 +53,20 @@ QgsLayoutRuler::QgsLayoutRuler( QWidget *parent, Qt::Orientation orientation )
52
53
mPixelsBetweenLineAndText = mRulerMinSize / 10 ;
53
54
mTextBaseline = mRulerMinSize / 1.667 ;
54
55
mMinSpacingVerticalLabels = mRulerMinSize / 5 ;
56
+
57
+ double guideMarkerSize = mRulerFontMetrics ->width ( " *" );
58
+ switch ( mOrientation )
59
+ {
60
+ case Qt::Horizontal:
61
+ mGuideMarker << QPoint ( -guideMarkerSize / 2 , mRulerMinSize - guideMarkerSize ) << QPoint ( 0 , mRulerMinSize ) <<
62
+ QPoint ( guideMarkerSize / 2 , mRulerMinSize - guideMarkerSize );
63
+ break ;
64
+
65
+ case Qt::Vertical:
66
+ mGuideMarker << QPoint ( mRulerMinSize - guideMarkerSize, -guideMarkerSize / 2 ) << QPoint ( mRulerMinSize , 0 ) <<
67
+ QPoint ( mRulerMinSize - guideMarkerSize, guideMarkerSize / 2 );
68
+ break ;
69
+ }
55
70
}
56
71
57
72
QSize QgsLayoutRuler::minimumSizeHint () const
@@ -70,6 +85,8 @@ void QgsLayoutRuler::paintEvent( QPaintEvent *event )
70
85
QgsLayout *layout = mView ->currentLayout ();
71
86
QPainter p ( this );
72
87
88
+ drawGuideMarkers ( &p, layout );
89
+
73
90
QTransform t = mTransform .inverted ();
74
91
p.setFont ( mRulerFont );
75
92
// keep same default color, but lower opacity a tad
@@ -260,6 +277,56 @@ void QgsLayoutRuler::drawMarkerPos( QPainter *painter )
260
277
}
261
278
}
262
279
280
+ void QgsLayoutRuler::drawGuideMarkers ( QPainter *p, QgsLayout *layout )
281
+ {
282
+ QList< int > visiblePageNumbers = mView ->visiblePageNumbers ();
283
+ QList< QgsLayoutGuide * > guides = layout->guides ().guides ( mOrientation == Qt::Horizontal ? QgsLayoutGuide::Vertical : QgsLayoutGuide::Horizontal );
284
+ p->save ();
285
+ p->setRenderHint ( QPainter::Antialiasing, true );
286
+ p->setBrush ( QBrush ( QColor ( 255 , 0 , 0 ) ) );
287
+ p->setPen ( Qt::NoPen );
288
+ Q_FOREACH ( QgsLayoutGuide *guide, guides )
289
+ {
290
+ if ( visiblePageNumbers.contains ( guide->page () ) )
291
+ {
292
+ QPointF point;
293
+ switch ( mOrientation )
294
+ {
295
+ case Qt::Horizontal:
296
+ point = QPointF ( guide->layoutPosition (), 0 );
297
+ break ;
298
+
299
+ case Qt::Vertical:
300
+ point = QPointF ( 0 , guide->layoutPosition () );
301
+ break ;
302
+ }
303
+ drawGuideAtPos ( p, convertLayoutPointToLocal ( point ) );
304
+ }
305
+ }
306
+ p->restore ();
307
+ }
308
+
309
+ void QgsLayoutRuler::drawGuideAtPos ( QPainter *painter, QPoint pos )
310
+ {
311
+ switch ( mOrientation )
312
+ {
313
+ case Qt::Horizontal:
314
+ {
315
+ painter->translate ( pos.x (), 0 );
316
+ painter->drawPolygon ( mGuideMarker );
317
+ painter->translate ( -pos.x (), 0 );
318
+ break ;
319
+ }
320
+ case Qt::Vertical:
321
+ {
322
+ painter->translate ( 0 , pos.y () );
323
+ painter->drawPolygon ( mGuideMarker );
324
+ painter->translate ( 0 , -pos.y () );
325
+ break ;
326
+ }
327
+ }
328
+ }
329
+
263
330
void QgsLayoutRuler::createTemporaryGuideItem ()
264
331
{
265
332
mGuideItem .reset ( new QGraphicsLineItem () );
@@ -279,6 +346,12 @@ QPointF QgsLayoutRuler::convertLocalPointToLayout( QPoint localPoint ) const
279
346
return mView ->mapToScene ( viewPoint );
280
347
}
281
348
349
+ QPoint QgsLayoutRuler::convertLayoutPointToLocal ( QPointF layoutPoint ) const
350
+ {
351
+ QPoint viewPoint = mView ->mapFromScene ( layoutPoint );
352
+ return mapFromGlobal ( mView ->mapToGlobal ( viewPoint ) );
353
+ }
354
+
282
355
void QgsLayoutRuler::drawRotatedText ( QPainter *painter, QPointF pos, const QString &text )
283
356
{
284
357
painter->save ();
@@ -467,20 +540,19 @@ void QgsLayoutRuler::mouseMoveEvent( QMouseEvent *event )
467
540
linePen.setColor ( QColor ( 255 , 0 , 0 , 225 ) );
468
541
}
469
542
mGuideItem ->setPen ( linePen );
470
-
471
543
switch ( mOrientation )
472
544
{
473
545
case Qt::Horizontal:
474
546
{
475
547
// mouse is creating a horizontal ruler, so don't show x coordinate
476
- mGuideItem ->setLine ( 0 , displayPos.y (), page->rect ().width (), displayPos.y () );
548
+ mGuideItem ->setLine ( page-> scenePos (). x () , displayPos.y (), page-> scenePos (). x () + page->rect ().width (), displayPos.y () );
477
549
displayPos.setX ( 0 );
478
550
break ;
479
551
}
480
552
case Qt::Vertical:
481
553
{
482
554
// mouse is creating a vertical ruler, so don't show a y coordinate
483
- mGuideItem ->setLine ( displayPos.x (), 0 , displayPos.x (), page->rect ().height () );
555
+ mGuideItem ->setLine ( displayPos.x (), page-> scenePos (). y () , displayPos.x (), page-> scenePos (). y () + page->rect ().height () );
484
556
displayPos.setY ( 0 );
485
557
break ;
486
558
}
0 commit comments