21 #include <QGraphicsView> 29 : QGraphicsRectItem( nullptr )
33 setCacheMode( QGraphicsItem::DeviceCoordinateCache );
36 void QgsLayoutReportSectionLabel::paint( QPainter *painter,
const QStyleOptionGraphicsItem *option, QWidget *widget )
47 if ( mLabel.isEmpty() )
53 QSize s = fm.size( 0, mLabel );
54 double margin = fm.height() / 5.0;
56 double scaleValue = scale() / painter->transform().m11();
58 painter->setRenderHint( QPainter::Antialiasing,
true );
59 painter->scale( scaleValue, scaleValue );
61 QRectF scaledRect( r.left() / scaleValue, r.top() / scaleValue, r.width() / scaleValue, r.height() / scaleValue );
63 if ( scaledRect.width() < s.width() + 2 * margin || scaledRect.height() < s.height() + 2 * margin )
69 QRectF textRect = QRectF( scaledRect.left() + margin, scaledRect.top() + margin, scaledRect.width() - 2 * margin, scaledRect.height() - 2 * margin );
70 QRectF boxRect = QRectF( scaledRect.left(), scaledRect.bottom() - ( s.height() + 2 * margin ), s.width() + 2 * margin, s.height() + 2 * margin );
73 p.moveTo( boxRect.bottomRight() );
74 p.lineTo( boxRect.right(), boxRect.top() + margin );
75 p.arcTo( boxRect.right() - 2 * margin, boxRect.top(), 2 * margin, 2 * margin, 0, 90 );
76 p.lineTo( boxRect.left() + margin, boxRect.top() );
77 p.arcTo( boxRect.left(), boxRect.top(), 2 * margin, 2 * margin, 90, 90 );
78 p.lineTo( boxRect.bottomLeft() );
79 p.lineTo( boxRect.bottomRight() );
81 painter->setPen( QColor( 150, 150, 150, 150 ) );
82 QLinearGradient g( 0, boxRect.top(), 0, boxRect.bottom() );
83 g.setColorAt( 0, QColor( 200, 200, 200, 150 ) );
84 g.setColorAt( 1, QColor( 150, 150, 150, 150 ) );
86 painter->setBrush( QBrush( g ) );
87 painter->drawPath( p );
89 painter->setPen( QPen( QColor( 0, 0, 0, 100 ) ) );
90 painter->setFont( f );
91 painter->drawText( textRect, Qt::AlignBottom, mLabel );
95 void QgsLayoutReportSectionLabel::setLabel(
const QString &label )
A graphical widget to display and interact with QgsLayouts.
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
bool isPreviewRender() const
Returns true if the render current being conducted is a preview render, i.e.