Commit d25b1b85 authored by Thomas Zander's avatar Thomas Zander

* make the krita shape able to read its data using the KoImageData user-object.

* Implement the waitUntilReady() method to allow the krita shape to finish loading
before we try to print it. (so nothing crashes or otherwise goes wrong)

svn path=/trunk/koffice/; revision=689940
parent 47fd30b9
/* This file is part of the KDE project
Copyright 2007 Boudewijn Rempt <boud@valdyas.org>
Copyright 2007 Thomas Zander <zander@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
......@@ -20,11 +21,13 @@
#include <QPainter>
#include <QFrame>
#include <QVBoxLayout>
#include <QCoreApplication>
#include <kdebug.h>
#include <KoColorProfile.h>
#include <KoColorSpaceRegistry.h>
#include <KoImageData.h>
#include "kis_image.h"
#include "kis_doc2.h"
......@@ -49,7 +52,7 @@ KritaShape::KritaShape(const KUrl& url, const QString & profileName)
}
m_d->displayProfile = KoColorSpaceRegistry::instance()->profileByName(profileName);
setKeepAspectRatio(true);
moveToThread(QCoreApplication::instance()->thread()); // its a QObject; lets me sure it always has a proper thread.
}
KritaShape::~KritaShape()
......@@ -61,21 +64,18 @@ void KritaShape::importImage(const KUrl & url )
{
delete m_d->doc;
m_d->doc = new KisDoc2(0, 0, false);
connect(m_d->doc, SIGNAL(sigLoadingFinished()), this, SLOT(slotLoadingFinished()));
m_d->doc->openURL(url);
if ( !m_d->doc->isLoading() ) {
slotLoadingFinished();
}
else {
connect(m_d->doc, SIGNAL(sigLoadingFinished()), this, SLOT(slotLoadingFinished()));
}
}
void KritaShape::slotLoadingFinished()
{
m_mutex.lock();
if ( m_d && m_d->doc && m_d->doc->image() ) {
m_waiter.wakeAll();
repaint();
}
m_mutex.unlock();
}
......@@ -95,7 +95,6 @@ void KritaShape::paint( QPainter& painter, const KoViewConverter& converter )
painter.drawImage(paintRect.toRect(), qimg);
}
}
void KritaShape::setDisplayProfile( const QString & profileName ) {
......@@ -110,4 +109,20 @@ bool KritaShape::loadOdf( const KoXmlElement & element, KoShapeLoadingContext &c
return false; // TODO
}
void KritaShape::waitUntilReady() const {
if ( m_d && m_d->doc && m_d->doc->image() ) // all done
return;
KoImageData *data = dynamic_cast<KoImageData*> (KoShape::userData());
if(data == 0 || !data->imageLocation().isValid())
return; // no data available at all.
KritaShape *me = const_cast<KritaShape*> (this);
m_mutex.lock();
me->importImage(data->imageLocation());
m_waiter.wait(&m_mutex);
m_mutex.unlock();
}
#include "KritaShape.moc"
......@@ -26,6 +26,9 @@
class QString;
class KUrl;
#include <QWaitCondition>
#include <QMutex>
#define KritaShapeId "KritaShape"
/**
......@@ -67,6 +70,8 @@ public:
virtual void saveOdf( KoShapeSavingContext & context ) const;
// reimplemented
virtual bool loadOdf( const KoXmlElement & element, KoShapeLoadingContext &context );
// reimplemented
virtual void waitUntilReady() const;
void setDisplayProfile( const QString & profileName );
void importImage( const KUrl & url );
......@@ -80,6 +85,8 @@ private:
class Private;
Private * m_d;
mutable QMutex m_mutex;
mutable QWaitCondition m_waiter;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment