Commit e4902926 authored by Thomas Zander's avatar Thomas Zander

The first loadable plugin; a very primitive text shape

svn path=/trunk/koffice/; revision=550993
parent 73f006b8
......@@ -87,16 +87,32 @@ kde4_add_dcop_skels(kotext_LIB_SRCS KoTextViewIface.h )
kde4_add_library(kotext SHARED ${kotext_LIB_SRCS})
target_link_libraries(kotext ${KDE4_KSPELL2_LIBS} kutils kofficecore kofficeui )
set_target_properties(kotext PROPERTIES VERSION ${GENERIC_KOFFICE_LIB_VERSION} SOVERSION ${GENERIC_KOFFICE_LIB_SOVERSION} )
install_targets(${LIB_INSTALL_DIR} kotext )
########### install files ###############
########### Flake Plugin library ###############
set(kotext2_PART_SRCS
KoTextShape.cpp
KoTextShapeFactory.cpp
)
kde4_automoc(${kotext2_PART_SRCS})
kde4_add_plugin(kotext2 ${kotext2_PART_SRCS})
kde4_install_libtool_file( ${PLUGIN_INSTALL_DIR} kotext2 )
target_link_libraries(kotext2 flake)
install_targets(${PLUGIN_INSTALL_DIR} kotext2 )
########### install files ###############
install_files( ${SERVICES_INSTALL_DIR} FILES textshape.desktop)
......
/* This file is part of the KDE project
* Copyright (C) 2006 Boudewijn Rempt <boud@valdyas.org>
* 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.
*/
#include "KoTextShape.h"
#include <QTextLayout>
#include <QFont>
#include <QAbstractTextDocumentLayout>
// ############ KoTextShapePrivate ################
KoTextShape::KoTextShapePrivate::KoTextShapePrivate()
{
m_document = new QTextDocument();
// The following avoids the normal case where the glyph metrices are rounded to integers and
// hinted to the screen by freetype, which you of course don't want to wysiwyg
m_document->setUseDesignMetrics(true);
m_document->setDefaultFont(QFont("Sans", 10, QFont::Normal, false));
m_document->setHtml( "<b>Koffie</b>, koffie... Querelanten\ndrinken geen KOffice maar groene thee.");
}
KoTextShape::KoTextShapePrivate::~KoTextShapePrivate() {
delete m_document;
}
// ############ KoTextShape ################
KoTextShape::KoTextShape() {
m_private = new KoTextShapePrivate();
}
KoTextShape::~KoTextShape() {
delete m_private;
}
void KoTextShape::paint(QPainter &painter, KoViewConverter &converter) {
painter.fillRect(converter.normalToView(QRectF(QPointF(0.0,0.0), size())), background());
applyConversion(painter, converter);
QAbstractTextDocumentLayout::PaintContext pc;
pc.cursorPosition = -1;
m_private->m_document->setPageSize(size());
m_private->m_document->documentLayout()->draw( &painter, pc);
}
/* This file is part of the KDE project
* Copyright (c) 2006 Boudewijn Rempt <boud@valdyas.org>
* 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.
*/
#ifndef KOTEXTSHAPE_H
#define KOTEXTSHAPE_H
#include <KoShape.h>
#include <QTextDocument>
#include <QPainter>
class KoTextShape : public KoShape {
public:
KoTextShape();
virtual ~KoTextShape();
void paint(QPainter &painter, KoViewConverter &converter);
private:
class KoTextShapePrivate {
public:
KoTextShapePrivate();
~KoTextShapePrivate();
private:
friend class KoTextShape;
QTextDocument *m_document;
};
KoTextShapePrivate *m_private;
};
#endif
/* 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.
*/
#include <KoTextShapeFactory.h>
#include "KoTextShape.h"
#include <klocale.h>
#include <kgenericfactory.h>
K_EXPORT_COMPONENT_FACTORY(kotext2,
KGenericFactory<KoTextShapeFactory>( "TextShape" ) )
KoTextShapeFactory::KoTextShapeFactory(QObject *parent, const QStringList&)
: KoShapeFactory(parent, "TextShape", i18n("A shape that shows text"))
{
setToolTip(i18n("A text shape"));
}
KoShape *KoTextShapeFactory::createDefaultShape() {
return new KoTextShape();
}
KoShape *KoTextShapeFactory::createShape(KoProperties * params) const {
return new KoTextShape();
}
KoShape *KoTextShapeFactory::createShapeFromTemplate(KoShapeTemplate * shapeTemplate) const {
return new KoTextShape();
}
#include "KoTextShapeFactory.moc"
/* 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.
*/
#ifndef TEXTSHAPEFACTORY_H
#define TEXTSHAPEFACTORY_H
#include <KoShapeFactory.h>
#include <KoShape.h>
#include <QWidget>
#include <koffice_export.h>
class KOTEXT_EXPORT KoTextShapeFactory : public KoShapeFactory {
Q_OBJECT
public:
/// constructor
KoTextShapeFactory(QObject *parent, const QStringList&);
~KoTextShapeFactory() {}
KoShape *createDefaultShape();
KoShape *createShape(KoProperties * params) const;
KoShape *createShapeFromTemplate(KoShapeTemplate * shapeTemplate) const;
QWidget *optionWidget() const { return 0; }
};
#endif
[Desktop Entry]
Encoding=UTF-8
Name=Text Shape
ServiceTypes=KOffice/Shape
Type=Service
X-KDE-Library=kotext2
X-Flake-Version=1
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