Exemplo n.º 1
0
/*!
    \reimp
*/
void QGraphicsColorizeEffect::draw(QPainter *painter)
{
    Q_D(QGraphicsColorizeEffect);

    if (!d->opaque) {
        drawSource(painter);
        return;
    }

    QPoint offset;
    if (sourceIsPixmap()) {
        // No point in drawing in device coordinates (pixmap will be scaled anyways).
        const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset, NoPad);
        if (!pixmap.isNull())
            d->filter->draw(painter, offset, pixmap);

        return;
    }

    // Draw pixmap in deviceCoordinates to avoid pixmap scaling.
    const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset);
    if (pixmap.isNull())
        return;

    QTransform restoreTransform = painter->worldTransform();
    painter->setWorldTransform(QTransform());
    d->filter->draw(painter, offset, pixmap);
    painter->setWorldTransform(restoreTransform);
}
Exemplo n.º 2
0
    void draw(QPainter *painter)
    {
        QVERIFY(sourcePixmap(Qt::LogicalCoordinates).pixmapData() == pixmap.pixmapData());
        QVERIFY((painter->worldTransform().type() <= QTransform::TxTranslate) == (sourcePixmap(Qt::DeviceCoordinates).pixmapData() == pixmap.pixmapData()));

        ++repaints;
    }
Exemplo n.º 3
0
void QgsComposerEffect::draw( QPainter *painter )
{
  QPoint offset;
  QPixmap pixmap;

  // Set desired composition mode then draw source
  painter->setCompositionMode( mCompositionMode );

  if ( mCompositionMode == QPainter::CompositionMode_SourceOver )
  {
    // Normal (sourceover) blending, do faster drawSource operation
    drawSource( painter );
    return;
  }

  // Otherwise, draw using pixmap so QPrinter output works as expected
  if ( sourceIsPixmap() )
  {
    // No point in drawing in device coordinates (pixmap will be scaled anyways).
    pixmap = sourcePixmap( Qt::LogicalCoordinates, &offset );
  }
  else
  {
    // Draw pixmap in device coordinates to avoid pixmap scaling;
    pixmap = sourcePixmap( Qt::DeviceCoordinates, &offset );
    painter->setWorldTransform( QTransform() );
  }

  painter->drawPixmap( offset, pixmap );

}
Exemplo n.º 4
0
void GraphicDeadEffect::draw(QPainter *painter)
{
    QPoint offset;
    // Draw pixmap in device coordinates to avoid pixmap scaling;
    const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset);

    if(_pix_size_x == 0) {
    // Initialisation
        _pix_size_x = pixmap.size().width();
        _pix_size_y = pixmap.size().height();
        _pixels_cleared = new bool*[_pix_size_x];
        for(int i = 0 ; i < _pix_size_x ; ++ i) {
            _pixels_cleared[i] = new bool(_pix_size_y);
        }
        _timer.start(UPDATE_PERIOD);
        // Connect animation timer
        connect(&_timer, SIGNAL(timeout()), this, SLOT(updateAnimation()));
    }

    QImage img = pixmap.toImage();
    painter->setWorldTransform(QTransform());

    for(int i = 0 ; i < _pix_size_x ; i ++) {
        for(int j = 0 ; j < _pix_size_y ; j ++) {
            if(_pixels_cleared[i][j]) {
                img.setPixel(i, j, qRgb(0, 0, 0));
            }
        }
    }
    painter->drawImage(offset, img);
}
Exemplo n.º 5
0
void ShadowEffect::draw(QPainter *painter)
{
    if (m_blurRadius < 0 && qFuzzyIsNull(m_xOffset) && qFuzzyIsNull(m_yOffset)) {
        drawSource(painter);
        return;
    }

    PixmapPadMode mode = PadToEffectiveBoundingRect;
    if (painter->paintEngine()->type() == QPaintEngine::OpenGL2) {
        mode = NoPad;
    }

    // Draw pixmap in device coordinates to avoid pixmap scaling.
    QPoint offset;
    const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, mode);
    if (pixmap.isNull()) {
        return;
    }

    QTransform restoreTransform = painter->worldTransform();
    painter->setWorldTransform(QTransform());
    if (m_shadow.isNull()) {
        m_shadow = generateShadow(pixmap);
    }
    // Draw shadow (draw it twice to darken it)
    painter->drawImage(offset, m_shadow);
    painter->drawImage(offset, m_shadow);
    // Draw the actual pixmap
    painter->drawPixmap(offset, pixmap);
    painter->setWorldTransform(restoreTransform);
}
void MGraphicsClipEffect::draw(QPainter *painter)
{
    Q_D(MGraphicsClipEffect);

    QPoint offset;
    QPixmap pixmap;

    pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset);

    QPoint topPosition = QPoint(offset.x(), offset.y() + d->drawRectangle.y());
    QPoint bottomPosition = QPoint(offset.x(), offset.y() + d->drawRectangle.y() + d->drawRectangle.height());
    QPoint topPartPosition = QPoint(topPosition.x(), topPosition.y() - d->margin);

    if (d->drawRectangle.height() > pixmap.rect().height() - d->margin * 2) {
        topPartPosition.setY(offset.y());
        bottomPosition.setY(offset.y() + pixmap.rect().height() - d->margin);
    }

    painter->drawPixmap(topPosition, pixmap,
                        QRect(d->drawRectangle.x(),  d->drawRectangle.y(), d->drawRectangle.size().width(),  d->drawRectangle.height()));
    painter->drawPixmap(topPartPosition, pixmap,
                        QRect(0, 0, d->drawRectangle.size().width(), d->margin));
    painter->drawPixmap(QPoint(bottomPosition.x(), bottomPosition.y()), pixmap,
                        QRect(0, pixmap.rect().height() - d->margin, d->drawRectangle.size().width(), d->margin));
}
Exemplo n.º 7
0
/** @details
 * Ze zadaneho korenoveho elementu <em>box</em> vytvori prototyp bedny
 * reprezentovane timto elementem. Pokud se pri zpracovani dokumentu
 * vyskytne chyba, zobrazi chybove hlaseni.
 * Zda jde o element se spravnym nazvem se j*z nezkouma, proto
 * by melo byt vzdy drive otestovano pomoci @c canHandle().
 * Predpoklada j*z nacteny zdrojovy obrazek v @c ResourceHandler.
 * @param rootEl korenovy element reprezentujici nacitanou bednu
 * @return Nove vytvoreny prototyp bedny (volajici se stava vlastnikem).
 * @retval 0 Doslo k chybe, bedna nemuze byt vytvoren.
 */
BombicMapObject * BoxResourceHandler::createMapObject(
		const QDomElement & rootEl) {
	QDomElement imgEl;
	if(getSubElement(rootEl, imgEl)) {
		// get attributes
		int x = 0;
		int y = 0;
		int w = 1;
		int h = 1;
		int t = 0; // toplapping
		bool success =
			getAttrsXY(imgEl, x, y) &&
			getIntAttr(imgEl, w, "width", true) &&
			getIntAttr(imgEl, h, "height", true) &&
			getIntAttr(imgEl, t, "toplapping", true);
		if(!success) {
			return 0;
		}
		// get pixmap
		QPixmap pixmap = sourcePixmap().copy(
			x, y, w*CELL_SIZE, (h+t)*CELL_SIZE);

		return new BombicBox(
			rootEl.attribute("name"), pixmap, w, h, t);
	} else {
		return 0;
	}
}
Exemplo n.º 8
0
//virtual
void GfxSepiaEffect::draw ( QPainter * painter )
{
	QPoint offset;
	if (!m_p_pix)
	{
		m_p_pix = new QPixmap(sourcePixmap(Qt::LogicalCoordinates, &m_offset));
		sepiaTone(m_p_pix);
	}
	painter->drawPixmap(m_offset, *m_p_pix);
}
//! [1]
MyGraphicsEffect::draw(QPainter *painter)
{
    ...
    QPoint offset;
    if (sourceIsPixmap()) {
        // No point in drawing in device coordinates (pixmap will be scaled anyways).
        const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset);
        ...
        painter->drawPixmap(offset, pixmap);
    } else {
Exemplo n.º 10
0
void Shadow::draw(QPainter* painter)
{
    // if nothing to show outside the item, just draw source
    if ((blurRadius() + distance()) <= 0) {
        drawSource(painter);
        return;
    }

    PixmapPadMode mode = QGraphicsEffect::PadToEffectiveBoundingRect;
    QPoint offset;
    const QPixmap px = sourcePixmap(Qt::DeviceCoordinates, &offset, mode);

    // return if no source
    if (px.isNull())
        return;

    // save world transform
    QTransform restoreTransform = painter->worldTransform();
    painter->setWorldTransform(QTransform());

    // Calculate size for the background image
    QSize szi(px.size().width() + 2 * distance(), px.size().height() + 2 * distance());

    QImage tmp(szi, QImage::Format_ARGB32_Premultiplied);
    QPixmap scaled = px.scaled(szi);
    tmp.fill(0);
    QPainter tmpPainter(&tmp);
    tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
    tmpPainter.drawPixmap(QPointF(-distance(), -distance()), scaled);
    tmpPainter.end();

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

    tmp = blurred;

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

    // draw the blurred shadow...
    painter->drawImage(offset, tmp);

    // draw the actual pixmap...
    painter->drawPixmap(offset, px, QRectF());

    // restore world transform
    painter->setWorldTransform(restoreTransform);
}
Exemplo n.º 11
0
    void draw(QPainter *painter)
    {
        QPoint offset;
        QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, QGraphicsEffect::NoPad);

        if (pixmap.isNull())
            return;

        painter->save();
        painter->setWorldTransform(QTransform());
        painter->drawPixmap(offset, pixmap);
        painter->restore();
    }
Exemplo n.º 12
0
/*!
    \reimp
*/
void QGraphicsBlurEffect::draw(QPainter *painter)
{
    Q_D(QGraphicsBlurEffect);
    if (d->filter->radius() < 1) {
        drawSource(painter);
        return;
    }

    PixmapPadMode mode = PadToEffectiveBoundingRect;

    QPoint offset;
    QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset, mode);
    if (pixmap.isNull())
        return;

    d->filter->draw(painter, offset, pixmap);
}
Exemplo n.º 13
0
QT_END_NAMESPACE

void ShadowEffect::draw(QPainter* painter){
    if((blurRadius() + distance()) <= 0){
        drawSource(painter);
        return;
    }

    PixmapPadMode mode = QGraphicsEffect::PadToEffectiveBoundingRect;
    QPoint offset;
    const QPixmap px = sourcePixmap(Qt::DeviceCoordinates, &offset, mode);

    if(px.isNull())
        return;

    QTransform restoreTransform = painter->worldTransform();
    painter->setWorldTransform(QTransform());

    QSize szi(px.size().width() + 2 * distance(), px.size().height() + 2 * distance());

    QImage tmp(szi, QImage::Format_ARGB32_Premultiplied);
    QPixmap scaled = px.scaled(szi);
    tmp.fill(0);
    QPainter tmpPainter(&tmp);
    tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
    tmpPainter.drawPixmap(QPointF(-distance(), -distance()), scaled);
    tmpPainter.end();

    QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied);
    blurred.fill(0);
    QPainter blurPainter(&blurred);
    qt_blurImage(&blurPainter, tmp, blurRadius(), false, true);
    blurPainter.end();

    tmp = blurred;

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

    painter->drawImage(offset, tmp);
    painter->drawPixmap(offset, px, QRectF());
    painter->setWorldTransform(restoreTransform);
}
void MirrorGraphicsEffect::draw(QPainter *painter)
{
	PixmapPadMode mode = PadToEffectiveBoundingRect;

	// Draw pixmap in device coordinates to avoid pixmap scaling.
	QPoint offset;
	const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, mode);
	if (pixmap.isNull())
		return;

	QTransform restoreTransform = painter->worldTransform();
	painter->setWorldTransform(QTransform());

	// We'll draw widget on this image
	QImage tmp(pixmap.size(), QImage::Format_ARGB32_Premultiplied);
	tmp.fill(Qt::transparent);
	// We're going to draw widget on tmp image using this painter object
	QPainter tmpPainter(&tmp);
	tmpPainter.setCompositionMode(QPainter::CompositionMode_Source);
	tmpPainter.drawPixmap(QPoint(0,0), pixmap);
	tmpPainter.end(); 

	// Now we need to mirror image and put alpha channel gradient on our image of control
	// First mirror it by Y axis
	QImage mirroredImage(tmp.mirrored(false, true));
	// Create gradient object
	QPoint p1, p2;
	p2.setY(mirroredImage.height());
	QLinearGradient gradient(p1, p2);
	gradient.setColorAt(0.3, QColor(0, 0, 0, 255));
	gradient.setColorAt(0.8, QColor(0, 0, 0, 0));

	// With this painter we'll draw gradient on mirror image
	QPainter mirroredImagePainter(&mirroredImage);
	mirroredImagePainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
	mirroredImagePainter.fillRect(0, 0, mirroredImage.width(), mirroredImage.height(), gradient);
	mirroredImagePainter.end();

	// Draw reflection first
	painter->drawImage(offset, mirroredImage);
	// Draw source widget
	painter->drawPixmap(offset, pixmap);
	painter->setWorldTransform(restoreTransform);
}
Exemplo n.º 15
0
/*!
    \reimp
*/
void QGraphicsOpacityEffect::draw(QPainter *painter)
{
    Q_D(QGraphicsOpacityEffect);

    // Transparent; nothing to draw.
    if (d->isFullyTransparent)
        return;

    // Opaque; draw directly without going through a pixmap.
    if (d->isFullyOpaque && !d->hasOpacityMask) {
        drawSource(painter);
        return;
    }

    QPoint offset;
    Qt::CoordinateSystem system = sourceIsPixmap() ? Qt::LogicalCoordinates : Qt::DeviceCoordinates;
    QPixmap pixmap = sourcePixmap(system, &offset, QGraphicsEffect::NoPad);
    if (pixmap.isNull())
        return;

    painter->save();
    painter->setOpacity(d->opacity);

    if (d->hasOpacityMask) {
        QPainter pixmapPainter(&pixmap);
        pixmapPainter.setRenderHints(painter->renderHints());
        pixmapPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
        if (system == Qt::DeviceCoordinates) {
            QTransform worldTransform = painter->worldTransform();
            worldTransform *= QTransform::fromTranslate(-offset.x(), -offset.y());
            pixmapPainter.setWorldTransform(worldTransform);
            pixmapPainter.fillRect(sourceBoundingRect(), d->opacityMask);
        } else {
            pixmapPainter.translate(-offset);
            pixmapPainter.fillRect(pixmap.rect(), d->opacityMask);
        }
    }

    if (system == Qt::DeviceCoordinates)
        painter->setWorldTransform(QTransform());

    painter->drawPixmap(offset, pixmap);
    painter->restore();
}
Exemplo n.º 16
0
void QGraphicsGlowEffect::draw(QPainter* painter) {
  QPoint offset;
  QPixmap source = sourcePixmap(Qt::LogicalCoordinates, &offset);
  source = source.scaled(source.size().width()/source.devicePixelRatio(), source.size().height()/source.devicePixelRatio());
  QPixmap glow;

  QGraphicsColorizeEffect *colorize = new QGraphicsColorizeEffect;
  colorize->setColor(_color);
  colorize->setStrength(1);
  glow = applyEffectToPixmap(source, colorize, 0);

  QGraphicsBlurEffect *blur = new QGraphicsBlurEffect;
  blur->setBlurRadius(_blurRadius);
  glow = applyEffectToPixmap(glow, blur, _extent);

  for (int i = 0; i < _strength; i++)
    painter->drawPixmap(offset - QPoint(_extent, _extent), glow);
  drawSource(painter);
}
Exemplo n.º 17
0
/** @details
 * Ze zadaneho korenoveho elementu <em>bonus</em> vytvori prototyp bonusu
 * reprezentovaneho timto elementem. Pokud se pri zpracovani dokumentu
 * vyskytne chyba, zobrazi chybove hlaseni.
 * Zda jde o element se spravnym nazvem se j*z nezkouma, proto
 * by melo byt vzdy drive otestovano pomoci @c canHandle().
 * Predpoklada j*z nacteny zdrojovy obrazek v @c ResourceHandler.
 * @param rootEl korenovy element reprezentujici nacitany bonus
 * @return Nove vytvoreny prototyp bonusu (volajici se stava vlastnikem).
 * @retval 0 Doslo k chybe, bonus nemuze byt vytvoren.
 */
BombicMapObject * BonusResourceHandler::createMapObject(
		const QDomElement & rootEl) {
	QDomElement imgEl;
	if(getSubElement(rootEl, imgEl)) {
		// get attributes
		int x = 0;
		int y = 0;
		if(!getAttrsXY(imgEl, x, y)) {
			return 0;
		}
		// get pixmap
		QPixmap pixmap = sourcePixmap().copy(
			x, y, CELL_SIZE, CELL_SIZE);

		return new BombicBonus(
			rootEl.attribute("name"), pixmap);
	} else {
		return 0;
	}
}
Exemplo n.º 18
0
void FadeOutEffect::draw(QPainter* painter)
{
    QPixmap sourceItem = sourcePixmap(Qt::LogicalCoordinates);

    QPixmap pixmap(sourceItem.size());
    pixmap.fill(Qt::transparent);

    QLinearGradient gradient(0, qMax(0, pixmap.size().height() - m_covered - 8),
        0, pixmap.size().height() - m_covered);
    gradient.setColorAt(0, "black");
    gradient.setColorAt(1, Qt::transparent);

    QPainter itemPainter(&pixmap);
    itemPainter.drawPixmap(0, 0, sourceItem);
    itemPainter.setBrush(QBrush(gradient));
    itemPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
    itemPainter.drawRect(QRect(0, 0, pixmap.size().width(), pixmap.size().height()));

    painter->drawPixmap(0, 0, pixmap);
}
Exemplo n.º 19
0
/*!
    \reimp
*/
void QGraphicsDropShadowEffect::draw(QPainter *painter)
{
    Q_D(QGraphicsDropShadowEffect);
    if (d->filter->blurRadius() <= 0 && d->filter->offset().isNull()) {
        drawSource(painter);
        return;
    }

    PixmapPadMode mode = PadToEffectiveBoundingRect;

    // Draw pixmap in device coordinates to avoid pixmap scaling.
    QPoint offset;
    const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, mode);
    if (pixmap.isNull())
        return;

    QTransform restoreTransform = painter->worldTransform();
    painter->setWorldTransform(QTransform());
    d->filter->draw(painter, offset, pixmap);
    painter->setWorldTransform(restoreTransform);
}
Exemplo n.º 20
0
void QuickMaskEffect::draw(QPainter *painter)
{
    if (!m_mask) {
        drawSource(painter);
        return;
    }
    QPoint offset;
    const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset, QGraphicsEffect::NoPad);
    if (pixmap.size() != m_buffer.size())
        m_buffer = pixmap;
    
    QPainter p(&m_buffer);
    
    p.setCompositionMode(QPainter::CompositionMode_Source);
    p.fillRect(0, 0, m_buffer.width(), m_buffer.height(), Qt::transparent);
    m_mask->paint(&p, 0, 0);
    
    p.setCompositionMode(QPainter::CompositionMode_SourceOut);
    p.drawPixmap(0, 0, pixmap);
    
    painter->drawPixmap(offset, m_buffer);
}
Exemplo n.º 21
0
void CWizShadowEffect::draw(QPainter *painter)
{
    PixmapPadMode mode = PadToEffectiveBoundingRect;
    if (painter->paintEngine()->type() == QPaintEngine::OpenGL2)
        mode = NoPad;

    // Draw pixmap in device coordinates to avoid pixmap scaling.
    QPoint offset(0, 0);
    const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset, mode);
    if (pixmap.isNull())
        return;
    //
    QTransform restoreTransform = painter->worldTransform();
    painter->setWorldTransform(QTransform());
    painter->setBrush(QBrush(Qt::NoBrush));
    QSize sz = pixmap.size();
    painter->drawPixmap(offset.x(), offset.y(), pixmap);
    //
    QRect rcBound(offset.x() - 1, offset.y() - 1, sz.width() + 1, sz.height() + 1);
    m_shadow->DrawBorder(painter, rcBound);
    //
    painter->setWorldTransform(restoreTransform);

}
}
//! [0]

//! [1]
MyGraphicsEffect::draw(QPainter *painter)
{
    ...
    QPoint offset;
    if (sourceIsPixmap()) {
        // No point in drawing in device coordinates (pixmap will be scaled anyways).
        const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset);
        ...
        painter->drawPixmap(offset, pixmap);
    } else {
        // Draw pixmap in device coordinates to avoid pixmap scaling;
        const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset);
        painter->setWorldTransform(QTransform());
        ...
        painter->drawPixmap(offset, pixmap);
    }
    ...
}
//! [1]

//! [2]
...
QLinearGradient alphaGradient(rect.topLeft(), rect.bottomLeft());
alphaGradient.setColorAt(0.0, Qt::transparent);
alphaGradient.setColorAt(0.5, Qt::black);
alphaGradient.setColorAt(1.0, Qt::transparent);
QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect;