diff -r 25ee6b988b73 -r 8f987e376035 exports.cpp --- a/exports.cpp Tue Dec 15 09:14:59 2009 +0000 +++ b/exports.cpp Mon Jan 04 20:36:06 2010 +0000 @@ -14,6 +14,23 @@ ExportBase::ExportBase() { + init(); +} + +ExportBase::ExportBase(VymModel *m) +{ + init(); + model=m; +} + +ExportBase::~ExportBase() +{ + // Cleanup tmpdir + removeDir (tmpDir); +} + +void ExportBase::init() +{ indentPerDepth=" "; bool ok; tmpDir.setPath (makeTmpDir(ok,"vym-export")); @@ -23,12 +40,6 @@ cancelFlag=false; } -ExportBase::~ExportBase() -{ - // Cleanup tmpdir - removeDir (tmpDir); -} - void ExportBase::setDir(const QDir &d) { outDir=d; @@ -262,7 +273,7 @@ { // Make indentstring curIndent=""; - for (i=0;idepth()-1;i++) curIndent+= indentPerDepth; + for (i=1;idepth()-1;i++) curIndent+= indentPerDepth; if (!cur->hasHiddenExportParent() ) { @@ -460,6 +471,176 @@ } //////////////////////////////////////////////////////////////////////// +ExportHTML::ExportHTML():ExportBase() +{ + init(); +} + +ExportHTML::ExportHTML(VymModel *m):ExportBase(m) +{ + init(); +} + +void ExportHTML::init() +{ + singularDelimiter=": "; + noSingulars=true; + frameURLs=true; + useMapColors=true; + + if (model &&model->getMapEditor()) + offset=model->getMapEditor()->getTotalBBox().topLeft(); +} + +QString ExportHTML::getBranchText(BranchItem *current) +{ + if (current) + { + bool vis=false; + QRectF hr; + LinkableMapObj *lmo=current->getLMO(); + if (lmo) + { + hr=((BranchObj*)lmo)->getBBoxHeading(); + if (lmo->isVisibleObj()) vis=true; + } + QString col; + QString id=model->getSelectString(current); + if (useMapColors) + col=QString("style='color:%1'").arg(current->getHeadingColor().name()); + QString s=QString("") + .arg(current->depth()) + .arg(col) + .arg(id); + QString url=current->getURL(); + if (!url.isEmpty()) + { + s+=QString ("").arg(url); + s+=QString ("%1").arg(quotemeta(current->getHeading())); + s+=""; + + QRectF fbox=current->getBBoxFlag ("system-url"); + if (vis) + imageMap+=QString(" \n") + .arg(fbox.left()-offset.x()) + .arg(fbox.top()-offset.y()) + .arg(fbox.right()-offset.x()) + .arg(fbox.bottom()-offset.y()) + .arg(url); + } else + s+=quotemeta(current->getHeading()); + s+=""; + + if (vis) + imageMap+=QString(" \n") + .arg(hr.left()-offset.x()) + .arg(hr.top()-offset.y()) + .arg(hr.right()-offset.x()) + .arg(hr.bottom()-offset.y()) + .arg(id); + + // Include note + if (!current->getNoteObj().isEmpty()) + s+="
"+current->getNote()+"
"; + + return s; + } + return QString(); +} + +QString ExportHTML::buildList (BranchItem *current) +{ + QString r; + + uint i=0; + BranchItem *bi=current->getFirstBranch(); + + // Only add itemized list, if we have more than one subitem. + // For only one subitem, just add a separator to keep page more compact + bool noSingularsHere=false; + if (current->branchCount()<2 && noSingulars) noSingularsHere=true; + + if (bi) + { + if (!noSingularsHere) + r+="\n"; + } + return r; +} + +void ExportHTML::doExport() +{ + QFile file (outputFile); + if ( !file.open( QIODevice::WriteOnly ) ) + { + QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile)); + mainWindow->statusMessage(QString(QObject::tr("Export failed."))); + return; + } + QTextStream ts( &file ); // use LANG decoding here... + ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8 + + // Write header + ts<<""+model->getMapName()<<""; + ts<<" \n"; + + // Include image + ts<<"
\n"; + + + // Main loop over all mapcenters + QString s; + TreeItem *rootItem=model->getRootItem(); + BranchItem *bi; + for (int i=0; ibranchCount(); i++) + { + bi=rootItem->getBranchNum(i); + if (!bi->hasHiddenExportParent()) + { + ts<\n"+imageMap+"\n"; + + // Write footer + ts<<"
\n"; + ts<<" \n\ + \n\ + \n\ + \n\ + \n\ + \n \ +
"+model->getFileName()+""+model->getDate()+" vym "+model->getVersion()+"
\n"; + ts<<""; + file.close(); +} + +//////////////////////////////////////////////////////////////////////// void ExportTaskjuggler::doExport() { model->exportXML(tmpDir.path(),false); @@ -550,11 +731,11 @@ BranchItem *bi=current->getFirstBranch(); if (bi) { - if (!bi->hasHiddenExportParent() ) // FIXME-3 use BranchItem... + // Start list + r+="\n"; + while (bi) { - // Start list - r+="\n"; - while (bi) + if (!bi->hasHiddenExportParent() ) { r+=""; r+=quotemeta(bi->getHeading()); @@ -564,11 +745,11 @@ r+=""; r+=buildList (bi); // recursivly add deeper branches r+="\n"; - i++; - bi=current->getBranchNum(i); } - r+="\n"; + i++; + bi=current->getBranchNum(i); } + r+="\n"; } return r; }