示例#1
0
void PageVariable::resize(const QTextDocument *document, QTextInlineObject object, int posInDocument, const QTextCharFormat &format, QPaintDevice *pd)
{
    KoTextPage *page = 0;
    if (m_type != PageCount) {
#if 0 // the code is left here to do some testing
        KoTextDocumentLayout *lay = qobject_cast<KoTextDocumentLayout*>(document->documentLayout());
        KoTextLayoutRootArea *rootArea = 0;
        KoTextPage *page2 = 0;
        if (lay) {
            rootArea = lay->rootAreaForPosition(posInDocument);
            if (rootArea) {
                page2 = rootArea->page();
            }
        }
#endif
        page = document->resource(KoTextDocument::LayoutTextPage, KoTextDocument::LayoutTextPageUrl).value<KoTextPage*>();
    }
    int pagenumber = 0;

    switch (m_type) {
    case PageCount:
        break;
    case PageNumber:
        if (page) {
            // the text is not yet layouted therefore we don't get the rootArea
            // if we don't do that we get an endless change of the variable.
            QString currentValue = value();
            if (currentValue.isEmpty() || ! m_fixed) {
                pagenumber = page->visiblePageNumber(m_pageselect, m_pageadjust);
                KoOdfNumberDefinition defaultDefinition; // FIXME Should fetch from pagestyle
                QString newValue = pagenumber >= 0 ? m_numberFormat.formattedNumber(pagenumber, &defaultDefinition) : QString();
                // only update value when changed
                if (currentValue != newValue) {
                     setValue(newValue);
                }
            }
        }
        break;
    case PageContinuation:
        if (page) {
            // the text is not yet layouted therefore we don't get the rootArea
            // if we don't do that we get an endless change of the variable.
            pagenumber = page->visiblePageNumber(m_pageselect);
            setValue(pagenumber >= 0 ? m_continuation : QString());
        }
        break;
    }
    KoVariable::resize(document, object, posInDocument, format, pd);
}
示例#2
0
void PresentationVariable::resize(const QTextDocument *document, QTextInlineObject &object, int posInDocument, const QTextCharFormat &format, QPaintDevice *pd)
{
    KoTextDocumentLayout *lay = qobject_cast<KoTextDocumentLayout*>(document->documentLayout());
    if (lay) {
        KoTextLayoutRootArea *rootArea = lay->rootAreaForPosition(posInDocument);
        if (rootArea) {
            if (KoPATextPage *textPage = dynamic_cast<KoPATextPage*>(rootArea->page())) {
                if (KPrPage *page = dynamic_cast<KPrPage*>(textPage->page())) {
                    setValue(page->declaration(m_type));
                }
            }
        }
    }
    KoVariable::resize(document, object, posInDocument, format, pd);
}