1
/***************************************************************************
2
* Copyright (c) 2008 Werner Mayer <wmayer@users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
28
# include <QByteArray>
33
#include "Thumbnail.h"
34
#include "View3DInventorViewer.h"
35
#include <Base/Writer.h>
36
#include <Base/Reader.h>
37
#include <App/Application.h>
41
Thumbnail::Thumbnail(int s) : viewer(0), size(s)
45
Thumbnail::~Thumbnail()
49
void Thumbnail::setViewer(View3DInventorViewer* v)
54
void Thumbnail::setSize(int s)
59
void Thumbnail::setFileName(const char* fn)
61
this->uri = QUrl::fromLocalFile(QString::fromUtf8(fn));
64
unsigned int Thumbnail::getMemSize (void) const
69
void Thumbnail::Save (Base::Writer &writer) const
71
// It's only possible to add extra information if force of XML is disabled
72
if (writer.isForceXML() == false)
73
writer.addFile("thumbnails/Thumbnail.png", this);
76
void Thumbnail::Restore(Base::XMLReader &reader)
78
//reader.addFile("Thumbnail.png",this);
81
void Thumbnail::SaveDocFile (Base::Writer &writer) const
86
this->viewer->savePicture(this->size, this->size, View3DInventorViewer::White, img);
88
// according to specification add some meta-information to the image
89
uint mt = QDateTime::currentDateTime().toTime_t();
90
QString mtime = QString::fromAscii("%1").arg(mt);
91
img.setText(QLatin1String("Software"), QString::fromUtf8(App::Application::Config()["ExeName"].c_str()));
92
img.setText(QLatin1String("Thumb::Mimetype"), QLatin1String("application/x-extension-fcstd"));
93
img.setText(QLatin1String("Thumb::MTime"), mtime);
94
img.setText(QLatin1String("Thumb::URI"), this->uri.toString());
98
buffer.open(QIODevice::WriteOnly);
99
img.save(&buffer, "PNG");
100
writer.Stream().write(ba.constData(), ba.length());
103
void Thumbnail::RestoreDocFile(Base::Reader &reader)