bool parseFeature(QDomElement& e, Layer* aLayer) { bool ret= false; QDomElement c = e.cloneNode().toElement(); while(!c.isNull()) { if (c.tagName() == "Placemark") ret = parsePlacemark(c, aLayer); else ret = parseContainer(c, aLayer); c = c.nextSiblingElement(); } return ret; }
void Model::parseContainer() { if (!m_container.isNull()) { QBuffer model(&m_container); model.open(QIODevice::ReadOnly); QIODevice *filter = KFilterDev::device(&model, "application/x-gzip", false /* will be deleted when unwinding stack */); filter->open(QIODevice::ReadOnly); QByteArray uncompressed = filter->readAll(); delete filter; //KTar doesn't work with KFilterDev for some reason... QBuffer uncompressedModel(&uncompressed); uncompressedModel.open(QIODevice::ReadOnly); KTar archive(&uncompressedModel); parseContainer(archive, m_modelCreationDate, m_modelName, m_type); } m_containerParsed = true; }
static void parseWindow(){ // option defaults bool fullScreen = false; // should it be fullscreen? bool disabled = false; // what size? (default is fit around widgets. Ignored for fullscreen.) int width=-1,height=-1; // if set, move the window to a screen of the given dimensions int swidth=-1,sheight=-1; // title if any char title[256]; // "tab" number - used to generate a shortcut to pull this window // to the front int number=-1; title[0]=0; int screensetline=-1; // set this window to not inverse ConfigManager::inverse=false; // get window options bool done = false; while(!done){ switch(tok.getnext()){ case T_OCURLY: done = true; break; case T_TITLE: tok.getnextstring(title); break; case T_NUMBER: number = tok.getnextint(); break; case T_INVERSE: ConfigManager::inverse=true; break; case T_FULLSCREEN: fullScreen = true; break; case T_SIZE: // size of window if not fullscreen width = tok.getnextint(); tok.getnextcheck(T_COMMA); height = tok.getnextint(); break; case T_SCREEN: // move to a screen of given dimensions swidth = tok.getnextint(); tok.getnextcheck(T_COMMA); screensetline = tok.getline(); sheight = tok.getnextint(); break; case T_DISABLE: // the window is disabled and should be immediately closed disabled=true; break; } } // create a window Window *w = getApp()->createWindow(); if(number>=0) getApp()->setWindowKey(number,w); ConfigManager::setStyle(w); // and parse the contents parseContainer(w->centralWidget()); if(*title){ w->setWindowTitle(title); } // move the window if we want to if(swidth>0){ QDesktopWidget *dt = QApplication::desktop(); QRect r; int i; for(i=0;i<dt->screenCount();i++){ r = dt->screenGeometry(i); printf("Found display : %d x %d\n",r.width(),r.height()); if(r.width() == swidth && r.height()==sheight) break; } if(i==dt->screenCount()) throw Exception(screensetline).set("could not find display of %d x %d",swidth,sheight); w->move(r.topLeft()); } // finally show the window and resize if required if(disabled){ w->hide(); // marked "disabled" in the config } else { w->setWindowState(Qt::WindowActive); w->raise(); w->activateWindow(); if(fullScreen){ w->showFullScreen(); } else { if(width>0) w->resize(width,height); w->showNormal(); } } }
static void parseFrame(QWidget *parent){ // first parse the pos block ConfigRect pos = ConfigManager::parseRect(); // followed by some optional stuff bool borderless=false; int spacing=2; bool done=false; char label[256]; bool hasLabel=false; while(!done){ switch(tok.getnext()){ case T_BORDERLESS: borderless=true; break; case T_LABEL: if(!tok.getnextstring(label)) throw UnexpException(&tok,"frame label"); hasLabel=true; break; case T_SPACING: spacing=tok.getnextint(); break; case T_OCURLY: done = true; break; default: throw UnexpException(&tok,"frame option or {"); } } // create frame and layout QFrame *f = new QFrame; f->setFrameStyle(borderless? QFrame::NoFrame: QFrame::Panel); QGridLayout *l = new QGridLayout; l->setSpacing(spacing); f->setLayout(l); parseContainer(f); // if there's a label, we need a containing vbox if(hasLabel){ QFrame *cont = new QFrame; QVBoxLayout *bl = new QVBoxLayout; cont->setLayout(bl); QLabel *lab = new QLabel(label); lab->setMaximumSize(10000,20); bl->addWidget(lab); bl->addWidget(f); f=cont; } // add to the parent's layout ((QGridLayout*)parent->layout())->addWidget(f,pos.y,pos.x,pos.h,pos.w); }
QString Model::modelName() { if (!m_containerParsed) parseContainer(); return m_modelName; }
QDateTime Model::modelCreationDate() { if (!m_containerParsed) parseContainer(); return m_modelCreationDate; }
void SvgParser::applyFillStyle(KoShape *shape) { SvgGraphicsContext *gc = m_context.currentGC(); if (! gc) return; if (gc->fillType == SvgGraphicsContext::None) { shape->setBackground(QSharedPointer<KoShapeBackground>(0)); } else if (gc->fillType == SvgGraphicsContext::Solid) { shape->setBackground(QSharedPointer<KoColorBackground>(new KoColorBackground(gc->fillColor))); } else if (gc->fillType == SvgGraphicsContext::Complex) { // try to find referenced gradient SvgGradientHelper *gradient = findGradient(gc->fillId); if (gradient) { // great, we have a gradient fill QSharedPointer<KoGradientBackground> bg; if (gradient->gradientUnits() == SvgGradientHelper::ObjectBoundingBox) { bg = QSharedPointer<KoGradientBackground>(new KoGradientBackground(*gradient->gradient())); bg->setTransform(gradient->transform()); } else { QGradient *convertedGradient = SvgGradientHelper::convertGradient(gradient->gradient(), shape->size()); bg = QSharedPointer<KoGradientBackground>(new KoGradientBackground(convertedGradient)); QTransform invShapematrix = shape->transformation().inverted(); bg->setTransform(gradient->transform() * gc->matrix * invShapematrix); } shape->setBackground(bg); } else { // try to find referenced pattern SvgPatternHelper *pattern = findPattern(gc->fillId); KoImageCollection *imageCollection = m_documentResourceManager->imageCollection(); if (pattern && imageCollection) { // great we have a pattern fill QRectF objectBound = QRectF(QPoint(), shape->size()); QRectF currentBoundbox = gc->currentBoundbox; // properties from the object are not inherited // so we are creating a new context without copying SvgGraphicsContext *gc = m_context.pushGraphicsContext(pattern->content(), false); // the pattern establishes a new coordinate system with its // origin at the patterns x and y attributes gc->matrix = QTransform(); // object bounding box units are relative to the object the pattern is applied if (pattern->patternContentUnits() == SvgPatternHelper::ObjectBoundingBox) { gc->currentBoundbox = objectBound; gc->forcePercentage = true; } else { // inherit the current bounding box gc->currentBoundbox = currentBoundbox; } applyStyle(0, pattern->content()); // parse the pattern content elements QList<KoShape*> patternContent = parseContainer(pattern->content()); // generate the pattern image from the shapes and the object bounding rect QImage image = pattern->generateImage(objectBound, patternContent); m_context.popGraphicsContext(); // delete the shapes created from the pattern content qDeleteAll(patternContent); if (!image.isNull()) { QSharedPointer<KoPatternBackground> bg(new KoPatternBackground(imageCollection)); bg->setPattern(image); QPointF refPoint = shape->documentToShape(pattern->position(objectBound)); QSizeF tileSize = pattern->size(objectBound); bg->setPatternDisplaySize(tileSize); if (pattern->patternUnits() == SvgPatternHelper::ObjectBoundingBox) { if (tileSize == objectBound.size()) bg->setRepeat(KoPatternBackground::Stretched); } // calculate pattern reference point offset in percent of tileSize // and relative to the topleft corner of the shape qreal fx = refPoint.x() / tileSize.width(); qreal fy = refPoint.y() / tileSize.height(); if (fx < 0.0) fx = floor(fx); else if (fx > 1.0) fx = ceil(fx); else fx = 0.0; if (fy < 0.0) fy = floor(fy); else if (fx > 1.0) fy = ceil(fy); else fy = 0.0; qreal offsetX = 100.0 * (refPoint.x() - fx * tileSize.width()) / tileSize.width(); qreal offsetY = 100.0 * (refPoint.y() - fy * tileSize.height()) / tileSize.height(); bg->setReferencePointOffset(QPointF(offsetX, offsetY)); shape->setBackground(bg); } } else { // no referenced fill found, use fallback color shape->setBackground(QSharedPointer<KoColorBackground>(new KoColorBackground(gc->fillColor))); } } } KoPathShape *path = dynamic_cast<KoPathShape*>(shape); if (path) path->setFillRule(gc->fillRule); }