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


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

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


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

示例1: 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 );
	}
}
开发者ID:miabrahams,项目名称:MPhoto,代码行数:32,代码来源:TouchUI.cpp

示例2: 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;
      }
开发者ID:AdrianShe,项目名称:MuseScore,代码行数:33,代码来源:miconengine.cpp

示例3: slotUpdateResponse

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);
}
开发者ID:NextGenIntelligence,项目名称:qucs,代码行数:30,代码来源:qucsactivefilter.cpp

示例4: 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;
}
开发者ID:9smart,项目名称:QQC_1_1_for_Symbian1,代码行数:59,代码来源:siconpool.cpp

示例5: 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

示例6: pixmap

QPixmap QSvgIconEngine::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);

    if (actualSize.isEmpty())
        return QPixmap();

    QImage img(actualSize, QImage::Format_ARGB32_Premultiplied);
    img.fill(0x00000000);
    QPainter p(&img);
    renderer.render(&p);
    p.end();
    pm = QPixmap::fromImage(img);
    if (qobject_cast<QGuiApplication *>(QCoreApplication::instance())) {
        const QPixmap generated = QGuiApplicationPrivate::instance()->applyQIconStyleHelper(mode, pm);
        if (!generated.isNull())
            pm = generated;
    }

    if (!pm.isNull())
        QPixmapCache::insert(pmckey, pm);

    return pm;
}
开发者ID:Drakey83,项目名称:steamlink-sdk,代码行数:44,代码来源:qsvgiconengine.cpp

示例7: slotUpdateSchematic

void QucsActiveFilter::slotUpdateSchematic()
{
    slotUpdateResponse();
    QString s;
    switch (cbxFilterType->currentIndex()) {
    case topoCauer : if ((ftyp==Filter::BandStop)||
                         (ftyp==Filter::BandPass)) {
            s = ":images/bitmaps/cauer-bandpass.svg"; // Cauer section
        } else {
            s = ":images/bitmaps/cauer.svg"; // Cauer section
        }
             break;
    case topoMFB : if (ftyp==Filter::HighPass) { // Multifeedback
            s = ":/images/bitmaps/mfb-highpass.svg";
        } else if (ftyp==Filter::LowPass) {
            s = ":/images/bitmaps/mfb-lowpass.svg";
        } else if (ftyp==Filter::BandPass) {
            s = ":/images/bitmaps/mfb-bandpass.svg";
        }
             break;
    case topoSallenKey : if (ftyp==Filter::HighPass) { // Sallen-Key
            s = ":/images/bitmaps/sk-highpass.svg";
        } else if (ftyp==Filter::LowPass) {
           s = ":/images/bitmaps/sk-lowpass.svg";
        } else if (ftyp==Filter::BandPass) {
           s = ":/images/bitmaps/sk-bandpass.svg";
        }
        break;
    case 3 : s = ":/images/bitmaps/mfb-lowpass.svg";
        break;
    default:
        break;
    }

    QSvgRenderer *ren = new QSvgRenderer(s);
    QSize sz = ren->defaultSize();
    sz *= 0.65;
    delete ren;

    sch_pic->load(s);
    sch_pic->setFixedSize(sz);
}
开发者ID:NextGenIntelligence,项目名称:qucs,代码行数:42,代码来源:qucsactivefilter.cpp

示例8: pixmap

QPixmap QSvgIconEngine::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_Premultiplied);
    img.fill(0x00000000);
    QPainter p(&img);
    renderer.render(&p);
    p.end();
    pm = QPixmap::fromImage(img);
    QStyleOption opt(0);
    opt.palette = QApplication::palette();
    QPixmap generated = QApplication::style()->generatedIconPixmap(mode, pm, &opt);
    if (!generated.isNull())
        pm = generated;

    if (!pm.isNull())
        QPixmapCache::insert(pmckey, pm);

    return pm;
}
开发者ID:Marforius,项目名称:qt,代码行数:41,代码来源:qsvgiconengine.cpp

示例9: scaledElementBounds

/*!
  \fn SvgImageProvider::scaledElementBounds(const QString &svgFile, const QString &element)

  Returns the bound of \a element in logical coordinates,
  scalled to the default size of svg document (so the bounds of whole doc would be (0,0,1,1) ).
*/
QRectF SvgImageProvider::scaledElementBounds(const QString &svgFile, const QString &elementName)
{
    QSvgRenderer *renderer = loadRenderer(svgFile);

    if (!renderer)
        return QRectF();

    if (!renderer->elementExists(elementName)) {
        qWarning() << "invalid element:" << elementName << "of" << svgFile;
        return QRectF();
    }

    QRectF elementBounds = renderer->boundsOnElement(elementName);
    QMatrix matrix = renderer->matrixForElement(elementName);
    elementBounds = matrix.mapRect(elementBounds);

    QSize docSize = renderer->defaultSize();
    return QRectF(elementBounds.x()/docSize.width(),
                  elementBounds.y()/docSize.height(),
                  elementBounds.width()/docSize.width(),
                  elementBounds.height()/docSize.height());
}
开发者ID:Trex4Git,项目名称:dRonin,代码行数:28,代码来源:svgimageprovider.cpp

示例10: defaultSize

QSize SIconPool::defaultSize(const QString &fileName)
{
    QSize defSize;

    // Get the default size from svg renderer or pixmap size
    if (!fileName.isEmpty()) {
        // SVG? Use QSvgRenderer
        if (fileName.endsWith(".svg")) {
            QSvgRenderer *svgRenderer = getSvgRenderer(fileName);
            if (svgRenderer->isValid()) {
                defSize = svgRenderer->defaultSize();
            }
        } else {
            // Otherwise load with QPixmap
            QPixmap pixmap;
            pixmap.load(fileName);
            defSize = pixmap.size();
        }
    }

    return defSize;
}
开发者ID:9smart,项目名称:QQC_1_1_for_Symbian1,代码行数:22,代码来源:siconpool.cpp

示例11: pixmap

QPixmap MIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
      {
      QPixmap pm;

      QString pmckey(d->pmcKey(size, mode, state));
      pmckey.prepend("Ms");

      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);

      // Generate an image of the requested size, but render the
      // the SVG with the correct aspect ratio centered in the image
      // to prevent scaling issues when setting non square icon size.
      QImage img(size, QImage::Format_ARGB32);
      img.fill(0x00000000);
      QPainter p(&img);
      renderer.render(&p, getBounds(size, actualSize));
      p.end();
      pm = QPixmap::fromImage(img);

      if (!pm.isNull())
            QPixmapCache::insert(pmckey, pm);
      return pm;
      }
开发者ID:IsaacWeiss,项目名称:MuseScore,代码行数:39,代码来源:miconengine.cpp

示例12: 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();

      bool light = Ms::preferences.globalStyle == Ms::STYLE_LIGHT;

      int ww = img.width();
      if (state == QIcon::On) {
            if (light) {
                  for (int y = 0; y < img.height(); ++y) {
                        QRgb *scanLine = (QRgb*)img.scanLine(y);
                        for (int x = 0; x < img.width(); ++x) {
                              QRgb pixel = *scanLine;
                              int alpha = qAlpha(pixel);
                              if (alpha < 0)
                                    alpha = 0;
                              *scanLine = qRgba(qRed(255-pixel), qGreen(255-pixel), qBlue(255-pixel), alpha);
                              ++scanLine;
                              }
                        }
                  }
            else {
                  for (int y = 0; y < img.height(); ++y) {
                        quint32* p = (quint32*)img.scanLine(y);
                        for (int x = 0; x < ww; ++x) {
                              if (*p & 0xff000000) {
                                    int d = 0xff - (*p & 0xff);
                                    int dd = 50;
                                    QColor color(QColor::fromRgba(*p));
                                    int r = 70 - d + dd;
                                    if (r < 0)
                                          r = 0;
                                    int g = 130 - d + dd;
                                    if (g < 0)
                                          g = 0;
                                    int b = 180 - d + dd;
                                    if (b < 0)
                                          b = 0;
                                    QColor nc = QColor(r, g, b, color.alpha());
                                    *p = nc.rgba();
                                    }
                              ++p;
                              }
                        }
                  }
            }
      else {
            // change alpha channel
            int delta = 51;
            if (mode == QIcon::Disabled)
                  delta = 178;
            else if (state == QIcon::On)
                  delta = 0;
            if (light) {
                  for (int y = 0; y < img.height(); ++y) {
                        QRgb *scanLine = (QRgb*)img.scanLine(y);
                        for (int x = 0; x < img.width(); ++x) {
                              QRgb pixel = *scanLine;
                              int alpha = qAlpha(pixel) - delta;
                              if (alpha < 0)
                                    alpha = 0;
                              *scanLine = qRgba(qRed(255-pixel), qGreen(255-pixel), qBlue(255-pixel), alpha);
                              ++scanLine;
                              }
                        }
                  }
            else {
                  for (int y = 0; y < img.height(); ++y) {
                        QRgb *scanLine = (QRgb*)img.scanLine(y);
                        for (int x = 0; x < img.width(); ++x) {
                              QRgb pixel = *scanLine;
                              int alpha = qAlpha(pixel) - delta;
                              if (alpha < 0)
                                    alpha = 0;
                              *scanLine = qRgba(qRed(pixel), qGreen(pixel), qBlue(pixel), alpha);
//.........这里部分代码省略.........
开发者ID:alekseyrum,项目名称:MuseScore,代码行数:101,代码来源:miconengine.cpp

示例13: modifier

QImage *ConvertThread::loadSvgImage(const QString &imagePath)
{
    QSvgRenderer renderer;
    if (shared.svgModifiersEnabled) {
        SvgModifier modifier(pd.imagePath);
        // modify SVG file
        if (!shared.svgRemoveTextString.isNull())
            modifier.removeText(shared.svgRemoveTextString);
        if (shared.svgRemoveEmptyGroup)
            modifier.removeEmptyGroups();
        // save SVG file
        if (shared.svgSave) {
            QString svgTargetFileName =
                    targetFilePath.left(targetFilePath.lastIndexOf('.')+1) + "svg";
            QFile file(svgTargetFileName);
            // ask overwrite
            if (file.exists()) {
                shared.mutex.lock();
                emit question(svgTargetFileName, Overwrite);
                shared.mutex.unlock();
            }
            if (shared.overwriteResult == QMessageBox::Yes ||
                    shared.overwriteResult == QMessageBox::YesToAll) {
                if (!file.open(QIODevice::WriteOnly)) {
                    emit imageStatus(pd.imgData, tr("Failed to save new SVG file"),
                                     Failed);
                    return NULL;
                }
                file.write(modifier.content());
            }
        }
        // and load QByteArray buffer to renderer
        if (!renderer.load(modifier.content())) {
            emit imageStatus(pd.imgData, tr("Failed to open changed SVG file"),
                             Failed);
            return NULL;
        }
    }
    else if (!renderer.load(pd.imagePath)) {
        emit imageStatus(pd.imgData, tr("Failed to open SVG file"), Failed);
        return NULL;
    }
    sizeComputed = computeSize(&renderer, pd.imagePath);
    if (sizeComputed == 2)
        return NULL;
    // keep aspect ratio
    if (shared.maintainAspect) {
        qreal w = width;
        qreal h = height;
        qreal targetRatio = w / h;
        QSizeF svgSize = renderer.defaultSize();
        qreal currentRatio = svgSize.width() / svgSize.height();
        if (currentRatio != targetRatio) {
            qreal diffRatio;
            if (currentRatio > targetRatio)
                diffRatio = w / svgSize.width();
            else
                diffRatio = h / svgSize.height();
            width = diffRatio * svgSize.width();
            height = diffRatio * svgSize.height();
        }
    }
    // create image
    QImage *img = new QImage(width, height, QImage::Format_ARGB32);
    fillImage(img);
    QPainter painter(img);
    renderer.render(&painter);
    // don't scale rendered image
    hasWidth = false;
    hasHeight = false;
    // finaly return the image pointer
    return img;
}
开发者ID:marek629,项目名称:SIR,代码行数:73,代码来源:ConvertThread.cpp

示例14: requestImage

/**
   Supported id format: fileName[!elementName[?parameters]]
   where parameters may be:
   vslice=1:2;hslice=2:4 - use the 3rd horizontal slice of total 4 slices, slice numbering starts from 0
   borders=1 - 1 pixel wide transparent border

   requestedSize is related to the whole element size, even if slice is requested.

   usage:

   Image {
       source: "image://svg/pfd.svg!world"
   }
*/
QImage SvgImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
    QString svgFile = id;
    QString element;
    QString parameters;

    int separatorPos = id.indexOf('!');
    if (separatorPos != -1) {
        svgFile = id.left(separatorPos);
        element = id.mid(separatorPos+1);
    }

    int parametersPos = element.indexOf('?');
    if (parametersPos != -1) {
        parameters = element.mid(parametersPos+1);
        element = element.left(parametersPos);
    }

    int hSlicesCount = 0;
    int hSlice = 0;
    int vSlicesCount = 0;
    int vSlice = 0;
    int border = 0;
    if (!parameters.isEmpty()) {
        QRegExp hSliceRx("hslice=(\\d+):(\\d+)");
        if (hSliceRx.indexIn(parameters) != -1) {
            hSlice = hSliceRx.cap(1).toInt();
            hSlicesCount = hSliceRx.cap(2).toInt();
        }
        QRegExp vSliceRx("vslice=(\\d+):(\\d+)");
        if (vSliceRx.indexIn(parameters) != -1) {
            vSlice = vSliceRx.cap(1).toInt();
            vSlicesCount = vSliceRx.cap(2).toInt();
        }
        QRegExp borderRx("border=(\\d+)");
        if (borderRx.indexIn(parameters) != -1) {
            border = borderRx.cap(1).toInt();
        }
    }

    if (size)
        *size = QSize();

    QSvgRenderer *renderer = loadRenderer(svgFile);
    if (!renderer)
        return QImage();

    qreal xScale = 1.0;
    qreal yScale = 1.0;

    QSize docSize = renderer->defaultSize();

    if (!requestedSize.isEmpty()) {
        if (!element.isEmpty()) {
            QRectF elementBounds = renderer->boundsOnElement(element);
            xScale = qreal(requestedSize.width())/elementBounds.width();
            yScale = qreal(requestedSize.height())/elementBounds.height();
        } else if (!docSize.isEmpty()) {
            xScale = qreal(requestedSize.width())/docSize.width();
            yScale = qreal(requestedSize.height())/docSize.height();
        }
    }

    //keep the aspect ratio
    //TODO: how to configure it? as a part of image path?
    xScale = yScale = qMin(xScale, yScale);

    if (!element.isEmpty()) {
        if (!renderer->elementExists(element)) {
            qWarning() << "invalid element:" << element << "of" << svgFile;
            return QImage();
        }

        QRectF elementBounds = renderer->boundsOnElement(element);
        int elementWidth = qRound(elementBounds.width() * xScale);
        int elementHeigh = qRound(elementBounds.height() * yScale);
        int w = elementWidth;
        int h = elementHeigh;
        int x = 0;
        int y = 0;

        if (hSlicesCount > 1) {
            x = (w*hSlice)/hSlicesCount;
            w = (w*(hSlice+1))/hSlicesCount - x;
        }

//.........这里部分代码省略.........
开发者ID:Trex4Git,项目名称:dRonin,代码行数:101,代码来源:svgimageprovider.cpp

示例15: pixmap

QPixmap QgsGrassModule::pixmap( QString path, int height )
{
  //QgsDebugMsg( QString( "path = %1" ).arg( path ) );

  QList<QPixmap> pixmaps;

  // Create vector of available pictures
  int cnt = 1;
  for ( ;; )
  {
    // SVG
    QString fpath = path + "." + QString::number( cnt ) + ".svg";
    QFileInfo fi( fpath );
    if ( fi.exists() )
    {
      QSvgRenderer pic;
      if ( ! pic.load( fpath ) )
        break;

      QRect br( QPoint( 0, 0 ), pic.defaultSize() );

      double scale = 1. * height / br.height();

      int width = ( int )( scale * br.width() );
      if ( width <= 0 )
        width = height; // should not happen
      QPixmap pixmap( width, height );
      pixmap.fill( Qt::transparent );
      //pixmap.fill( QColor( 255, 255, 255 ) );
      QPainter painter( &pixmap );
      painter.setRenderHint( QPainter::Antialiasing );

      pic.render( &painter );
      painter.end();

      pixmaps << pixmap;
    }
    else // PNG
    {
      fpath = path + "." + QString::number( cnt ) + ".png";
      fi.setFile( fpath );

      if ( !fi.exists() )
        break;

      QPixmap pixmap;

      if ( ! pixmap.load( fpath, "PNG" ) )
        break;

      double scale = 1. * height / pixmap.height();
      int width = ( int )( scale * pixmap.width() );

      QImage img = pixmap.toImage();
      img = img.scaled( width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
      pixmap = QPixmap::fromImage( img );

      pixmaps.push_back( pixmap );
    }
    cnt++;
  }

  if ( pixmaps.isEmpty() )
  {
    return QPixmap();
  }

  // Get total width
  int width = 0;
  for ( int i = 0; i < pixmaps.size(); i++ )
  {
    width += pixmaps[i].width();
  }

  if ( width <= 0 )
    width = height; //should not happen

  QString iconsPath = QgsApplication::pkgDataPath() + "/grass/modules/";
  QFileInfo iconsfi( iconsPath );

  int plusWidth = 8;
  int arrowWidth = 9;

  QString arrowPath = iconsPath + "grass_arrow.png";
  QPixmap arrowPixmap;
  iconsfi.setFile( arrowPath );
  if ( iconsfi.exists() && arrowPixmap.load( arrowPath, "PNG" ) )
  {
    double scale = 1. * height / arrowPixmap.height();
    arrowWidth = ( int )( scale * arrowPixmap.width() );

    QImage img = arrowPixmap.toImage();
    img = img.scaled( arrowWidth, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation );
    arrowPixmap = QPixmap::fromImage( img );
  }
#if 0
  if ( iconsfi.exists() )
  {
    QSvgRenderer pic;
    if ( pic.load( arrowPath ) )
//.........这里部分代码省略.........
开发者ID:exlimit,项目名称:QGIS,代码行数:101,代码来源:qgsgrassmodule.cpp


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