KoTextShapeFactory.cpp 2.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* This file is part of the KDE project
 * Copyright (C) 2006 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
 * 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., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

20
#include "KoProperties.h"
21 22 23 24 25
#include "KoTextShape.h"
#include "KoTextShapeData.h"
#include "KoTextToolFactory.h"
#include "KoToolRegistry.h"
#include <KoTextShapeFactory.h>
26 27 28 29 30 31 32

#include <klocale.h>
#include <kgenericfactory.h>

K_EXPORT_COMPONENT_FACTORY(kotext2,
         KGenericFactory<KoTextShapeFactory>( "TextShape" ) )

33
KoTextShapeFactory::KoTextShapeFactory(QObject *parent, const QStringList& list)
34
: KoShapeFactory(parent, KoTextShape_SHAPEID, i18n("A shape that shows text"))
35 36
{
    setToolTip(i18n("A text shape"));
37 38 39 40 41 42 43 44

    KoShapeTemplate t;
    t.name = "Simple text";
    t.toolTip = "Text shape with some text";
    KoProperties *props = new KoProperties();
    t.properties = props;
    props->setProperty("text", "<b>Koffie</b>, koffie... Querelanten\ndrinken geen KOffice maar groene thee.");
    addTemplate(t);
45 46 47

    // init tool factory here, since this is the only public factory in the lib
    KoToolRegistry::instance()->add(new KoTextToolFactory(parent, list));
48 49 50
}

KoShape *KoTextShapeFactory::createDefaultShape() {
51 52 53
    KoTextShape *text = new KoTextShape();
    text->setShapeId(shapeId());
    return text;
54 55
}

56
KoShape *KoTextShapeFactory::createShape(const KoProperties * params) const {
57
    KoTextShape *shape = new KoTextShape();
58
    shape->setShapeId(shapeId());
59 60 61
    QTextDocument *doc = new QTextDocument();
    doc->setDefaultFont(QFont("Sans", 10, QFont::Normal, false));
    doc->setHtml( params->getProperty("text").toString() );
62 63
    KoTextShapeData *data = static_cast<KoTextShapeData*> (shape->userData());
    data->setDocument(doc);
64
    return shape;
65 66 67
}

#include "KoTextShapeFactory.moc"