Ejemplo n.º 1
0
QPixmap StylePainterMobile::findLineEdit(const QSize & size, bool focused) const
{
    QPixmap result;
    KeyIdentifier id;
    id.type = KeyIdentifier::LineEdit;
    id.width = size.width();
    id.height = size.height();
    id.trait1 = focused;

    if (!findCachedControl(id, &result)) {
        const int focusFrame = painterScale(painter);
        result = QPixmap(size + QSize(2 * focusFrame, 2 * focusFrame));
        result.fill(Qt::transparent);
        const QRect rect = result.rect().adjusted(focusFrame, focusFrame, -focusFrame, -focusFrame);
        QPainter cachePainter(&result);
        drawControlBackground(&cachePainter, borderPen(painter), rect, Qt::white);

        if (focused) {
            QPen focusPen(highlightColor, focusFrame, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
            drawControlBackground(&cachePainter, focusPen, rect, Qt::NoBrush);
        }
        insertIntoCache(id, result);
    }
    return result;
}
Ejemplo n.º 2
0
/*!
  \brief Draw a set of points of a curve.
  When observing an measurement while it is running, new points have to be
  added to an existing curve. drawCurve can be used to display them avoiding
  a complete redraw of the canvas.

  \param key curve key
  \param from index of the first point to be painted
  \param to index of the last point to be painted. If to < 0 the
         curve will be painted to its last point.
  \sa QwtCurve::draw
*/
void QwtPlot::drawCurve(long key, int from, int to)
{
    QwtPlotCurve *curve = d_curves->find(key);
    if ( !curve )
        return;

    QPainter p(canvas());

    p.setClipping(TRUE);
    p.setClipRect(canvas()->contentsRect());

    curve->draw(&p,
        canvasMap(curve->xAxis()), canvasMap(curve->yAxis()),
        from, to);

    if ( canvas()->cacheMode() && canvas()->cache())
    {
        QPainter cachePainter(canvas()->cache());
        cachePainter.translate(-canvas()->contentsRect().x(),
            -canvas()->contentsRect().y());

        curve->draw(&cachePainter,
            canvasMap(curve->xAxis()), canvasMap(curve->yAxis()),
            from, to);
    }
}
Ejemplo n.º 3
0
QPixmap StylePainterMobile::findComboButton(const QSize& size, bool multiple, bool enabled) const
{
    if (size.isNull())
        return QPixmap();
    QPixmap result;
    KeyIdentifier id;
    id.type = KeyIdentifier::ComboButton;
    id.width = size.width();
    id.height = size.height();
    id.trait1 = multiple;
    id.trait2 = enabled;

    if (!findCachedControl(id, &result)) {
        result = QPixmap(size);
        const qreal border = painterScale(painter);
        const QSizeF padding(2 * border, 2 * border);
        const QSizeF innerSize = size - padding;
        ASSERT(innerSize.isValid());
        result.fill(Qt::transparent);
        QPainter cachePainter(&result);
        cachePainter.translate(border, border);
        if (multiple)
            drawMultipleComboButton(&cachePainter, innerSize, enabled ? darkColor : Qt::lightGray);
        else
            drawSimpleComboButton(&cachePainter, innerSize, enabled ? darkColor : Qt::lightGray);
        insertIntoCache(id, result);
    }
    return result;
}
Ejemplo n.º 4
0
/*!
  Draw the canvas

  Paints all plot items to the canvasRect, using QwtPolarPlot::drawCanvas
  and updates the paint cache.

  \sa QwtPolarPlot::drawCanvas, setPaintAttributes(), testPaintAttributes()
*/
void QwtPolarCanvas::drawCanvas( QPainter *painter,
                                 const QwtDoubleRect& canvasRect )
{
  if ( !canvasRect.isValid() )
    return;

  if ( testPaintAttribute( PaintCached ) && d_data->cache )
  {
    *d_data->cache = QPixmap( contentsRect().size() );

#ifdef Q_WS_X11
#if QT_VERSION >= 0x040000
    if ( d_data->cache->x11Info().screen() != x11Info().screen() )
      d_data->cache->x11SetScreen( x11Info().screen() );
#else
    if ( d_data->cache->x11Screen() != x11Screen() )
      d_data->cache->x11SetScreen( x11Screen() );
#endif
#endif

    d_data->cache->fill( this, d_data->cache->rect().topLeft() );

    QPainter cachePainter( d_data->cache );
    cachePainter.translate( -contentsRect().x(),
                            -contentsRect().y() );

    plot()->drawCanvas( &cachePainter, canvasRect );

    cachePainter.end();

    painter->drawPixmap( canvasRect.topLeft().toPoint(), *d_data->cache );
  }
  else
    plot()->drawCanvas( painter, canvasRect );
}
Ejemplo n.º 5
0
/*!
  Draw the the canvas

  Paints all plot items to the contentsRect(), using QwtPlot::drawCanvas
  and updates the paint cache.

  \param painter Painter

  \sa QwtPlot::drawCanvas(), setPaintAttributes(), testPaintAttributes()
*/
void QwtPlotCanvas::drawCanvas( QPainter *painter )
{
    if ( !contentsRect().isValid() )
        return;

    QBrush bgBrush = palette().brush( backgroundRole() );

    if ( d_data->paintAttributes & PaintCached && d_data->cache )
    {
        *d_data->cache = QPixmap( contentsRect().size() );

#ifdef Q_WS_X11
        if ( d_data->cache->x11Info().screen() != x11Info().screen() )
            d_data->cache->x11SetScreen( x11Info().screen() );
#endif

        if ( d_data->paintAttributes & PaintPacked )
        {
            QPainter bgPainter( d_data->cache );
            bgPainter.setPen( Qt::NoPen );

            bgPainter.setBrush( bgBrush );
            bgPainter.drawRect( d_data->cache->rect() );
        }
        else
            d_data->cache->fill( this, d_data->cache->rect().topLeft() );

        QPainter cachePainter( d_data->cache );
        cachePainter.translate( -contentsRect().x(),
            -contentsRect().y() );

        ( ( QwtPlot * )parent() )->drawCanvas( &cachePainter );

        cachePainter.end();

        painter->drawPixmap( contentsRect(), *d_data->cache );
    }
    else
    {
        if ( d_data->paintAttributes & PaintPacked )
        {
            painter->save();

            painter->setPen( Qt::NoPen );
            painter->setBrush( bgBrush );
            painter->drawRect( contentsRect() );

            painter->restore();
        }

        ( ( QwtPlot * )parent() )->drawCanvas( painter );
    }
}
void QwtPlotCanvas::drawCanvas(QPainter *painter)
{
    if ( !contentsRect().isValid() )
        return;

    QRect clipRect = contentsRect();
    if ( !cacheMode() || !QwtPaintBuffer::isEnabled() )
    {
        // If we don´t need the paint buffer as cache we can
        // use the clip for painting to the buffer too. 

        if ( painter && !painter->clipRegion().isNull() )
            clipRect = painter->clipRegion().boundingRect();
    }

    QwtPaintBuffer paintBuffer(this, clipRect, painter);
    ((QwtPlot *)parent())->drawCanvas(paintBuffer.painter());

    if ( cacheMode() )
    {
        if ( d_cache == NULL )
        {
            d_cache = new QPixmap(contentsRect().size());
#if QT_VERSION >= 300
#ifdef Q_WS_X11
            if ( d_cache->x11Screen() != x11Screen() )
                d_cache->x11SetScreen(x11Screen());
#endif
#endif
        }
        else
            d_cache->resize(contentsRect().size());

        if ( QwtPaintBuffer::isEnabled() )
            *d_cache = paintBuffer.buffer();
        else
        {
            d_cache->fill(this, 0, 0);
            QPainter cachePainter(d_cache);
            cachePainter.translate(-contentsRect().x(),
                -contentsRect().y());
            ((QwtPlot *)parent())->drawCanvas(&cachePainter);
        }
    }
}
Ejemplo n.º 7
0
QPixmap StylePainterMobile::findRadio(const QSize& size, bool checked, bool enabled) const
{
    ASSERT(size.width() == size.height());
    QPixmap result;
    KeyIdentifier id;
    id.type = KeyIdentifier::Radio;
    id.height = size.height();
    id.trait1 = enabled;
    id.trait2 = checked;
    if (!findCachedControl(id, &result)) {
        result = QPixmap(size);
        result.fill(Qt::transparent);
        QPainter cachePainter(&result);
        drawRadio(&cachePainter, size, checked, enabled);
        insertIntoCache(id, result);
    }
    return result;
}
Ejemplo n.º 8
0
void StylePainterMobile::drawSliderThumb(const QRect & rect, bool pressed) const
{
    QPixmap result;
    const QSize size = sizeForPainterScale(rect);
    KeyIdentifier id;
    id.type = KeyIdentifier::SliderThumb;
    id.width = size.width();
    id.height = size.height();
    id.trait1 = pressed;
    if (!findCachedControl(id, &result)) {
        if (size.isNull())
            return;
        result = QPixmap(size);
        result.fill(Qt::transparent);
        QPainter cachePainter(&result);
        drawControlBackground(&cachePainter, borderPen(painter), QRect(QPoint(0, 0), size), pressed? Qt::lightGray : buttonGradientBottom);
        insertIntoCache(id, result);
    }
    painter->drawPixmap(rect, result);
}
Ejemplo n.º 9
0
QPixmap StylePainterMobile::findCheckBox(const QSize& size, bool checked, bool enabled) const
{
    ASSERT(size.width() == size.height());
    QPixmap result;
    KeyIdentifier id;
    id.type = KeyIdentifier::CheckBox;
    id.height = size.height();
    id.trait1 = enabled;
    id.trait2 = checked;
    if (!findCachedControl(id, &result)) {
        result = QPixmap(size);
        result.fill(Qt::transparent);
        QPainter cachePainter(&result);
        QRect rect(QPoint(0, 0), size);
        drawCheckableBackground(&cachePainter, rect, checked, enabled);
        if (checked || !enabled)
            drawChecker(&cachePainter, rect, enabled ? Qt::white : Qt::gray);
        insertIntoCache(id, result);
    }
    return result;
}
Ejemplo n.º 10
0
QPixmap StylePainterMobile::findPushButton(const QSize& size, bool sunken, bool enabled) const
{
    QPixmap result;
    KeyIdentifier id;
    id.type = KeyIdentifier::PushButton;
    id.width = size.width();
    id.height = size.height();
    id.trait1 = sunken;
    id.trait2 = enabled;
    if (!findCachedControl(id, &result)) {
        const qreal dropShadowSize = painterScale(painter);
        result = QPixmap(size);
        result.fill(Qt::transparent);
        const QRect rect = QRect(0, 0, size.width(), size.height() - dropShadowSize);
        QPainter cachePainter(&result);
        drawControlBackground(&cachePainter, Qt::NoPen, rect.adjusted(0, dropShadowSize, 0, dropShadowSize), shadowColor);

        QBrush brush;
        if (enabled && !sunken) {
            QLinearGradient linearGradient;
            linearGradient.setStart(rect.bottomLeft());
            linearGradient.setFinalStop(rect.topLeft());
            linearGradient.setColorAt(0.0, buttonGradientBottom);
            linearGradient.setColorAt(1.0, Qt::white);
            brush = linearGradient;
        } else if (!enabled)
            brush = QColor(241, 242, 243);
        else { // sunken
            QLinearGradient linearGradient;
            linearGradient.setStart(rect.bottomLeft());
            linearGradient.setFinalStop(rect.topLeft());
            linearGradient.setColorAt(0.0, highlightColor);
            linearGradient.setColorAt(1.0, highlightColor.lighter());
            brush = linearGradient;
        }
        drawControlBackground(&cachePainter, borderPen(painter), rect, brush);
        insertIntoCache(id, result);
    }
    return result;
}
Ejemplo n.º 11
0
static void qt_plastique_draw_gradient(QPainter *painter, const QRect &rect, const QColor &gradientStart,
                                       const QColor &gradientStop)
{
    QString gradientName;
    gradientName.sprintf("%dx%d-%x-%x", rect.width(), rect.height(), gradientStart.rgba(), gradientStop.rgba());
    QPixmap cache;
    if (!UsePixmapCache || !QPixmapCache::find(gradientName, cache)) {
        cache = QPixmap(rect.size());
        cache.fill(Qt::white);
        QPainter cachePainter(&cache);
        QRect pixmapRect(0, 0, rect.width(), rect.height());
        int x = pixmapRect.center().x();
        QLinearGradient gradient(x, pixmapRect.top(), x, pixmapRect.bottom());
        gradient.setColorAt(0, gradientStart);
        gradient.setColorAt(1, gradientStop);
        cachePainter.fillRect(pixmapRect, gradient);
        cachePainter.end();
        if (UsePixmapCache)
            QPixmapCache::insert(gradientName, cache);
    }
    painter->drawPixmap(rect, cache);
}
Ejemplo n.º 12
0
void AdvancedImageWidget::setImage(QSharedPointer<QImage> newImage)
{
    if (mIsFreezed)
        return;

    /*if (newImage.isNull())
        return;*/

    mImage = newImage;

    delete_safe(mResizeCache);

    if (mSaveProcStarted)
    {
        mResizeCache = new QImage(mOutputRect.size(), QImage::Format_RGB32);
        mResizeCache->fill(0);
        QPainter cachePainter(mResizeCache);
        drawResized(cachePainter);
        cachePainter.setPen(QColor(Qt::red));
        cachePainter.drawRect(mResizeCache->rect().adjusted(0,0,-1,-1));

        cachePainter.end();
        saveFlowImage(mResizeCache);
    }

    if ((!mImage.isNull() && mImageSize != mImage->size()) || (mZoomCenter == QPoint(-1,-1)))
    {
        if (mImage.isNull()) {
            mImageSize = QSize();
        } else {
            mImageSize = mImage->size();
        }
        recalculateZoomCenter();
    }
    recomputeRects();
    forceUpdate();
}
Ejemplo n.º 13
0
// Draws a cached pixmap with shadow
void StyleHelper::drawIconWithShadow(const QIcon &icon, const QRect &rect,
                                     QPainter *p, QIcon::Mode iconMode, int radius, const QColor &color, const QPoint &offset)
{
    QPixmap cache;
    QString pixmapName = QString("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height());

    if (!QPixmapCache::find(pixmapName, cache)) {
        QPixmap px = icon.pixmap(rect.size());
        cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
        cache.fill(Qt::transparent);

        QPainter cachePainter(&cache);
        if (iconMode == QIcon::Disabled) {
            QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32);
            for (int y=0; y<im.height(); ++y) {
                QRgb *scanLine = (QRgb*)im.scanLine(y);
                for (int x=0; x<im.width(); ++x) {
                    QRgb pixel = *scanLine;
                    char intensity = qGray(pixel);
                    *scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel));
                    ++scanLine;
                }
            }
            px = QPixmap::fromImage(im);
        }

        // Draw shadow
        QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1), QImage::Format_ARGB32_Premultiplied);
        tmp.fill(Qt::transparent);

        QPainter tmpPainter(&tmp);
        tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
        tmpPainter.drawPixmap(QPoint(radius, radius), px);
        tmpPainter.end();

        // blur the alpha channel
        QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
        blurred.fill(Qt::transparent);
        QPainter blurPainter(&blurred);
        qt_blurImage(&blurPainter, tmp, radius, false, true);
        blurPainter.end();

        tmp = blurred;

        // blacken the image...
        tmpPainter.begin(&tmp);
        tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
        tmpPainter.fillRect(tmp.rect(), color);
        tmpPainter.end();

        tmpPainter.begin(&tmp);
        tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
        tmpPainter.fillRect(tmp.rect(), color);
        tmpPainter.end();

        // draw the blurred drop shadow...
        cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp);

        // Draw the actual pixmap...
        cachePainter.drawPixmap(QPoint(radius, radius) + offset, px);
        QPixmapCache::insert(pixmapName, cache);
    }

    QRect targetRect = cache.rect();
    targetRect.moveCenter(rect.center());
    p->drawPixmap(targetRect.topLeft() - offset, cache);
}
Ejemplo n.º 14
0
// Draws a cached pixmap with shadow
void FancyTabBar::drawIconWithShadow(const QIcon &icon, const QRect &rect, QPainter *p, QIcon::Mode iconMode, int dipRadius, const QColor &color, const QPoint &dipOffset)
{
    QPixmap cache;
    QString pixmapName = QString::fromLatin1("icon %0 %1 %2").arg(icon.cacheKey()).arg(iconMode).arg(rect.height());

    if (!QPixmapCache::find(pixmapName, cache)) {
        // High-dpi support: The in parameters (rect, radius, offset) are in
        // device-independent pixels. The call to QIcon::pixmap() below might
        // return a high-dpi pixmap, which will in that case have a devicePixelRatio
        // different than 1. The shadow drawing caluculations are done in device
        // pixels.
        QPixmap px = icon.pixmap(rect.size());
        //jassuncao int devicePixelRatio = qCeil(px.devicePixelRatio());
        int devicePixelRatio = 1;
        int radius = dipRadius * devicePixelRatio;
        QPoint offset = dipOffset * devicePixelRatio;
        cache = QPixmap(px.size() + QSize(radius * 2, radius * 2));
        cache.fill(Qt::transparent);

        QPainter cachePainter(&cache);
        if (iconMode == QIcon::Disabled) {
            QImage im = px.toImage().convertToFormat(QImage::Format_ARGB32);
            for (int y=0; y<im.height(); ++y) {
                QRgb *scanLine = (QRgb*)im.scanLine(y);
                for (int x=0; x<im.width(); ++x) {
                    QRgb pixel = *scanLine;
                    char intensity = qGray(pixel);
                    *scanLine = qRgba(intensity, intensity, intensity, qAlpha(pixel));
                    ++scanLine;
                }
            }
            px = QPixmap::fromImage(im);
        }

        // Draw shadow
        QImage tmp(px.size() + QSize(radius * 2, radius * 2 + 1), QImage::Format_ARGB32_Premultiplied);
        tmp.fill(Qt::transparent);

        QPainter tmpPainter(&tmp);
        tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
        tmpPainter.drawPixmap(QRect(radius, radius, px.width(), px.height()), px);
        tmpPainter.end();

        // blur the alpha channel
        QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
        blurred.fill(Qt::transparent);
        QPainter blurPainter(&blurred);
        qt_blurImage(&blurPainter, tmp, radius, false, true);
        blurPainter.end();

        tmp = blurred;

        // blacken the image...
        tmpPainter.begin(&tmp);
        tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
        tmpPainter.fillRect(tmp.rect(), color);
        tmpPainter.end();

        tmpPainter.begin(&tmp);
        tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
        tmpPainter.fillRect(tmp.rect(), color);
        tmpPainter.end();

        // draw the blurred drop shadow...
        cachePainter.drawImage(QRect(0, 0, cache.rect().width(), cache.rect().height()), tmp);

        // Draw the actual pixmap...
        cachePainter.drawPixmap(QRect(QPoint(radius, radius) + offset, QSize(px.width(), px.height())), px);
        //jassuncao: cache.setDevicePixelRatio(devicePixelRatio);
        QPixmapCache::insert(pixmapName, cache);
    }

    QRect targetRect = cache.rect();
    //jassuncao targetRect.setSize(targetRect.size() / cache.devicePixelRatio());
    targetRect.moveCenter(rect.center() - dipOffset);
    p->drawPixmap(targetRect, cache);
}
Ejemplo n.º 15
0
/*!
  \brief Draw a set of points of a curve.

  When observing an measurement while it is running, new points have to be
  added to an existing curve. drawCurve can be used to display them avoiding
  a complete redraw of the canvas.

  Setting plot()->canvas()->setAttribute(Qt::WA_PaintOutsidePaintEvent, true);
  will result in faster painting, if the paint engine of the canvas widget
  supports this feature. 

  \param from Index of the first point to be painted
  \param to Index of the last point to be painted. If to < 0 the
         curve will be painted to its last point.

  \sa drawCurve(), drawSymbols()
*/
void QwtPlotCurve::draw(int from, int to) const
{
    if ( !plot() )
        return;

    QwtPlotCanvas *canvas = plot()->canvas();

#if QT_VERSION >= 0x040000
#if 0
    if ( canvas->paintEngine()->type() == QPaintEngine::OpenGL )
    {
        /*
            OpenGL alway repaint the complete widget.
            So for this operation OpenGL is one of the slowest
            environments.
         */
        canvas->repaint();
        return;
    }
#endif

    if ( !canvas->testAttribute(Qt::WA_WState_InPaintEvent) &&
        !canvas->testAttribute(Qt::WA_PaintOutsidePaintEvent) )
    {
        /*
          We save curve and range in helper and call repaint.
          The helper filters the Paint event, to repeat
          the QwtPlotCurve::draw, but now from inside the paint
          event.
         */

        QwtPlotCurvePaintHelper helper(this, from, to);
        canvas->installEventFilter(&helper);

        const bool noSystemBackground =
            canvas->testAttribute(Qt::WA_NoSystemBackground);
        canvas->setAttribute(Qt::WA_NoSystemBackground, true);
        canvas->repaint();
        canvas->setAttribute(Qt::WA_NoSystemBackground, noSystemBackground);

        return;
    }
#endif

    const QwtScaleMap xMap = plot()->canvasMap(xAxis());
    const QwtScaleMap yMap = plot()->canvasMap(yAxis());

    if ( canvas->testPaintAttribute(QwtPlotCanvas::PaintCached) &&
        canvas->paintCache() && !canvas->paintCache()->isNull() )
    {
        QPainter cachePainter((QPixmap *)canvas->paintCache());
        cachePainter.translate(-canvas->contentsRect().x(),
            -canvas->contentsRect().y());

        draw(&cachePainter, xMap, yMap, from, to);
    }

#if QT_VERSION >= 0x040000
    if ( canvas->testAttribute(Qt::WA_WState_InPaintEvent) )
    {
        QPainter painter(canvas);

        painter.setClipping(true);
        painter.setClipRect(canvas->contentsRect());

        draw(&painter, xMap, yMap, from, to);
    }
    else
#endif
    {
        QPainter *painter = d_data->guardedPainter.begin(canvas);
        draw(painter, xMap, yMap, from, to);
    }
}
Ejemplo n.º 16
0
void KisCurveWidget::paintEvent(QPaintEvent *)
{
    int    wWidth = width() - 1;
    int    wHeight = height() - 1;

    QPainter p(this);
    // Antialiasing is not a good idea here, because
    // the grid will drift one pixel to any side due to rounding of int
    // FIXME: let's user tell the last word (in config)
    //p.setRenderHint(QPainter::Antialiasing);

    // fill with color to show widget bounds
    p.fillRect(rect(), palette().base());

    //  draw background
    if (!d->m_pix.isNull()) {
        if (d->m_pixmapDirty || !d->m_pixmapCache) {
            delete d->m_pixmapCache;
            d->m_pixmapCache = new QPixmap(width(), height());
            QPainter cachePainter(d->m_pixmapCache);

            cachePainter.scale(1.0*width() / d->m_pix.width(), 1.0*height() / d->m_pix.height());
            cachePainter.drawPixmap(0, 0, d->m_pix);
            d->m_pixmapDirty = false;
        }
        p.drawPixmap(0, 0, *d->m_pixmapCache);
    }

    d->drawGrid(p, wWidth, wHeight);


    p.setRenderHint(QPainter::Antialiasing);

    // Draw default line
    p.setPen(QPen(palette().mid().color(), 1, Qt::SolidLine));
    p.drawLine(QLineF(0, wHeight, wWidth, 0));

    // Draw curve.
    int x;
    QPolygonF poly;

    p.setPen(QPen(palette().text().color(), 1, Qt::SolidLine));
    for (x = 0 ; x < wWidth ; ++x) {
        double normalizedX = double(x) / wWidth;
        double curY = wHeight - d->m_curve.value(normalizedX) * wHeight;
        poly.append(QPointF(x, curY));
    }
    poly.append(QPointF(x, wHeight - d->m_curve.value(1.0) * wHeight));
    p.drawPolyline(poly);

    // Drawing curve handles.
    if (!d->m_readOnlyMode) {
        for (int i = 0; i < d->m_curve.points().count(); ++i) {
            double curveX = d->m_curve.points().at(i).x();
            double curveY = d->m_curve.points().at(i).y();

            if (i == d->m_grab_point_index) {
                p.setPen(QPen(Qt::red, 3, Qt::SolidLine));
                p.drawEllipse(QRectF(curveX * wWidth - 2,
                                     wHeight - 2 - curveY * wHeight, 4, 4));
            } else {
                p.setPen(QPen(Qt::red, 1, Qt::SolidLine));
                p.drawEllipse(QRectF(curveX * wWidth - 3,
                                     wHeight - 3 - curveY * wHeight, 6, 6));
            }
        }
    }
}
Ejemplo n.º 17
0
void KisCurveWidget::paintEvent(QPaintEvent *)
{
    int    wWidth = width() - 1;
    int    wHeight = height() - 1;

    QPainter p(this);

    // Antialiasing is not a good idea here, because
    // the grid will drift one pixel to any side due to rounding of int
    // FIXME: let's user tell the last word (in config)
    //p.setRenderHint(QPainter::Antialiasing);


    //  draw background
    if (!d->m_pix.isNull()) {
        if (d->m_pixmapDirty || !d->m_pixmapCache) {
            delete d->m_pixmapCache;
            d->m_pixmapCache = new QPixmap(width(), height());
            QPainter cachePainter(d->m_pixmapCache);

            cachePainter.scale(1.0*width() / d->m_pix.width(), 1.0*height() / d->m_pix.height());
            cachePainter.drawPixmap(0, 0, d->m_pix);
            d->m_pixmapDirty = false;
        }
        p.drawPixmap(0, 0, *d->m_pixmapCache);
    } else
        p.fillRect(rect(), palette().background());


    d->drawGrid(p, wWidth, wHeight);

    KisConfig cfg;
    if (cfg.antialiasCurves())
        p.setRenderHint(QPainter::Antialiasing);

    // Draw curve.
    double curY;
    double normalizedX;
    int x;

    QPolygonF poly;

    p.setPen(QPen(Qt::black, 1, Qt::SolidLine));
    for (x = 0 ; x < wWidth ; x++) {
        normalizedX = double(x) / wWidth;
        curY = wHeight - d->m_curve.value(normalizedX) * wHeight;

        /**
         * Keep in mind that QLineF rounds doubles
         * to ints mathematically, not just rounds down
         * like in C
         */
        poly.append(QPointF(x, curY));
    }
    poly.append(QPointF(x, wHeight - d->m_curve.value(1.0) * wHeight));
    p.drawPolyline(poly);

    // Drawing curve handles.
    double curveX;
    double curveY;
    if (!d->m_readOnlyMode) {
        for (int i = 0; i < d->m_curve.points().count(); ++i) {
            curveX = d->m_curve.points().at(i).x();
            curveY = d->m_curve.points().at(i).y();

            if (i == d->m_grab_point_index) {
                p.setPen(QPen(Qt::red, 3, Qt::SolidLine));
                p.drawEllipse(QRectF(curveX * wWidth - 2,
                                     wHeight - 2 - curveY * wHeight, 4, 4));
            } else {
                p.setPen(QPen(Qt::red, 1, Qt::SolidLine));
                p.drawEllipse(QRectF(curveX * wWidth - 3,
                                     wHeight - 3 - curveY * wHeight, 6, 6));
            }
        }
    }
}
Ejemplo n.º 18
0
void EqCurve::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
{
    painter->setRenderHint( QPainter::Antialiasing, true );
    if( m_modelChanged )
    {
        setModelChanged( false );
        //counts the active bands
        int activeHandles=0;
        for ( int thatHandle = 0; thatHandle<m_handle->count(); thatHandle++ )
        {
            if ( m_handle->at(thatHandle)->isActiveHandle() == true )
            {
                activeHandles++;
            }
        }
        //Computes the main curve
        //if a band is active the curve will be computed by averaging the curves of each band
        QMap<float,float> mainCurve;
        for ( int thatHandle = 0; thatHandle<m_handle->count(); thatHandle++ )
        {
            if ( m_handle->at(thatHandle)->isActiveHandle() == true )
            {
                for ( int x = 0; x < m_width ; x=x+1 )
                {
                    if ( m_handle->at( thatHandle )->getType() == highpass )
                    {
                        mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getLowCutCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) );
                    }
                    if ( m_handle->at(thatHandle)->getType() == lowshelf )
                    {
                        mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getLowShelfCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) );
                    }
                    if ( m_handle->at( thatHandle )->getType() == para )
                    {
                        mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getPeakCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) );
                    }
                    if ( m_handle->at( thatHandle )->getType() == highshelf )
                    {
                        mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getHighShelfCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) );
                    }
                    if ( m_handle->at(thatHandle)->getType() == lowpass )
                    {
                        mainCurve[x]= ( mainCurve[x] + ( m_handle->at( thatHandle )->getHighCutCurve( x ) * ( activeHandles ) ) - ( ( activeHandles * ( m_heigth/2 ) ) - m_heigth ) );
                    }
                }
            }
        }
        //compute a QPainterPath
        m_curve = QPainterPath();
        for ( int x = 0; x < m_width ; x++ )
        {
            mainCurve[x] = ( ( mainCurve[x] / activeHandles ) ) - ( m_heigth/2 );
            if ( x==0 )
            {
                m_curve.moveTo( x, mainCurve[x] );
            }
            m_curve.lineTo( x, mainCurve[x] );
        }
        //we cache the curve painting in a pixmap for saving cpu
        QPixmap cacheMap( boundingRect().size().toSize() );
        cacheMap.fill( QColor( 0, 0, 0, 0 ) );
        QPainter cachePainter( &cacheMap );
        cachePainter.setRenderHint( QPainter::Antialiasing, true );
        QPen pen;
        pen.setWidth( 2 );
        pen.setColor( Qt::white );
        cachePainter.setPen( pen );
        cachePainter.drawPath( m_curve );
        cachePainter.end();

        m_curvePixmapCache.fill( QColor( 0, 0, 0, 0 ) );
        m_curvePixmapCache.swap( cacheMap );
    }
    //we paint our cached curve pixmap
    painter->drawPixmap( 0, 0, m_width, m_heigth, m_curvePixmapCache );
    // if mouse hover a handle, m_alpha counts up slow for blend in the filled EQ curve
    // todo: a smarter way of this "if-monster"
    QColor curveColor;
    if( m_handle->at( 0 )->isMouseHover()
            || m_handle->at( 1 )->isMouseHover()
            || m_handle->at( 2 )->isMouseHover()
            || m_handle->at( 3 )->isMouseHover()
            || m_handle->at( 4 )->isMouseHover()
            || m_handle->at( 5 )->isMouseHover()
            || m_handle->at( 6 )->isMouseHover()
            || m_handle->at( 7 )->isMouseHover()
      )
    {
        if ( m_alpha < 40 )
        {
            m_alpha = m_alpha + 10;
        }
    }
    else
    {
        if ( m_alpha > 0 )
        {
            m_alpha = m_alpha - 10;
        }
    }
    //draw on mouse hover the curve of hovered filter in different colors
    for ( int i = 0; i < m_handle->count(); i++ )
    {
        if ( m_handle->at(i)->isMouseHover() )
        {
            switch ( i+1 )
            {
            case 1:
                curveColor = QColor( 163, 23, 23, 10*m_alpha/4 );
                break;
            case 2:
                curveColor = QColor( 229,108,0, 10*m_alpha/4 );
                break;
            case 3:
                curveColor = QColor( 255,240,0, 10*m_alpha/4 );
                break;
            case 4:
                curveColor = QColor( 12, 255, 0, 10*m_alpha/4 );
                break;
            case 5:
                curveColor = QColor( 0, 252, 255, 10*m_alpha/4 );
                break;
            case 6:
                curveColor = QColor( 59, 96, 235, 10*m_alpha/4 );
                break;
            case 7:
                curveColor = QColor( 112, 73, 255, 10*m_alpha/4 );
                break;
            case 8:
                curveColor = QColor( 255, 71, 227, 10*m_alpha/4 );
            }
            QPen pen ( curveColor);
            pen.setWidth( 2 );
            painter->setPen( pen );
            painter->drawPath( m_handle->at( i )->getCurvePath() );
        }
    }
    //draw on mouse hover the EQ curve filled. with m_alpha it blends in and out smooth
    QPainterPath cPath;
    cPath.addPath( m_curve );
    cPath.lineTo( cPath.currentPosition().x(), m_heigth );
    cPath.lineTo( cPath.elementAt( 0 ).x  , m_heigth );
    painter->fillPath( cPath, QBrush ( QColor( 255,255,255, m_alpha ) ) );
}