コード例 #1
0
void GroundPreviewer::paintEvent(QPaintEvent *event)
{
    QWidget::paintEvent(event);
    //Initial the painter.
    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing |
                           QPainter::TextAntialiasing |
                           QPainter::SmoothPixmapTransform, true);
    //Fill the background.
    painter.fillRect(rect(), m_groundGlobal->baseColor());
    //Paint the border.
    painter.setPen(m_groundGlobal->borderColor());
    painter.setPen(Qt::NoPen);
    QBrush borderBrush(Qt::SolidPattern);
    borderBrush.setColor(m_groundGlobal->groundColor());
    painter.setBrush(borderBrush);
    painter.drawPolygon(m_previewGround);
    painter.setPen(m_groundGlobal->borderColor());
    borderBrush.setStyle(Qt::FDiagPattern);
    borderBrush.setColor(m_groundGlobal->borderColor());
    painter.setBrush(borderBrush);
    painter.drawPolygon(m_previewGround);
    //Paint the barracks.
    painter.setPen(m_groundGlobal->barracksColor());
    painter.setBrush(QColor(0,0,0,0));
    painter.drawPolygon(m_previewBarracks);
    //If display the preview robot.
    if(m_showPreviewPoint)
    {
        //Paint the preview robot.
        painter.setPen(Qt::NoPen);
        m_previewRobot->paintRobotDetectArea(&painter);
        painter.setPen(RobotBase::directionLineColor());
        painter.setBrush(Qt::NoBrush);
        m_previewRobot->paintRobotParameter(&painter);
        QPen robotPen(RobotBase::robotBorder());
        robotPen.setWidth(2);
        painter.setPen(robotPen);
        painter.setBrush(RobotBase::robotColor());
        m_previewRobot->paintRobot(&painter);
    }
    //If display the preview enemy.
    if(m_showPreviewEnemy)
    {
        //Paint the preview enemy.
        painter.setPen(Qt::NoPen);
        m_previewEnemy->paintEnemyDetectArea(&painter);
        QPen robotPen(RobotBase::robotBorder());
        robotPen.setWidth(2);
        painter.setPen(robotPen);
        painter.setBrush(RobotBase::robotColor());
        m_previewEnemy->paintRobot(&painter);
    }
}
コード例 #2
0
ファイル: nodeitemdelegate.cpp プロジェクト: maadborn/VisNode
/*
 *  Reimplemented paint from QStyledItemDelegate
 *  Very much a work in progress
 */
void NodeItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
    // Save painter state (according to docs.. purpose in this case?)
    painter->save();

    QString itemTitleText = index.data(Qt::DisplayRole).toString();

//    QList<QVariant> children = index.data(NodeItem::ChildrenRole).toList();
//    QPoint nodePoint = qvariant_cast<QPoint>(index.data(NodeItem::PositionRole));

    QPen oriPen = painter->pen();

//    for (int child = 0; child < children.size(); ++child) {
//        painter->drawLine(nodePoint, children.at(child).toPoint());
//    }

    // Draw a rectangle around the item
    QRect borderRect = option.rect;
    borderRect.adjust(-BORDER_PADDING, -BORDER_PADDING, BORDER_PADDING, BORDER_PADDING);

    QColor bgColor = index.data(NodeItem::ColorRole).value<QColor>();

    if (!bgColor.isValid())
        bgColor.setRgb(255,255,255);

    QPen borderPen(Qt::darkGreen, BORDER_WIDTH, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
    QBrush borderBrush(bgColor);
    painter->setPen(borderPen);
    painter->setBrush(borderBrush);
    painter->drawRoundedRect(borderRect, BORDER_CORNER_ROUNDING, BORDER_CORNER_ROUNDING);

    // Draw the title text
    painter->setPen(oriPen);
    painter->drawText(option.rect, itemTitleText, QTextOption(Qt::AlignCenter));

    // Restore painter state (according to docs.. purpose in this case?)
    painter->restore();

    // TODO Lines to other nodes - here or in the view?
}
コード例 #3
0
void KDReports::AbstractTableElement::fillTableFormat( QTextTableFormat& tableFormat, QTextCursor& textDocCursor ) const
{
    if ( d->m_width ) {
        if ( d->m_unit == Millimeters ) {
            tableFormat.setWidth( QTextLength( QTextLength::FixedLength, mmToPixels( d->m_width ) ) );
        } else {
            tableFormat.setWidth( QTextLength( QTextLength::PercentageLength, d->m_width ) );
        }
    }

    tableFormat.setBorder( border() );
#if QT_VERSION >= 0x040300
    tableFormat.setBorderBrush( borderBrush() );
    tableFormat.setBorderStyle( QTextFrameFormat::BorderStyle_Solid );
#endif
    tableFormat.setCellPadding( mmToPixels( padding() ) );
    tableFormat.setCellSpacing( -1 ); // HTML-like table borders look so old century
    if ( d->m_fontSpecified ) {
        QTextCharFormat charFormat = textDocCursor.charFormat();
        charFormat.setFont( d->m_defaultFont );
        textDocCursor.setCharFormat( charFormat );
    }
}