/*! 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(); }
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; }
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; }
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 ); } }
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); } }
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; }
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(); }
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; }
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; }
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; }
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); }
bool SvgRenderer::load(const QString &filename) { if (renderer.load(filename) && renderer.isValid()) return true; return false; }
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; }
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 {
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; }
// 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); } }
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(); }
int KGameRenderer::frameCount(const QString& key) const { //ensure that some theme is loaded if (!d->m_currentTheme) { d->_k_setTheme(d->m_provider->currentTheme()); } //look up in in-process cache QHash<QString, int>::const_iterator it = d->m_frameCountCache.constFind(key); if (it != d->m_frameCountCache.constEnd()) { return it.value(); } //look up in shared cache (if SVG is not yet loaded) int count = -1; bool countFound = false; const QString cacheKey = d->m_frameCountPrefix + key; if (d->m_rendererPool.hasAvailableRenderers() && (d->m_strategies & KGameRenderer::UseDiskCache)) { QByteArray buffer; if (d->m_imageCache->find(cacheKey, &buffer)) { count = buffer.toInt(); countFound = true; } } //determine from SVG if (!countFound) { QSvgRenderer* renderer = d->m_rendererPool.allocRenderer(); //look for animated sprite first count = d->m_frameBaseIndex; while (renderer->elementExists(d->spriteFrameKey(key, count, false))) { ++count; } count -= d->m_frameBaseIndex; //look for non-animated sprite instead if (count == 0) { if (!renderer->elementExists(key)) { count = -1; } } d->m_rendererPool.freeRenderer(renderer); //save in shared cache for following requests if (d->m_strategies & KGameRenderer::UseDiskCache) { d->m_imageCache->insert(cacheKey, QByteArray::number(count)); } } d->m_frameCountCache.insert(key, count); return count; }
QSvgRenderer* DiagramView::getSvgRenderer(QString filePath) { if (!_svgRendererPool.contains(filePath)) { QSvgRenderer* renderer = new QSvgRenderer(filePath); renderer->setViewBox(renderer->viewBox().adjusted( -NodeItem::OFFSET, -NodeItem::OFFSET, NodeItem::OFFSET, NodeItem::OFFSET)); _svgRendererPool.insert(filePath, renderer); } return _svgRendererPool.value(filePath); }
bool QSvgIOHandlerPrivate::load(QIODevice *device) { if (loaded) return true; if (r->load(device->readAll())) { defaultSize = QSize(r->viewBox().width(), r->viewBox().height()); if (currentSize.isEmpty()) currentSize = defaultSize; } loaded = r->isValid(); return loaded; }
/* * 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")); } }
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))); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); //! [0] QSvgWidget window(":/files/spheres.svg"); window.show(); //! [0] QSvgRenderer *renderer = window.renderer(); QImage image(150, 150, QImage::Format_RGB32); QPainter painter; painter.begin(&image); renderer->render(&painter); painter.end(); image.save("spheres.png", "PNG", 9); return app.exec(); }
void QgsComposerArrow::setEndMarker( const QString& svgPath ) { QSvgRenderer r; mEndMarkerFile = svgPath; if ( svgPath.isEmpty() || !r.load( svgPath ) ) { mStopArrowHeadHeight = 0; } else { //calculate mArrowHeadHeight from svg file and mArrowHeadWidth QRect viewBox = r.viewBox(); mStopArrowHeadHeight = mArrowHeadWidth / viewBox.width() * viewBox.height(); } adaptItemSceneRect(); }
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); }
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(); }
const QImage gradientImage(DesignElementType type) { QSvgRenderer *renderer = designRenderer(); const QString gradientId = idPrefix + (type == DesignElementTypeButton ? buttonString : frameString) + QStringLiteral("gradient"); Q_ASSERT(renderer->boundsOnElement(gradientId).size().toSize() == QSize(256, 1)); QImage result(256, 1, QImage::Format_ARGB32); result.fill(0); QPainter p(&result); renderer->render(&p, gradientId, result.rect()); #if 0 // for debugging p.fillRect(0, 0, 16, 1, Qt::red); p.fillRect(120, 0, 16, 1, Qt::green); p.fillRect(240, 0, 16, 1, Qt::blue); #endif return result; }
/* * 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); }
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; }
void QStarPawn::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QGraphicsEllipseItem::paint(painter, option, widget); if (_isStarOn) { QSvgRenderer *renderer = new QSvgRenderer(QString(":/resources/star.svg")); QGraphicsSvgItem *star = new QGraphicsSvgItem(); star->setSharedRenderer(renderer); renderer->render(painter, boundingRect()); } }