当前位置: 首页>>代码示例>>C++>>正文


C++ QSvgRenderer::load方法代码示例

本文整理汇总了C++中QSvgRenderer::load方法的典型用法代码示例。如果您正苦于以下问题:C++ QSvgRenderer::load方法的具体用法?C++ QSvgRenderer::load怎么用?C++ QSvgRenderer::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QSvgRenderer的用法示例。


在下文中一共展示了QSvgRenderer::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: load

bool QSvgIOHandlerPrivate::load(QIODevice *device)
{
    if (loaded)
        return true;
    if (q->format().isEmpty())
        q->canRead();

    // # The SVG renderer doesn't handle trailing, unrelated data, so we must
    // assume that all available data in the device is to be read.
    bool res = false;
    QBuffer *buf = qobject_cast<QBuffer *>(device);
    if (buf) {
        const QByteArray &ba = buf->data();
        res = r.load(QByteArray::fromRawData(ba.constData() + buf->pos(), ba.size() - buf->pos()));
        buf->seek(ba.size());
    } else if (q->format() == "svgz") {
        res = r.load(device->readAll());
    } else {
        xmlReader.setDevice(device);
        res = r.load(&xmlReader);
    }

    if (res) {
        defaultSize = QSize(r.viewBox().width(), r.viewBox().height());
        loaded = true;
    }

    return loaded;
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.vendor,代码行数:29,代码来源:qsvgiohandler.cpp

示例2: setSkin

/*!
    With this function you can set the skin that will be displayed in the widget.

    \code
        QtScrollDial * scroll = new QtScrollDial(this);
        scroll->setSkin("Beryl");
    \endcode

    This function has to be called before using the QtScrollDial.

    \sa skin()

*/
void QtScrollDial::setSkin(const QString& skin)
{
    m_skin = skin;
    const QString base = ":/scrolldial/" + skin + '/';


    if(m_popup != NULL)
        m_popup->setSkin(skin);

    m_label->setStyleSheet("color: white; border-width: 2px;"
                           "border-image: url(" + base + "label.svg);");

    // set to null pictures
    m_background = QPicture();
    m_hoverBackground = QPicture();

    QSvgRenderer renderer;
    QPainter painter;

    if (renderer.load(base + "background.svg")) {
        painter.begin(&m_background);
        renderer.render(&painter, QRectF(0.0, 0.0, 1.0, 1.0));
        painter.end();
    }

    if (renderer.load(base + "background_hover.svg")) {
        painter.begin(&m_hoverBackground);
        renderer.render(&painter, QRectF(0.0, 0.0, 1.0, 1.0));
        painter.end();
    }

    // update geometry for new sizeHint and repaint
    updateGeometry();
    update();
}
开发者ID:baltoboard,项目名称:qtbaltodemo,代码行数:48,代码来源:qtscrolldial.cpp

示例3: buildPixmaps

bool GoTableWidget::buildPixmaps(int diameter) {
    QSvgRenderer svgR;

    delete blackStonePixmap;
    blackStonePixmap = new QPixmap(diameter, diameter);
    blackStonePixmap->fill(Qt::transparent);
    svgR.load(QString(":/resources/cursorBlack.svg"));
    QPainter bPainter(blackStonePixmap);
    svgR.render(&bPainter);
    delete blackCursor;
    blackCursor = new QCursor(*blackStonePixmap);

    delete whiteStonePixmap;
    whiteStonePixmap = new QPixmap(diameter, diameter);
    whiteStonePixmap->fill(QColor(0, 0, 0, 0));
    svgR.load(QString(":/resources/cursorWhite.svg"));
    QPainter wPainter(whiteStonePixmap);
    svgR.render(&wPainter);
    delete whiteCursor;
    whiteCursor = new QCursor(*whiteStonePixmap);

    delete redStonePixmap;
    redStonePixmap = new QPixmap(diameter, diameter);
    redStonePixmap->fill(QColor(0, 0, 0, 0));
    svgR.load(QString(":/resources/cursorRed.svg"));
    QPainter rPainter(redStonePixmap);
    svgR.render(&rPainter);
    delete redCursor;
    redCursor = new QCursor(*redStonePixmap);

    return true;
}
开发者ID:alecs1,项目名称:home,代码行数:32,代码来源:GoTablePaint.cpp

示例4: paint

qreal PdfElementImage::paint(QPainter *painter) {
	qreal x = toQReal(_attributes.value("x", "0"));
	qreal y = toQReal(_attributes.value("y", "0")) + _offsetY;
	qreal w = toQReal(_attributes.value("width", "0"));
	qreal h = toQReal(_attributes.value("height", "0"));
	
	if (w > 0 && h > 0) {
		painter->setPen(Qt::NoPen);
		painter->setBrush(Qt::NoBrush);
		QRectF box(QPointF(x, y), QSizeF(w, h));
		QImage picture;
		
		// Get the variable defined in the attribute "file"
		QString var = _attributes.value("file", "");
		bool drawn = FALSE;
		
		// No variable found, the attribute "file" might point to an imagefile
		if (_variables->value(var, "").isEmpty()) {
			
			// Load the image (or default image) and print it
			QList<QString> images = replaceVariables(var);
			QString img;
			for (int i = 0; i < images.size(); i++) {
				img = QString("/").prepend(_templatePath).append(images.at(i));
				if (picture.load(img)) {
					painter->drawImage( box, picture, QRectF(picture.rect()) );
					drawn = TRUE;
					break;
				}
			}
			
		} else {
			// if an attribute exists with the addition "_file" the string in the attribute should be iinterpreted as a file, otherwise as SVG-Content
			bool imageIsFile = _variables->contains(var) && !_variables->value(var.append("_file"), "").isEmpty();
			
			// Try to render a normal pixel image or as an SVG Image / Content
			QSvgRenderer svg;
			if (imageIsFile && picture.load(_variables->value(var))) {
				painter->drawImage( box, picture, QRectF(picture.rect()) );
				drawn = TRUE;
				
			} else if ( (imageIsFile && svg.load( _variables->value(var) )) ||
			            (!imageIsFile && svg.load( _variables->value(var).toUtf8() ))
			) {
				svg.render(painter, box);
				drawn = TRUE;
			}
		}
		
		// If the Image isn't drawn, show the default one
		if (!drawn) {
			showDefaultImage(painter, box);
		}
	}
	return bottom();
}
开发者ID:LukyLuke,项目名称:PiTres,代码行数:56,代码来源:PdfElement.cpp

示例5: thumbnail

QPixmap SCPageLayout::thumbnail() const
{
    static KIconLoader * loader = KIconLoader::global();

    QSvgRenderer renderer;

    QSize size(80, 60);
    QPixmap pic(size);
    pic.fill();
    QPainter p(&pic);

    QString file = loader->iconPath("layout-elements", KIconLoader::User);
    if (renderer.load(file)) {
        QList<SCPlaceholder *>::const_iterator it(m_placeholders.begin());
        for (; it != m_placeholders.end(); ++it) {
            kDebug(33001) << "-----------------" <<(*it)->presentationObject() << (*it)->rect(size);
            renderer.render(&p, (*it)->presentationObject(), (*it)->rect(size));
        }
    }
    else {
        kWarning(33001) << "could not load" << file;
    }

    return pic;
}
开发者ID:KDE,项目名称:koffice,代码行数:25,代码来源:SCPageLayout.cpp

示例6: fillWaitedPlayersCombo

void KWaitedPlayerSetupDialog::fillWaitedPlayersCombo()
{
  kDebug() << "Filling nations combo" << endl;

  QList<PlayerMatrix>::iterator it, it_end;
  it = m_automaton->game()->waitedPlayers().begin();
  it_end = m_automaton->game()->waitedPlayers().end();
  for (; it != it_end; it++)
  {
    kDebug() << "Adding waited player " << (*it).name << endl;
    QString imgName = m_automaton->game()->theWorld()->nationNamed((*it).nation)->flagFileName();
//     load image
    QPixmap flag;
    QSize size(flag.width()/Sprites::SkinSpritesData::single().intData("flag-frames"),flag.height());
    QImage image(size, QImage::Format_ARGB32_Premultiplied);
    image.fill(0);
    QPainter p(&image);
    QSvgRenderer renderer;
    renderer.load(imgName);
    renderer.render(&p/*, svgid*/);
    QPixmap allpm = QPixmap::fromImage(image);
    flag = allpm.copy(0, 0, size.width(), size.height());

//     get name
    QString name = (*it).name;
    name += QString(" (");
    name += (i18n((*it).nation.toUtf8().data()));
    name += QString(")");
//     fill a combo entry
    waitedPlayersCombo->addItem(QIcon(flag),name);
  }
  
}
开发者ID:KDE,项目名称:ksirk,代码行数:33,代码来源:kwaitedplayersetupdialog.cpp

示例7: load

bool SvgRenderer::load(const QString &filename)
{
    if (renderer.load(filename) && renderer.isValid())
        return true;

    return false;
}
开发者ID:muromec,项目名称:qtopia-ezx,代码行数:7,代码来源:renderer.cpp

示例8: drawSvgMarker

void QgsLayoutItemPolyline::drawSvgMarker( QPainter *p, QPointF point, double angle, const QString &markerPath, double height ) const
{
  // translate angle from ccw from axis to cw from north
  angle = 90 - angle;

  if ( mArrowHeadWidth <= 0 || height <= 0 )
  {
    //bad image size
    return;
  }

  if ( markerPath.isEmpty() )
    return;

  QSvgRenderer r;
  const QByteArray &svgContent = QgsApplication::svgCache()->svgContent( markerPath, mArrowHeadWidth, mArrowHeadFillColor, mArrowHeadStrokeColor, mArrowHeadStrokeWidth,
                                 1.0 );
  r.load( svgContent );

  p->save();
  p->translate( point.x(), point.y() );
  p->rotate( angle );
  p->translate( -mArrowHeadWidth / 2.0, -height / 2.0 );
  r.render( p, QRectF( 0, 0, mArrowHeadWidth, height ) );
  p->restore();
}
开发者ID:alexbruy,项目名称:QGIS,代码行数:26,代码来源:qgslayoutitempolyline.cpp

示例9: searchfile

void B9Edit::importSlicesFromSvg(QString file, double pixelsizemicrons)
{
	int layers = 0;
	double xsizemm = 0.0;
	double ysizemm = 0.0;
	double x = 0;
	double y = 0;
    bool inverted = false;

	QSvgRenderer SvgRender;
	
	
	if(!SvgRender.load(file))
	{
		QMessageBox msgBox;
		msgBox.setText("Unable to import SVG file.");
		msgBox.exec();
		return;
	}
	if(!SvgRender.elementExists("layer0"))
	{
		QMessageBox msgBox;
		msgBox.setText("SVG file does not contain compatible layer information\nUnable to import.");
		msgBox.exec();
		return;
	}

    //do a quick search for the word "slic3r:type="contour"" and then the following "style="fill:"
    //to figure out whether the image is inverted or not.
    QString buff = "";
    QFile searchfile(file);
    searchfile.open(QIODevice::ReadOnly);
    QTextStream searchstream(&searchfile);


    while(buff != "slic3r:type=\"contour\"" && !searchstream.atEnd())
    {
        searchstream >> buff;
    }
    if(!searchstream.atEnd())//we must have found it.
    {
        while(buff != "style=\"fill:" && !searchstream.atEnd())
        {
            searchstream >> buff;
        }
        if(!searchstream.atEnd())
        {
            searchstream >> buff;
            if(buff == "white\"")
            {
                inverted = false;
            }
            else
            {
                inverted = true;
            }
        }
        else
        {
开发者ID:denisoft,项目名称:B9Creator,代码行数:59,代码来源:b9edit.cpp

示例10: requestImage

QImage SvgElementProvider::requestImage(const QString& id, QSize* size, const QSize& requestedSize)
{
	// Resolve URL
	QUrl url = QUrl(id);
	if (url.isRelative() && !mBaseUrl.isEmpty())
		url = mBaseUrl.resolved(url);

	if (!url.isValid())
		return placeholder(QString("Invalid URL\nBase: %1\nInput: %2").arg(mBaseUrl.toString()).arg(id), requestedSize);

	// Make a filename from the given URL
	QString imagepath = QQmlFile::urlToLocalFileOrQrc(url);
	// Fragment is used to specify SVG element
	QString elementId = url.fragment();

	// Load image
	QSvgRenderer renderer;
	if (!renderer.load(imagepath))
	{
		qWarning() << "Unable to load image:" << imagepath;
		return placeholder(QStringLiteral("Unable to load image:\n") + imagepath, requestedSize);
	}

	// Check whether requested element exists
	if (!elementId.isEmpty() && !renderer.elementExists(elementId))
		return placeholder(QStringLiteral("Unable to find element:\n") + elementId + "\nin image:\n" + imagepath,
		                   requestedSize);

	// Get image or element size
	QSize itemSize = elementId.isEmpty() ? renderer.defaultSize() : renderer.boundsOnElement(elementId).size().toSize();

	if (size)
		*size = itemSize;

	// Create image
	QImage image(requestedSize.width() > 0 ? requestedSize.width() : itemSize.width(),
	             requestedSize.height() > 0 ? requestedSize.height() : itemSize.height(),
	             QImage::Format_ARGB32_Premultiplied);
	image.fill(Qt::transparent);

	// Paint svg or element
	QPainter p(&image);
	if (elementId.isEmpty())
		renderer.render(&p);
	else
		renderer.render(&p, elementId);

	return image;
}
开发者ID:mNisblee,项目名称:QTouch,代码行数:49,代码来源:svgelementprovider.cpp

示例11: QGraphicsView

/*
 * Initialize the widget
 */
GpsConstellationWidget::GpsConstellationWidget(QWidget *parent) : QGraphicsView(parent)
{
    // Create a layout, add a QGraphicsView and put the SVG inside.
    // The constellation widget looks like this:
    // |--------------------|
    // |                    |
    // |                    |
    // |     Constellation  |
    // |                    |
    // |                    |
    // |                    |
    // |--------------------|


    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    QSvgRenderer *renderer = new QSvgRenderer();
    renderer->load(QString(":/gpsgadget/images/gpsEarth.svg"));

    world = new QGraphicsSvgItem();
    world->setSharedRenderer(renderer);
    world->setElementId("map");

    scene = new QGraphicsScene(this);
    scene->addItem(world);
    scene->setSceneRect(world->boundingRect());
    setScene(scene);

    QFontDatabase::addApplicationFont(":/gpsgadget/font/digital-7_mono.ttf");

    // Now create 'maxSatellites' satellite icons which we will move around on the map:
    for (int i = 0; i < MAX_SATTELITES; i++) {
        satellites[i][0] = 0;
        satellites[i][1] = 0;
        satellites[i][2] = 0;
        satellites[i][3] = 0;

        satIcons[i] = new QGraphicsSvgItem(world);
        satIcons[i]->setSharedRenderer(renderer);
        satIcons[i]->setElementId("sat-notSeen");
        satIcons[i]->hide();

        satTexts[i] = new QGraphicsSimpleTextItem("##", satIcons[i]);
        satTexts[i]->setBrush(QColor("Black"));
        satTexts[i]->setFont(QFont("Digital-7"));
    }
}
开发者ID:FabianFrancoRoldan,项目名称:OpenPilot,代码行数:51,代码来源:gpsconstellationwidget.cpp

示例12: setEndSvgMarkerPath

void QgsLayoutItemPolyline::setEndSvgMarkerPath( const QString &path )
{
  QSvgRenderer r;
  mEndMarkerFile = path;
  if ( path.isEmpty() || !r.load( path ) )
  {
    mEndArrowHeadHeight = 0;
  }
  else
  {
    //calculate mArrowHeadHeight from svg file and mArrowHeadWidth
    QRect viewBox = r.viewBox();
    mEndArrowHeadHeight = mArrowHeadWidth / viewBox.width() * viewBox.height();
  }
  updateBoundingRect();
}
开发者ID:alexbruy,项目名称:QGIS,代码行数:16,代码来源:qgslayoutitempolyline.cpp

示例13: AbstractWizardPage

SelectionPage::SelectionPage(SetupWizard *wizard, QString shapeFile, QWidget *parent) :
    AbstractWizardPage(wizard, parent), Selection(),
    ui(new Ui::SelectionPage)
{
    ui->setupUi(this);

    QSvgRenderer *renderer = new QSvgRenderer();
    renderer->load(shapeFile);
    m_shape = new QGraphicsSvgItem();
    m_shape->setSharedRenderer(renderer);
    QGraphicsScene *scene = new QGraphicsScene(this);
    scene->addItem(m_shape);
    ui->typeGraphicsView->setScene(scene);

    connect(ui->typeCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(selectionChanged(int)));
}
开发者ID:FabianFrancoRoldan,项目名称:OpenPilot,代码行数:16,代码来源:selectionpage.cpp

示例14: earthpix

/*
 * Initialize the widget
 */
GpsDisplayWidget::GpsDisplayWidget(QWidget *parent) : QWidget(parent)
{
    setupUi(this);

    //Not elegant, just load the image for now
    QGraphicsScene *fescene = new QGraphicsScene(this);
    QPixmap earthpix( ":/gpsgadget/images/flatEarth.png" );
    fescene->addPixmap( earthpix );
    flatEarth->setScene(fescene);
    marker = new QGraphicsSvgItem();
    QSvgRenderer *renderer = new QSvgRenderer();
    renderer->load(QString(":/gpsgadget/images/marker.svg"));
    marker->setSharedRenderer(renderer);
    fescene->addItem(marker);
    double scale = earthpix.width()/(marker->boundingRect().width()*20);
    marker->setScale(scale);
}
开发者ID:mcu786,项目名称:my_OpenPilot_mods,代码行数:20,代码来源:gpsdisplaywidget.cpp

示例15: showDefaultImage

void PdfElementImage::showDefaultImage(QPainter *painter, QRectF box) {
	QSvgRenderer svg;
	QImage picture;
	QString img;
	QList<QString> images = replaceVariables(_attributes.value("default", ""));
	
	// Try to load the image as SVG and after as a pixel graphic
	for (int i = 0; i < images.size(); i++) {
		img = QString("/").prepend(_templatePath).append( images.at(i) );
		if (svg.load(img)) {
			painter->setPen(Qt::NoPen);
			svg.render(painter, box);
			break;
		} else if (picture.load( img )) {
			painter->drawImage( box, picture, QRectF(picture.rect()) );
			break;
		}
	}
}
开发者ID:LukyLuke,项目名称:PiTres,代码行数:19,代码来源:PdfElement.cpp


注:本文中的QSvgRenderer::load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。