本文整理汇总了C++中QSvgRenderer类的典型用法代码示例。如果您正苦于以下问题:C++ QSvgRenderer类的具体用法?C++ QSvgRenderer怎么用?C++ QSvgRenderer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QSvgRenderer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: quantity
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;
}
示例2: limitScroll
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 );
}
}
示例3: kDebug
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);
}
}
示例4: qWarning
QSvgRenderer *SvgImageProvider::loadRenderer(const QString &svgFile)
{
QSvgRenderer *renderer = m_renderers.value(svgFile, NULL);
if (!renderer) {
QString fn = svgFile;
if(!QFileInfo::exists(fn)) {
//convert path to be relative to base
fn = QUrl::fromLocalFile(m_basePath).resolved(svgFile).toLocalFile();
}
if(!QFileInfo::exists(fn)) {
//it's really missing this time
qWarning() << "[SvgImageProvider::loadRenderer]SVG file not found:" << svgFile;
return 0;
}
renderer = new QSvgRenderer(fn);
if (!renderer->isValid()) {
qWarning() << "[SvgImageProvider::loadRenderer]Failed to load svg file:" << svgFile;
delete renderer;
return 0;
}
m_renderers.insert(svgFile, renderer);
}
return renderer;
}
示例5: QSvgRenderer
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;
}
示例6: QtScrollDial
/*!
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();
}
示例7: 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;
}
示例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: pmckey
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;
}
示例10: switch
void QucsActiveFilter::slotUpdateResponse()
{
QString s = ":/images/bitmaps/AFR.svg";
switch (cbxResponse->currentIndex()) {
case tLowPass :
s = ":/images/bitmaps/AFR.svg";
ftyp = Filter::LowPass;
break;
case tHiPass : s = ":/images/bitmaps/high-pass.svg";
ftyp = Filter::HighPass;
break;
case tBandPass : s = ":/images/bitmaps/bandpass.svg";
ftyp = Filter::BandPass;
break;
case tBandStop : s = ":/images/bitmaps/bandstop.svg";
ftyp = Filter::BandStop;
break;
default: ftyp = Filter::NoFilter;
break;
}
QSvgRenderer *ren = new QSvgRenderer(s);
QSize sz = ren->defaultSize();
sz *= 1.1;
delete ren;
imgAFR->load(s);
imgAFR->setFixedSize(sz);
}
示例11: elementsWithSizes
ElementVariationList elementsWithSizes(const QString &elementBase)
{
ElementVariationList result;
QSvgRenderer *renderer = designRenderer();
ElementVariations element;
element.widthToHeightRatio = -1;
for (int i = 1; ; i++) {
const QString id = elementBase + QLatin1Char('_') + QString::number(i);
if (!renderer->elementExists(idPrefix + id))
break;
const QSizeF size = renderer->boundsOnElement(idPrefix + id).size();
const qreal widthToHeightRatio = size.width() / size.height();
if (!qFuzzyCompare(widthToHeightRatio, element.widthToHeightRatio)) {
if (element.widthToHeightRatio > 0) // Check, is it is the first element
result.append(element);
element.widthToHeightRatio = widthToHeightRatio;
element.elementIds.clear();
}
element.elementIds.append(id);
}
if (!element.elementIds.isEmpty())
result.append(element);
qSort(result);
return result;
}
示例12: 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
{
示例13: getSvgRenderer
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: config_to_string
// 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); }
}
示例15: toQReal
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();
}