Ejemplo n.º 1
0
void BarChartWidget::drawLabel(QPainter &painter) {
    QRect baseRectangle = rect();
    painter.setPen(mainColor);

    int topY = (int) std::floor(baseRectangle.top());
    QPoint pointTopLeft(baseRectangle.left(), topY);
    QPoint pointBottomRight(baseRectangle.right(), topY + PADDING_TOP);
    QRect textRectangle(pointTopLeft, pointBottomRight);
    painter.drawText(textRectangle, Qt::AlignHCenter | Qt::AlignBottom, "Кратность пропущенных ошибок");
}
Ejemplo n.º 2
0
void TimeEditDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
                         const QModelIndex &index) const
{
    QDateTime dtval = index.model()->data(index, Qt::DisplayRole).toDateTime();

    QString indexvalue = tr("Date not set");
    if(dtval.isValid())
    {
        indexvalue = dtval.toString(timeformat);
    }
    Q_ASSERT(index.isValid());
    QStyleOptionViewItemV3 opt = setOptions(index, option);
    const QStyleOptionViewItemV2 *v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(&option);
    opt.features = v2 ? v2->features
                    : QStyleOptionViewItemV2::ViewItemFeatures(QStyleOptionViewItemV2::None);
    const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option);
    opt.locale = v3 ? v3->locale : QLocale();
    opt.widget = v3 ? v3->widget : 0;
    // prepare
    painter->save();
    painter->setClipRect(opt.rect);
    // get the data and the rectangles
    QVariant value;
    QPixmap pixmap;
    QRect decorationRect;
    value = index.data(Qt::DecorationRole);
    QString text;
    QRect displayRect;
    value = index.data(Qt::DisplayRole);
    if (value.isValid()) {
        text = indexvalue;
        displayRect = textRectangle(painter, option.rect, opt.font, text);
    }
    QRect checkRect;
    Qt::CheckState checkState = Qt::Unchecked;
    value = index.data(Qt::CheckStateRole);
    if (value.isValid()) {
        checkState = static_cast<Qt::CheckState>(value.toInt());
        //checkRect = check(opt, opt.rect, value);
    }
    // do the layout
    doLayout(opt, &checkRect, &decorationRect, &displayRect, false);
    // draw the item
    drawBackground(painter, opt, index);
    drawCheck(painter, opt, checkRect, checkState);
    drawDecoration(painter, opt, decorationRect, pixmap);
    drawDisplay(painter, opt, displayRect, text);
    drawFocus(painter, opt, displayRect);
    // done
    painter->restore();
}
Ejemplo n.º 3
0
void QItemDelegate::updateEditorGeometry(QWidget *editor,
                                         const QStyleOptionViewItem &option,
                                         const QModelIndex &index) const
{
    if (!editor)
        return;
    Q_ASSERT(index.isValid());
    QPixmap pixmap = decoration(option, index.data(Qt::DecorationRole));
    QString text = QItemDelegatePrivate::replaceNewLine(index.data(Qt::DisplayRole).toString());
    QRect pixmapRect = QRect(QPoint(0, 0), option.decorationSize).intersected(pixmap.rect());
    QRect textRect = textRectangle(0, option.rect, option.font, text);
    QRect checkRect = check(option, textRect, index.data(Qt::CheckStateRole));
    QStyleOptionViewItem opt = option;
    opt.showDecorationSelected = true; // let the editor take up all available space
    doLayout(opt, &checkRect, &pixmapRect, &textRect, false);
    editor->setGeometry(textRect);
}
Ejemplo n.º 4
0
/*!
    Renders the delegate using the given \a painter and style \a option for
    the item specified by \a index.

    When reimplementing this function in a subclass, you should update the area
    held by the option's \l{QStyleOption::rect}{rect} variable, using the
    option's \l{QStyleOption::state}{state} variable to determine the state of
    the item to be displayed, and adjust the way it is painted accordingly.

    For example, a selected item may need to be displayed differently to
    unselected items, as shown in the following code:

    \snippet examples/itemviews/pixelator/pixeldelegate.cpp 2
    \dots

    After painting, you should ensure that the painter is returned to its
    the state it was supplied in when this function was called. For example,
    it may be useful to call QPainter::save() before painting and
    QPainter::restore() afterwards.

    \sa QStyle::State
*/
void QItemDelegate::paint(QPainter *painter,
                          const QStyleOptionViewItem &option,
                          const QModelIndex &index) const
{
    Q_D(const QItemDelegate);
    Q_ASSERT(index.isValid());

    QStyleOptionViewItemV4 opt = setOptions(index, option);

    const QStyleOptionViewItemV2 *v2 = qstyleoption_cast<const QStyleOptionViewItemV2 *>(&option);
    opt.features = v2 ? v2->features
                    : QStyleOptionViewItemV2::ViewItemFeatures(QStyleOptionViewItemV2::None);
    const QStyleOptionViewItemV3 *v3 = qstyleoption_cast<const QStyleOptionViewItemV3 *>(&option);
    opt.locale = v3 ? v3->locale : QLocale();
    opt.widget = v3 ? v3->widget : 0;

    // prepare
    painter->save();
    if (d->clipPainting)
        painter->setClipRect(opt.rect);

    // get the data and the rectangles

    QVariant value;

    QPixmap pixmap;
    QRect decorationRect;
    value = index.data(Qt::DecorationRole);
    if (value.isValid()) {
        // ### we need the pixmap to call the virtual function
        pixmap = decoration(opt, value);
        if (value.type() == QVariant::Icon) {
            d->tmp.icon = qvariant_cast<QIcon>(value);
            d->tmp.mode = d->iconMode(option.state);
            d->tmp.state = d->iconState(option.state);
            const QSize size = d->tmp.icon.actualSize(option.decorationSize,
                                                      d->tmp.mode, d->tmp.state);
            decorationRect = QRect(QPoint(0, 0), size);
        } else {
            d->tmp.icon = QIcon();
            decorationRect = QRect(QPoint(0, 0), pixmap.size());
        }
    } else {
        d->tmp.icon = QIcon();
        decorationRect = QRect();
    }

    QString text;
    QRect displayRect;
    value = index.data(Qt::DisplayRole);
    if (value.isValid() && !value.isNull()) {
        text = QItemDelegatePrivate::valueToText(value, opt);
        displayRect = textRectangle(painter, d->textLayoutBounds(opt), opt.font, text);
    }

    QRect checkRect;
    Qt::CheckState checkState = Qt::Unchecked;
    value = index.data(Qt::CheckStateRole);
    if (value.isValid()) {
        checkState = static_cast<Qt::CheckState>(value.toInt());
        checkRect = check(opt, opt.rect, value);
    }

    // do the layout

    doLayout(opt, &checkRect, &decorationRect, &displayRect, false);

    // draw the item

    drawBackground(painter, opt, index);
    drawCheck(painter, opt, checkRect, checkState);
    drawDecoration(painter, opt, decorationRect, pixmap);
    drawDisplay(painter, opt, displayRect, text);
    drawFocus(painter, opt, displayRect);

    // done
    painter->restore();
}
Ejemplo n.º 5
0
void GraphicsItemNode::paint(QPainter * painter, const QStyleOptionGraphicsItem *, QWidget *)
{
    QPainterPath outlinePath = shape();

    //Fill the node's colour
    QBrush brush(m_colour);
    painter->fillPath(outlinePath, brush);

    //If the node contains a BLAST hit, draw that on top.
    if (g_settings->nodeColourScheme == BLAST_HITS_COLOUR)
    {
        std::vector<BlastHitPart> parts;

        if (g_settings->doubleMode)
        {
            if (m_deBruijnNode->thisNodeHasBlastHits())
                parts = m_deBruijnNode->getBlastHitPartsForThisNode();
        }
        else
        {
            if (m_deBruijnNode->thisNodeOrReverseComplementHasBlastHits())
                parts = m_deBruijnNode->getBlastHitPartsForThisNodeOrReverseComplement();
        }

        if (parts.size() > 0)
        {
            QPen partPen;
            partPen.setWidthF(m_width);
            partPen.setCapStyle(Qt::FlatCap);
            partPen.setJoinStyle(Qt::BevelJoin);

            for (size_t i = 0; i < parts.size(); ++i)
            {
                partPen.setColor(parts[i].m_colour);
                painter->setPen(partPen);

                painter->drawPath(makePartialPath(parts[i].m_nodeFractionStart, parts[i].m_nodeFractionEnd));
            }
        }
    }

    //Draw the node outline
    QColor outlineColour = g_settings->outlineColour;
    double outlineThickness = g_settings->outlineThickness;
    if (isSelected())
    {
        outlineColour = g_settings->selectionColour;
        outlineThickness = g_settings->selectionThickness;
    }
    if (outlineThickness > 0.0)
    {
        outlinePath = outlinePath.simplified();
        QPen outlinePen(QBrush(outlineColour), outlineThickness, Qt::SolidLine, Qt::FlatCap, Qt::RoundJoin);
        painter->setPen(outlinePen);
        painter->drawPath(outlinePath);
    }


    //Draw text if there is any to display.
    if (g_settings->anyNodeDisplayText())
    {
        //The text should always be displayed upright, so
        //counter the view's rotation here.

        painter->setRenderHint(QPainter::TextAntialiasing, true);
        painter->setFont(g_settings->labelFont);
        QString displayText = getNodeText();
        QSize textSize = getNodeTextSize(displayText);

        double textWidth = textSize.width();
        double textHeight = textSize.height();

        //The text outline is made by drawing the text first in white at a slight offset
        //at many angles.  The larger the text outline, the more angles are needed to
        //make the outline look nice.
        if (g_settings->textOutline)
        {
            int offsetSteps = 8;
            if (g_settings->textOutlineThickness > 0.5)
                offsetSteps = 16;
            if (g_settings->textOutlineThickness > 1.0)
                offsetSteps = 32;

            double offsetDistance = g_settings->textOutlineThickness;

            painter->translate(getCentre());
            painter->rotate(-g_graphicsView->m_rotation);

            for (int i = 0; i < offsetSteps; ++i)
            {
                double offsetAngle = 6.2832 * (double(i) / offsetSteps);
                double xOffset = offsetDistance * cos(offsetAngle);
                double yOffset = offsetDistance * sin(offsetAngle);
                QRectF shadowTextRectangle(-textWidth / 2.0 + xOffset,
                                           -textHeight / 2.0 + yOffset,
                                           textWidth, textHeight);
                painter->setPen(Qt::white);
                painter->drawText(shadowTextRectangle, Qt::AlignCenter, displayText);
            }

            painter->rotate(g_graphicsView->m_rotation);
            painter->translate(-1.0 * getCentre());
        }

        QRectF textRectangle(-textWidth / 2.0, -textHeight / 2.0,
                             textWidth, textHeight);
        painter->setPen(g_settings->textColour);

        painter->translate(getCentre());
        painter->rotate(-g_graphicsView->m_rotation);
        painter->drawText(textRectangle, Qt::AlignCenter, displayText);
        painter->rotate(g_graphicsView->m_rotation);
        painter->translate(-1.0 * getCentre());
    }
}