Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 33ba042e authored by Pierre Ducroquet's avatar Pierre Ducroquet

Beginning for a pageVariable. Currently, only the page-count field is supported.

svn path=/trunk/koffice/; revision=689683
parent 7197b201
......@@ -45,7 +45,6 @@
#include <KoInlineTextObjectManager.h>
#include <KoInlineObjectRegistry.h>
#include <KoProperties.h>
#include <KoVariable.h>
#include "../styles/KoStyleManager.h"
#include "../styles/KoParagraphStyle.h"
......@@ -829,17 +828,17 @@ void KoTextLoader::loadSpan(KoTextLoadingContext& context, const KoXmlElement& p
dateFormat = dataFormat.prefix + dataFormat.formatStr + dataFormat.suffix;
}
}
KoProperties *dateProperties = new KoProperties();
dateProperties->setProperty("fixed", QVariant(ts.attributeNS(KoXmlNS::text, "fixed") == "true"));
dateProperties->setProperty("time", ts.attributeNS(KoXmlNS::text, localName + "-value"));
dateProperties->setProperty("definition", dateFormat);
dateProperties->setProperty("adjust", ts.attributeNS(KoXmlNS::text, localName + "-adjust"));
KoProperties dateProperties;
dateProperties.setProperty("fixed", QVariant(ts.attributeNS(KoXmlNS::text, "fixed") == "true"));
dateProperties.setProperty("time", ts.attributeNS(KoXmlNS::text, localName + "-value"));
dateProperties.setProperty("definition", dateFormat);
dateProperties.setProperty("adjust", ts.attributeNS(KoXmlNS::text, localName + "-adjust"));
if (dateFormat.isEmpty())
dateProperties->setProperty("displayType", localName);
dateProperties.setProperty("displayType", localName);
else
dateProperties->setProperty("displayType", "custom");
dateProperties.setProperty("displayType", "custom");
KoInlineObject *dateObject = dateFactory->createInlineObject(dateProperties);
KoInlineObject *dateObject = dateFactory->createInlineObject(&dateProperties);
textObjectManager->insertInlineObject(cursor, dateObject);
}
}
......@@ -847,6 +846,30 @@ void KoTextLoader::loadSpan(KoTextLoadingContext& context, const KoXmlElement& p
}
}
}
else if ( isTextNS && (localName == "page-count" || localName == "page-number") ) {
KoTextDocumentLayout *layout = dynamic_cast<KoTextDocumentLayout*> (cursor.block().document()->documentLayout());
if ( layout ) {
KoInlineTextObjectManager *textObjectManager = layout->inlineObjectTextManager();
if ( textObjectManager ) {
KoVariableManager *varManager = textObjectManager->variableManager();
if (varManager) {
if (KoInlineObjectRegistry::instance()->contains("page")) {
KoInlineObjectFactory *pageFactory = KoInlineObjectRegistry::instance()->value("page");
if (pageFactory) {
KoProperties props;
if (localName == "page-count")
props.setProperty("count", true);
else
props.setProperty("count", false);
KoInlineObject *pageObject = pageFactory->createInlineObject(&props);
textObjectManager->insertInlineObject(cursor, pageObject);
}
}
}
}
}
}
else
{
#if 0 //1.6:
......
......@@ -7,6 +7,8 @@ set(textvariables_SRCS
DateVariable.cpp
DateVariableFactory.cpp
FixedDateFormat.cpp
PageVariable.cpp
PageVariableFactory.cpp
)
......
/* This file is part of the KDE project
* Copyright (C) 2007 Pierre Ducroquet <pinaraf@gmail.com>
*
* 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 "PageVariable.h"
#include <KoProperties.h>
#include <kdebug.h>
#include <KoDocument.h>
PageVariable::PageVariable()
: KoVariable(true),
m_type(PageCount)
{
}
void PageVariable::setProperties(const KoProperties *props) {
// Nothing to be done here ?
if (props->boolProperty("count")) {
m_type = PageCount;
} else {
m_type = PageNumber;
}
}
void PageVariable::propertyChanged(Property property, const QVariant &value) {
if ((property == KoInlineObject::PageCount) && (m_type == PageCount)) {
setValue(value.toString());
}// else if ((property == KoInlineObject::StartPage) && (m_type == PageNumber)) {
// setValue(value.toString());
//}
//TODO: support for the PageNumber...
}
/* This file is part of the KDE project
* Copyright (C) 2007 Pierre Ducroquet <pinaraf@gmail.com>
*
* 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 PAGEVARIABLE_H
#define PAGEVARIABLE_H
#include <KoVariable.h>
#include <QString>
/**
* This is a KoVariable for page numbers.
*/
class PageVariable : public KoVariable {
public:
enum PageType {
PageCount,
PageNumber
};
/**
* Constructor.
*/
PageVariable();
void setProperties(const KoProperties *props);
void propertyChanged(Property property, const QVariant &value);
private:
PageType m_type;
};
#endif
/* This file is part of the KDE project
* Copyright (C) 2007 Pierre Ducroquet <pinaraf@gmail.com>
*
* 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 "PageVariableFactory.h"
#include "PageVariable.h"
#include <KoProperties.h>
#include <kdebug.h>
PageVariableFactory::PageVariableFactory(QObject *parent)
: KoInlineObjectFactory(parent, "page")
{
// Nothing
kDebug() << "Creating the page variable factory" << endl;
}
KoInlineObject *PageVariableFactory::createInlineObject(const KoProperties *properties) const {
PageVariable *var = new PageVariable;
var->setProperties(properties);
return var;
}
/* This file is part of the KDE project
* Copyright (C) 2007 Pierre Ducroquet <pinaraf@gmail.com>
*
* 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 KO_PAGE_VARIABLE_FACTORY
#define KO_PAGE_VARIABLE_FACTORY
#include <KoInlineObjectFactory.h>
class KoVariable;
class PageVariableFactory : public KoInlineObjectFactory {
public:
explicit PageVariableFactory(QObject *parent);
~PageVariableFactory() {}
KoInlineObject *createInlineObject(const KoProperties *properties) const;
ObjectType type() const { return TextVariable; }
};
#endif
......@@ -18,6 +18,7 @@
*/
#include "VariablesPlugin.h"
#include "DateVariableFactory.h"
#include "PageVariableFactory.h"
#include <kgenericfactory.h>
#include <KoInlineObjectRegistry.h>
......@@ -28,6 +29,7 @@ K_EXPORT_COMPONENT_FACTORY(textvariables,
VariablesPlugin::VariablesPlugin( QObject *parent, const QStringList& )
: QObject(parent)
{
KoInlineObjectRegistry::instance()->add( new PageVariableFactory( parent));
KoInlineObjectRegistry::instance()->add( new DateVariableFactory( parent));
}
......
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