Esempio n. 1
0
void KisNodeDelegate::drawText(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    KisNodeViewColorScheme scm;
    const QRect rc = textRect(option, index)
        .adjusted(scm.textMargin(), 0, -scm.textMargin(), 0);

    QPen oldPen = p->pen();
    const qreal oldOpacity = p->opacity(); // remember previous opacity

    p->setPen(option.palette.color(QPalette::Active,QPalette::Text ));



    if (!(option.state & QStyle::State_Enabled)) {
        p->setOpacity(0.55);
    }


    const QString text = index.data(Qt::DisplayRole).toString();
    const QString elided = elidedText(p->fontMetrics(), rc.width(), Qt::ElideRight, text);
    p->drawText(rc, Qt::AlignLeft | Qt::AlignVCenter, elided);

    p->setPen(oldPen); // restore pen settings
    p->setOpacity(oldOpacity);
}
Esempio n. 2
0
void KisNodeDelegate::drawFrame(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    KisNodeViewColorScheme scm;

    QPen oldPen = p->pen();
    p->setPen(scm.gridColor(option, d->view));

    const QPoint base = option.rect.topLeft();

    QPoint p2 = base + QPoint(-scm.indentation() - 1, 0);
    QPoint p3 = base + QPoint(-2 * scm.border() - 2 * scm.decorationMargin() - scm.decorationSize(), 0);
    QPoint p4 = base + QPoint(-1, 0);
    QPoint p5(iconsRect(option,
                           index).left() - 1, base.y());
    QPoint p6(option.rect.right(), base.y());

    QPoint v(0, option.rect.height());

    const bool paintForParent =
        index.parent().isValid() &&
        !index.row();

    if (paintForParent) {
        QPoint p1(-2 * scm.indentation() - 1, 0);
        p1 += base;
        p->drawLine(p1, p2);
    }


    QPoint k0(0, base.y());
    QPoint k1(1 * scm.border() + 2 * scm.visibilityMargin() + scm.visibilitySize(), base.y());
    p->drawLine(k0, k1);
    p->drawLine(k0 + v, k1 + v);
    p->drawLine(k0, k0 + v);
    p->drawLine(k1, k1 + v);

    p->drawLine(p2, p6);
    p->drawLine(p2 + v, p6 + v);
    p->drawLine(p2, p2 + v);
    p->drawLine(p3, p3 + v);
    p->drawLine(p4, p4 + v);
    p->drawLine(p5, p5 + v);
    p->drawLine(p6, p6 + v);

    //// For debugging purposes only
    //p->setPen(Qt::blue);
    //KritaUtils::renderExactRect(p, iconsRect(option, index));
    //KritaUtils::renderExactRect(p, textRect(option, index));
    //KritaUtils::renderExactRect(p, scm.relThumbnailRect().translated(option.rect.topLeft()));

    p->setPen(oldPen);
}
Esempio n. 3
0
QRect KisNodeDelegate::textRect(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    KisNodeViewColorScheme scm;

    static QFont f;
    static int minbearing = 1337 + 666; //can be 0 or negative, 2003 is less likely
    if (minbearing == 2003 || f != option.font) {
        f = option.font; //getting your bearings can be expensive, so we cache them
        minbearing = option.fontMetrics.minLeftBearing() + option.fontMetrics.minRightBearing();
    }

    const int decorationOffset =
        2 * scm.border() +
        2 * scm.decorationMargin() +
        scm.decorationSize();

    const int width =
        iconsRect(option, index).left() - option.rect.x() -
        scm.border() + minbearing - decorationOffset;

    return QRect(option.rect.x() - minbearing + decorationOffset,
                 option.rect.y() + scm.border(),
                 width,
                 scm.rowHeight() - scm.border());
}
Esempio n. 4
0
void KisNodeDelegate::drawColorLabel(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    KisNodeViewColorScheme scm;
    const int label = index.data(KisNodeModel::ColorLabelIndexRole).toInt();
    QColor color = scm.colorLabel(label);
    if (color.alpha() <= 0) return;

    QColor bgColor = qApp->palette().color(QPalette::Base);
    color = KritaUtils::blendColors(color, bgColor, 0.2);

    const QRect rect = option.state & QStyle::State_Selected ?
        iconsRect(option, index) :
        option.rect.adjusted(-scm.indentation(), 0, 0, 0);

    p->fillRect(rect, color);
}
Esempio n. 5
0
void KisNodeDelegate::drawThumbnail(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    KisNodeViewColorScheme scm;

    const int thumbSize = scm.thumbnailSize();
    const qreal oldOpacity = p->opacity(); // remember previous opacity

    QImage img = index.data(int(KisNodeModel::BeginThumbnailRole) + thumbSize).value<QImage>();
    if (!(option.state & QStyle::State_Enabled)) {
        p->setOpacity(0.35);
    }

    QRect fitRect = scm.relThumbnailRect().translated(option.rect.topLeft());

    QPoint offset;
    offset.setX((fitRect.width() - img.width()) / 2);
    offset.setY((fitRect.height() - img.height()) / 2);
    offset += fitRect.topLeft();

    KisConfig cfg;

    // paint in a checkerboard pattern behind the layer contents to represent transparent
    const int step = scm.thumbnailSize() / 6;
    QImage checkers(2 * step, 2 * step, QImage::Format_ARGB32);
    QPainter gc(&checkers);
    gc.fillRect(QRect(0, 0, step, step), cfg.checkersColor1());
    gc.fillRect(QRect(step, 0, step, step), cfg.checkersColor2());
    gc.fillRect(QRect(step, step, step, step), cfg.checkersColor1());
    gc.fillRect(QRect(0, step, step, step), cfg.checkersColor2());

    QBrush brush(checkers);
    p->setBrushOrigin(offset);
    p->fillRect(img.rect().translated(offset), brush);

    p->drawImage(offset, img);
    p->setOpacity(oldOpacity); // restore old opacity

    QRect borderRect = kisGrowRect(img.rect(), 1).translated(offset);
    KritaUtils::renderExactRect(p, borderRect, scm.gridColor(option, d->view));
}
Esempio n. 6
0
void KisNodeDelegate::drawThumbnail(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    KisNodeViewColorScheme scm;

    const int thumbSize = scm.thumbnailSize();
    const qreal oldOpacity = p->opacity(); // remember previous opacity

    QImage img = index.data(int(KisNodeModel::BeginThumbnailRole) + thumbSize).value<QImage>();
    if (!(option.state & QStyle::State_Enabled)) {
        p->setOpacity(0.35);
    }

    QRect fitRect = scm.relThumbnailRect().translated(option.rect.topLeft());

    QPoint offset;
    offset.setX((fitRect.width() - img.width()) / 2);
    offset.setY((fitRect.height() - img.height()) / 2);
    offset += fitRect.topLeft();

    // {   // paint the checkers: we need a proper GUI design for them to be uncommented
    //     const int step = scm.thumbnailSize() / 4;
    //     QImage checkers(2 * step, 2 * step, QImage::Format_ARGB32);
    //     QPainter gc(&checkers);
    //     gc.fillRect(QRect(0, 0, step, step), Qt::white);
    //     gc.fillRect(QRect(step, 0, step, step), Qt::gray);
    //     gc.fillRect(QRect(step, step, step, step), Qt::white);
    //     gc.fillRect(QRect(0, step, step, step), Qt::gray);
    //     QBrush brush(checkers);
    //     p->setBrushOrigin(offset);
    //     p->fillRect(img.rect().translated(offset), brush);*/
    // }

    p->fillRect(img.rect().translated(offset), Qt::white);
    p->drawImage(offset, img);
    p->setOpacity(oldOpacity); // restore old opacity

    QRect borderRect = kisGrowRect(img.rect(), 1).translated(offset);
    KritaUtils::renderExactRect(p, borderRect, scm.gridColor(option, d->view));
}
Esempio n. 7
0
QRect KisNodeDelegate::iconsRect(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    KisNodeViewColorScheme scm;

    int propCount = d->numProperties(index);

    const int iconsWidth =
        propCount * (scm.iconSize() + 2 * scm.iconMargin()) +
        (propCount - 1) * scm.border();

    const int x = option.rect.x() + option.rect.width()
        - (iconsWidth + scm.border());
    const int y = option.rect.y() + scm.border();

    return QRect(x, y,
                 iconsWidth,
                 scm.rowHeight() - scm.border());
}
Esempio n. 8
0
QSize KisNodeDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    Q_UNUSED(index);
    KisNodeViewColorScheme scm;
    return QSize(option.rect.width(), scm.rowHeight());
}
Esempio n. 9
0
void KisNodeDelegate::drawIcons(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    KisNodeViewColorScheme scm;
    const QRect r = iconsRect(option, index);

    QTransform oldTransform = p->transform();
    QPen oldPen = p->pen();
    p->setTransform(QTransform::fromTranslate(r.x(), r.y()));
    p->setPen(scm.gridColor(option, d->view));

    int x = 0;
    const int y = (scm.rowHeight() - scm.border() - scm.iconSize()) / 2;
    KisBaseNode::PropertyList props = index.data(KisNodeModel::PropertiesRole).value<KisBaseNode::PropertyList>();
    QList<OptionalProperty> realProps = d->rightmostProperties(props);

    Q_FOREACH (OptionalProperty prop, realProps) {
        x += scm.iconMargin();
        if (prop) {
            QIcon icon = prop->state.toBool() ? prop->onIcon : prop->offIcon;
            bool fullColor = prop->state.toBool() && option.state & QStyle::State_Enabled;
            const qreal oldOpacity = p->opacity(); // remember previous opacity


            if (fullColor) {              
                 p->setOpacity(1.0);
            }
            else {
                p->setOpacity(0.35);
            }

            p->drawPixmap(x, y, icon.pixmap(scm.iconSize(), QIcon::Normal));
            p->setOpacity(oldOpacity); // restore old opacity


        }
        x += scm.iconSize() + scm.iconMargin();
        p->drawLine(x, 0, x, scm.rowHeight() - scm.border());
        x += scm.border();
    }
Esempio n. 10
0
void KisNodeDelegate::drawBranch(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const {
    Q_UNUSED(index);

    KisNodeViewColorScheme scm;
    const QPoint base = scm.relThumbnailRect().translated(option.rect.topLeft()).topLeft() - QPoint( scm.indentation(), 0);

    // there is no indention if we are starting negative, so don't draw a branch
    if (base.x() < 0) {
        return;
    }


    QPen oldPen = p->pen();
    const qreal oldOpacity = p->opacity(); // remember previous opacity
    p->setOpacity(1.0);

    QColor color = scm.gridColor(option, d->view);
    QColor bgColor = option.state & QStyle::State_Selected ?
        qApp->palette().color(QPalette::Base) :
        qApp->palette().color(QPalette::Text);
    color = KritaUtils::blendColors(color, bgColor, 0.9);


    // TODO: if we are a mask type, use dotted lines for the branch style
    // p->setPen(QPen(p->pen().color(), 2, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin));
    p->setPen(QPen(color, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));

    QPoint p2 = base + QPoint(scm.iconSize() - scm.decorationMargin()*2, scm.iconSize()*0.45);
    QPoint p3 =  base + QPoint(scm.iconSize() - scm.decorationMargin()*2, scm.iconSize());
    QPoint p4 = base + QPoint(scm.iconSize()*1.4, scm.iconSize());
    p->drawLine(p2, p3);
    p->drawLine(p3, p4);



     // draw parent lines (keep drawing until x position is less than 0
    QPoint p5 = p2 - QPoint(scm.indentation(), 0);
    QPoint p6 = p3 - QPoint(scm.indentation(), 0);

     QPoint parentBase1 = p5;
     QPoint parentBase2 = p6;

     // indent lines needs to be very subtle to avoid making the docker busy looking
     color = KritaUtils::blendColors(color, bgColor, 0.9); // makes it a little lighter than L lines
     p->setPen(QPen(color, 0, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));

     while (parentBase1.x() > scm.visibilityColumnWidth()) {
         p->drawLine(parentBase1, parentBase2);

         parentBase1 = parentBase1 - QPoint(scm.indentation(), 0);
         parentBase2 = parentBase2 - QPoint(scm.indentation(), 0);
     }




     p->setPen(oldPen);
     p->setOpacity(oldOpacity);
}