#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDateTime>
#include<QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QString qstrFile=qApp->applicationDirPath()+"/test.html";
QFile f1(qstrFile);
f1.open(QFile::WriteOnly);
QTextStream ts(&f1);
WriteHTML(ts);
f1.close();
QDesktopServices::openUrl(QUrl::fromLocalFile(qstrFile));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::WriteHTML(QTextStream &ts)
{
ts<<" <!DOCTYPE html>"<<endl;
ts<<" <html>"<<endl;
ts<<"<head>"<<endl;
ts<<"<meta charset='UTF-8'>"<<endl;
ts<< "<title>AccoTest </title>"<<endl;
ts<<"<style>"<<endl;
ts<<"table{text-align:left; border-collapse:collapse; margin-top:20px;}"<<endl;
ts<<"tr,td,th { border: solid 1px #000; }"<<endl;
ts<<"</style>"<<endl;
ts<<"</head>"<<endl;
ts<<"<body>"<<endl;
ts<<"<tr>";
ts<<"<th>";
ts<<"AccoTest Correlation Version 1.0";
ts<<"</th>";
ts<<"</tr>"<<endl;
ts<<"<p><tr>";
ts<<"<th><strong>";
ts<<"Data Time: ";
ts<<"</strong></th>";
ts<<"<th>";
QDateTime dt=QDateTime::currentDateTime();
ts<<dt.toString("yyyy/MM/dd hh:mm:ss");
ts<<"</th>";
ts<<"</tr></p>";
ts<<"<p><tr>";
ts<<"<th>";
ts<<"PGS File:"<<"D:/test/acm.pgs";
ts<<"</th>";
ts<<"</tr></p>"<<endl;
ts<< "<table>"<<endl;
ts<<"<tr> "<<endl;
ts<< " <th><strong>Site </strong></th> "<<endl;
ts<< " <th>ID</th> "<<endl;
ts<< " <th>NUM</th> "<<endl;
ts<<" </tr> "<<endl;
ts<<" <tr>"<<endl;
ts<< " <td>1</td>"<<endl;
ts<< " <td>2</td>"<<endl;
ts<< " <td>3</td>"<<endl;
ts<<" </tr>"<<endl;
ts<<" <tr>"<<endl;
ts<< " <td>4</td>"<<endl;
ts<< " <td>5</td>"<<endl;
ts<< " <td>6</td>"<<endl;
ts<<" </tr>"<<endl;
ts<<" <tr>"<<endl;
ts<< " <td>7</td>"<<endl;
ts<< " <td>8</td>"<<endl;
ts<< " <td> 9</td>"<<endl;
ts<<" </tr>"<<endl;
ts<<"</table>"<<endl;
ts<<"</body>"<<endl;
ts <<"</html>"<<endl;
}
void MainWindow::WirteTest1(QTextStream &ts)
{
ts<<"<!DOCTYPE html>"<<endl;
ts<<"<html lang='en'>"<<endl;
ts<<"<head>"<<endl;
ts<< " <meta charset='utf-8'>"<<endl;
ts<< "<p align='center'><strong>1123</strong></p>"<<endl;
ts<<"<p align='right'><em>111</em></p>"<<endl;
ts<<"<p style='color: blue'>1111<p>"<<endl;
ts<<" <p><u>555555</u></p>"<<endl;
ts<<"<p style='color: blue'>99999'</p>"<<endl;
ts<<"<p><del> 888888</del></p>"<<endl;
ts<<"</body>"<<endl;
ts<<"</html>"<<endl;
}
void MainWindow::on_pushButton_clicked()
{
QString htmlPath=qApp->applicationDirPath();
QDesktopServices::openUrl(QUrl::fromLocalFile(htmlPath+QDir::separator()+"1.html"));
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include<QDesktopServices>
#include<QUrl>
#include<QDir>
#include<QFile>
#include<QTextStream>
#pragma execution_character_set("utf-8")
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
void WriteHTML(QTextStream & ts);
void WirteTest1(QTextStream & ts);
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
};
#endif