Thumbnail.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #ifndef _PreComp_
00027 # include <QBuffer>
00028 # include <QByteArray>
00029 # include <QDateTime>
00030 # include <QImage>
00031 #endif
00032
00033 #include "Thumbnail.h"
00034 #include "BitmapFactory.h"
00035 #include "View3DInventorViewer.h"
00036 #include <Base/Writer.h>
00037 #include <Base/Reader.h>
00038 #include <App/Application.h>
00039
00040 using namespace Gui;
00041
00042 Thumbnail::Thumbnail(int s) : viewer(0), size(s)
00043 {
00044 }
00045
00046 Thumbnail::~Thumbnail()
00047 {
00048 }
00049
00050 void Thumbnail::setViewer(View3DInventorViewer* v)
00051 {
00052 this->viewer = v;
00053 }
00054
00055 void Thumbnail::setSize(int s)
00056 {
00057 this->size = s;
00058 }
00059
00060 void Thumbnail::setFileName(const char* fn)
00061 {
00062 this->uri = QUrl::fromLocalFile(QString::fromUtf8(fn));
00063 }
00064
00065 unsigned int Thumbnail::getMemSize (void) const
00066 {
00067 return 0;
00068 }
00069
00070 void Thumbnail::Save (Base::Writer &writer) const
00071 {
00072
00073 if (writer.isForceXML() == false)
00074 writer.addFile("thumbnails/Thumbnail.png", this);
00075 }
00076
00077 void Thumbnail::Restore(Base::XMLReader &reader)
00078 {
00079
00080 }
00081
00082 void Thumbnail::SaveDocFile (Base::Writer &writer) const
00083 {
00084 if (!this->viewer)
00085 return;
00086 QImage img;
00087 try {
00088 this->viewer->savePicture(this->size, this->size, View3DInventorViewer::Current, img);
00089 }
00090 catch (...) {
00091 return;
00092 }
00093
00094 QPixmap px = Gui::BitmapFactory().pixmap(App::Application::Config()["AppIcon"].c_str());
00095 px = BitmapFactory().merge(QPixmap::fromImage(img),px,BitmapFactoryInst::BottomRight);
00096
00097
00098 uint mt = QDateTime::currentDateTime().toTime_t();
00099 QString mtime = QString::fromAscii("%1").arg(mt);
00100 img.setText(QLatin1String("Software"), QString::fromUtf8(App::GetApplication().getExecutableName()));
00101 img.setText(QLatin1String("Thumb::Mimetype"), QLatin1String("application/x-extension-fcstd"));
00102 img.setText(QLatin1String("Thumb::MTime"), mtime);
00103 img.setText(QLatin1String("Thumb::URI"), this->uri.toString());
00104
00105 QByteArray ba;
00106 QBuffer buffer(&ba);
00107 buffer.open(QIODevice::WriteOnly);
00108 px.save(&buffer, "PNG");
00109 writer.Stream().write(ba.constData(), ba.length());
00110 }
00111
00112 void Thumbnail::RestoreDocFile(Base::Reader &reader)
00113 {
00114 }