[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: Continuing thumbnail obsession
From: Simon MacMullen <simon.macmullen () aspect-proteus ! com>
Date: 2002-02-28 12:37:25
[Download RAW message or body]
My continuing obsession with thumbnails has now created one for koffice
files:
http://www.babysimon.co.uk/kde/kofficepreview.png
If you look carefully at the code you may see traces of the HTML preview and
Philippe Fremy's KParts tutorial :)
However, it's not quite as I would like it. I can't seem to control the
scaling in a very meaningful way. What I would like to do is find out how
wide the document "wants" to be, then scale for that (particularly important
for KWord docs). But I can't mind a method that tells me this. Is there one?
Also, when adjusting the zoom parameters which are passed to
KoDocument::paintEverything, font sizes don't seem to change. I recall this
used to be a problem but I don't know whether it's been fixed yet (ummm, I'm
afraid I hardly use KOffice...). Also, it completely fails to work with
KPresenter. I don't know why.
The attached patch provides two .desktop files to switch it on and off - one
for KOffice and one for MSOffice. I don't know if this is the best way to do
it - should it be lots of little .desktops or one big one maybe?
What else? Oh, to reply to the list admin's question, yes, it probably is
quite slow. "Unfortunately" I developed it on my fast work machine. It might
go faster if it "reused" the KoDocuments (like the HTML preview reuses
KHTML), but it would probably need a QDict of them. Hmmm...
Cheers,
Simon
<<koffice.diff>> <<kofficecreator.cpp>> <<kofficethumbnail.desktop>>
<<msofficethumbnail.desktop>> <<kofficecreator.h>>
["koffice.diff" (application/octet-stream)]
? koffice.diff
? karbon/core/vtext.loT
? kword/serialletter/Makefile.in
? kword/serialletter/Makefile
? kword/serialletter/sql/Makefile.in
? kword/serialletter/sql/Makefile
? kword/serialletter/sql/qtsqldatasourceeditor.h
? kword/serialletter/sql/qtsqlopenwidget.h
? kword/serialletter/sql/kwqtsqlpower.h
? kword/serialletter/sql/serialletter_qtsql_base.kidl
? kword/serialletter/sql/serialletter_qtsql_base_skel.cc
? kword/serialletter/sql/qtsqldatasourceeditor.cc
? kword/serialletter/sql/qtsqlopenwidget.cc
? kword/serialletter/sql/serialletter_qtsql_power_plugin.kidl
? kword/serialletter/sql/serialletter_qtsql_power_plugin_skel.cc
? kword/serialletter/sql/kwqtsqlpower.cc
? tools/thumbnail/kofficecreator.cpp
? tools/thumbnail/kofficecreator.h
? tools/thumbnail/kofficethumbnail.desktop
? tools/thumbnail/msofficethumbnail.desktop
Index: tools/thumbnail/Makefile.am
===================================================================
RCS file: /home/kde/koffice/tools/thumbnail/Makefile.am,v
retrieving revision 1.2
diff -u -3 -p -r1.2 Makefile.am
--- tools/thumbnail/Makefile.am 2001/09/20 17:01:35 1.2
+++ tools/thumbnail/Makefile.am 2002/02/28 12:18:36
@@ -2,10 +2,15 @@ INCLUDES = $(KOFFICE_INCLUDES) $(all_inc
LDFLAGS = $(all_libraries) $(KDE_RPATH)
METASOURCES = AUTO
-kde_module_LTLIBRARIES = clipartthumbnail.la
+kde_module_LTLIBRARIES = clipartthumbnail.la kofficethumbnail.la
clipartthumbnail_la_SOURCES = clipartcreator.cpp
clipartthumbnail_la_LIBADD = $(LIB_KOFFICECORE) # for KoClipartCollection
clipartthumbnail_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
-kde_services_DATA = clipartthumbnail.desktop
+kofficethumbnail_la_SOURCES = kofficecreator.cpp
+kofficethumbnail_la_LIBADD = $(LIB_KOFFICECORE)
+kofficethumbnail_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+
+kde_services_DATA = clipartthumbnail.desktop kofficethumbnail.desktop msofficethumbnail.desktop
+
["kofficecreator.cpp" (application/octet-stream)]
/* This file is part of the KDE libraries
Copyright (C) 2000 Malte Starostik <malte@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
// $Id: htmlcreator.cpp,v 1.7 2001/12/29 17:22:21 mueller Exp $
#include <time.h>
#include <qpixmap.h>
#include <qimage.h>
#include <qpainter.h>
#include <kapplication.h>
#include <kfileitem.h>
#include <ktrader.h>
#include <klibloader.h>
#include <kparts/part.h>
#include <iostream.h>
#include "kofficecreator.h"
extern "C"
{
ThumbCreator *new_creator()
{
return new KOfficeCreator;
}
};
KOfficeCreator::KOfficeCreator()
: m_doc(0)
{
}
KOfficeCreator::~KOfficeCreator()
{
delete m_doc;
}
bool KOfficeCreator::create(const QString &path, int width, int height, QImage &img)
{
KFileItem document ( KFileItem::Unknown, KFileItem::Unknown, path);
// Copied straight from the tutorial
KTrader::OfferList offers = KTrader::self()->query(document.mimetype(),
"'KOfficePart' in ServiceTypes");
KLibFactory *factory = 0;
KTrader::OfferList::Iterator it(offers.begin());
for( ; it != offers.end(); ++it) {
KService::Ptr ptr = (*it);
factory = KLibLoader::self()->factory( ptr->library().latin1() );
if (factory) {
m_doc = static_cast<KoDocument *>(factory->create(0,
ptr->name().latin1(), "KParts::ReadOnlyPart"));
break;
}
}
if (!m_doc) return false;
connect(m_doc, SIGNAL(completed()), SLOT(slotCompleted()));
m_doc->openURL(path);
m_completed = false;
startTimer(5000);
while (!m_completed)
kapp->processOneEvent();
killTimers();
// render the page on a bigger pixmap and use smoothScale,
// looks better than directly scaling with the QPainter (malte)
QPixmap pix;
if (width > 400 || height > 400)
{
if (height > width )
pix.resize(height, height);
else
pix.resize(width, width);
}
else
pix.resize(400, 400);
// light-grey background, in case loadind the page failed
pix.fill( QColor( 245, 245, 245 ) );
int borderX = pix.width() / width,
borderY = pix.height() / height;
QRect rc(borderX, borderY, pix.width() - borderX * 2, pix.width() - borderX * 2);
QPainter p;
p.begin(&pix);
m_doc->paintEverything(p, rc);
p.end();
delete m_doc;
m_doc = 0L;
img = pix.convertToImage();
return true;
}
void KOfficeCreator::timerEvent(QTimerEvent *)
{
m_doc->closeURL();
m_completed = true;
}
void KOfficeCreator::slotCompleted()
{
m_completed = true;
}
ThumbCreator::Flags KOfficeCreator::flags() const
{
return (Flags)(DrawFrame | BlendIcon);
}
#include "kofficecreator.moc"
["kofficethumbnail.desktop" (application/octet-stream)]
["msofficethumbnail.desktop" (application/octet-stream)]
["kofficecreator.h" (application/octet-stream)]
_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic