本文整理汇总了C++中QSvgRenderer::render方法的典型用法代码示例。如果您正苦于以下问题:C++ QSvgRenderer::render方法的具体用法?C++ QSvgRenderer::render怎么用?C++ QSvgRenderer::render使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSvgRenderer
的用法示例。
在下文中一共展示了QSvgRenderer::render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: result
inline static QImage colorBlot(const QColor &color, int blotVariation, QSize *size, const QSize &requestedSize)
{
QSvgRenderer *renderer = designRenderer();
const static QString elementIdBase = QStringLiteral("colorblot");
const static int variationsCnt = variationsCount(renderer, elementIdBase);
const int actualVariation = (blotVariation % variationsCnt) + 1;
const QString elementId = elementIdBase + QLatin1Char('_') + QString::number(actualVariation);
const QString maskElementId = elementId + QStringLiteral("_mask");
const QString highlightElementId = elementId + QStringLiteral("_highlight");
const QRectF backgroundRect = renderer->boundsOnElement(idPrefix + elementId);
QSize resultSize = backgroundRect.size().toSize();
if (size)
*size = resultSize;
resultSize.scale(requestedSize, Qt::KeepAspectRatio);
const qreal scaleFactor = resultSize.width() / backgroundRect.width();
QTransform transform =
QTransform::fromScale(scaleFactor, scaleFactor);
transform.translate(-backgroundRect.topLeft().x(), -backgroundRect.topLeft().y());
QImage result(resultSize, QImage::Format_ARGB32);
if (result.isNull())
qDebug() << Q_FUNC_INFO << "clock image is NULL! Variation:" << blotVariation;
result.fill(0);
QPainter p(&result);
p.setTransform(transform);
renderer->render(&p, idPrefix + maskElementId, renderer->boundsOnElement(idPrefix + maskElementId));
p.save();
p.setCompositionMode(QPainter::CompositionMode_SourceIn);
p.fillRect(backgroundRect, color);
p.restore();
renderer->render(&p, idPrefix + highlightElementId, renderer->boundsOnElement(idPrefix + highlightElementId));
return result;
}
示例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();
}
示例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;
}
示例4: 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;
}
示例5: draw
void TouchUI::draw( QPainter & painter )
{
_screen_width = painter.window().width();
_screen_height = painter.window().height();
limitScroll();
// draw background
QRect rect(0,0,painter.window().width(),_height);
painter.drawTiledPixmap( rect, _background );
// draw icons
for ( int i = 0; i < _items.count(); i++ )
{
UIItem * t = _items[i];
int posx = t->x1;
int posy = t->y1;
if ( posx < 0 ) posx = _screen_width+posx;
QSvgRenderer * image = t->image;
if ( t->highlighted )
painter.setCompositionMode( QPainter::CompositionMode_HardLight );
else
painter.setCompositionMode( QPainter::CompositionMode_SourceOver );
if ( image == NULL ) continue;
int h = image->defaultSize().height();
int w = image->defaultSize().width();
int img_width = g_config.ui_size;
int img_height = g_config.ui_size;
ImageLoadThread::fitImage( w,h, img_width, img_height, false );
QRectF r( posx+_xoffset, posy+_yoffset, w, h );
image->render( &painter, r );
}
}
示例6: paintEvent
void DistroMesas::paintEvent ( QPaintEvent * event ) {
QPainter painter;
painter.begin ( this ); // paint in picture
QSvgRenderer *arender;
if (m_background.isEmpty()) {
arender = new QSvgRenderer(mui_widget);
} else {
arender = new QSvgRenderer(m_background, mui_widget);
} // end if
arender->render(&painter);
painter.end();
QList<Mesa *> mesas = findChildren<Mesa *>();
for (int i = 0; i < mesas.size(); ++i) {
if ( mesas.at(i)->m_pantalla == m_pantallaactual) {
mesas.at(i)->setVisible(TRUE);
} else {
mesas.at(i)->setVisible(FALSE);
} // end if
} // end for
delete arender;
}
示例7: pixmap
QPixmap MIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
{
QPixmap pm;
QString pmckey(d->pmcKey(size, mode, state));
if (QPixmapCache::find(pmckey, pm))
return pm;
if (d->addedPixmaps) {
pm = d->addedPixmaps->value(d->hashKey(mode, state));
if (!pm.isNull() && pm.size() == size)
return pm;
}
QSvgRenderer renderer;
d->loadDataForModeAndState(&renderer, mode, state);
if (!renderer.isValid())
return pm;
QSize actualSize = renderer.defaultSize();
if (!actualSize.isNull())
actualSize.scale(size, Qt::KeepAspectRatio);
QImage img(actualSize, QImage::Format_ARGB32);
img.fill(0x00000000);
QPainter p(&img);
renderer.render(&p);
p.end();
pm = QPixmap::fromImage(img);
if (!pm.isNull())
QPixmapCache::insert(pmckey, pm);
return pm;
}
示例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();
}
示例9: 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;
}
示例10: 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);
}
}
示例11: resultSize
inline static QImage quantity(int quantity, const QString &item, QSize *size, const QSize &requestedSize)
{
QSvgRenderer *renderer = countablesRenderer();
const int columns = ceil(sqrt(qreal(quantity)));
const int rows = ceil(quantity / qreal(columns));
const int columnsInLastRow = quantity % columns == 0 ? columns : quantity % columns;
const int itemSize = qMin((requestedSize.width() / qMax(3, columns)), (requestedSize.height() / qMax(3, rows)));
const QSize resultSize(itemSize * columns, itemSize * rows);
QImage result(resultSize, QImage::Format_ARGB32);
result.fill(Qt::transparent);
QPainter p(&result);
for (int row = 0; row < rows; row++) {
for (int column = 0; column < columns; column++) {
if (columns * row + column >= quantity)
break;
const QString itemId = item + QLatin1Char('_') + QString::number((qrand() % 8 + 1));
const QRect itemRect(column * itemSize + (row == rows-1 ? (columns - columnsInLastRow) * itemSize / 2 : 0),
row * itemSize, itemSize, itemSize);
renderer->render(&p, idPrefix + itemId, itemRect);
}
}
if (size)
*size = resultSize;
return result;
}
示例12: drawPrimitive
void ClassicStyle::drawPrimitive( PrimitiveElement pe, const QStyleOption *opt,
QPainter *p, const QWidget *w ) const
{
static QSvgRenderer onRenderer(QString(":/vpiano/led_green.svg"));
static QSvgRenderer offRenderer(QString(":/vpiano/led_grey.svg"));
if (pe == PE_IndicatorCheckBox) {
QRect r = opt->rect;
if (opt->state & State_On)
onRenderer.render(p, r);
else if (opt->state & State_Off)
offRenderer.render(p, r);
return;
} else if (pe == PE_FrameFocusRect)
return;
QCommonStyle::drawPrimitive(pe, opt, p, w);
}
示例13: loadIcon
QPixmap SIconPool::loadIcon(
const QString &fileName,
const QSize &size,
Qt::AspectRatioMode mode,
const QColor &color)
{
QPixmap pm;
// SVG? Use QSvgRenderer
if (fileName.endsWith(".svg")) {
QSvgRenderer *renderer = getSvgRenderer(fileName);
if (renderer->isValid()) {
QSize renderSize = renderer->defaultSize();
// If given size is valid, scale default size to it using the given aspect ratio mode
if (size.isValid()) {
renderSize.scale(size, mode);
// If only one dimension is valid, scale other dimension keeping the aspect ratio
} else if (size.height() > 0) {
Qt::AspectRatioMode scaleMode = size.height() > renderSize.height()
? Qt::KeepAspectRatioByExpanding
: Qt::KeepAspectRatio;
renderSize.scale(renderSize.width(), size.height(), scaleMode);
} else if (size.width() > 0) {
Qt::AspectRatioMode scaleMode = size.width() > renderSize.width()
? Qt::KeepAspectRatioByExpanding
: Qt::KeepAspectRatio;
renderSize.scale(size.width(), renderSize.height(), scaleMode);
}
// Otherwise (-1,-1) was given as size, leave renderSize as icon's default size
pm = QPixmap(renderSize);
pm.fill(QColor(0, 0, 0, 0));
QPainter painter(&pm);
renderer->render(&painter, QRectF(QPointF(), renderSize));
}
} else {
// Otherwise load with QPixmap
pm.load(fileName);
if (!pm.isNull()) {
pm = pm.scaled(size, mode, Qt::SmoothTransformation);
}
}
if (!pm.isNull() && color.isValid()) {
// Colorize the icon
QPixmap mask = pm.alphaChannel();
pm.fill(color);
pm.setAlphaChannel(mask);
}
#ifdef Q_DEBUG_ICON
if (pm.isNull()) {
qDebug() << "Fail to load icon: " << filename;
}
#endif
return pm;
}
示例14: 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();
}
示例15: back
// QtPluginIconPalletTool Interface
void
dmz::QtPluginIconPalletTool::_add_type (const ObjectType &Type) {
const String IconResource = config_to_string (
get_plugin_name () + ".resource",
Type.get_config());
const String IconName = _rc.find_file (IconResource);
if (IconName) {
const String Name = Type.get_name ();
if (Name) {
QImage back (
(int)_iconExtent,
(int)_iconExtent,
QImage::Format_ARGB32_Premultiplied);
QPainter painter (&back);
painter.setCompositionMode (QPainter::CompositionMode_Source);
painter.fillRect (back.rect (), Qt::transparent);
painter.setCompositionMode (QPainter::CompositionMode_SourceOver);
QSvgRenderer qsr (QString (IconName.get_buffer ()));
QRectF size = qsr.viewBoxF ();
qreal width = size.width ();
qreal height = size.height ();
qreal scale = (width > height) ? width : height;
if (scale <= 0.0f) { scale = 1.0f; }
scale = _iconExtent / scale;
width *= scale;
height *= scale;
size.setWidth (width);
size.setHeight (height);
if (height < _iconExtent) { size.moveTop ((_iconExtent - height) * 0.5f); }
if (width < _iconExtent) { size.moveLeft ((_iconExtent - width) * 0.5f); }
qsr.render (&painter, size);
painter.end ();
QIcon icon;
icon.addPixmap (QPixmap::fromImage (back));
QStandardItem *item = new QStandardItem (icon, Name.get_buffer ());
item->setEditable (false);
_model.appendRow (item);
}
}
else if (IconResource) {
_log.error << "Unable to find icon resource: " << IconResource
<< " for object type: " << Type.get_name () << endl;
}
RuntimeIterator it;
ObjectType next;
while (Type.get_next_child (it, next)) { _add_type (next); }
}