[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    RE: Continuing thumbnail obsession
From:       Simon MacMullen <simon.macmullen () aspect-proteus ! com>
Date:       2002-03-04 17:50:40
[Download RAW message or body]

David:
> > Hmm, each applications handles the KoPageLayout itself.
> > The way to gain access to this from KoDocument would be to centralize
even
> > more code in kofficecore, e.g. storing the page layout there and porting
the
> > koffice apps to use that variable instead of storing it themselves.

Me:
> This sounds like a lot of work, right?

Well, I was wrong. The attached patch does this (in a very basic way; just
moves m_pageLayout into KoDocument). It now looks much nicer. 

http://www.babysimon.co.uk/kde/kofficepreview.png

But I'm afraid something's definitely up with the font sizes. The text "Big
heading" in the KWord file, and the text "Groovy presentation" in the
KPresenter file (thank you Laurent!) are both meant to be centred. But I
still think it looks quite cool.

Me again:
> In that case, maybe the save functionality should create a thumbnail and
> embed it within the file (blue sky thinking here really).

Just in case I was crazy enough to want to do this, would
KoDocument::saveToStore be the right place to put it?

I think this should get two desktop files - one for KOffice native formats
and one for everything else (since when/if I get this embedded thumbnail
thing to work KOffice native documents should be much faster).

Would this be able to go into CVS? That way someone else might fill in the
rest of the mimetypes ;)

Thanks,

Simon


["koffice.diff" (application/octet-stream)]

? koffice.diff
? doc/kformula/.memdump
? doc/koffice/.memdump
? doc/kontour/.memdump
? doc/koshell/.memdump
? doc/kpresenter/.memdump
? doc/kspread/.memdump
? doc/kugar/.memdump
? doc/kword/.memdump
? doc/thesaurus/.memdump
? kontour/kontour_viewiface.kidl
? kontour/kontour_viewiface_skel.cc
? krayon/Makefile.in
? krayon/Makefile
? krayon/core/Makefile.in
? krayon/core/Makefile
? krayon/data/Makefile.in
? krayon/data/Makefile
? krayon/data/brushes/Makefile.in
? krayon/data/brushes/Makefile
? krayon/data/images/Makefile.in
? krayon/data/images/Makefile
? krayon/data/patterns/Makefile.in
? krayon/data/patterns/Makefile
? krayon/dtd/Makefile.in
? krayon/dtd/Makefile
? krayon/pics/Makefile.in
? krayon/pics/Makefile
? krayon/plugins/Makefile.in
? krayon/plugins/Makefile
? krayon/plugins/example/Makefile.in
? krayon/plugins/example/Makefile
? krayon/test/Makefile.in
? krayon/test/Makefile
? krayon/tools/Makefile.in
? krayon/tools/Makefile
? krayon/ui/Makefile.in
? krayon/ui/Makefile
? 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/otherofficethumbnail.desktop
Index: kpresenter/kpresenter_doc.cc
===================================================================
RCS file: /home/kde/koffice/kpresenter/kpresenter_doc.cc,v
retrieving revision 1.436
diff -u -3 -p -r1.436 kpresenter_doc.cc
--- kpresenter/kpresenter_doc.cc	2002/03/03 17:33:02	1.436
+++ kpresenter/kpresenter_doc.cc	2002/03/04 17:36:27
@@ -189,7 +189,7 @@ KPresenterDoc::KPresenterDoc( QWidget *p
     emit sig_changeActivePage(newpage );
     m_stickyPage=new KPrPage(this);
     objStartY = 0;
-    setPageLayout( _pageLayout );
+    setPageLayout( m_pageLayout );
     _presPen = QPen( red, 3, SolidLine );
     presSpeed = 2;
     ignoreSticky = TRUE;
@@ -406,18 +406,18 @@ QDomDocument KPresenterDoc::saveXML()
     presenter.setAttribute("syntaxVersion", CURRENT_SYNTAX_VERSION);
     doc.appendChild(presenter);
     QDomElement paper=doc.createElement("PAPER");
-    paper.setAttribute("format", static_cast<int>( _pageLayout.format ));
-    paper.setAttribute("ptWidth", _pageLayout.ptWidth);
-    paper.setAttribute("ptHeight", _pageLayout.ptHeight);
+    paper.setAttribute("format", static_cast<int>( m_pageLayout.format ));
+    paper.setAttribute("ptWidth", m_pageLayout.ptWidth);
+    paper.setAttribute("ptHeight", m_pageLayout.ptHeight);
 
-    paper.setAttribute("orientation", static_cast<int>( _pageLayout.orientation ));
+    paper.setAttribute("orientation", static_cast<int>( m_pageLayout.orientation ));
     paper.setAttribute("unit", m_unit );
     QDomElement paperBorders=doc.createElement("PAPERBORDERS");
 
-    paperBorders.setAttribute("ptLeft", _pageLayout.ptLeft);
-    paperBorders.setAttribute("ptTop", _pageLayout.ptTop);
-    paperBorders.setAttribute("ptRight", _pageLayout.ptRight);
-    paperBorders.setAttribute("ptBottom", _pageLayout.ptBottom);
+    paperBorders.setAttribute("ptLeft", m_pageLayout.ptLeft);
+    paperBorders.setAttribute("ptTop", m_pageLayout.ptTop);
+    paperBorders.setAttribute("ptRight", m_pageLayout.ptRight);
+    paperBorders.setAttribute("ptBottom", m_pageLayout.ptBottom);
     paper.appendChild(paperBorders);
     presenter.appendChild(paper);
 
@@ -1579,7 +1579,7 @@ bool KPresenterDoc::completeLoading( KoS
 	    setPageLayout( __pgLayout );
         }
 	else
-	    setPageLayout( _pageLayout );
+	    setPageLayout( m_pageLayout );
     }
     recalcVariables( VT_FIELD );
     return true;
@@ -1645,7 +1645,7 @@ void KPresenterDoc::setPageLayout( KoPag
     //     if ( _pageLayout == pgLayout )
     //	return;
 
-    _pageLayout = pgLayout;
+    m_pageLayout = pgLayout;
 
     //for ( int i = 0; i < static_cast<int>( m_pageList.count() ); i++ )
     //    m_pageList.at( i )->updateBackgroundSize();
@@ -1773,12 +1773,12 @@ QValueList<int> KPresenterDoc::reorderPa
 /*================== get size of page ===========================*/
 QRect KPresenterDoc::getPageRect( bool decBorders ) const
 {
-    int pw, ph, bl = static_cast<int>(_pageLayout.ptLeft);
-    int br = static_cast<int>(_pageLayout.ptRight);
-    int bt = static_cast<int>(_pageLayout.ptTop);
-    int bb = static_cast<int>(_pageLayout.ptBottom);
-    int wid = static_cast<int>(_pageLayout.ptWidth);
-    int hei = static_cast<int>(_pageLayout.ptHeight);
+    int pw, ph, bl = static_cast<int>(m_pageLayout.ptLeft);
+    int br = static_cast<int>(m_pageLayout.ptRight);
+    int bt = static_cast<int>(m_pageLayout.ptTop);
+    int bb = static_cast<int>(m_pageLayout.ptBottom);
+    int wid = static_cast<int>(m_pageLayout.ptWidth);
+    int hei = static_cast<int>(m_pageLayout.ptHeight);
 
     if ( !decBorders ) {
 	br = 0;
@@ -1796,24 +1796,24 @@ QRect KPresenterDoc::getPageRect( bool d
 /*================================================================*/
 int KPresenterDoc::getLeftBorder() const
 {
-    return static_cast<int>(_pageLayout.ptLeft);
+    return static_cast<int>(m_pageLayout.ptLeft);
 }
 
 /*================================================================*/
 int KPresenterDoc::getTopBorder() const
 {
-    return static_cast<int>(_pageLayout.ptTop);
+    return static_cast<int>(m_pageLayout.ptTop);
 }
 
 /*================================================================*/
 int KPresenterDoc::getBottomBorder() const
 {
-    return static_cast<int>(_pageLayout.ptBottom);
+    return static_cast<int>(m_pageLayout.ptBottom);
 }
 
 int KPresenterDoc::getRightBorder() const
 {
-    return static_cast<int>(_pageLayout.ptRight);
+    return static_cast<int>(m_pageLayout.ptRight);
 }
 
 
@@ -2437,8 +2437,8 @@ void KPresenterDoc::updateRulerPageLayou
     QPtrListIterator<KoView> it( views() );
     for (; it.current(); ++it )
     {
-        ((KPresenterView*)it.current())->getHRuler()->setPageLayout(_pageLayout );
-        ((KPresenterView*)it.current())->getVRuler()->setPageLayout( _pageLayout );
+        ((KPresenterView*)it.current())->getHRuler()->setPageLayout(m_pageLayout );
+        ((KPresenterView*)it.current())->getVRuler()->setPageLayout(m_pageLayout );
 
     }
 
Index: kpresenter/kpresenter_doc.h
===================================================================
RCS file: /home/kde/koffice/kpresenter/kpresenter_doc.h,v
retrieving revision 1.227
diff -u -3 -p -r1.227 kpresenter_doc.h
--- kpresenter/kpresenter_doc.h	2002/03/03 16:16:13	1.227
+++ kpresenter/kpresenter_doc.h	2002/03/04 17:36:27
@@ -121,8 +121,6 @@ public:
     void createHeaderFooter();
     void updateHeaderFooterPosition();
 
-    KoPageLayout pageLayout() const { return _pageLayout; }
-
     bool insertNewTemplate( bool clean=false );
 
     const QPtrList<KPrPage> & getPageList() const {return m_pageList;}
@@ -376,9 +374,6 @@ protected:
         QString filename;
         QString pix_string;
     };
-
-    // page layout
-    KoPageLayout _pageLayout;
 
     // screenpresentations
     bool _spInfinitLoop, _spManualSwitch, _showPresentationDuration;
Index: kword/kwdoc.h
===================================================================
RCS file: /home/kde/koffice/kword/kwdoc.h,v
retrieving revision 1.146
diff -u -3 -p -r1.146 kwdoc.h
--- kword/kwdoc.h	2002/02/28 20:16:24	1.146
+++ kword/kwdoc.h	2002/03/04 17:36:28
@@ -162,7 +162,6 @@ public:
     void setPageLayout( const KoPageLayout& _layout, const KoColumns& _cl, const \
KoKWHeaderFooter& _hf );  
     void getPageLayout( KoPageLayout& _layout, KoColumns& _cl, KoKWHeaderFooter& _hf \
                );
-    KoPageLayout pageLayout() const { return m_pageLayout; }
 
     KWTextFrameSet * textFrameSet ( unsigned int _num ) const;
     // Return the frameset number @p _num
@@ -554,7 +553,6 @@ private:
     QPtrList<KWView> m_lstViews;
     QPtrList<KWChild> m_lstChildren;
 
-    KoPageLayout m_pageLayout;
     KoColumns m_pageColumns;
     KoKWHeaderFooter m_pageHeaderFooter;
 
Index: lib/kofficecore/koDocument.cc
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/koDocument.cc,v
retrieving revision 1.200
diff -u -3 -p -r1.200 koDocument.cc
--- lib/kofficecore/koDocument.cc	2002/03/02 20:39:19	1.200
+++ lib/kofficecore/koDocument.cc	2002/03/04 17:36:28
@@ -185,6 +185,13 @@ KoDocument::KoDocument( QWidget * parent
     }
 
   d->m_docInfo = new KoDocumentInfo( this, "document info" );
+
+  m_pageLayout.ptWidth = 0;
+  m_pageLayout.ptHeight = 0;
+  m_pageLayout.ptTop = 0;
+  m_pageLayout.ptBottom = 0;
+  m_pageLayout.ptLeft = 0;
+  m_pageLayout.ptRight = 0;
 }
 
 KoDocument::~KoDocument()
Index: lib/kofficecore/koDocument.h
===================================================================
RCS file: /home/kde/koffice/lib/kofficecore/koDocument.h,v
retrieving revision 1.105
diff -u -3 -p -r1.105 koDocument.h
--- lib/kofficecore/koDocument.h	2002/03/02 20:39:19	1.105
+++ lib/kofficecore/koDocument.h	2002/03/04 17:36:28
@@ -28,6 +28,7 @@ using namespace std;
 #include <kparts/part.h>
 #include <kurl.h>
 #include <kservice.h>
+#include <koGlobal.h>
 
 class QDomElement;
 class QDomDocument;
@@ -440,6 +441,8 @@ public:
    */
   virtual bool isStoredExtern();
 
+  KoPageLayout pageLayout() const { return m_pageLayout; }
+
 signals:
   /**
    * This signal is emitted, if a direct or indirect child document changes
@@ -570,6 +573,8 @@ protected:
 
   /** @internal */
   virtual void insertChild(QObject *o) { QObject::insertChild(o); }
+
+  KoPageLayout m_pageLayout;
 
 private slots:
   void slotChildChanged( KoChild *c );
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/03/04 17:36:28
@@ -1,11 +1,16 @@
-INCLUDES = $(KOFFICE_INCLUDES) $(all_includes)
+INCLUDES = $(KOFFICE_INCLUDES) $(all_includes) -I../../kword/ -I../../kpresenter \
-I../../lib/kotext  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 \
otherofficethumbnail.desktop +


["kofficecreator.cpp" (application/octet-stream)]

/*  This file is part of the KDE libraries
    Copyright (C) 2002 Simon MacMullen

    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 <kwdoc.h>
#include <kpresenter_doc.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();

	double docWidth, docHeight;
	int dpi = 75; // FIXME

    KoPageLayout layout = m_doc->pageLayout();

	if (layout.ptWidth > 1.0) {
	    // for eg KWord we want the first page
		docWidth = layout.ptWidth / 72 * dpi;
        docHeight = layout.ptHeight / 72 * dpi;

	} else {
	    // For eg kspread we just want the top left hand corner
	    docWidth = 500.0;
		docHeight = 500.0;
	}

	double ratio = docWidth / docHeight;

    // render the page on a bigger pixmap and use smoothScale,
    // looks better than directly scaling with the QPainter (malte)
    QPixmap pix;
    if (width > 400)
    {
        pix.resize(width, (int)(width / ratio));
    }
    else
        pix.resize(400, (int)(400 / ratio));

    pix.fill( QColor( 245, 245, 245 ) );

    int borderX = pix.width() / width,
        borderY = pix.height() / height;
    QRect rc(borderX, borderY, pix.width() - borderX * 2, pix.height() - borderY * 2);
	
	double zoomX = pix.width() / docWidth;
	double zoomY = pix.height() / docHeight;

    QPainter p;
    p.begin(&pix);
    m_doc->paintEverything(p, rc, false, 0, zoomX, zoomY);
    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"


["kofficecreator.h" (application/octet-stream)]
["kofficethumbnail.desktop" (application/octet-stream)]
["otherofficethumbnail.desktop" (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