22#include <QGraphicsView>
30 : QGraphicsRectItem( nullptr )
34 setCacheMode( QGraphicsItem::DeviceCoordinateCache );
37void QgsLayoutReportSectionLabel::paint( QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget )
42 if ( !mLayout || !mLayout->renderContext().isPreviewRender() )
48 if ( mLabel.isEmpty() )
53 const QFontMetrics fm( f );
54 const QSize s = fm.size( 0, mLabel );
55 const double margin = fm.height() / 5.0;
57 const double scaleValue = scale() / painter->transform().m11();
59 painter->setRenderHint( QPainter::Antialiasing,
true );
60 painter->scale( scaleValue, scaleValue );
61 const QRectF r = rect();
62 const QRectF scaledRect( r.left() / scaleValue, r.top() / scaleValue, r.width() / scaleValue, r.height() / scaleValue );
64 if ( scaledRect.width() < s.width() + 2 * margin || scaledRect.height() < s.height() + 2 * margin )
70 const QRectF textRect = QRectF( scaledRect.left() + margin, scaledRect.top() + margin, scaledRect.width() - 2 * margin, scaledRect.height() - 2 * margin );
71 const QRectF boxRect = QRectF( scaledRect.left(), scaledRect.bottom() - ( s.height() + 2 * margin ), s.width() + 2 * margin, s.height() + 2 * margin );
74 p.moveTo( boxRect.bottomRight() );
75 p.lineTo( boxRect.right(), boxRect.top() + margin );
76 p.arcTo( boxRect.right() - 2 * margin, boxRect.top(), 2 * margin, 2 * margin, 0, 90 );
77 p.lineTo( boxRect.left() + margin, boxRect.top() );
78 p.arcTo( boxRect.left(), boxRect.top(), 2 * margin, 2 * margin, 90, 90 );
79 p.lineTo( boxRect.bottomLeft() );
80 p.lineTo( boxRect.bottomRight() );
82 painter->setPen( QColor( 150, 150, 150, 150 ) );
83 QLinearGradient g( 0, boxRect.top(), 0, boxRect.bottom() );
84 g.setColorAt( 0, QColor( 200, 200, 200, 150 ) );
85 g.setColorAt( 1, QColor( 150, 150, 150, 150 ) );
87 painter->setBrush( QBrush( g ) );
88 painter->drawPath( p );
90 painter->setPen( QPen( QColor( 0, 0, 0, 100 ) ) );
91 painter->setFont( f );
92 painter->drawText( textRect, Qt::AlignBottom, mLabel );
95void QgsLayoutReportSectionLabel::setLabel(
const QString &label )
A graphical widget to display and interact with QgsLayouts.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Scoped object for saving and restoring a QPainter object's state.