Commit 42f7fbda authored by Sebastian Sauer's avatar Sebastian Sauer

made text:select-page=previous

svn path=/trunk/koffice/; revision=851479
parent 5e5514e0
......@@ -57,7 +57,8 @@ public:
position(-1),
endPosition(-1),
pageNumber(-1),
direction(KoText::AutoDirection)
direction(KoText::AutoDirection),
pageNumberSelectType(KoTextShapeData::PageNumberSelectPageCurrent)
{
}
......@@ -72,6 +73,7 @@ public:
int position, endPosition, pageNumber;
KoInsets margins;
KoText::Direction direction;
PageNumberSelectType pageNumberSelectType;
};
......@@ -171,6 +173,14 @@ KoText::Direction KoTextShapeData::pageDirection() const {
return d->direction;
}
KoTextShapeData::PageNumberSelectType KoTextShapeData::pageNumberSelectType() const {
return d->pageNumberSelectType;
}
void KoTextShapeData::setPageNumberSelectType(KoTextShapeData::PageNumberSelectType selecttype) {
d->pageNumberSelectType = selecttype;
}
bool KoTextShapeData::loadOdf(const KoXmlElement & element, KoShapeLoadingContext & context) {
KoTextLoader loader( context );
......
......@@ -96,7 +96,7 @@ public:
/// mark shape as dirty triggering a re-layout of its text.
void foul();
/// mark shape as not-dirty
void wipe();
......@@ -113,8 +113,9 @@ public:
* @param margins the margins that shrink the text area.
*/
void setShapeMargins(const KoInsets &margins);
/// returns the currently set margins for the shape.
/**
* returns the currently set margins for the shape.
*/
KoInsets shapeMargins() const;
/**
......@@ -126,6 +127,29 @@ public:
*/
int pageNumber() const;
/**
* Display Previous or Following Page Numbers. The PageNumberSelectType represents
* the text:select-page attribute which is used to display the number of the previous
* or the following page rather than the number of the current page.
*
* \note To display the current page number on all pages except the first or last
* page, use a combination of the text:select page and text:page adjust attributes.
*
* Example: Displaying the current page number on all pages except the first page
* \code
* <text:page-number text:select-page="previous" text:page-adjust="1" style:num-format="1"/>
* \endcode
*/
enum PageNumberSelectType {
PageNumberSelectPageCurrent, ///< Select the "current" page.
PageNumberSelectPagePrev, ///< Select the "previous" page.
PageNumberSelectPageNext ///< Select the "next" page.
};
/// Returns the text:select-page value.
PageNumberSelectType pageNumberSelectType() const;
/// Sets the text:select-page value.
void setPageNumberSelectType(PageNumberSelectType selecttype);
/**
* Load the TextShape from ODF.
*
......@@ -134,7 +158,6 @@ public:
* to load the ODF.
*/
bool loadOdf(const KoXmlElement & element, KoShapeLoadingContext & context);
/**
* Store the TextShape data as ODF.
* @param saveDefaultStyles If set to false, the default styles won't be saved. This way, you can have several
......@@ -155,6 +178,7 @@ public:
* new paragraphs default direction.
*/
KoText::Direction pageDirection() const;
signals:
/**
* emitted when the shape thinks it should be relayouted, for example after
......
......@@ -25,7 +25,6 @@
#include <KoXmlWriter.h>
#include <KoProperties.h>
#include <kdebug.h>
#include <KoTextShapeData.h>
#include <KoShape.h>
#include <KoShapeSavingContext.h>
#include <KoShapeLoadingContext.h>
......@@ -35,6 +34,7 @@ PageVariable::PageVariable()
: KoVariable(true),
m_type(PageCount),
m_pageadjust(0),
m_selectpage(KoTextShapeData::PageNumberSelectPageCurrent),
m_fixed(false)
{
}
......@@ -66,18 +66,12 @@ void PageVariable::variableMoved(const KoShape *shape, const QTextDocument *docu
case PageCount:
break;
case PageNumber:
if (shape && ! m_fixed) {
if (shape && ( !m_fixed || value().isNull() )) {
KoTextShapeData *shapeData = dynamic_cast<KoTextShapeData *>(shape->userData());
if (shapeData) {
shapeData->setPageNumberSelectType(m_selectpage);
int pagenumber = shapeData->pageNumber();
if(m_selectpage == "previous") {
//TODO fetch prev page and use that pagenum
}
else if(m_selectpage == "next") {
//TODO fetch next page and use that pagenum
}
setValue(QString::number(pagenumber + m_pageadjust + 1));
}
}
......@@ -98,11 +92,25 @@ void PageVariable::saveOdf( KoShapeSavingContext & context )
case PageNumber:
// <text:page-number text:select-page="current" >3</text:page-number>
writer->startElement("text:page-number", false);
writer->addAttribute("text:select-page", m_selectpage.isEmpty() ? "current" : m_selectpage);
switch(m_selectpage) {
case KoTextShapeData::PageNumberSelectPagePrev:
writer->addAttribute("text:select-page", "previous");
break;
case KoTextShapeData::PageNumberSelectPageNext:
writer->addAttribute("text:select-page", "next");
break;
case KoTextShapeData::PageNumberSelectPageCurrent:
writer->addAttribute("text:select-page", "current");
break;
}
if(m_pageadjust != 0)
writer->addAttribute("text:page-adjust", m_pageadjust);
if(m_fixed)
writer->addAttribute("text:fixed", "true");
writer->addTextNode(value());
writer->endElement();
break;
......@@ -126,7 +134,16 @@ bool PageVariable::loadOdf( const KoXmlElement & element, KoShapeLoadingContext
// The text:select-page attribute is used to display the number of the previous or the following
// page rather than the number of the current page.
m_selectpage = element.attributeNS( KoXmlNS::text, "select-page", QString() );
QString selectpage = element.attributeNS( KoXmlNS::text, "select-page", QString() );
if(selectpage == "previous") {
m_selectpage = KoTextShapeData::PageNumberSelectPagePrev;
}
else if(selectpage == "next") {
m_selectpage = KoTextShapeData::PageNumberSelectPageNext;
}
else {
m_selectpage = KoTextShapeData::PageNumberSelectPageCurrent;
}
// The text:fixed attribute specifies whether or not the value of a field element is fixed. If the
// value of a field is fixed, the value of the field element to which this attribute is attached is
......
......@@ -22,6 +22,7 @@
#define PAGEVARIABLE_H
#include <KoVariable.h>
#include <KoTextShapeData.h>
class KoShapeSavingContext;
......@@ -56,7 +57,7 @@ private:
PageType m_type;
int m_pageadjust;
QString m_selectpage;
KoTextShapeData::PageNumberSelectType m_selectpage;
bool m_fixed;
};
......
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