File: latexviewdialog.cpp

package info (click to toggle)
algobox 1.0.3+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,380 kB
  • sloc: cpp: 13,758; makefile: 13; xml: 8; sh: 5
file content (67 lines) | stat: -rw-r--r-- 2,478 bytes parent folder | download
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
/***************************************************************************
 *   copyright       : (C) 2009-2019 by Pascal Brachet                     *
 *                                                                         *
 *   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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "latexviewdialog.h"

#include <QFontDatabase>
#include <QFile>
#include <QFileDialog>
#include <QFileInfo>
#include <QTextStream>


LatexviewDialog::LatexviewDialog(QWidget *parent, int mode)
    :QDialog( parent)
{
ui.setupUi(this);
setModal(true);
connect(ui.barreOutils->actionSauver, SIGNAL(triggered()), this, SLOT(Sauver()));
highlighter = new LatexHighlighter(ui.textEdit->document());
QFont efont;
QFontDatabase fdb;
QStringList xf = fdb.families();
QString deft;
if (xf.contains("Liberation Mono",Qt::CaseInsensitive)) deft="Liberation Mono";
else if (xf.contains("DejaVu Sans Mono",Qt::CaseInsensitive)) deft="DejaVu Sans Mono";
#if defined( Q_WS_MACX )
else if (xf.contains("Courier",Qt::CaseInsensitive)) deft="Courier";
#endif
#if defined(Q_WS_WIN)
else if (xf.contains("Courier New",Qt::CaseInsensitive)) deft="Courier New";
#endif
else deft=qApp->font().family();  
efont.setFamily(deft);
efont.setPointSize(qApp->font().pointSize());
ui.textEdit->setFont(efont);
ui.textEdit->setWordWrapMode(QTextOption::NoWrap);
if (mode==1) codec = QTextCodec::codecForName("ISO-8859-1");
else codec = QTextCodec::codecForName("UTF-8");
ui.label->setText(QString::fromUtf8("Pas encore enregistré"));
show();
}

LatexviewDialog::~LatexviewDialog(){
}

void LatexviewDialog::Sauver()
{
QString exportFichier = QFileDialog::getSaveFileName(this,QString::fromUtf8("Enregistrer sous"),QDir::homePath(),QString::fromUtf8("Document LaTeX (*.tex)"));
if (!exportFichier.isEmpty()) 
    {
    QFile fichier;
    fichier.setFileName(exportFichier);
    fichier.open(QIODevice::WriteOnly);
    QTextStream out (&fichier);
    out.setCodec(codec);
    out << ui.textEdit->toPlainText();
    fichier.close();
    ui.label->setText(QString::fromUtf8("Fichier enregistré"));
    }  
}