~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Gui/Thumbnail.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2008 Werner Mayer <wmayer@users.sourceforge.net>        *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
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.      *
 
10
 *                                                                         *
 
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.                  *
 
15
 *                                                                         *
 
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                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
#include "PreCompiled.h"
 
25
 
 
26
#ifndef _PreComp_
 
27
# include <QBuffer>
 
28
# include <QByteArray>
 
29
# include <QDateTime>
 
30
# include <QImage>
 
31
#endif
 
32
 
 
33
#include "Thumbnail.h"
 
34
#include "View3DInventorViewer.h"
 
35
#include <Base/Writer.h>
 
36
#include <Base/Reader.h>
 
37
#include <App/Application.h>
 
38
 
 
39
using namespace Gui;
 
40
 
 
41
Thumbnail::Thumbnail(int s) : viewer(0), size(s)
 
42
{
 
43
}
 
44
 
 
45
Thumbnail::~Thumbnail()
 
46
{
 
47
}
 
48
 
 
49
void Thumbnail::setViewer(View3DInventorViewer* v)
 
50
{
 
51
    this->viewer = v;
 
52
}
 
53
 
 
54
void Thumbnail::setSize(int s)
 
55
{
 
56
    this->size = s;
 
57
}
 
58
 
 
59
void Thumbnail::setFileName(const char* fn)
 
60
{
 
61
    this->uri = QUrl::fromLocalFile(QString::fromUtf8(fn));
 
62
}
 
63
 
 
64
unsigned int Thumbnail::getMemSize (void) const
 
65
{
 
66
    return 0;
 
67
}
 
68
 
 
69
void Thumbnail::Save (Base::Writer &writer) const
 
70
{
 
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);
 
74
}
 
75
 
 
76
void Thumbnail::Restore(Base::XMLReader &reader)
 
77
{
 
78
    //reader.addFile("Thumbnail.png",this);
 
79
}
 
80
 
 
81
void Thumbnail::SaveDocFile (Base::Writer &writer) const
 
82
{
 
83
    if (!this->viewer)
 
84
        return;
 
85
    QImage img;
 
86
    this->viewer->savePicture(this->size, this->size, View3DInventorViewer::White, img);
 
87
 
 
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());
 
95
 
 
96
    QByteArray ba;
 
97
    QBuffer buffer(&ba);
 
98
    buffer.open(QIODevice::WriteOnly);
 
99
    img.save(&buffer, "PNG");
 
100
    writer.Stream().write(ba.constData(), ba.length());
 
101
}
 
102
 
 
103
void Thumbnail::RestoreDocFile(Base::Reader &reader)
 
104
{
 
105
}