-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
350 lines (305 loc) · 10.3 KB
/
MainWindow.cpp
File metadata and controls
350 lines (305 loc) · 10.3 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/****************************************************************************
** This is a part of ColorFreeFeCode **
** Copyright (C) 2016 Simon Garnotel **
** **
** This program is free software: you can redistribute it and/or modify **
** it under the terms of the GNU General Public License as published by **
** the Free Software Foundation, either version 3 of the License, or **
** (at your option) any later version. **
** **
** This program is distributed in the hope that it will be useful, **
** but WITHOUT ANY WARRANTY; without even the implied warranty of **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the **
** GNU General Public License for more details. **
** **
** You should have received a copy of the GNU General Public License **
** along with this program. If not, see <http://www.gnu.org/licenses/>. **
** **
** **************************************************************************
** **
** Author: Simon Garnotel **
** Contact: simon.garnotel@gmail.com **
** Date: 04/2016 **
** Version: 1.0 **
****************************************************************************/
#include "MainWindow.h"
/*!
* \brief MainWindow::InitVar
*
* Initialisation of QtWidgets
*/
void MainWindow::InitVar(){
//Menu
MenuEdit = menuBar()->addMenu("Edit");
MenuHelp = menuBar()->addMenu("Help");
//Action
ActionEditSettings = new QAction(this);
ActionHelpAboutQt = new QAction(this);
ActionHelpAbout = new QAction(this);
//Widget
CentralWidget = new QWidget(this);
//Grid
Grid = new QGridLayout(CentralWidget);
//Label
LabelEdpFile = new QLabel(CentralWidget);
LabelTexFile = new QLabel(CentralWidget);
//LineEdit
LineEdpFile = new QLineEdit(CentralWidget);
LineTexFile = new QLineEdit(CentralWidget);
//Button
ButtonEdpFile = new QPushButton(CentralWidget);
ButtonTexFile = new QPushButton(CentralWidget);
ButtonEdp2Tex = new QPushButton(CentralWidget);
//CheckBox
CheckBoxGroup = new QButtonGroup(CentralWidget);
CheckBoxAutoCompile = new QCheckBox(CentralWidget);
CheckBoxAutoRead = new QCheckBox(CentralWidget);
//Process
ProcessPdfLatex = new QProcess(CentralWidget);
ProcessEvince = new QProcess(CentralWidget);
//String
StringDirectory = DEFAULT_DIRECTORY;
StringLatex = DEFAULT_PDF_LATEX;
StringLatexOption = DEFAULT_PDF_LATEX_OPTIONS;
StringViewer = DEFAULT_PDF_VIEWER;
}
/*!
* \brief MainWindow::InitWin
*
* Construction of Window
*/
void MainWindow::InitWin(){
//Widget
setCentralWidget(CentralWidget);
CentralWidget->setLayout(Grid);
//Menu
MenuEdit->addAction(ActionEditSettings);
MenuHelp->addAction(ActionHelpAboutQt);
MenuHelp->addAction(ActionHelpAbout);
//Action
ActionEditSettings->setText("Settings");
ActionEditSettings->setIcon(QIcon("img/settings.png"));
ActionHelpAboutQt->setText("About Qt");
ActionHelpAboutQt->setIcon(QIcon("img/Qt.png"));
ActionHelpAbout->setText("About ColorFreeFemCode");
ActionHelpAbout->setIcon(QIcon("img/freefem.png"));
//Grid
Grid->addWidget(LabelEdpFile, 10, 10, 1, 1);
Grid->addWidget(LineEdpFile, 10, 11, 1, 1);
Grid->addWidget(ButtonEdpFile, 10, 12, 1, 1);
Grid->addWidget(LabelTexFile, 11, 10, 1, 1);
Grid->addWidget(LineTexFile, 11, 11, 1, 1);
Grid->addWidget(ButtonTexFile, 11, 12, 1, 1);
Grid->addWidget(ButtonEdp2Tex, 12, 10, 1, 3);
Grid->addWidget(CheckBoxAutoCompile, 10, 20, 1, 1);
Grid->addWidget(CheckBoxAutoRead, 11, 20, 1, 1);
//Label
LabelEdpFile->setText("Input: .edp File");
LabelTexFile->setText("Output: .tex File");
//LineEdit
//
//Button
ButtonEdpFile->setIcon(QIcon("img/folder.png"));
ButtonTexFile->setIcon(QIcon("img/folder.png"));
ButtonEdp2Tex->setIcon(QIcon("img/run.png"));
ButtonEdp2Tex->setText("Convert");
//CheckBox
CheckBoxGroup->addButton(CheckBoxAutoCompile);
CheckBoxGroup->addButton(CheckBoxAutoRead);
CheckBoxGroup->setExclusive(false);
CheckBoxAutoCompile->setText("Compile Latex");
CheckBoxAutoRead->setText("Read PDF");
//String
{
QString TMPDirectory;
bool Res = GetDirectory(&TMPDirectory);
if (Res){
StringDirectory = TMPDirectory;
}
}
{
QString TMPLatex;
QString TMPLatexOption;
bool Res = GetPdfLatex(&TMPLatex, &TMPLatexOption);
if (Res){
StringLatex = TMPLatex;
StringLatexOption = TMPLatexOption;
}
}
{
QString TMPViewer;
bool Res = GetPdfViewer(&TMPViewer);
if (Res){
StringViewer = TMPViewer;
}
}
}
/*!
* \brief MainWindow::InitSig
*
* Construction of Signals
*/
void MainWindow::InitSig(){
//Button
connect(ButtonEdpFile, SIGNAL(clicked()), this, SLOT(__ButtonEdpFile()));
connect(ButtonTexFile, SIGNAL(clicked()), this, SLOT(__ButtonTexFile()));
connect(ButtonEdp2Tex, SIGNAL(clicked()), this, SLOT(__ButtonEdp2Tex()));
//Action
connect(ActionEditSettings, SIGNAL(triggered(bool)), this, SLOT(__Settings()));
connect(ActionHelpAboutQt, SIGNAL(triggered(bool)), this, SLOT(__AboutQt()));
connect(ActionHelpAbout, SIGNAL(triggered(bool)), this, SLOT(__About()));
}
/*!
* \brief MainWindow::InitCss
*
* Declaration of CSS Style Sheet
*/
void MainWindow::InitCss(){
//Window
setWindowTitle("ColorFreeFemCode - version 1.0");
setWindowIcon(QIcon("img/freefem.png"));
}
/*!
* \brief MainWindow::closeEvent
*/
void MainWindow::closeEvent(QCloseEvent *){
//Process
//TODO: avoid "QProcess: Destroyed while process ("evince") is still running."
}
/*!
* \brief MainWindow::MainWindow
* \param parent
*
* Constructor of the Main Window
*/
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
InitVar();
InitWin();
InitSig();
InitCss();
}
/*!
* \brief MainWindow::__ButtonEdpFile
*
* Click on ButtonEdpFile
*/
void MainWindow::__ButtonEdpFile(){
QString EdpFile = QFileDialog::getOpenFileName(this, "Select a FreeFem++ .edp file", StringDirectory, "FreeFem++ (*.edp)");
if (!EdpFile.isEmpty()){
LineEdpFile->setText(EdpFile);
}
}
/*!
* \brief MainWindow::__ButtonTexFile
*
* Click on ButtonTexFile
*/
void MainWindow::__ButtonTexFile(){
QString TexFile = QFileDialog::getSaveFileName(this, "Select a Latex .tex file name", StringDirectory, "Latex (*.tex)");
if (!TexFile.isEmpty()){
LineTexFile->setText(TexFile);
}
}
/*!
* \brief MainWindow::__ButtonEdp2Tex
*
* Click on ButtonEdp2Tex
*/
void MainWindow::__ButtonEdp2Tex(){
QString EdpFile = LineEdpFile->text();
if (EdpFile.isEmpty()){
QMessageBox::information(this, "Information", ".edp file name empty");
return;
}
QString TexFile = LineTexFile->text();
if (TexFile.isEmpty()){
QMessageBox::information(this, "Information", ".tex file name empty");
return;
}
if (!Edp2Tex(EdpFile, TexFile)){
QMessageBox::warning(this, "Warning", "Unable to convert .edp file to .tex file");
return;
}
if (CheckBoxAutoCompile->isChecked()){
QString Program = StringLatex;
QString Directory = QString(TexFile);
{
int Pos = Directory.lastIndexOf("/");
Directory = Directory.remove(Pos, Directory.length()-Pos);
}
QStringList Arguments;
Arguments.append(StringLatexOption);
Arguments.append("-output-directory="+Directory);
Arguments.append(TexFile);
ProcessPdfLatex->start(Program, Arguments);
if (!ProcessPdfLatex->waitForFinished()){
QMessageBox::warning(this, "Warning", "pdflatex command failed");
return;
}
}
if (CheckBoxAutoRead->isChecked()){
QString Program = StringViewer;
QString PdfFile = QString(TexFile);
{
int Pos = PdfFile.lastIndexOf(".tex");
PdfFile.replace(Pos, 4, ".pdf");
}
QStringList Arguments;
Arguments.append(PdfFile);
ProcessEvince->start(Program, Arguments);
}
}
/*!
* \brief MainWindow::__Settings
*/
void MainWindow::__Settings(){
DialogSettings *dialog = new DialogSettings(this);
int Results = dialog->exec();
if (Results == QDialog::Accepted){
{
QString TMPDirectory;
bool Res = GetDirectory(&TMPDirectory);
if (Res){
StringDirectory = TMPDirectory;
}
}
{
QString TMPLatex;
QString TMPLatexOption;
bool Res = GetPdfLatex(&TMPLatex, &TMPLatexOption);
if (Res){
StringLatex = TMPLatex;
StringLatexOption = TMPLatexOption;
}
}
{
QString TMPViewer;
bool Res = GetPdfViewer(&TMPViewer);
if (Res){
StringViewer = TMPViewer;
}
}
}
}
/*!
* \brief MainWindow::__AboutQt
*/
void MainWindow::__AboutQt(){
QMessageBox::aboutQt(this, "About Qt");
}
/*!
* \brief MainWindow::__About
*/
void MainWindow::__About(){
QString text = "<h1>ColorFreeFemCode</h1>"
"ColorFreeFemCode provide an open source solution to convert FreeFem++ code (.edp) in a colored LateX document<br/><br/>"
"This software is licensed under GNU GPL version 3<br/><br/>"
"Thank to :"
"<ul><li>Everaldo Coelho for the Crystal Clear icon set</li></ul><br/>"
"Author: Simon Garnotel<br/>"
"Year: 2016<br/>"
"Version: 1.0";
QMessageBox::about(this, "About ColorFreeFemCode", text);
}