-
Notifications
You must be signed in to change notification settings - Fork 5
/
mainwindow.cpp
113 lines (104 loc) · 3.13 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
//module button click
void MainWindow::on_module_btn_clicked(){
modulePath = QFileDialog::getOpenFileName(this, "Open Module File", "F:/PR/录制/PrSubtitle", "*.prtl");
if(modulePath.isEmpty()){
return;
}
ui->module_edit->setText(modulePath);
}
//word button click
void MainWindow::on_word_btn_clicked(){
wordPath = QFileDialog::getOpenFileName(this, "Open Module File", "F:/PR/录制/PrSubtitle", "*.txt");
if(wordPath.isEmpty()){
return;
}
ui->word_edit->setText(wordPath);
}
//out button click
void MainWindow::on_out_btn_clicked(){
outPath = QFileDialog::getExistingDirectory(this, "Open Out Files Directory", "F:/PR/录制/PrSubtitle");
if(outPath.isEmpty()){
return;
}
ui->out_edit->setText(outPath);
}
//module edit change
void MainWindow::on_module_edit_textChanged(const QString &arg1){
modulePath = arg1;
}
//word edit change
void MainWindow::on_word_edit_textChanged(const QString &arg1){
wordPath = arg1;
}
//out dir edit change
void MainWindow::on_out_edit_textChanged(const QString &arg1){
outPath = arg1;
}
//open out dir button click
void MainWindow::on_open_clicked(){
if(!outPath.isEmpty()){
QDesktopServices::openUrl(QUrl("file:///" + QDir::toNativeSeparators(outPath)));
}
}
//start button click
void MainWindow::on_start_clicked(){
if(modulePath.isEmpty() || wordPath.isEmpty() || outPath.isEmpty()){
return;
}
QFileInfo file;
file.setFile(modulePath);
if(!file.isFile() || file.suffix().compare("prtl")){
return;
}
file.setFile(wordPath);
if(!file.isFile() || file.suffix().compare("txt")){
return;
}
QFile m(modulePath);
if (!m.open(QIODevice::ReadOnly | QIODevice::Text)){
return;
}
QFile w(wordPath);
if (!w.open(QIODevice::ReadOnly | QIODevice::Text)){
return;
}
QTextStream word(&w);
QTextStream module(&m);
QString s = module.readAll();
// qDebug()<<s.length();
int i = 0;
while (!word.atEnd()) {
QString line = word.readLine();
qDebug()<<line;
QString rep1 = QString("<TRString>%1</TRString>").arg(line);
QString rep2 = QString("RunCount=\"%1\" StyleRef").arg(line.length()+1);
QString out = QString::fromUtf8("%1").arg(s.replace(QRegExp("<TRString>.*</TRString>"), rep1).replace(QRegExp("RunCount=\".*\" StyleRef"), rep2));
//write file
QString name = QString("%1/字幕%2.prtl").arg(outPath).arg(i);
QFile outFile(name);
if (!outFile.open(QIODevice::WriteOnly|QIODevice::Text)) {
QMessageBox::critical(NULL, "提示", "无法创建文件");
return;
}
QTextStream outTS(&outFile);
outTS.setCodec(QTextCodec::codecForName("UTF-8"));
outTS<<out<<endl;
outTS.setGenerateByteOrderMark(true);
outTS.flush();
outFile.close();
i++;
}
}