• 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.14
  • kdeedu
  • cantor
  • src
  • lib
imageresult.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 "imageresult.h"
22 using namespace Cantor;
23 
24 #include <QImage>
25 #include <QImageWriter>
26 #include <kzip.h>
27 #include <kdebug.h>
28 
29 class Cantor::ImageResultPrivate
30 {
31  public:
32  ImageResultPrivate()
33  {
34 
35  }
36 
37  KUrl url;
38  QImage img;
39  QString alt;
40 };
41 
42 ImageResult::ImageResult(const KUrl& url, const QString& alt) : d(new ImageResultPrivate)
43 {
44  d->url=url;
45  d->alt=alt;
46 }
47 
48 ImageResult::~ImageResult()
49 {
50  delete d;
51 }
52 
53 QString ImageResult::toHtml()
54 {
55  return QString("<img src=\"%1\" alt=\"%2\"/>").arg(d->url.toLocalFile(), d->alt);
56 }
57 
58 QString ImageResult::toLatex()
59 {
60  return QString(" \\begin{center} \n \\includegraphics[width=12cm]{%1} \n \\end{center}").arg(d->url.fileName());
61 }
62 
63 QVariant ImageResult::data()
64 {
65  if(d->img.isNull())
66  d->img.load(d->url.toLocalFile());
67 
68  return QVariant(d->img);
69 }
70 
71 KUrl ImageResult::url()
72 {
73  return d->url;
74 }
75 
76 int ImageResult::type()
77 {
78  return ImageResult::Type;
79 }
80 
81 QString ImageResult::mimeType()
82 {
83  const QList<QByteArray> formats=QImageWriter::supportedImageFormats();
84  QString mimetype;
85  foreach(const QByteArray& format, formats)
86  {
87  mimetype+="image/"+format.toLower()+' ';
88  }
89  kDebug()<<"type: "<<mimetype;
90 
91  return mimetype;
92 }
93 
94 QDomElement ImageResult::toXml(QDomDocument& doc)
95 {
96  kDebug()<<"saving imageresult "<<toHtml();
97  QDomElement e=doc.createElement("Result");
98  e.setAttribute("type", "image");
99  e.setAttribute("filename", d->url.fileName());
100  kDebug()<<"done";
101 
102  return e;
103 }
104 
105 void ImageResult::saveAdditionalData(KZip* archive)
106 {
107  archive->addLocalFile(d->url.toLocalFile(), d->url.fileName());
108 }
109 
110 void ImageResult::save(const QString& filename)
111 {
112  //load into memory and let Qt save it, instead of just copying d->url
113  //to give possibility to convert file format
114  QImage img=data().value<QImage>();
115 
116  img.save(filename);
117 }
118 
QByteArray::toLower
QByteArray toLower() const
QByteArray
QImage::save
bool save(const QString &fileName, const char *format, int quality) const
imageresult.h
Cantor::ImageResult::~ImageResult
~ImageResult()
Definition: imageresult.cpp:48
QVariant::value
T value() const
QImageWriter::supportedImageFormats
QList< QByteArray > supportedImageFormats()
QDomElement::setAttribute
void setAttribute(const QString &name, const QString &value)
Cantor::ImageResult::mimeType
QString mimeType()
returns the mimetype, this result is
Definition: imageresult.cpp:81
QString
QList
Cantor::ImageResult::saveAdditionalData
void saveAdditionalData(KZip *archive)
saves all the data, that can't be saved in xml in an extra file in the archive.
Definition: imageresult.cpp:105
QDomDocument
QImage
Cantor::ImageResult::Type
Definition: imageresult.h:35
Cantor::ImageResult::type
int type()
returns an unique number, representing the type of this result.
Definition: imageresult.cpp:76
Cantor::ImageResult::toXml
QDomElement toXml(QDomDocument &doc)
returns a DomElement, containing the information of the result
Definition: imageresult.cpp:94
Cantor::ImageResult::toHtml
QString toHtml()
returns html code, that represents this result, e.g.
Definition: imageresult.cpp:53
Cantor::ImageResult::save
void save(const QString &filename)
saves this to a file
Definition: imageresult.cpp:110
QDomDocument::createElement
QDomElement createElement(const QString &tagName)
Cantor::ImageResult::toLatex
QString toLatex()
returns latex code, that represents this result e.g.
Definition: imageresult.cpp:58
QDomElement
Cantor::ImageResult::ImageResult
ImageResult(const KUrl &url, const QString &alt=QString())
Definition: imageresult.cpp:42
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
Cantor::ImageResult::data
QVariant data()
returns data associated with this result (text/images/etc)
Definition: imageresult.cpp:63
QVariant
Cantor::ImageResult::url
KUrl url()
returns an url, data for this result resides at
Definition: imageresult.cpp:71
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:16:33 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
  • 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