exports.cpp
changeset 819 8f987e376035
parent 818 25ee6b988b73
child 822 c2ce9944148c
     1.1 --- a/exports.cpp	Tue Dec 15 09:14:59 2009 +0000
     1.2 +++ b/exports.cpp	Mon Jan 04 20:36:06 2010 +0000
     1.3 @@ -14,6 +14,23 @@
     1.4  
     1.5  ExportBase::ExportBase()
     1.6  {
     1.7 +	init();
     1.8 +}
     1.9 +
    1.10 +ExportBase::ExportBase(VymModel *m)
    1.11 +{
    1.12 +	init();
    1.13 +	model=m;
    1.14 +}
    1.15 +
    1.16 +ExportBase::~ExportBase()
    1.17 +{
    1.18 +	// Cleanup tmpdir
    1.19 +	removeDir (tmpDir);
    1.20 +}
    1.21 +
    1.22 +void ExportBase::init()
    1.23 +{
    1.24  	indentPerDepth="  ";
    1.25  	bool ok;
    1.26      tmpDir.setPath (makeTmpDir(ok,"vym-export"));
    1.27 @@ -23,12 +40,6 @@
    1.28  	cancelFlag=false;				   
    1.29  }
    1.30  
    1.31 -ExportBase::~ExportBase()
    1.32 -{
    1.33 -	// Cleanup tmpdir
    1.34 -	removeDir (tmpDir);
    1.35 -}
    1.36 -
    1.37  void ExportBase::setDir(const QDir &d)
    1.38  {
    1.39  	outDir=d;
    1.40 @@ -262,7 +273,7 @@
    1.41  		{
    1.42  			// Make indentstring
    1.43  			curIndent="";
    1.44 -			for (i=0;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
    1.45 +			for (i=1;i<cur->depth()-1;i++) curIndent+= indentPerDepth;
    1.46  
    1.47  			if (!cur->hasHiddenExportParent() )
    1.48  			{
    1.49 @@ -460,6 +471,176 @@
    1.50  }
    1.51  
    1.52  ////////////////////////////////////////////////////////////////////////
    1.53 +ExportHTML::ExportHTML():ExportBase()
    1.54 +{
    1.55 +	init();
    1.56 +}
    1.57 +
    1.58 +ExportHTML::ExportHTML(VymModel *m):ExportBase(m)
    1.59 +{
    1.60 +	init();
    1.61 +}
    1.62 +
    1.63 +void ExportHTML::init()
    1.64 +{
    1.65 +	singularDelimiter=": ";
    1.66 +	noSingulars=true;	
    1.67 +	frameURLs=true;
    1.68 +	useMapColors=true;
    1.69 +
    1.70 +	if (model &&model->getMapEditor()) 
    1.71 +		offset=model->getMapEditor()->getTotalBBox().topLeft();
    1.72 +}
    1.73 +
    1.74 +QString ExportHTML::getBranchText(BranchItem *current)
    1.75 +{
    1.76 +	if (current)
    1.77 +	{
    1.78 +		bool vis=false;
    1.79 +		QRectF hr;
    1.80 +		LinkableMapObj *lmo=current->getLMO();
    1.81 +		if (lmo)
    1.82 +		{
    1.83 +			hr=((BranchObj*)lmo)->getBBoxHeading();
    1.84 +			if (lmo->isVisibleObj()) vis=true;
    1.85 +		}
    1.86 +		QString col;
    1.87 +		QString id=model->getSelectString(current);
    1.88 +		if (useMapColors)
    1.89 +			col=QString("style='color:%1'").arg(current->getHeadingColor().name());
    1.90 +		QString s=QString("<span class='vym-branch%1' %2 id='%3'>")
    1.91 +			.arg(current->depth())
    1.92 +			.arg(col)
    1.93 +			.arg(id);
    1.94 +		QString url=current->getURL();	
    1.95 +		if (!url.isEmpty())
    1.96 +		{
    1.97 +			s+=QString ("<a href=\"%1\">").arg(url);
    1.98 +			s+=QString ("<img src=\"flags/flag-url-16x16.png\">%1</a>").arg(quotemeta(current->getHeading()));
    1.99 +			s+="</a>";
   1.100 +			
   1.101 +			QRectF fbox=current->getBBoxFlag ("system-url");
   1.102 +			if (vis)
   1.103 +				imageMap+=QString("  <area shape='rect' coords='%1,%2,%3,%4' href='%5'>\n")
   1.104 +					.arg(fbox.left()-offset.x())
   1.105 +					.arg(fbox.top()-offset.y())
   1.106 +					.arg(fbox.right()-offset.x())
   1.107 +					.arg(fbox.bottom()-offset.y())
   1.108 +					.arg(url);
   1.109 +		} else	
   1.110 +			s+=quotemeta(current->getHeading());
   1.111 +		s+="</span>";
   1.112 +
   1.113 +		if (vis)
   1.114 +			imageMap+=QString("  <area shape='rect' coords='%1,%2,%3,%4' href='#%5'>\n")
   1.115 +				.arg(hr.left()-offset.x())
   1.116 +				.arg(hr.top()-offset.y())
   1.117 +				.arg(hr.right()-offset.x())
   1.118 +				.arg(hr.bottom()-offset.y())
   1.119 +				.arg(id);
   1.120 +
   1.121 +		// Include note
   1.122 +		if (!current->getNoteObj().isEmpty())
   1.123 +			s+="<table border=1><tr><td>"+current->getNote()+"</td></tr></table>";
   1.124 +
   1.125 +		return s;
   1.126 +	} 
   1.127 +	return QString();
   1.128 +}
   1.129 +
   1.130 +QString ExportHTML::buildList (BranchItem *current)
   1.131 +{
   1.132 +    QString r;
   1.133 +
   1.134 +    uint i=0;
   1.135 +	BranchItem *bi=current->getFirstBranch();
   1.136 +
   1.137 +	// Only add itemized list, if we have more than one subitem.
   1.138 +	// For only one subitem, just add a separator to keep page more compact
   1.139 +	bool noSingularsHere=false;
   1.140 +	if (current->branchCount()<2 && noSingulars) noSingularsHere=true;
   1.141 +
   1.142 +	if (bi)
   1.143 +    {
   1.144 +		if (!noSingularsHere)
   1.145 +			r+="<ul>\n";
   1.146 +		else
   1.147 +			r+=singularDelimiter;
   1.148 +
   1.149 +		while (bi)
   1.150 +		{
   1.151 +			if (!bi->hasHiddenExportParent() )	
   1.152 +			{
   1.153 +				if (!noSingularsHere) r+="<li>";
   1.154 +				r+=getBranchText (bi);
   1.155 +				if (!bi->getURL().isEmpty() && frameURLs && noSingularsHere)
   1.156 +					// Add frame, if we have subitems to an URL
   1.157 +					r+="<table border=1><tr><td>"+buildList (bi)+"</td></tr></table>";	// recursivly add deeper branches
   1.158 +				else
   1.159 +					r+=buildList (bi);	// recursivly add deeper branches
   1.160 +				if (!noSingularsHere) r+="</li>";
   1.161 +				r+="\n";
   1.162 +			}
   1.163 +			i++;
   1.164 +			bi=current->getBranchNum(i);
   1.165 +		}
   1.166 +
   1.167 +		if (!noSingularsHere) r+="</ul>\n";
   1.168 +	}
   1.169 +    return r;
   1.170 +}
   1.171 +
   1.172 +void ExportHTML::doExport() 
   1.173 +{
   1.174 +	QFile file (outputFile);
   1.175 +	if ( !file.open( QIODevice::WriteOnly ) ) 
   1.176 +	{
   1.177 +		QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
   1.178 +		mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
   1.179 +		return;
   1.180 +	}
   1.181 +	QTextStream ts( &file );	// use LANG decoding here...
   1.182 +	ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
   1.183 +
   1.184 +	// Write header
   1.185 +	ts<<"<html><title>"+model->getMapName()<<"</title><body>";
   1.186 +	ts<<" <link rel='stylesheet' id='css.stylesheet' href='vym.css' />\n";
   1.187 +
   1.188 +	// Include image
   1.189 +	ts<<"<center><img src=\"xxx.png\" usemap='#imagemap'></center>\n";
   1.190 +
   1.191 +
   1.192 +	// Main loop over all mapcenters
   1.193 +	QString s;
   1.194 +	TreeItem *rootItem=model->getRootItem();
   1.195 +	BranchItem *bi;
   1.196 +	for (int i=0; i<rootItem->branchCount(); i++)
   1.197 +	{
   1.198 +		bi=rootItem->getBranchNum(i);
   1.199 +		if (!bi->hasHiddenExportParent())
   1.200 +		{
   1.201 +			ts<<getBranchText (bi);
   1.202 +			ts<<buildList (bi);
   1.203 +		}
   1.204 +	}	
   1.205 +
   1.206 +	// Imagemap
   1.207 +	ts<<"<map name='imagemap'>\n"+imageMap+"</map>\n";
   1.208 +
   1.209 +	// Write footer 
   1.210 +	ts<<"<hr/>\n";
   1.211 +	ts<<"<table class=\"vym-footer\">   \n\
   1.212 +      <tr> \n\
   1.213 +        <td class=\"vym-footerL\">"+model->getFileName()+"</td> \n\
   1.214 +        <td class=\"vym-footerC\">"+model->getDate()+"</td> \n\
   1.215 +        <td class=\"vym-footerR\"> vym "+model->getVersion()+"</td> \n\
   1.216 +      </tr> \n \
   1.217 +    </table>\n";
   1.218 +	ts<<"</body></html>";
   1.219 +	file.close();
   1.220 +}
   1.221 +
   1.222 +////////////////////////////////////////////////////////////////////////
   1.223  void ExportTaskjuggler::doExport() 
   1.224  {
   1.225  	model->exportXML(tmpDir.path(),false);
   1.226 @@ -550,11 +731,11 @@
   1.227  	BranchItem *bi=current->getFirstBranch();
   1.228  	if (bi)
   1.229      {
   1.230 -		if (!bi->hasHiddenExportParent() )	// FIXME-3 use BranchItem...
   1.231 +		// Start list
   1.232 +		r+="<text:list text:style-name=\"vym-list\">\n";
   1.233 +		while (bi)
   1.234  		{
   1.235 -			// Start list
   1.236 -			r+="<text:list text:style-name=\"vym-list\">\n";
   1.237 -			while (bi)
   1.238 +			if (!bi->hasHiddenExportParent() )	
   1.239  			{
   1.240  				r+="<text:list-item><text:p >";
   1.241  				r+=quotemeta(bi->getHeading());
   1.242 @@ -564,11 +745,11 @@
   1.243  				r+="</text:p>";
   1.244  				r+=buildList (bi);	// recursivly add deeper branches
   1.245  				r+="</text:list-item>\n";
   1.246 -				i++;
   1.247 -				bi=current->getBranchNum(i);
   1.248  			}
   1.249 -			r+="</text:list>\n";
   1.250 +			i++;
   1.251 +			bi=current->getBranchNum(i);
   1.252  		}
   1.253 +		r+="</text:list>\n";
   1.254      }
   1.255      return r;
   1.256  }