filters
table.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <kdebug.h>
00023 #include <qbitarray.h>
00024 #include "listtable.h"
00025 #include "textFrame.h"
00026
00027
00028
00029
00030 Table::Table()
00031 {
00032 setMaxCol(0);
00033 setMaxRow(0);
00034 }
00035
00036 Table::Table(QString grpMgr)
00037 {
00038 setGrpMgr(grpMgr);
00039 setMaxCol(0);
00040 setMaxRow(0);
00041 }
00042
00043
00044
00045
00046 Table::~Table()
00047 {
00048 kdDebug(30522) << "Destruction of a list of frames" << endl;
00049 }
00050
00051
00052
00053
00054 EEnv Table::getCellFlow(int col)
00055 {
00056 for(int row = 0; row<= getMaxRow(); row++)
00057 {
00058 Element* elt = at(row * getMaxRow() + col);
00059 if(elt->getType() == ST_TEXT)
00060 {
00061 kdDebug(30522) << ((TextFrame*) elt)->getFirstPara()->getEnv() << endl;
00062 return ((TextFrame*) elt)->getFirstPara()->getEnv();
00063 }
00064 }
00065 kdDebug(30522) << "Default flow for cell" << endl;
00066 return ENV_JUSTIFY;
00067 }
00068
00069
00070
00071
00072 double Table::getCellSize(int col)
00073 {
00074
00075 for(int row = 0; row<= getMaxRow(); row++)
00076 {
00077 Element* elt = at(row * getMaxRow() + col);
00078 if(elt->getType() == ST_TEXT)
00079 {
00080 kdDebug(30522) << "size : " << ((TextFrame*) elt)->getLeft() << endl;
00081 return ((TextFrame*) elt)->getRight() - ((TextFrame*) elt)->getLeft();
00082 }
00083 }
00084 kdDebug(30522) << "Default size for cell" << endl;
00085 return 3;
00086 }
00087
00088
00089
00090
00091 Element* Table::searchCell(int row, int col)
00092 {
00093 Element* current = 0;
00094
00095
00096 for(current = first(); current != 0; current = next())
00097 {
00098 kdDebug(30522) << "+" << current->getRow() << "," << current->getCol() << endl;
00099 if(current->getRow() == row && current->getCol() == col)
00100 return current;
00101 }
00102 return 0;
00103 }
00104
00105
00106
00107
00108 void Table::append(Element* elt)
00109 {
00110 if(elt->getRow() > getMaxRow())
00111 setMaxRow(elt->getRow());
00112
00113 if(elt->getCol() > getMaxCol())
00114 setMaxCol(elt->getCol());
00115
00116 QPtrList<Element>::append(elt);
00117 }
00118
00119
00120
00121
00122 void Table::generate(QTextStream& out)
00123 {
00124 Element* elt = 0;
00125 kdDebug(30522) << "GENERATION OF A TABLE " << count() << endl;
00126 out << endl << "\\begin{tabular}";
00127 generateTableHeader(out);
00128 out << endl;
00129 Config::instance()->indent();
00130
00131 int row= 0;
00132 while(row <= getMaxRow())
00133 {
00134 generateTopLineBorder(out, row);
00135 for(int col= 0; col <= getMaxCol(); col++)
00136 {
00137 Config::instance()->writeIndent(out);
00138
00139
00140 elt = searchCell(row, col);
00141
00142 out << "\\multicolumn{1}{";
00143 if(elt->hasLeftBorder())
00144 out << "|";
00145 out << "m{" << getCellSize(col) << "pt}";
00146
00147 if(elt->hasRightBorder())
00148 out << "|";
00149 out << "}{" << endl;
00150
00151 generateCell(out, row, col);
00152 out << "}" << endl;
00153 if(col < getMaxCol())
00154 out << "&" << endl;
00155 }
00156 out << "\\\\" << endl;
00157 Config::instance()->writeIndent(out);
00158 row = row + 1;
00159 }
00160 generateBottomLineBorder(out, row - 1);
00161 out << "\\end{tabular}" << endl << endl;
00162 Config::instance()->desindent();
00163 kdDebug(30522) << "END OF GENERATINO OF A TABLE" << endl;
00164 }
00165
00166
00167
00168
00169 void Table::generateTopLineBorder(QTextStream& out, int row)
00170 {
00171 Element* elt = 0;
00172 QBitArray border(getMaxCol());
00173 bool fullLine = true;
00174
00175 for(int index = 0; index <= getMaxCol(); index++)
00176 {
00177
00178 elt = searchCell(row, index);
00179 kdDebug(30522) << endl << "name (" << row << ", " << index << ") = " << elt->getName() << endl << endl;
00180
00181
00182 if(elt->hasTopBorder())
00183 {
00184 border[index] = 1;
00185 }
00186 else
00187 {
00188 border[index] = 0;
00189 fullLine = false;
00190 }
00191 }
00192
00193 if(fullLine)
00194 {
00195
00196 Config::instance()->writeIndent(out);
00197 out << "\\hline" << endl;
00198 }
00199 else
00200 {
00201 int index = 0;
00202 while(index <= getMaxCol())
00203 {
00204 if(border[index])
00205 {
00206 int begin = index;
00207 int end = index;
00208 while(border[index] && index < getMaxCol())
00209 {
00210 index = index + 1;
00211 }
00212 end = index - 1;
00213 out << "\\cline{" << (begin + 1) << "-" << (end + 1) << "} " << endl;
00214 }
00215 index = index + 1;
00216 }
00217 }
00218 }
00219
00220
00221
00222
00223 void Table::generateBottomLineBorder(QTextStream& out, int row)
00224 {
00225 Element* elt = 0;
00226 QBitArray border(getMaxCol());
00227 bool fullLine = true;
00228
00229 for(int index = 0; index <= getMaxCol(); index++)
00230 {
00231
00232 elt = searchCell(row, index);
00233
00234
00235 if(elt->hasBottomBorder())
00236 {
00237 border[index] = 1;
00238 }
00239 else
00240 {
00241 border[index] = 0;
00242 fullLine = false;
00243 }
00244 }
00245
00246 if(fullLine)
00247 {
00248
00249 Config::instance()->writeIndent(out);
00250 out << "\\hline" << endl;
00251 }
00252 else
00253 {
00254 int index = 0;
00255 while(index <= getMaxCol())
00256 {
00257 if(border[index])
00258 {
00259 int begin = index;
00260 int end = index;
00261 while(border[index] && index <= getMaxCol())
00262 {
00263 index = index + 1;
00264 }
00265 end = index - 1;
00266 out << "\\cline{" << (begin + 1) << "-" << (end + 1) << "} " << endl;
00267 }
00268 index = index + 1;
00269 }
00270 }
00271 }
00272
00273
00274
00275
00276 void Table::generateCell(QTextStream& out, int row, int col)
00277 {
00278 Element* elt = 0;
00279
00280 kdDebug(30522) << "NEW CELL : " << row << "," << col << endl;
00281
00282
00283 elt = searchCell(row, col);
00284
00285
00286 if(elt != 0)
00287 elt->generate(out);
00288 kdDebug(30522) << "END OF A CELL" << endl;
00289 }
00290
00291
00292
00293
00294 void Table::generateTableHeader(QTextStream& out)
00295 {
00296 Element* elt = 0;
00297 bool fullRightBorder = true;
00298 bool fullLeftBorder = true;
00299
00300 out << "{";
00301
00302 for(int col = 0; col <= getMaxCol(); col++)
00303 {
00304 for(int row = 0; row < getMaxRow(); row++)
00305 {
00306
00307 elt = searchCell(row, col);
00308
00309
00310 if(!elt->hasRightBorder())
00311 fullRightBorder = false;
00312 if(!elt->hasLeftBorder())
00313 fullLeftBorder = false;
00314 }
00315 if(fullLeftBorder)
00316 out << "|";
00317 out << "m{" << getCellSize(col) << "pt}";
00318 if(fullRightBorder)
00319 out << "|";
00320 }
00321 out << "}";
00322 }
00323
|