1
/***************************************************************************
2
* Copyright (c) 2008 Werner Mayer <wmayer[at]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
***************************************************************************/
23
#include "PreCompiled.h"
26
# include <QApplication>
34
#include <App/Application.h>
35
#include <Base/Reader.h>
36
#include <Base/Writer.h>
39
#include "BitmapFactory.h"
40
#include "View3DInventorViewer.h"
45
Thumbnail::Thumbnail(int s) : size(s)
49
Thumbnail::~Thumbnail() = default;
51
void Thumbnail::setViewer(View3DInventorViewer* v)
56
void Thumbnail::setSize(int s)
61
void Thumbnail::setFileName(const char* fn)
63
this->uri = QUrl::fromLocalFile(QString::fromUtf8(fn));
66
unsigned int Thumbnail::getMemSize () const
71
void Thumbnail::Save (Base::Writer &writer) const
73
// It's only possible to add extra information if force of XML is disabled
74
if (!writer.isForceXML())
75
writer.addFile("thumbnails/Thumbnail.png", this);
78
void Thumbnail::Restore(Base::XMLReader &reader)
81
//reader.addFile("Thumbnail.png",this);
84
void Thumbnail::SaveDocFile (Base::Writer &writer) const
89
if (this->viewer->thread() != QThread::currentThread()) {
90
qWarning("Cannot create a thumbnail from non-GUI thread");
95
this->viewer->imageFromFramebuffer(this->size, this->size, 4, invalid, img);
97
// Get app icon and resize to half size to insert in topbottom position over the current view snapshot
98
QPixmap appIcon = Gui::BitmapFactory().pixmap(App::Application::Config()["AppIcon"].c_str());
101
// Create a small "Fc" Application icon in the bottom right of the thumbnail
102
if (App::GetApplication().GetParameterGroupByPath
103
("User parameter:BaseApp/Preferences/Document")->GetBool("AddThumbnailLogo",false)) {
104
// only scale app icon if an offscreen image could be created
105
appIcon = appIcon.scaled(this->size / 4, this->size /4, Qt::KeepAspectRatio, Qt::SmoothTransformation);
106
px = BitmapFactory().merge(QPixmap::fromImage(img), appIcon, BitmapFactoryInst::BottomRight);
109
px = QPixmap::fromImage(img);
114
// according to specification add some meta-information to the image
115
qint64 mt = QDateTime::currentDateTimeUtc().toSecsSinceEpoch();
116
QString mtime = QString::fromLatin1("%1").arg(mt);
117
img.setText(QLatin1String("Software"), qApp->applicationName());
118
img.setText(QLatin1String("Thumb::Mimetype"), QLatin1String("application/x-extension-fcstd"));
119
img.setText(QLatin1String("Thumb::MTime"), mtime);
120
img.setText(QLatin1String("Thumb::URI"), this->uri.toString());
124
buffer.open(QIODevice::WriteOnly);
125
px.save(&buffer, "PNG");
126
writer.Stream().write(ba.constData(), ba.length());
130
void Thumbnail::RestoreDocFile(Base::Reader &reader)