• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

cantor/src/lib

  • sources
  • kde-4.12
  • kdeedu
  • cantor
  • src
  • lib
latexresult.cpp
Go to the documentation of this file.
1 /*
2  This program is free software; you can redistribute it and/or
3  modify it under the terms of the GNU General Public License
4  as published by the Free Software Foundation; either version 2
5  of the License, or (at your option) any later version.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin Street, Fifth Floor,
15  Boston, MA 02110-1301, USA.
16 
17  ---
18  Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com>
19  */
20 
21 #include "latexresult.h"
22 using namespace Cantor;
23 
24 #include <QFile>
25 #include <QTextStream>
26 #include <kdebug.h>
27 
28 class Cantor::LatexResultPrivate
29 {
30  public:
31  LatexResultPrivate()
32  {
33  showCode=false;
34  }
35 
36  bool showCode;
37  QString code;
38  QString plain;
39 };
40 
41 LatexResult::LatexResult(const QString& code, const KUrl& url, const QString& plain) : EpsResult( url ),
42  d(new LatexResultPrivate)
43 {
44  d->code=code;
45  d->plain=plain;
46 }
47 
48 LatexResult::~LatexResult()
49 {
50  delete d;
51 }
52 
53 int LatexResult::type()
54 {
55  return LatexResult::Type;
56 }
57 
58 QString LatexResult::mimeType()
59 {
60  if(isCodeShown())
61  return "text/plain";
62  else
63  return EpsResult::mimeType();
64 }
65 
66 QString LatexResult::code()
67 {
68  return d->code;
69 }
70 
71 QString LatexResult::plain()
72 {
73  return d->plain;
74 }
75 
76 bool LatexResult::isCodeShown()
77 {
78  return d->showCode;
79 }
80 
81 void LatexResult::showCode()
82 {
83  d->showCode=true;
84 }
85 
86 void LatexResult::showRendered()
87 {
88  d->showCode=false;
89 }
90 
91 QVariant LatexResult::data()
92 {
93  if(isCodeShown())
94  return QVariant(code());
95  else
96  return EpsResult::data();
97 }
98 
99 QString LatexResult::toHtml()
100 {
101  if (isCodeShown())
102  {
103  QString s=code();
104  s.replace('\n', "<br/>\n");
105  return s;
106  }
107  else
108  {
109  return EpsResult::toHtml();
110  }
111 }
112 
113 QString LatexResult::toLatex()
114 {
115  return code();
116 }
117 
118 QDomElement LatexResult::toXml(QDomDocument& doc)
119 {
120  kDebug()<<"saving textresult "<<toHtml();
121  QDomElement e=doc.createElement("Result");
122  e.setAttribute("type", "latex");
123  KUrl url=KUrl(EpsResult::data().toUrl());
124  e.setAttribute("filename", url.fileName());
125  QDomText txt=doc.createTextNode(code());
126  e.appendChild(txt);
127 
128  return e;
129 }
130 
131 void LatexResult::save(const QString& filename)
132 {
133  if(isCodeShown())
134  {
135  QFile file(filename);
136 
137  if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
138  return;
139 
140  QTextStream stream(&file);
141 
142  stream<<code();
143 
144  file.close();
145  }else
146  {
147  EpsResult::save(filename);
148  }
149 }
150 
Cantor::LatexResult::showCode
void showCode()
Definition: latexresult.cpp:81
Cantor::LatexResult::toXml
QDomElement toXml(QDomDocument &doc)
returns a DomElement, containing the information of the result
Definition: latexresult.cpp:118
Cantor::EpsResult::url
KUrl url()
returns an url, data for this result resides at
Definition: epsresult.cpp:64
Cantor::LatexResult::~LatexResult
~LatexResult()
Definition: latexresult.cpp:48
Cantor::LatexResult::toLatex
QString toLatex()
returns latex code, that represents this result e.g.
Definition: latexresult.cpp:113
Cantor::EpsResult::mimeType
QString mimeType()
returns the mimetype, this result is
Definition: epsresult.cpp:74
Cantor::EpsResult::save
void save(const QString &filename)
saves this to a file
Definition: epsresult.cpp:95
Cantor::EpsResult::toHtml
QString toHtml()
returns html code, that represents this result, e.g.
Definition: epsresult.cpp:49
Cantor::LatexResult::data
QVariant data()
returns data associated with this result (text/images/etc)
Definition: latexresult.cpp:91
Cantor::EpsResult::data
QVariant data()
returns data associated with this result (text/images/etc)
Definition: epsresult.cpp:59
Cantor::LatexResult::code
QString code()
Definition: latexresult.cpp:66
Cantor::LatexResult::save
void save(const QString &filename)
saves this to a file
Definition: latexresult.cpp:131
Cantor::LatexResult::toHtml
QString toHtml()
returns html code, that represents this result, e.g.
Definition: latexresult.cpp:99
Cantor::LatexResult::plain
QString plain()
Definition: latexresult.cpp:71
latexresult.h
Cantor::EpsResult
Definition: epsresult.h:32
Cantor::LatexResult::showRendered
void showRendered()
Definition: latexresult.cpp:86
Cantor::LatexResult::LatexResult
LatexResult(const QString &code, const KUrl &url, const QString &plain=QString())
Definition: latexresult.cpp:41
Cantor::LatexResult::type
int type()
returns an unique number, representing the type of this result.
Definition: latexresult.cpp:53
Cantor::LatexResult::mimeType
QString mimeType()
returns the mimetype, this result is
Definition: latexresult.cpp:58
Cantor::LatexResult::isCodeShown
bool isCodeShown()
Definition: latexresult.cpp:76
Cantor::LatexResult::Type
Definition: latexresult.h:38
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:42:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

cantor/src/lib

Skip menu "cantor/src/lib"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal