Beispiel #1
0
void nodeWidget::paint( QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * )
    {
    QString title( "Hello" );
    QList <QString> properties;

    properties << "Thing" << "lalala" << "bouind" << "hahaha";

    QRectF originalRect( titlebarRect( painter->font() ) );

    _titlePath = QPainterPath();
    _titlePath.addRect( originalRect );

    QRectF titleRect( originalRect );
    titleRect.setHeight( titleRect.height() + ( ROUNDRADIUS * 2 + 1 ) );

    QRectF contentsRect( titleRect );
    contentsRect.setY( originalRect.height() );
    contentsRect.setHeight( originalRect.height() + NODEPROPERTYHEIGHT*( properties.size() - 1 ) - 2*ROUNDRADIUS - 4 );

    QPainterPath titleBar( makeRoundedPath( titleRect ) );
    QPainterPath contents( makeRoundedPath( contentsRect ) );

    QPen outlinePen( Qt::black, 3 );
    if( isSelected() )
        {
        outlinePen.setColor( SELECTED_COLOUR );
        }
    QPainterPath globalLine( makeRoundedPath( titleRect.unite( contentsRect ) ) );
    painter->setPen( outlinePen );
    painter->drawPath( globalLine );
    painter->fillPath( titleBar, titleGradient( titleRect ) );


    painter->fillPath( contents, contentsBrush( contentsRect ) );

    QColor separatingLineColor( Qt::black );
    if( isSelected() )
        {
        separatingLineColor = SELECTED_COLOUR;
        }
    separatingLineColor.setAlpha( 128 );
    QPen separatingLinePen( separatingLineColor );
    QPen whitePen( Qt::white );

    painter->setPen( whitePen );
    painter->drawText( originalRect, Qt::AlignCenter, title );

    QRectF textRect( titleRect );
    textRect.moveTop( textRect.top() + originalRect.height() - 2*ROUNDRADIUS - 2 );
    FOREACH( properties, prop )
        {
        painter->setPen( whitePen );
        painter->drawText( textRect, Qt::AlignCenter, *prop );
        if( &(*prop) != &(properties.back()) )
            {
            painter->setPen( separatingLinePen );
            painter->drawLine( titleRect.x(), textRect.y()+NODEPROPERTYHEIGHT+4, titleRect.x()+titleRect.width(), textRect.y()+NODEPROPERTYHEIGHT+4 );
            }
        textRect.moveTop( textRect.top() + NODEPROPERTYHEIGHT );
        }
Beispiel #2
0
//-----------------------------------------------------------------------------
// Function: RibbonGroup::paintEvent()
//-----------------------------------------------------------------------------
void RibbonGroup::paintEvent(QPaintEvent* /*event*/)
{
    QPainter painter(this);

    // Draw the base gradient.
    QLinearGradient gradient(rect().topLeft(), rect().bottomLeft());
	gradient.setColorAt(0.0, RibbonTheme::GRADIENTTOP);
	gradient.setColorAt(0.1, Qt::white);
	gradient.setColorAt(0.3, RibbonTheme::GRADIENTTOP);
	gradient.setColorAt(1.0, RibbonTheme::GRADIENTBOTTOM);

    painter.setRenderHints(QPainter::Antialiasing);
    painter.fillRect(rect(), gradient);

    // Draw a nice frame around the group area.
	painter.setPen(QPen(RibbonTheme::GROUPTITLEGRADIENTTOP, 1));
    painter.drawRect(rect());

    // Draw the title background.
    QRect titleRect = rect();
    titleRect.setTop(rect().height() - TITLE_HEIGHT);

    QLinearGradient titleGradient(titleRect.topLeft(), titleRect.bottomLeft());
	titleGradient.setColorAt(0.0, RibbonTheme::GROUPTITLEGRADIENTTOP);
	titleGradient.setColorAt(1.0, RibbonTheme::GROUPTITLEGRADIENTBOTTOM);

    painter.fillRect(titleRect, titleGradient);

    // Draw the title text.
    QTextOption opt;
    opt.setAlignment(Qt::AlignCenter);

	painter.setPen(QPen(RibbonTheme::GROUPTITLETEXT));
    painter.drawText(titleRect, title_, opt);
}