exports.cpp
author insilmaril
Tue, 03 Jan 2006 09:44:41 +0000
changeset 167 f7efd8c7c407
parent 163 30b22f7bd009
child 171 a98a07994eed
permissions -rw-r--r--
1.7.6 New features for floatimages and fixes
insilmaril@0
     1
#include "exports.h"
insilmaril@0
     2
insilmaril@131
     3
#include <qregexp.h>
insilmaril@131
     4
insilmaril@0
     5
#include "linkablemapobj.h"
insilmaril@131
     6
#include "texteditor.h"
insilmaril@0
     7
insilmaril@0
     8
insilmaril@0
     9
Export::Export()
insilmaril@0
    10
{
insilmaril@0
    11
	indentPerDepth="  ";
insilmaril@0
    12
}
insilmaril@0
    13
insilmaril@0
    14
void Export::setPath (const QString &p)
insilmaril@0
    15
{
insilmaril@0
    16
	filepath=p;
insilmaril@0
    17
}
insilmaril@0
    18
insilmaril@0
    19
void Export::setMapCenter(MapCenterObj *mc)
insilmaril@0
    20
{
insilmaril@0
    21
	mapCenter=mc;
insilmaril@0
    22
}
insilmaril@0
    23
insilmaril@163
    24
QString Export::getSectionString(BranchObj *bostart)
insilmaril@163
    25
{
insilmaril@163
    26
	QString r;
insilmaril@163
    27
	BranchObj *bo=bostart;
insilmaril@163
    28
	int depth=bo->getDepth();
insilmaril@163
    29
	while (depth>0)
insilmaril@163
    30
	{
insilmaril@163
    31
		r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
insilmaril@163
    32
		bo=(BranchObj*)(bo->getParObj());
insilmaril@163
    33
		depth=bo->getDepth();
insilmaril@163
    34
	}	
insilmaril@163
    35
	if (r.isEmpty())
insilmaril@163
    36
		return r;
insilmaril@163
    37
	else	
insilmaril@163
    38
		return r + " ";
insilmaril@163
    39
}
insilmaril@163
    40
insilmaril@0
    41
void Export::exportMap()
insilmaril@0
    42
{
insilmaril@0
    43
	QFile file (filepath);
insilmaril@0
    44
	if ( !file.open( IO_WriteOnly ) )
insilmaril@0
    45
	{
insilmaril@131
    46
		// FIXME experimental, testing
insilmaril@0
    47
		cout << "Export::exportMap  couldn't open "<<filepath<<endl;
insilmaril@0
    48
		return;
insilmaril@0
    49
	}
insilmaril@0
    50
	QTextStream ts( &file );	// use LANG decoding here...
insilmaril@0
    51
insilmaril@0
    52
	// Main loop over all branches
insilmaril@0
    53
	QString s;
insilmaril@0
    54
	QString actIndent("");
insilmaril@160
    55
	int i;
insilmaril@160
    56
	uint j;
insilmaril@0
    57
	BranchObj *bo;
insilmaril@0
    58
	bo=mapCenter->first();
insilmaril@0
    59
	while (bo) 
insilmaril@0
    60
	{
insilmaril@0
    61
		// Make indentstring
insilmaril@0
    62
		for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
insilmaril@0
    63
insilmaril@0
    64
		// Write heading
insilmaril@0
    65
		//	write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
insilmaril@131
    66
		if (bo->getDepth()==0)
insilmaril@131
    67
		{
insilmaril@131
    68
			ts << (bo->getHeading()+ "\n");
insilmaril@160
    69
			for (j=0;j<bo->getHeading().length();j++) ts<<"=";
insilmaril@131
    70
			ts << "\n";
insilmaril@131
    71
		} else 	if (bo->getDepth()==1)
insilmaril@131
    72
			ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
insilmaril@131
    73
		else	if (bo->getDepth()==2)
insilmaril@131
    74
			ts << (actIndent + " o " + bo->getHeading()+ "\n");
insilmaril@0
    75
		else	
insilmaril@0
    76
			ts << (actIndent + " - " + bo->getHeading()+ "\n");
insilmaril@0
    77
		
insilmaril@0
    78
		// If necessary, write note
insilmaril@0
    79
		if (!bo->getNote().isEmpty())
insilmaril@0
    80
		{
insilmaril@131
    81
			s =textConvertToASCII(bo->getNote());
insilmaril@131
    82
			s=s.replace ("\n","\n"+actIndent);
insilmaril@131
    83
			ts << (s+"\n\n");
insilmaril@0
    84
		}
insilmaril@0
    85
		
insilmaril@0
    86
		bo=bo->next();
insilmaril@0
    87
		actIndent="";
insilmaril@0
    88
	}
insilmaril@0
    89
	file.close();
insilmaril@0
    90
}
insilmaril@0
    91
insilmaril@163
    92
// Exports a map to a LaTex file.  This file needs to be included or inported into a LaTex document
insilmaril@163
    93
// it will not add a preamble, or anything that makes a full LaTex document.
insilmaril@163
    94
void Export::exportLaTeX() 
insilmaril@0
    95
{
insilmaril@163
    96
  QFile file (filepath);
insilmaril@163
    97
  if ( !file.open( IO_WriteOnly ) ) {
insilmaril@163
    98
    // FIXME
insilmaril@163
    99
    cout << "Export::exportMap  couldn't open "<<filepath<<endl;
insilmaril@163
   100
    return;
insilmaril@163
   101
  }
insilmaril@163
   102
  QTextStream ts( &file );	// use LANG decoding here...
insilmaril@163
   103
  ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
insilmaril@163
   104
  
insilmaril@163
   105
  // Main loop over all branches
insilmaril@163
   106
  QString s;
insilmaril@163
   107
  // QString actIndent("");
insilmaril@163
   108
  // int i;
insilmaril@163
   109
  BranchObj *bo;
insilmaril@163
   110
  bo=mapCenter->first();
insilmaril@163
   111
  while (bo) {
insilmaril@163
   112
    if (bo->getDepth()==0);
insilmaril@163
   113
    else if (bo->getDepth()==1) {
insilmaril@163
   114
      ts << ("\\chapter{" + bo->getHeading()+ "}\n");
insilmaril@163
   115
    }
insilmaril@163
   116
    else if (bo->getDepth()==2) {
insilmaril@163
   117
      ts << ("\\section{" + bo->getHeading()+ "}\n");
insilmaril@163
   118
    }
insilmaril@163
   119
    else if (bo->getDepth()==3) {
insilmaril@163
   120
      ts << ("\\subsection{" + bo->getHeading()+ "}\n");
insilmaril@163
   121
    }
insilmaril@163
   122
    else if (bo->getDepth()==4) {
insilmaril@163
   123
      ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
insilmaril@163
   124
    }
insilmaril@163
   125
    else {
insilmaril@163
   126
      ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
insilmaril@163
   127
    }
insilmaril@163
   128
    
insilmaril@163
   129
    // If necessary, write note
insilmaril@163
   130
    if (!bo->getNote().isEmpty()) {
insilmaril@163
   131
      ts << (textConvertToASCII(bo->getNote()));
insilmaril@163
   132
      ts << ("\n");
insilmaril@163
   133
    }
insilmaril@163
   134
    
insilmaril@163
   135
    bo=bo->next();
insilmaril@163
   136
   }
insilmaril@163
   137
  file.close();
insilmaril@0
   138
}
insilmaril@0
   139
insilmaril@163
   140
#include "settings.h"
insilmaril@163
   141
insilmaril@163
   142
void Export::exportOOPresentation()
insilmaril@163
   143
{
insilmaril@163
   144
	QString templateDir="oo-test/suse-template/";
insilmaril@163
   145
	QString templateContent="content.xml";
insilmaril@163
   146
	QString tmpDir="/tmp/vym-ootest/";
insilmaril@163
   147
	QString header="";
insilmaril@163
   148
insilmaril@163
   149
insilmaril@163
   150
	// Create tmpdir
insilmaril@163
   151
		// TODO
insilmaril@163
   152
insilmaril@163
   153
	// Copy template to tmpdir
insilmaril@163
   154
		// TODO
insilmaril@163
   155
insilmaril@163
   156
insilmaril@163
   157
	// Read content-template
insilmaril@163
   158
		// TODO
insilmaril@163
   159
	QString content;
insilmaril@163
   160
	if (!loadStringFromDisk (templateDir+templateContent,content))
insilmaril@163
   161
	{
insilmaril@163
   162
		qWarning ("Export::exportOOPresentation() Couldn't load from "+templateDir+templateContent);
insilmaril@163
   163
		return;
insilmaril@163
   164
	}
insilmaril@163
   165
insilmaril@163
   166
insilmaril@163
   167
	// Walk through map
insilmaril@163
   168
	QString s;
insilmaril@163
   169
	QString actIndent("");
insilmaril@163
   170
	uint j;
insilmaril@163
   171
	int i;
insilmaril@163
   172
	BranchObj *bo;
insilmaril@163
   173
	bo=mapCenter->first();
insilmaril@163
   174
	while (bo) 
insilmaril@163
   175
	{
insilmaril@163
   176
		// Make indentstring
insilmaril@163
   177
		for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
insilmaril@163
   178
insilmaril@163
   179
		// Write heading
insilmaril@163
   180
		//	write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
insilmaril@163
   181
		if (bo->getDepth()==0)
insilmaril@163
   182
		{
insilmaril@163
   183
			s+= (bo->getHeading()+ "\n");
insilmaril@163
   184
			for (j=0;j<bo->getHeading().length();j++) s+="=";
insilmaril@163
   185
			s+= "\n";
insilmaril@163
   186
		} else 	if (bo->getDepth()==1)
insilmaril@163
   187
			s+= ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
insilmaril@163
   188
		else	if (bo->getDepth()==2)
insilmaril@163
   189
			s+= (actIndent + " o " + bo->getHeading()+ "\n");
insilmaril@163
   190
		else	
insilmaril@163
   191
			s+ (actIndent + " - " + bo->getHeading()+ "\n");
insilmaril@163
   192
		
insilmaril@163
   193
		/*
insilmaril@163
   194
		// If necessary, write note
insilmaril@163
   195
		if (!bo->getNote().isEmpty())
insilmaril@163
   196
		{
insilmaril@163
   197
			s =textConvertToASCII(bo->getNote());
insilmaril@163
   198
			s=s.replace ("\n","\n"+actIndent);
insilmaril@163
   199
			ts << (s+"\n\n");
insilmaril@163
   200
		}
insilmaril@163
   201
		*/
insilmaril@163
   202
		bo=bo->next();
insilmaril@163
   203
		actIndent="";
insilmaril@163
   204
	}
insilmaril@163
   205
insilmaril@163
   206
	
insilmaril@163
   207
	// Insert new content
insilmaril@163
   208
		// TODO
insilmaril@163
   209
	cout <<"\n\ns="<<s<<endl;
insilmaril@163
   210
	content.replace ("<!--INSERT PAGES HERE-->",s);
insilmaril@163
   211
	cout << "ExportOO: content=\n"<<content<<endl;
insilmaril@163
   212
insilmaril@163
   213
	// zip tmpdir to destination
insilmaril@163
   214
		// TODO
insilmaril@163
   215
insilmaril@163
   216
}
insilmaril@163
   217