示例#1
0
void IconsWidget::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    if (crashed) {
        painter.setPen(QPen(Qt::red));
        painter.drawText(rect(), Qt::AlignCenter|Qt::TextWordWrap, errText);
        return;
    }

    if (compareView) {
        renderSvg(inpath,  &painter, QRect(0,   0, 100, 100));
        renderSvg(outpath, &painter, QRect(105, 0, 100, 100));
    } else {
        renderSvg(outpath, &painter, QRect(0, 0, width(), height()));
    }
}
示例#2
0
void
SvgWindow::updateSvgContext ()
{
    if (context)
    {
	finiTexture (context->texture[0]);
	finiTexture (context->texture[1]);
    }
    else
    {
	context = new SvgContext;

	if (!context)
	    return;
    }

    int      x1, y1, x2, y2;
    CompSize wSize;

    initTexture (source, context->texture[1], context->size);

    context->source = source;

    wSize.setWidth (window->geometry ().width ());
    wSize.setHeight (window->geometry ().height ());

    decor_apply_gravity (source->p1.gravity,
			 source->p1.x, source->p1.y,
			 wSize.width (), wSize.height (),
			 &x1, &y1);

    decor_apply_gravity (source->p2.gravity,
			 source->p2.x, source->p2.y,
			 wSize.width (), wSize.height (),
			 &x2, &y2);

    x1 = MAX (x1, 0);
    y1 = MAX (y1, 0);
    x2 = MIN (x2, wSize.width ());
    y2 = MIN (y2, wSize.height ());

    if (!initTexture (source, context->texture[0], wSize))
    {
	delete context;
	context = NULL;
    }
    else
    {
	renderSvg (source, context->texture[0], wSize, 0.0f, 0.0f, 1.0f, 1.0f);

	initTexture (source, context->texture[1], CompSize ());

	context->box += CompRect (x1, y1, x2 - x1, y2 - y1);
	context->box.translate (window->geometry ().x (), window->geometry ().y ());

	updateSvgMatrix ();
    }
}
示例#3
0
void SvgHandler::paintCustomSlider( QPainter *p, int x, int y, int width, int height, qreal percentage, bool active )
{
    int knobSize = height - 4;
    int sliderRange = width - ( knobSize + 4 );
    int knobRelPos = x + sliderRange * percentage + 2;
    int knobY = y + ( height - knobSize ) / 2 + 1;

    int sliderY = y + ( height / 2 ) - 1;


    //first draw the played part
    p->drawPixmap( x, sliderY,
                   renderSvg(
                   "new_slider_top_played",
                   width, 2,
                   "new_slider_top_played" ),
                   0, 0, knobRelPos - x, 2 );

    //and then the unplayed part
    p->drawPixmap( knobRelPos + 1, sliderY,
                   renderSvg(
                   "new_slider_top",
                   width, 2,
                   "new_slider_top" ),
                   knobRelPos + 1 - x, 0, -1, 2 );

    //and then the bottom
    p->drawPixmap( x, sliderY + 2,
                   renderSvg(
                   "new_slider_bottom",
                   width, 2,
                   "new_slider_bottom" ) );

    //draw end markers
    p->drawPixmap( x, y,
                   renderSvg(
                   "new_slider_end",
                   2, height,
                   "new_slider_end" ) );

    p->drawPixmap( x + width - 2, y,
                   renderSvg(
                   "new_slider_end",
                   2, height,
                   "new_slider_endr" ) );


    if ( active )
        p->drawPixmap( knobRelPos, knobY,
                       renderSvg(
                       "new_slider_knob_active",
                       knobSize, knobSize,
                       "new_slider_knob_active" ) );
    else
        p->drawPixmap( knobRelPos, knobY,
                       renderSvg(
                       "new_slider_knob",
                       knobSize, knobSize,
                       "new_slider_knob" ) );
}
示例#4
0
void IconsWidget::makeToolTip()
{
    QImage image(620, 310, QImage::Format_ARGB32);
    image.fill(0);
    mainPix = QPixmap::fromImage(image, Qt::NoOpaqueDetection | Qt::AutoColor);
    QPainter painter(&mainPix);
    QPalette pal;
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setRenderHint(QPainter::SmoothPixmapTransform);
    painter.setBrush(QBrush(pal.color(QPalette::Background)));
    painter.setPen(QPen(QColor("#636363"), 2));
    painter.drawRoundedRect(2, 2, image.width()-4, image.height()-4, 5, 5);

    renderSvg(inpath,  &painter, QRect(5,   5, 300, 300));
    renderSvg(outpath, &painter, QRect(310, 5, 300, 300));

    toolTip->setPixmap(mainPix);
    toolTip->setMask(mainPix.mask());
    newToolTip = false;
}
示例#5
0
bool ImageView::exportSvg(const ExportData &ed)
{
    const bool result = renderSvg(ed.size).save(ed.fileName);
    if (result) {
        const QString message = tr("Exported \"%1\", %2x%3, %4 bytes")
            .arg(QDir::toNativeSeparators(ed.fileName))
            .arg(ed.size.width()).arg(ed.size.height())
            .arg(QFileInfo(ed.fileName).size());
        Core::MessageManager::write(message);
    } else {
        const QString message = tr("Could not write file \"%1\".").arg(QDir::toNativeSeparators(ed.fileName));
        QMessageBox::critical(this, tr("Export Image"), message);
    }
    return result;
}
示例#6
0
void KdmPixmap::drawContents(QPainter *p, const QRect &r)
{
    // choose the correct pixmap class
    PixmapStruct::PixmapClass *pClass = &pixmap.normal;
    if(state == Sactive && pixmap.active.present)
        pClass = &pixmap.active;
    if(state == Sprelight && pixmap.prelight.present)
        pClass = &pixmap.prelight;

    if(pClass->pixmap.isNull())
    {
        if(pClass->fullpath.isEmpty()) // if neither is set, we're empty
            return;

        kdDebug() << "renderSVG\n";
        renderSvg(pClass, area);
    }

    int px = area.left() + r.left();
    int py = area.top() + r.top();
    int sx = r.x();
    int sy = r.y();
    int sw = r.width();
    int sh = r.height();
    if(px < 0)
    {
        px *= -1;
        sx += px;
        px = 0;
    }
    if(py < 0)
    {
        py *= -1;
        sy += py;
        py = 0;
    }


    if(pClass->readyPixmap.isNull())
    {
        QImage scaledImage;

        // use the loaded pixmap or a scaled version if needed

        if(area.size() != pClass->pixmap.size())
        {
            if(pClass->fullpath.endsWith(".svg"))
            {
                kdDebug() << "renderSVG\n";
                renderSvg(pClass, area);
                scaledImage = pClass->pixmap.convertToImage();
            }
            else
            {
                kdDebug() << "convertFromImage\n";
                QImage tempImage = pClass->pixmap.convertToImage();
                scaledImage = tempImage.smoothScale(area.width(), area.height());
            }
        }
        else
            scaledImage = pClass->pixmap.convertToImage();

        bool haveTint = pClass->tint.rgb() != 0xFFFFFF;
        bool haveAlpha = pClass->alpha < 1.0;

        if(haveTint || haveAlpha)
        {
            // blend image(pix) with the given tint

            scaledImage = scaledImage.convertDepth(32);
            int w = scaledImage.width();
            int h = scaledImage.height();
            float tint_red = float(pClass->tint.red()) / 255;
            float tint_green = float(pClass->tint.green()) / 255;
            float tint_blue = float(pClass->tint.blue()) / 255;
            float tint_alpha = pClass->alpha;

            for(int y = 0; y < h; ++y)
            {
                QRgb *ls = (QRgb *)scaledImage.scanLine(y);
                for(int x = 0; x < w; ++x)
                {
                    QRgb l = ls[x];
                    int r = int(qRed(l) * tint_red);
                    int g = int(qGreen(l) * tint_green);
                    int b = int(qBlue(l) * tint_blue);
                    int a = int(qAlpha(l) * tint_alpha);
                    ls[x] = qRgba(r, g, b, a);
                }
            }
        }

        pClass->readyPixmap.convertFromImage(scaledImage);
    }
    // kdDebug() << "Pixmap::drawContents " << pClass->readyPixmap.size() << " " << px << " " << py << " " << sx << " " << sy << " " << sw << " " <<
    // sh << endl;
    p->drawPixmap(px, py, pClass->readyPixmap, sx, sy, sw, sh);
}
示例#7
0
文件: svg.c 项目: zmike/compiz
static void
updateWindowSvgContext(CompWindow *w,
                       SvgSource *source)
{
    int x1, y1, x2, y2;

    SVG_WINDOW(w);

    if (sw->context)
    {
        finiSvgTexture(w->screen, &sw->context->texture[0]);
        finiSvgTexture(w->screen, &sw->context->texture[1]);
    }
    else
    {
        sw->context = malloc(sizeof (SvgContext));
        if (!sw->context)
            return;
    }

    memset(&sw->context->rect, 0, sizeof (BoxRec));

    sw->context->width = 0;
    sw->context->height = 0;

    initSvgTexture(w, source, &sw->context->texture[1], 0, 0);

    sw->context->source = source;

    sw->context->box.rects = &sw->context->box.extents;
    sw->context->box.numRects = 1;

    decor_apply_gravity(source->p1.gravity,
                        source->p1.x, source->p1.y,
                        w->width, w->height,
                        &x1, &y1);

    decor_apply_gravity(source->p2.gravity,
                        source->p2.x, source->p2.y,
                        w->width, w->height,
                        &x2, &y2);

    x1 = MAX(x1, 0);
    y1 = MAX(y1, 0);
    x2 = MIN(x2, w->width);
    y2 = MIN(y2, w->height);

    if (!initSvgTexture(w, source, &sw->context->texture[0],
                        w->width, w->height))
    {
        free(sw->context);
        sw->context = NULL;
    }
    else
    {
        renderSvg(w->screen, source, &sw->context->texture[0],
                  0.0f, 0.0f, 1.0f, 1.0f, w->width, w->height);

        initSvgTexture(w, source, &sw->context->texture[1], 0, 0);

        sw->context->box.extents.x1 = x1;
        sw->context->box.extents.y1 = y1;
        sw->context->box.extents.x2 = x2;
        sw->context->box.extents.y2 = y2;

        sw->context->box.extents.x1 += w->attrib.x;
        sw->context->box.extents.y1 += w->attrib.y;
        sw->context->box.extents.x2 += w->attrib.x;
        sw->context->box.extents.y2 += w->attrib.y;

        updateWindowSvgMatrix(w);
    }
}
示例#8
0
文件: svg.c 项目: zmike/compiz
static Bool
svgDrawWindow(CompWindow *w,
              const CompTransform *transform,
              const FragmentAttrib *attrib,
              Region region,
              unsigned int mask)
{
    Bool status;

    SVG_SCREEN(w->screen);

    UNWRAP(ss, w->screen, drawWindow);
    status = (*w->screen->drawWindow)(w, transform, attrib, region, mask);
    WRAP(ss, w->screen, drawWindow, svgDrawWindow);

    if (status)
    {
        SVG_WINDOW(w);

        if (mask & PAINT_WINDOW_TRANSFORMED_MASK)
            region = &infiniteRegion;

        if (sw->context && region->numRects)
        {
            CompTexture *texture = &sw->context->texture[0].texture;
            CompMatrix *matrix = &sw->context->texture[0].matrix;
            REGION r;

            r.rects = &r.extents;
            r.numRects = 1;

            r.extents = sw->context->box.extents;

            if (r.extents.x1 < ss->zoom.x1)
                r.extents.x1 = ss->zoom.x1;
            if (r.extents.y1 < ss->zoom.y1)
                r.extents.y1 = ss->zoom.y1;
            if (r.extents.x2 > ss->zoom.x2)
                r.extents.x2 = ss->zoom.x2;
            if (r.extents.y2 > ss->zoom.y2)
                r.extents.y2 = ss->zoom.y2;

            w->vCount = w->indexCount = 0;

            (*w->screen->addWindowGeometry)(w,
                                            matrix, 1,
                                            &sw->context->box,
                                            region);

            if (mask & PAINT_WINDOW_TRANSLUCENT_MASK)
                mask |= PAINT_WINDOW_BLEND_MASK;

            (*w->screen->drawWindowTexture)(w, texture, attrib, mask);

            if (r.extents.x1 < r.extents.x2 && r.extents.y1 < r.extents.y2)
            {
                float xScale, yScale;
                float dx, dy;
                int width, height;
                int saveFilter;

                r.extents.x1--;
                r.extents.y1--;
                r.extents.x2++;
                r.extents.y2++;

                xScale = w->screen->width / (float)
                         (ss->zoom.x2 - ss->zoom.x1);
                yScale = w->screen->height / (float)
                         (ss->zoom.y2 - ss->zoom.y1);

                dx = r.extents.x2 - r.extents.x1;
                dy = r.extents.y2 - r.extents.y1;

                width = dx * xScale + 0.5f;
                height = dy * yScale + 0.5f;

                if (r.extents.x1 != sw->context->rect.x1 ||
                        r.extents.y1 != sw->context->rect.y1 ||
                        r.extents.x2 != sw->context->rect.x2 ||
                        r.extents.y2 != sw->context->rect.y2 ||
                        width != sw->context->width ||
                        height != sw->context->height)
                {
                    float x1, y1, x2, y2;

                    sw->context->rect = r.extents;

                    sw->context->width = width;
                    sw->context->height = height;

                    dx = sw->context->box.extents.x2 -
                         sw->context->box.extents.x1;
                    dy = sw->context->box.extents.y2 -
                         sw->context->box.extents.y1;

                    x1 = (r.extents.x1 - sw->context->box.extents.x1) / dx;
                    y1 = (r.extents.y1 - sw->context->box.extents.y1) / dy;
                    x2 = (r.extents.x2 - sw->context->box.extents.x1) / dx;
                    y2 = (r.extents.y2 - sw->context->box.extents.y1) / dy;

                    finiSvgTexture(w->screen, &sw->context->texture[1]);

                    if (initSvgTexture(w, sw->context->source,
                                       &sw->context->texture[1],
                                       width, height))
                    {
                        renderSvg(w->screen, sw->context->source,
                                  &sw->context->texture[1],
                                  x1, y1, x2, y2,
                                  width, height);

                        updateWindowSvgMatrix(w);
                    }
                }

                texture = &sw->context->texture[1].texture;
                matrix = &sw->context->texture[1].matrix;

                w->vCount = w->indexCount = 0;

                saveFilter = w->screen->filter[SCREEN_TRANS_FILTER];
                w->screen->filter[SCREEN_TRANS_FILTER] =
                    COMP_TEXTURE_FILTER_GOOD;

                (*w->screen->addWindowGeometry)(w, matrix, 1, &r, region);
                (*w->screen->drawWindowTexture)(w, texture, attrib, mask);

                w->screen->filter[SCREEN_TRANS_FILTER] = saveFilter;
            }
            else if (sw->context->texture[1].width)
            {
                finiSvgTexture(w->screen, &sw->context->texture[1]);
                initSvgTexture(w, sw->source, &sw->context->texture[1], 0, 0);

                memset(&sw->context->rect, 0, sizeof (BoxRec));

                sw->context->width = 0;
                sw->context->height = 0;
            }
        }
    }

    return status;
}
示例#9
0
bool
SvgWindow::glDraw (const GLMatrix     &transform,
		   const GLWindowPaintAttrib &attrib,
		   const CompRegion   &region,
		   unsigned int       mask)
{
    bool status = gWindow->glDraw (transform, attrib, region, mask);

    if (!status)
	return status;

    const CompRegion &reg = (mask & PAINT_WINDOW_TRANSFORMED_MASK) ?
			    infiniteRegion : region;

    if (context && reg.numRects ())
    {
	GLTexture::MatrixList matrix (1);
	int		      x1, y1, x2, y2;
	CompRect              rect = context->box.boundingRect ();

	x1 = MIN (rect.x1 (), sScreen->zoom.x1 ());
	y1 = MIN (rect.y1 (), sScreen->zoom.y1 ());
	x2 = MAX (rect.x2 (), sScreen->zoom.x2 ());
	y2 = MAX (rect.y2 (), sScreen->zoom.y2 ());

	rect.setGeometry (x1, y1, x2 - x1, y2 - y1);

	for (unsigned int i = 0; i < context->texture[0].textures.size (); i++)
	{
	    matrix[0] = context->texture[0].matrices[i];

	    gWindow->vertexBuffer ()->begin ();
	    gWindow->glAddGeometry (matrix, context->box, reg);
	    gWindow->vertexBuffer ()->end ();

	    if (mask & PAINT_WINDOW_TRANSLUCENT_MASK)
		mask |= PAINT_WINDOW_BLEND_MASK;

	    gWindow->glDrawTexture (context->texture[0].textures[i], transform,
	                            attrib, mask);

	    if (rect.width () > 0 && rect.height () > 0)
	    {
		float    xScale, yScale;
		float    dx, dy;
		int      width, height;

		rect.setGeometry (rect.x1 () - 1,
				  rect.y1 () - 1,
				  rect.width () + 1,
				  rect.height () + 1);

		xScale = screen->width  () /
		         (float) (sScreen->zoom.width ());
		yScale = screen->height () /
		         (float) (sScreen->zoom.height ());

		dx = rect.width ();
		dy = rect.height ();

		width  = dx * xScale + 0.5f;
		height = dy * yScale + 0.5f;

		if (rect   != context->rect          ||
		    width  != context->size.width () ||
		    height != context->size.height ())
		{
		    float x1, y1, x2, y2;

		    context->rect = rect;
		    context->size.setWidth (width);
		    context->size.setHeight (height);

		    dx = context->box.boundingRect ().width ();
		    dy = context->box.boundingRect ().height ();

		    x1 = (rect.x1 () - context->box.boundingRect ().x ()) / dx;
		    y1 = (rect.y1 () - context->box.boundingRect ().y ()) / dy;
		    x2 = (rect.x2 () - context->box.boundingRect ().x ()) / dx;
		    y2 = (rect.y2 () - context->box.boundingRect ().y ()) / dy;

		    finiTexture (context->texture[1]);

		    if (initTexture (context->source, context->texture[1],
				     context->size))
		    {
			renderSvg (context->source, context->texture[1],
				   context->size, x1, y1, x2, y2);

			updateSvgMatrix ();
		    }
		}

		for (unsigned int j = 0; j < context->texture[1].textures.size (); j++)
		{
		    GLTexture::Filter saveFilter;
		    CompRegion        r (rect);

		    matrix[0] = context->texture[1].matrices[j];

		    saveFilter = gScreen->filter (SCREEN_TRANS_FILTER);
		    gScreen->setFilter (SCREEN_TRANS_FILTER, GLTexture::Good);

		    gWindow->vertexBuffer ()->begin ();
		    gWindow->glAddGeometry (matrix, r, reg);
		    gWindow->vertexBuffer ()->end ();

		    gWindow->glDrawTexture (context->texture[1].textures[j],
					    transform, attrib, mask);

		    gScreen->setFilter (SCREEN_TRANS_FILTER, saveFilter);
		}
	    }
	    else if (context->texture[1].size.width ())
	    {
		finiTexture (context->texture[1]);
		initTexture (source, context->texture[1], CompSize ());

		memset (&context->rect, 0, sizeof (BoxRec));
		context->size.setWidth (0);
		context->size.setHeight (0);
	    }
	}
    }

    return status;
}
示例#10
0
QPixmap SvgHandler::renderSvg(const QString & keyname, int width, int height, const QString & element)
{
    return renderSvg( m_themeFile, keyname, width, height, element );
}
示例#11
0
// Experimental, using a mockup from Nuno Pinheiro (new_slider_nuno)
void SvgHandler::paintCustomSlider( QPainter *p, QStyleOptionSlider *slider, qreal percentage, bool paintMoodbar )
{
    int sliderHeight = slider->rect.height() - 6;
    const bool inverse = ( slider->orientation == Qt::Vertical ) ? slider->upsideDown :
                         ( (slider->direction == Qt::RightToLeft) != slider->upsideDown );
    QRect knob = sliderKnobRect( slider->rect, percentage, inverse );
    QPoint pt = slider->rect.topLeft() + QPoint( 0, 2 );

    //debug() << "rel: " << knobRelPos << ", width: " << width << ", height:" << height << ", %: " << percentage;

    //if we should paint moodbar, paint this as the bottom layer
    bool moodbarPainted = false;
    if ( paintMoodbar )
    {
        Meta::TrackPtr currentTrack = The::engineController()->currentTrack();
        if ( currentTrack )
        {
            if( The::moodbarManager()->hasMoodbar( currentTrack ) )
            {
                QPixmap moodbar = The::moodbarManager()->getMoodbar( currentTrack, slider->rect.width() - sliderHeight, sliderHeight, inverse );
                p->drawPixmap( pt, renderSvg( "moodbar_end_left", sliderHeight / 2, sliderHeight, "moodbar_end_left" ) );

                pt.rx() += sliderHeight / 2;
                p->drawPixmap( pt, moodbar );

                pt.rx() += slider->rect.width() - sliderHeight;
                p->drawPixmap( pt, renderSvg( "moodbar_end_right", sliderHeight / 2, sliderHeight, "moodbar_end_right" ) );

                moodbarPainted = true;
            }
        }
    }

    if( !moodbarPainted )
    {
        // Draw the slider background in 3 parts

        p->drawPixmap( pt, renderSvg( "progress_slider_left", sliderHeight, sliderHeight, "progress_slider_left" ) );

        pt.rx() += sliderHeight;
        QRect midRect(pt, QSize(slider->rect.width() - sliderHeight * 2, sliderHeight) );
        p->drawTiledPixmap( midRect, renderSvg( "progress_slider_mid", 32, sliderHeight, "progress_slider_mid" ) );

        pt = midRect.topRight() + QPoint( 1, 0 );
        p->drawPixmap( pt, renderSvg( "progress_slider_right", sliderHeight, sliderHeight, "progress_slider_right" ) );

        //draw the played background.

        int playedBarHeight = sliderHeight - 6;

        int sizeOfLeftPlayed = qBound( 0, inverse ? slider->rect.right() - knob.right() + 2 :
                                                    knob.x() - 2, playedBarHeight );

        if( sizeOfLeftPlayed > 0 )
        {
            QPoint tl, br;
            if ( inverse )
            {
                tl = knob.topRight() + QPoint( -5, 5 ); // 5px x padding to avoid a "gap" between it and the top and bottom of the round knob.
                br = slider->rect.topRight() + QPoint( -3, 5 + playedBarHeight - 1 );
                QPixmap rightEnd = renderSvg( "progress_slider_played_right", playedBarHeight, playedBarHeight, "progress_slider_played_right" );
                p->drawPixmap( br.x() - rightEnd.width() + 1, tl.y(), rightEnd, qMax(0, rightEnd.width() - (sizeOfLeftPlayed + 3)), 0, sizeOfLeftPlayed + 3, playedBarHeight );
                br.rx() -= playedBarHeight;
            }
            else
            {
                tl = slider->rect.topLeft() + QPoint( 3, 5 );
                br = QPoint( knob.x() + 5, tl.y() + playedBarHeight - 1 );
                QPixmap leftEnd = renderSvg( "progress_slider_played_left", playedBarHeight, playedBarHeight, "progress_slider_played_left" );
                p->drawPixmap( tl.x(), tl.y(), leftEnd, 0, 0, sizeOfLeftPlayed + 3, playedBarHeight );
                tl.rx() += playedBarHeight;
            }
            if ( sizeOfLeftPlayed == playedBarHeight )
                p->drawTiledPixmap( QRect(tl, br), renderSvg( "progress_slider_played_mid", 32, playedBarHeight, "progress_slider_played_mid" ) );

        }
    }

    if ( slider->state & QStyle::State_Enabled )
    {   // Draw the knob (handle)
        const char *string = ( slider->activeSubControls & QStyle::SC_SliderHandle ) ?
                             "slider_knob_200911_active" : "slider_knob_200911";
        p->drawPixmap( knob.topLeft(), renderSvg( string, knob.width(), knob.height(), string ) );
    }
}