#include <QApplication>
#include <zftpclient.h>
#include <zpdfviewer.h>
#include <QTableWidget>
#include <QHash>
#include <QFile>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableWidget tTable;
tTable.setColumnCount(10);
tTable.setRowCount(20);
for(qint32 i=0;i<tTable.rowCount();i++)
{
for(qint32 j=0;j<tTable.columnCount();j++)
{
QTableWidgetItem *tItem=new QTableWidgetItem;
tTable.setItem(i,j,tItem);
}
}
tTable.setSpan(0,0,1,3);
tTable.item(0,0)->setText("(Left,Top)");
tTable.setSpan(2,2,3,2);
tTable.item(2,2)->setText("This is beijing hour,open the door to the world.Join us ,couldn't you?");
tTable.setSpan(13,5,3,6);
tTable.item(13,5)->setText("hello,this is a html test page ,used to test subtitle parse server.is it work correct?");
tTable.show();
#if 0
for(qint32 i=0;i<tTable.rowCount();i++)
{
for(qint32 j=0;j<tTable.columnCount();j++)
{
qDebug()<<"("<<i<<","<<j<<"):"<<tTable.rowSpan(i,j)<<tTable.columnSpan(i,j);
}
}
qDebug()<<"ends...................";
#endif
//find out the invalid cells.
QList<QString> tInvalidCellsList;
for(qint32 i=0;i<tTable.rowCount();i++)
{
for(qint32 j=0;j<tTable.columnCount();j++)
{
QString tKey=QString("%1,%2").arg(i).arg(j);
if(tInvalidCellsList.contains(tKey))
{
continue;
}
qint32 tRowSpan=tTable.rowSpan(i,j);
qint32 tColSpan=tTable.columnSpan(i,j);
if(tRowSpan>1 || tColSpan>1)
{
for(qint32 m=i;m<i+tRowSpan;m++)
{
for(qint32 n=j;n<j+tColSpan;n++)
{
if(m==i && n==j)
{
//bypass myself.
continue;
}
QString tKey=QString("%1,%2").arg(m).arg(n);
tInvalidCellsList.append(tKey);
}
}
}
}
}
//generate html.
qreal tColWidth=100.0/tTable.columnCount();
QString tHtml;
tHtml.append("<html>");
tHtml.append(QString("<head><style type=\"text/css\">body{font-size:12px;}table td{width:%1%;height:50px}table tr td{word-break:break-all;}</style></head>").arg(tColWidth));
tHtml.append("<body>");
tHtml.append("<table width=\"100%\" height=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">");
tHtml.append("\n");
for(qint32 i=0;i<tTable.rowCount();i++)
{
tHtml.append(QString("<tr>"));
tHtml.append("\n");
for(qint32 j=0;j<tTable.columnCount();j++)
{
QString tKey=QString("%1,%2").arg(i).arg(j);
if(tInvalidCellsList.contains(tKey))
{
//bypass invalid cells.
continue;
}
qint32 tRowSpan=tTable.rowSpan(i,j);
qint32 tColSpan=tTable.columnSpan(i,j);
tHtml.append(QString("<td rowspan=\"%1\" colspan=\"%2\" align=\"left\">").arg(tRowSpan).arg(tColSpan));
tHtml.append("<input type=\"checkbox\" checked=\"checked\">");
tHtml.append(tTable.item(i,j)->text());
tHtml.append("</td>");
tHtml.append("\n");
}
tHtml.append(QString("</tr>"));
tHtml.append("\n");
}
tHtml.append("</table>");
tHtml.append("\n");
tHtml.append("</body>");
tHtml.append("</html>");
QFile tFile("/home/shell.albert/subtitle.html");
if(tFile.open(QIODevice::WriteOnly))
{
tFile.write(tHtml.toUtf8());
tFile.flush();
tFile.close();
}
return 0;
return a.exec();
}
#include <zftpclient.h>
#include <zpdfviewer.h>
#include <QTableWidget>
#include <QHash>
#include <QFile>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableWidget tTable;
tTable.setColumnCount(10);
tTable.setRowCount(20);
for(qint32 i=0;i<tTable.rowCount();i++)
{
for(qint32 j=0;j<tTable.columnCount();j++)
{
QTableWidgetItem *tItem=new QTableWidgetItem;
tTable.setItem(i,j,tItem);
}
}
tTable.setSpan(0,0,1,3);
tTable.item(0,0)->setText("(Left,Top)");
tTable.setSpan(2,2,3,2);
tTable.item(2,2)->setText("This is beijing hour,open the door to the world.Join us ,couldn't you?");
tTable.setSpan(13,5,3,6);
tTable.item(13,5)->setText("hello,this is a html test page ,used to test subtitle parse server.is it work correct?");
tTable.show();
#if 0
for(qint32 i=0;i<tTable.rowCount();i++)
{
for(qint32 j=0;j<tTable.columnCount();j++)
{
qDebug()<<"("<<i<<","<<j<<"):"<<tTable.rowSpan(i,j)<<tTable.columnSpan(i,j);
}
}
qDebug()<<"ends...................";
#endif
//find out the invalid cells.
QList<QString> tInvalidCellsList;
for(qint32 i=0;i<tTable.rowCount();i++)
{
for(qint32 j=0;j<tTable.columnCount();j++)
{
QString tKey=QString("%1,%2").arg(i).arg(j);
if(tInvalidCellsList.contains(tKey))
{
continue;
}
qint32 tRowSpan=tTable.rowSpan(i,j);
qint32 tColSpan=tTable.columnSpan(i,j);
if(tRowSpan>1 || tColSpan>1)
{
for(qint32 m=i;m<i+tRowSpan;m++)
{
for(qint32 n=j;n<j+tColSpan;n++)
{
if(m==i && n==j)
{
//bypass myself.
continue;
}
QString tKey=QString("%1,%2").arg(m).arg(n);
tInvalidCellsList.append(tKey);
}
}
}
}
}
//generate html.
qreal tColWidth=100.0/tTable.columnCount();
QString tHtml;
tHtml.append("<html>");
tHtml.append(QString("<head><style type=\"text/css\">body{font-size:12px;}table td{width:%1%;height:50px}table tr td{word-break:break-all;}</style></head>").arg(tColWidth));
tHtml.append("<body>");
tHtml.append("<table width=\"100%\" height=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\">");
tHtml.append("\n");
for(qint32 i=0;i<tTable.rowCount();i++)
{
tHtml.append(QString("<tr>"));
tHtml.append("\n");
for(qint32 j=0;j<tTable.columnCount();j++)
{
QString tKey=QString("%1,%2").arg(i).arg(j);
if(tInvalidCellsList.contains(tKey))
{
//bypass invalid cells.
continue;
}
qint32 tRowSpan=tTable.rowSpan(i,j);
qint32 tColSpan=tTable.columnSpan(i,j);
tHtml.append(QString("<td rowspan=\"%1\" colspan=\"%2\" align=\"left\">").arg(tRowSpan).arg(tColSpan));
tHtml.append("<input type=\"checkbox\" checked=\"checked\">");
tHtml.append(tTable.item(i,j)->text());
tHtml.append("</td>");
tHtml.append("\n");
}
tHtml.append(QString("</tr>"));
tHtml.append("\n");
}
tHtml.append("</table>");
tHtml.append("\n");
tHtml.append("</body>");
tHtml.append("</html>");
QFile tFile("/home/shell.albert/subtitle.html");
if(tFile.open(QIODevice::WriteOnly))
{
tFile.write(tHtml.toUtf8());
tFile.flush();
tFile.close();
}
return 0;
return a.exec();
}