Exemplo n.º 1
0
void TableOfContentsConfigure::setDisplay()
{
    setVisible(true);

    ui.lineEditTitle->setText(m_tocInfo->m_indexTitleTemplate.text);
    ui.useOutline->setCheckState(m_tocInfo->m_useOutlineLevel ? Qt::Checked : Qt::Unchecked);
    ui.useStyles->setCheckState(m_tocInfo->m_useIndexSourceStyles ? Qt::Checked : Qt::Unchecked);

    connect(ui.lineEditTitle, SIGNAL(textChanged(QString)), this, SLOT(titleTextChanged(QString)));
    connect(ui.useOutline, SIGNAL(stateChanged(int)), this, SLOT(useOutline(int)));
    connect(ui.useStyles, SIGNAL(stateChanged(int)), this, SLOT(useIndexSourceStyles(int)));

    m_tocEntryStyleModel = new TableOfContentsEntryModel(KoTextDocument(m_textEditor->document()).styleManager(), m_tocInfo);
    connect(m_tocEntryStyleModel, SIGNAL(tocEntryDataChanged()), this, SLOT(updatePreview()));

    m_tocEntryConfigureDelegate = new TableOfContentsEntryDelegate(KoTextDocument(m_textEditor->document()).styleManager());

    ui.configureToCEntryStyle->setModel(m_tocEntryStyleModel);

    ui.configureToCEntryStyle->setItemDelegateForColumn(1, m_tocEntryConfigureDelegate);

    ui.configureToCEntryStyle->setShowGrid(false);
    ui.configureToCEntryStyle->verticalHeader()->hide();
    ui.configureToCEntryStyle->setEditTriggers(QAbstractItemView::CurrentChanged | QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked);
    ui.configureToCEntryStyle->setSelectionBehavior(QAbstractItemView::SelectRows);
    ui.configureToCEntryStyle->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
    ui.configureToCEntryStyle->horizontalHeader()->setResizeMode(1, QHeaderView::Stretch);

    connect(this, SIGNAL(accepted()), this, SLOT(save()));
    connect(this, SIGNAL(rejected()), this, SLOT(cleanUp()));

    updatePreview();
}
ShowChangesCommand::ShowChangesCommand(bool showChanges, QTextDocument *document, KoCanvasBase *canvas, KUndo2Command *parent) :
    KoTextCommandBase (parent),
    m_document(document),
    m_first(true),
    m_showChanges(showChanges),
    m_canvas(canvas)
{
    Q_ASSERT(document);
    m_changeTracker = KoTextDocument(m_document).changeTracker();
    m_textEditor = KoTextDocument(m_document).textEditor();
    if (showChanges)
      setText(i18nc("(qtundo-format)", "Show Changes"));
    else
      setText(i18nc("(qtundo-format)", "Hide Changes"));
}
void SimpleTableOfContentsWidget::prepareTemplateMenu()
{
    m_previewGenerator.clear();
    if (m_signalMapper) {
        delete m_signalMapper;
        m_signalMapper = 0;
    }
    qDeleteAll(m_templateList.begin(), m_templateList.end());
    m_templateList.clear();

    m_signalMapper = new QSignalMapper();

    m_templateList = m_templateGenerator->templates();

    connect(m_signalMapper, SIGNAL(mapped(int)), this, SLOT(pixmapReady(int)));

    int index = 0;
    foreach (KoTableOfContentsGeneratorInfo *info, m_templateList) {
        TableOfContentsPreview *preview = new TableOfContentsPreview();
        preview->setStyleManager(KoTextDocument(m_referenceTool->editor()->document()).styleManager());
        preview->setPreviewSize(QSize(200,120));
        preview->updatePreview(info);
        connect(preview, SIGNAL(pixmapGenerated()), m_signalMapper, SLOT(map()));
        m_signalMapper->setMapping(preview, index);
        m_previewGenerator.append(preview);
        ++index;

        //put dummy pixmaps until the actual pixmap previews are generated and added in pixmapReady()
        if (! widget.addToC->hasItemId(index)) {
            QPixmap pmm(QSize(200,120));
            pmm.fill(Qt::white);
            widget.addToC->addItem(pmm, index);
        }
    }
ChangeListLevelCommand::ChangeListLevelCommand(const QTextCursor &cursor, ChangeListLevelCommand::CommandType type,
                                               int coef, KUndo2Command *parent)
    : KoTextCommandBase(parent),
      m_type(type),
      m_coefficient(coef),
      m_first(true)
{
    setText(kundo2_i18n("Change List Level"));

    int selectionStart = qMin(cursor.anchor(), cursor.position());
    int selectionEnd = qMax(cursor.anchor(), cursor.position());

    QTextBlock block = cursor.block().document()->findBlock(selectionStart);

    bool oneOf = (selectionStart == selectionEnd); //ensures the block containing the cursor is selected in that case

    while (block.isValid() && ((block.position() < selectionEnd) || oneOf)) {
        m_blocks.append(block);
        if (block.textList()) {
            m_lists.insert(m_blocks.size() - 1, KoTextDocument(block.document()).list(block.textList()));
            Q_ASSERT(m_lists.value(m_blocks.size() - 1));
            m_levels.insert(m_blocks.size() - 1, effectiveLevel(m_lists.value(m_blocks.size() - 1)->level(block)));
        }
        oneOf = false;
        block = block.next();
    }
}
Exemplo n.º 5
0
/// This method is used to start an on-the-fly macro command. Use KoTextEditor::endEditBlock to stop it.
/// ***
/// Important note:
/// ***
/// The framework does not allow to push a complete KUndo2Command (through KoTextEditor::addCommand) from within an EditBlock. Doing so will lead in the best case to several undo/redo commands on the application's stack instead of one, in the worst case to an out of sync application's stack.
/// ***
KUndo2Command *KoTextEditor::beginEditBlock(const QString &title)
{
    kDebug(32500) << "beginEditBlock";
    kDebug(32500) << "commandStack count: " << d->commandStack.count();
    kDebug(32500) << "customCommandCount counter: " << d->customCommandCount;
    if (!d->customCommandCount) {
        // We are not in a custom macro command. So we first need to update the KoTextEditor's state to Custom. Additionally, if the commandStack is empty, we need to create a master headCommand for our macro and push it on the stack.
        kDebug(32500) << "we are not in a custom command. will update state to custom";
        d->updateState(KoTextEditor::Private::Custom, title);
        kDebug(32500) << "commandStack count: " << d->commandStack.count();
        if (d->commandStack.isEmpty()) {
            kDebug(32500) << "the commandStack is empty. we need a dummy headCommand both on the commandStack and on the application's stack";
            KUndo2Command *command = new KUndo2Command(title);
            d->commandStack.push(command);
            ++d->customCommandCount;
            d->dummyMacroAdded = true; //This bool is used to tell endEditBlock that we have created a master headCommand.
            KUndo2QStack *stack = KoTextDocument(d->document).undoStack();
            if (stack) {
                stack->push(command);
            } else {
                command->redo();
            }
            kDebug(32500) << "done adding the headCommand. commandStack count: " << d->commandStack.count() << " inCommand counter: " << d->customCommandCount;
        }
    }
    //QTextDocument sends the undoCommandAdded signal at the end of the QTextCursor edit block. Since we want our master headCommand to parent the signal induced UndoTextCommands, we should not call QTextCursor::beginEditBlock for the headCommand.
    if (!(d->dummyMacroAdded && d->customCommandCount == 1)) {
        kDebug(32500) << "we did not add a dummy command, or we are further down nesting. call beginEditBlock on the caret to nest the QTextDoc changes";
        //we don't call beginEditBlock for the first headCommand because we want the signals to be sent before we finished our command.
        d->caret.beginEditBlock();
    }
    kDebug(32500) << "will return top od commandStack";
    return (d->commandStack.isEmpty())?0:d->commandStack.top();
}
Exemplo n.º 6
0
 void undo() {
     QTextDocument *doc = m_document.data();
     if (doc == 0)
         return;
     doc->undo(KoTextDocument(doc).textEditor()->cursor());
     m_p->emitTextFormatChanged();
 }
void ShowChangesCommand::insertDeletedChanges()
{
    int numAddedChars = 0;
    QVector<KoChangeTrackerElement *> elementVector;
    KoTextDocument(m_textEditor->document()).changeTracker()->getDeletedChanges(elementVector);
    qSort(elementVector.begin(), elementVector.end());
}
Exemplo n.º 8
0
void TestChangeTrackedDelete::testPrefixMerge()
{
    TextTool *textTool = new TextTool(new MockCanvas);
    KoTextEditor *textEditor = textTool->textEditor();
    QVERIFY(textEditor);
    QTextDocument *document = textEditor->document();
    KoTextDocumentLayout *layout = qobject_cast<KoTextDocumentLayout *>(document->documentLayout());
    QTextCursor *cursor = textEditor->cursor();
    cursor->insertText("Hello World");
    cursor->setPosition(3);
    ChangeTrackedDeleteCommand *delCommand = new ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, textTool);
    textEditor->addCommand(delCommand);
    QCOMPARE(document->characterAt(3).unicode(), (ushort)(QChar::ObjectReplacementCharacter));
    cursor->setPosition(4);
    delCommand = new ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, textTool);
    textEditor->addCommand(delCommand);
    // This is weird. Without this loop present the succeeding call to inlineTextObject returs NULL. Why ??????
    for (int i = 0; i < document->characterCount(); i++) {
        cursor->setPosition(i);
    }
    cursor->setPosition(4);
    KoDeleteChangeMarker *testMarker = dynamic_cast<KoDeleteChangeMarker *>(layout->inlineTextObjectManager()->inlineTextObject(*cursor));
    QTextDocumentFragment deleteData =  KoTextDocument(document).changeTracker()->elementById(testMarker->changeId())->getDeleteData();
    QCOMPARE(deleteData.toPlainText(), QString("lo"));
    delete textTool;
}
Exemplo n.º 9
0
void TableOfContentsConfigure::showStyleConfiguration()
{
    if (!m_tocStyleConfigure) {
        m_tocStyleConfigure = new TableOfContentsStyleConfigure(KoTextDocument(m_textEditor->document()).styleManager(), this);
    }
    m_tocStyleConfigure->initializeUi(m_tocInfo);

}
Exemplo n.º 10
0
RenameSectionCommand::RenameSectionCommand(KoSection *section, const QString &newName, QTextDocument *document)
    : KUndo2Command()
    , m_sectionModel(KoTextDocument(document).sectionModel())
    , m_section(section)
    , m_newName(newName)
    , m_first(true)
{
    setText(kundo2_i18n("Rename Section"));
}
Exemplo n.º 11
0
void TestChangeTrackedDelete::testListDelete()
{
    TextTool *textTool = new TextTool(new MockCanvas);
    KoTextEditor *textEditor = textTool->textEditor();
    QVERIFY(textEditor);
    QTextDocument *document = textEditor->document();
    KoTextDocumentLayout *layout = qobject_cast<KoTextDocumentLayout *>(document->documentLayout());
    QTextCursor *cursor = textEditor->cursor();
    insertSampleList(document);

    cursor->setPosition(16);
    cursor->setPosition(152, QTextCursor::KeepAnchor);
    ChangeTrackedDeleteCommand *delCommand = new ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, textTool);
    textEditor->addCommand(delCommand);
    QCOMPARE(document->characterAt(16).unicode(), (ushort)(QChar::ObjectReplacementCharacter));

    // This is weird. Without this loop present the succeeding call to inlineTextObject returs NULL. Why ??????
    for (int i = 0; i < document->characterCount(); i++) {
        cursor->setPosition(i);
    }

    cursor->setPosition(17);
    KoDeleteChangeMarker *testMarker = dynamic_cast<KoDeleteChangeMarker *>(layout->inlineTextObjectManager()->inlineTextObject(*cursor));
    QTextDocumentFragment deleteData =  KoTextDocument(document).changeTracker()->elementById(testMarker->changeId())->getDeleteData();

    QTextDocument deleteDocument;
    QTextCursor deleteCursor(&deleteDocument);

    deleteCursor.insertFragment(deleteData);
    bool listFound = false;

    for (int i = 0; i < deleteDocument.characterCount(); i++) {
        deleteCursor.setPosition(i);
        if (deleteCursor.currentList()) {
            listFound = true;
            continue;
        }
    }

    QVERIFY(listFound == true);
    QTextList *deletedList = deleteCursor.currentList();
    bool deletedListStatus = deletedList->format().boolProperty(KoDeleteChangeMarker::DeletedList);
    QVERIFY(deletedListStatus == true);
    bool deletedListItemStatus;
    deletedListItemStatus  = deletedList->item(0).blockFormat().boolProperty(KoDeleteChangeMarker::DeletedListItem);
    QVERIFY(deletedListItemStatus == true);
    deletedListItemStatus  = deletedList->item(1).blockFormat().boolProperty(KoDeleteChangeMarker::DeletedListItem);
    QVERIFY(deletedListItemStatus == true);
    deletedListItemStatus  = deletedList->item(2).blockFormat().boolProperty(KoDeleteChangeMarker::DeletedListItem);
    QVERIFY(deletedListItemStatus == true);
    deletedListItemStatus  = deletedList->item(3).blockFormat().boolProperty(KoDeleteChangeMarker::DeletedListItem);
    QVERIFY(deletedListItemStatus == true);
    deletedListItemStatus  = deletedList->item(4).blockFormat().boolProperty(KoDeleteChangeMarker::DeletedListItem);
    QVERIFY(deletedListItemStatus == true);
    delete textTool;
}
Exemplo n.º 12
0
void DeleteAnnotationsCommand::redo()
{
    KUndo2Command::redo();
    m_deleteAnnotations = true;
    KoTextRangeManager *rangeManager = KoTextDocument(m_document).textRangeManager();
    if (rangeManager) {
        foreach (KoAnnotation *annotation, m_annotations) {
            rangeManager->remove(annotation);
        }
    }
void NotesConfigurationDialog::footnoteSetup()
{
    m_notesConfig = KoTextDocument(m_document).styleManager()
                                ->notesConfiguration(KoOdfNotesConfiguration::Footnote);
    if (!m_notesConfig) {
        m_notesConfig = new KoOdfNotesConfiguration();
        m_notesConfig->setNoteClass(KoOdfNotesConfiguration::Footnote);
    }
    widget.prefixLineEdit->setText(m_notesConfig->numberFormat().prefix());
    widget.suffixLineEdit->setText(m_notesConfig->numberFormat().suffix());
    widget.startAtSpinBox->setValue(m_notesConfig->startValue());
    widget.endlineEdit->setText(m_notesConfig->footnoteContinuationForward());
    widget.startlineEdit->setText(m_notesConfig->footnoteContinuationBackward());

    switch (m_notesConfig->numberFormat().formatSpecification()) {
    default:
    case KoOdfNumberDefinition::Numeric:
        widget.numStyleCombo->setCurrentIndex(0);
        break;
    case KoOdfNumberDefinition::AlphabeticLowerCase:
        if (m_notesConfig->numberFormat().letterSynchronization()) {
            widget.numStyleCombo->setCurrentIndex(3);
        } else {
            widget.numStyleCombo->setCurrentIndex(1);
        }
        break;
    case KoOdfNumberDefinition::AlphabeticUpperCase:
        if (m_notesConfig->numberFormat().letterSynchronization()) {
            widget.numStyleCombo->setCurrentIndex(4);
        } else {
            widget.numStyleCombo->setCurrentIndex(2);
        }
        break;
    case KoOdfNumberDefinition::RomanLowerCase:
        widget.numStyleCombo->setCurrentIndex(5);
        break;
    case KoOdfNumberDefinition::RomanUpperCase:
        widget.numStyleCombo->setCurrentIndex(6);
        break;
    }

    switch (m_notesConfig->numberingScheme()) {
    case KoOdfNotesConfiguration::BeginAtPage:
        widget.beginAtCombo->setCurrentIndex(0);
        break;
    case KoOdfNotesConfiguration::BeginAtChapter:
        widget.beginAtCombo->setCurrentIndex(1);
        break;
    case KoOdfNotesConfiguration::BeginAtDocument:
        widget.beginAtCombo->setCurrentIndex(2);
        break;
    }
}
Exemplo n.º 14
0
void DeleteCommand::undo()
{
    KoTextCommandBase::undo();
    UndoRedoFinalizer finalizer(this); // Look at KoTextCommandBase documentation

    // KoList
    updateListChanges();

    // KoTextRange
    KoTextRangeManager *rangeManager = KoTextDocument(m_document).textRangeManager();
    foreach (KoTextRange *range, m_rangesToRemove) {
        rangeManager->insert(range);
    }
Exemplo n.º 15
0
ToCGenerator::ToCGenerator(QTextDocument *tocDocument, KoTableOfContentsGeneratorInfo *tocInfo)
    : QObject(tocDocument)
    , m_ToCDocument(tocDocument)
    , m_ToCInfo(tocInfo)
    , m_document(0)
    , m_documentLayout(0)
{
    Q_ASSERT(tocDocument);
    Q_ASSERT(tocInfo);

    tocDocument->setUndoRedoEnabled(false);
    tocDocument->setDocumentLayout(new DummyDocumentLayout(tocDocument));
    KoTextDocument(tocDocument).setRelativeTabs(tocInfo->m_relativeTabStopPosition);
}
Exemplo n.º 16
0
/// This method is used to push a complete KUndo2Command on the KoTextEditor. This command will be pushed on the application's stack if needed. The logic allows to push several commands which are then going to be nested, provided these children are pushed from within the redo method of their parent.
void KoTextEditor::addCommand(KUndo2Command *command)
{
    kDebug(32500) << "we receive a command to add on the stack.";
    kDebug(32500) << "commandStack count: " << d->commandStack.count();
    kDebug(32500) << "customCommandCount counter: " << d->customCommandCount << " will increase";

    //We increase the customCommandCount counter to inform the framework that we are having a further KUndo2Command and update the KoTextEditor's state to Custom.
    //However, this update will request a new headCommand to be pushed on the commandStack. This is what we want for internal complex editions but not in this case. Indeed, it must be the KUndo2Command which will parent the UndoTextCommands. Therefore we set the addNewCommand back to false.
    //If the commandStack is empty, we are the highest "macro" command and we should therefore push the KUndo2Command on the application's stack.
    //On the contrary, if the commandStack is not empty, or the pushed command has a parent, it means that we are adding a nested KUndo2Command. In which case we just want to put it on the commandStack to parent UndoTextCommands. We need to call the redo method manually though.
    ++d->customCommandCount;
    kDebug(32500) << "we will now go to custom state";
    d->updateState(KoTextEditor::Private::Custom, (!command->text().isEmpty())?command->text():i18n("Text"));
    kDebug(32500) << "but will set the addCommand to false. we don't want a new headCommand";
    d->addNewCommand = false;
    kDebug(32500) << "commandStack count is: " << d->commandStack.count();
    if (d->commandStack.isEmpty()) {
        kDebug(32500) << "the commandStack is empty. this means we are the top most command";
        d->commandStack.push(command);
        kDebug(32500) << "command pushed on the commandStack. count: " << d->commandStack.count();
        KUndo2QStack *stack = KoTextDocument(d->document).undoStack();
        if (stack && !command->hasParent()) {
            kDebug(32500) << "we have an application stack and the command is not a sub command of a non text command (which have been pushed outside kotext";
            stack->push(command);
            kDebug(32500) << "so we pushed it on the application's' stack";
        } else {
            kDebug(32500) << "we either have no application's stack, or our command is actually the child of a non kotext command";
            command->redo();
            kDebug(32500) << "still called redo on it";
        }
    }
    else {
        kDebug(32500) << "the commandStack is not empty, our command is actually nested in another kotext command. we don't push on the application stack but only on the commandStack";
        d->commandStack.push(command);
        kDebug(32500) << "commandStack count after push: " << d->commandStack.count();
        command->redo();
        kDebug(32500) << "called redo still";
    }

    //When we reach that point, the command has been executed. We first need to clean up all the automatically generated headCommand on our commandStack, which could potentially have been created during the editing. When we reach our pushed command, the commandStack is clean. We can then call a state update to NoOp and decrease the customCommandCount counter.
    kDebug(32500) << "the command has been executed. we need to clean up the commandStack of the auto generated headCommands";
    kDebug(32500) << "before cleaning. commandStack count: " << d->commandStack.count();
    while (d->commandStack.top() != command) {
        d->commandStack.pop();
    }
    kDebug(32500) << "after cleaning. commandStack count: " << d->commandStack.count() << " will set NoOp";
    d->updateState(KoTextEditor::Private::NoOp);
    kDebug(32500) << "after NoOp set. inCustomCounter: " << d->customCommandCount << " will decrease and return";
    --d->customCommandCount;
}
Exemplo n.º 17
0
QTextCursor TestTableLayout::setupTest()
{
    delete m_doc;
    m_doc = new QTextDocument;
    Q_ASSERT(m_doc);

    MockRootAreaProvider *provider = new MockRootAreaProvider();
    Q_ASSERT(provider);
    KoTextDocument(m_doc).setInlineTextObjectManager(new KoInlineTextObjectManager);

    m_doc->setDefaultFont(QFont("Sans Serif", 12, QFont::Normal, false)); //do it manually since we do not load the appDefaultStyle

    m_styleManager = new KoStyleManager(0);
    KoTextDocument(m_doc).setStyleManager(m_styleManager);

    m_layout = new KoTextDocumentLayout(m_doc, provider);
    Q_ASSERT(m_layout);
    m_doc->setDocumentLayout(m_layout);

    m_block = m_doc->begin();
    QTextCursor cursor(m_doc);

    return cursor;
}
Exemplo n.º 18
0
void KPrPlaceholderTextStrategy::saveOdf( KoShapeSavingContext & context )
{
    if (m_textShape) {
        KoTextShapeData *shapeData = qobject_cast<KoTextShapeData*>(m_textShape->userData());
        if (shapeData) {
            KoStyleManager *styleManager = KoTextDocument(shapeData->document()).styleManager();
            if (styleManager) {
                QTextDocument *document = shapeData->document();
                QTextBlock block = document->begin();
                QString styleName = KoTextWriter::saveParagraphStyle(block, styleManager, context);
                context.xmlWriter().addAttribute("draw:text-style-name", styleName);
            }
        }
    }
    KPrPlaceholderStrategy::saveOdf( context );
}
SimpleTableOfContentsWidget::SimpleTableOfContentsWidget(ReferencesTool *tool, QWidget *parent)
        : QWidget(parent),
        m_blockSignals(false),
        m_referenceTool(tool),
        m_signalMapper(0)
{
    widget.setupUi(this);
    Q_ASSERT(tool);

    m_templateGenerator = new TableOfContentsTemplate(KoTextDocument(m_referenceTool->editor()->document()).styleManager());

    widget.addToC->setIcon(koIcon("insert-tableofcontents"));
    widget.addToC->setNumColumns(1);
    connect(widget.addToC, SIGNAL(clicked(bool)), this, SIGNAL(doneWithFocus()));
    connect(widget.addToC, SIGNAL(aboutToShowMenu()), this, SLOT(prepareTemplateMenu()));
    connect(widget.addToC, SIGNAL(itemTriggered(int)), this, SLOT(applyTemplate(int)));
}
Exemplo n.º 20
0
void NotesConfigurationDialog::endnoteSetup()
{
    widget.continuationBox->hide();
    widget.beginAtCombo->hide();
    m_notesConfig = KoTextDocument(m_document).styleManager()
                                    ->notesConfiguration(KoOdfNotesConfiguration::Endnote);
    if (!m_notesConfig) {
        // TODO: object will be leaked, also will it never be stored on the stylemanager, so any editing is lost
        m_notesConfig = new KoOdfNotesConfiguration(KoOdfNotesConfiguration::Endnote);
    }
    widget.prefixLineEdit->setText(m_notesConfig->numberFormat().prefix());
    widget.suffixLineEdit->setText(m_notesConfig->numberFormat().suffix());
    widget.startAtSpinBox->setValue(m_notesConfig->startValue());

    switch(m_notesConfig->numberFormat().formatSpecification()) {
    case KoOdfNumberDefinition::Numeric:
        widget.numStyleCombo->setCurrentIndex(0);
        break;
    case KoOdfNumberDefinition::AlphabeticLowerCase:
        if (m_notesConfig->numberFormat().letterSynchronization()) {
            widget.numStyleCombo->setCurrentIndex(3);
        } else {
            widget.numStyleCombo->setCurrentIndex(1);
        }
        break;
    case KoOdfNumberDefinition::AlphabeticUpperCase:
        if (m_notesConfig->numberFormat().letterSynchronization()) {
            widget.numStyleCombo->setCurrentIndex(4);
        } else {
            widget.numStyleCombo->setCurrentIndex(2);
        }
        break;
    default:
    case KoOdfNumberDefinition::RomanLowerCase:
        widget.numStyleCombo->setCurrentIndex(5);
        break;
    case KoOdfNumberDefinition::RomanUpperCase:
        widget.numStyleCombo->setCurrentIndex(6);
        break;
    }
}
Exemplo n.º 21
0
void TableOfContentsConfigure::init()
{
    ui.setupUi(this);

    setWindowTitle(i18n("Table of Contents - Configure"));

    ui.lineEditTitle->setText(i18n("Table Title"));
    ui.useOutline->setText(i18n("Use outline"));
    ui.useStyles->setText(i18n("Use styles"));
    ui.configureStyles->setText(i18n("Configure"));
    ui.tabWidget->setTabText(0, i18n("Index"));
    ui.tabWidget->setTabText(1, i18n("Styles"));
    ui.tabWidget->setCurrentIndex(0);

    ui.tocPreview->setStyleManager(KoTextDocument(m_textEditor->document()).styleManager());

    connect(this, SIGNAL(accepted()), this, SLOT(save()));
    connect(this, SIGNAL(rejected()), this, SLOT(cleanUp()));
    connect(ui.configureStyles, SIGNAL(clicked(bool)), this, SLOT(showStyleConfiguration()));
    connect(ui.lineEditTitle, SIGNAL(returnPressed()), this, SLOT(updatePreview()));
}
Exemplo n.º 22
0
QString RdfTest::insertTableWithSemItem(KoTextEditor &editor,
                               KoDocumentRdf &rdfDoc,
                               const QString name)
{
    editor.insertTable(5,10);
#define TABLESIZE (5*10)
    const QTextTable *table = editor.currentTable();

    QTextCursor cur(editor.document());
    cur.setPosition(table->firstPosition());
    KoBookmark *bookmark = new KoBookmark(cur);
    bookmark->setPositionOnlyMode(false); // we want it to be several chars long

    KoTextInlineRdf *inlineRdf(new KoTextInlineRdf(editor.document(), bookmark));
    QString newId = inlineRdf->createXmlId();
    inlineRdf->setXmlId(newId);

    bookmark->setName(newId);
    bookmark->setInlineRdf(inlineRdf);
    KoTextDocument(editor.document()).textRangeManager()->insert(bookmark);

    editor.setPosition(table->firstPosition());
    editor.movePosition(QTextCursor::PreviousCharacter);

    hTestSemanticItem testItem(new TestSemanticItem(0, &rdfDoc));
    testItem->setName(name);
    Soprano::Statement st(
                testItem->linkingSubject(), // subject
                Soprano::Node::createResourceNode(QUrl("http://docs.oasis-open.org/ns/office/1.2/meta/pkg#idref")), // predicate
                Soprano::Node::createLiteralNode(newId), // object
                rdfDoc.manifestRdfNode()); // manifest datastore
    rdfDoc.model()->addStatement(st);
    rdfDoc.rememberNewInlineRdfObject(inlineRdf);

    Q_ASSERT(rdfDoc.model()->statementCount() > 0);

    bookmark->setRangeEnd(table->lastPosition());

    return newId;
}
Exemplo n.º 23
0
void ShowChangesCommand::checkAndRemoveAnchoredShapes(int position, int length)
{
    KoInlineTextObjectManager *inlineObjectManager
                = KoTextDocument(m_document).inlineTextObjectManager();
    Q_ASSERT(inlineObjectManager);

    QTextCursor cursor = m_textEditor->document()->find(QString(QChar::ObjectReplacementCharacter), position);
    while(!cursor.isNull() && cursor.position() < position + length) {
        QTextCharFormat fmt = cursor.charFormat();
        KoInlineObject *object = inlineObjectManager->inlineTextObject(fmt);
        Q_ASSERT(object);
        /* FIXME
        KoTextAnchor *anchor = dynamic_cast<KoTextAnchor *>(object);
        if (!anchor)
            continue;

        KUndo2Command *shapeCommand = m_canvas->shapeController()->removeShape(anchor->shape());
        shapeCommand->redo();
        m_shapeCommands.push_front(shapeCommand);
        */
    }
}
Exemplo n.º 24
0
SectionFormatDialog::SectionFormatDialog(QWidget *parent, KoTextEditor *editor)
    : KoDialog(parent)
    , m_editor(editor)
{
    setCaption(i18n("Configure sections"));
    setButtons(KoDialog::Ok | KoDialog::Cancel);
    showButtonSeparator(true);
    QWidget *form = new QWidget;
    m_widget.setupUi(form);
    setMainWidget(form);

    m_sectionModel = KoTextDocument(editor->document()).sectionModel();
    m_widget.sectionTree->setModel(new ProxyModel(m_sectionModel, this));
    m_widget.sectionTree->expandAll();

    m_widget.sectionNameLineEdit->setEnabled(false);

    connect(m_widget.sectionTree, SIGNAL(activated(QModelIndex)), this, SLOT(sectionSelected(QModelIndex)));
    connect(m_widget.sectionNameLineEdit, SIGNAL(editingFinished()), this, SLOT(sectionNameChanged()));
    connect(m_widget.sectionNameLineEdit, SIGNAL(textEdited(QString)), this, SLOT(updateTreeState()));

    m_curIdx = m_widget.sectionTree->currentIndex();
}
SimpleCitationBibliographyWidget::SimpleCitationBibliographyWidget(ReferencesTool *tool, QWidget *parent)
        : QWidget(parent),
          m_blockSignals(false),
          m_referenceTool(tool),
          m_signalMapper(0)
{
    widget.setupUi(this);
    Q_ASSERT(tool);

    m_templateGenerator = new BibliographyTemplate(KoTextDocument(m_referenceTool->editor()->document()).styleManager());

    widget.addCitation->setDefaultAction(tool->action("insert_citation"));
    connect(widget.addCitation,SIGNAL(clicked(bool)),this,SIGNAL(doneWithFocus()));

    widget.addBibliography->setDefaultAction(tool->action("insert_bibliography"));
    widget.addBibliography->setNumColumns(1);
    connect(widget.addBibliography,SIGNAL(clicked(bool)),this,SIGNAL(doneWithFocus()));
    connect(widget.addBibliography, SIGNAL(aboutToShowMenu()), this, SLOT(prepareTemplateMenu()));
    connect(widget.addBibliography, SIGNAL(itemTriggered(int)), this, SLOT(applyTemplate(int)));

    widget.configureBibliography->setDefaultAction(tool->action("configure_bibliography"));
    connect(widget.configureBibliography,SIGNAL(clicked(bool)),this,SIGNAL(doneWithFocus()));
}
Exemplo n.º 26
0
void ShowChangesCommand::checkAndAddAnchoredShapes(int position, int length)
{
    KoInlineTextObjectManager *inlineObjectManager
                = KoTextDocument(m_document).inlineTextObjectManager();
    Q_ASSERT(inlineObjectManager);

    QTextCursor cursor = m_textEditor->document()->find(QString(QChar::ObjectReplacementCharacter), position);
    while(!cursor.isNull() && cursor.position() < position + length) {
        QTextCharFormat fmt = cursor.charFormat();
        KoInlineObject *object = inlineObjectManager->inlineTextObject(fmt);
        Q_ASSERT(object);
/* FIXME
        KoTextAnchor *anchor = dynamic_cast<KoTextAnchor *>(object);
        if (!anchor) {
            continue;
        }
        */
#if 0
        // TODO -- since March 2010...
        KoTextDocumentLayout *lay = qobject_cast<KoTextDocumentLayout*>(m_document->documentLayout());

        KoShapeContainer *container = dynamic_cast<KoShapeContainer *>(lay->shapeForPosition(i));

        // a very ugly hack. Since this class is going away soon, it should be okay
        if (!container)
            container = dynamic_cast<KoShapeContainer *>((lay->shapes()).at(0));

        if (container) {
            container->addShape(anchor->shape());
            KUndo2Command *shapeCommand = m_canvas->shapeController()->addShapeDirect(anchor->shape());
            shapeCommand->redo();
            m_shapeCommands.push_front(shapeCommand);
        }
#endif
        cursor = m_textEditor->document()->find(QString(QChar::ObjectReplacementCharacter), position);
    }
}
Exemplo n.º 27
0
void KoTextLoader::loadBody(const KoXmlElement &bodyElem, QTextCursor &cursor)
{
    const QTextBlockFormat defaultBlockFormat = cursor.blockFormat();
    const QTextCharFormat defaultCharFormat = cursor.charFormat();

    const QTextDocument *document = cursor.block().document();
    d->styleManager = KoTextDocument(document).styleManager();
    Q_ASSERT(d->styleManager);

    d->changeTracker = KoTextDocument(document).changeTracker();
//    if (!d->changeTracker)
//        d->changeTracker = dynamic_cast<KoChangeTracker *>(d->context.dataCenterMap().value("ChangeTracker"));
//    Q_ASSERT(d->changeTracker);

    kDebug(32500) << "text-style:" << KoTextDebug::textAttributes( cursor.blockCharFormat() );
#if 0
    if ((document->isEmpty()) && (d->styleManager)) {
        QTextBlock block = cursor.block();
        d->styleManager->defaultParagraphStyle()->applyStyle(block);
    }
#endif

    startBody(KoXml::childNodesCount(bodyElem));
    KoXmlElement tag;
    bool usedParagraph = false; // set to true if we found a tag that used the paragraph, indicating that the next round needs to start a new one.
    forEachElement(tag, bodyElem) {
        if (! tag.isNull()) {
            const QString localName = tag.localName();
            if (tag.namespaceURI() == KoXmlNS::text) {
                if (usedParagraph)
                    cursor.insertBlock(defaultBlockFormat, defaultCharFormat);
                usedParagraph = true;
                if (d->changeTracker && localName == "tracked-changes") {
                    d->changeTracker->loadOdfChanges(tag);
                    usedParagraph = false;
                } else if (d->changeTracker && localName == "change-start") {
                    loadChangedRegion(tag, cursor);
                    usedParagraph = false;
                } else if (d->changeTracker && localName == "change-end") {
                    d->currentChangeId = 0;
                    usedParagraph = false;
                } else if (localName == "p") {    // text paragraph
                    loadParagraph(tag, cursor);
                } else if (localName == "h") {  // heading
                    loadHeading(tag, cursor);
                } else if (localName == "unordered-list" || localName == "ordered-list" // OOo-1.1
                           || localName == "list" || localName == "numbered-paragraph") {  // OASIS
                    loadList(tag, cursor);
                } else if (localName == "section") {  // Temporary support (###TODO)
                    loadSection(tag, cursor);
                } else {
                    KoVariable *var = KoVariableRegistry::instance()->createFromOdf(tag, d->context);

                    if (var) {
                        KoTextDocumentLayout *layout = dynamic_cast<KoTextDocumentLayout*>(cursor.block().document()->documentLayout());
                        if (layout) {
                            KoInlineTextObjectManager *textObjectManager = layout->inlineTextObjectManager();
                            if (textObjectManager) {
                                KoVariableManager *varManager = textObjectManager->variableManager();
                                if (varManager) {
                                    textObjectManager->insertInlineObject(cursor, var);
                                }
                            }
                        }
                    } else {
                        usedParagraph = false;
                        kWarning(32500) << "unhandled text:" << localName;
                    }
                }
            } else if (tag.namespaceURI() == KoXmlNS::draw) {
                loadShape(tag, cursor);
            } else if (tag.namespaceURI() == KoXmlNS::table) {
                if (localName == "table") {
                    loadTable(tag, cursor);
                } else {
                    kWarning(32500) << "unhandled table:" << localName;
                }
#if 0 // TODO commented out for now
                if (localName == "table") {
                    cursor.insertText("\n");
                    cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1);
                    QTextTable *tbl = cursor.insertTable(1, 1);
                    int rows = 0;
                    int columns = 0;
                    kDebug(32500) << "Table inserted";
                    KoXmlElement tblTag;
                    forEachElement(tblTag, tag) {
                        if (! tblTag.isNull()) {
                            const QString tblLocalName = tblTag.localName();
                            if (tblTag.namespaceURI() == KoXmlNS::table) {
                                if (tblLocalName == "table-column") {
                                    // Do some parsing with the column, see §8.2.1, ODF 1.1 spec
                                    int repeatColumn = tblTag.attributeNS(KoXmlNS::table, "number-columns-repeated", "1").toInt();
                                    columns = columns + repeatColumn;
                                    if (rows > 0)
                                        tbl->resize(rows, columns);
                                    else
                                        tbl->resize(1, columns);
                                } else if (tblLocalName == "table-row") {
                                    // Lot of work to do here...
                                    rows++;
                                    if (columns > 0)
                                        tbl->resize(rows, columns);
                                    else
                                        tbl->resize(rows, 1);
                                    // Added a row
                                    int currentCell = 0;
                                    KoXmlElement rowTag;
                                    forEachElement(rowTag, tblTag) {
                                        if (!rowTag.isNull()) {
                                            const QString rowLocalName = rowTag.localName();
                                            if (rowTag.namespaceURI() == KoXmlNS::table) {
                                                if (rowLocalName == "table-cell") {
                                                    // Ok, it's a cell...
                                                    const int currentRow = tbl->rows() - 1;
                                                    QTextTableCell cell = tbl->cellAt(currentRow, currentCell);
                                                    if (cell.isValid()) {
                                                        cursor = cell.firstCursorPosition();
                                                        loadBody(context, rowTag, cursor);
                                                    } else
                                                        kDebug(32500) << "Invalid table-cell row=" << currentRow << " column=" << currentCell;
                                                    currentCell++;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    cursor = tbl->lastCursorPosition();
                    cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 1);
                } else {
                    kWarning(32500) << "KoTextLoader::loadBody unhandled table::" << localName;
                }
#endif
            }
Exemplo n.º 28
0
 KoSectionModel *sectionModel()
 {
     return KoTextDocument(m_document).sectionModel();
 }
Exemplo n.º 29
0
 KoTextEditor *textEditor()
 {
     return KoTextDocument(m_document).textEditor();
 }
Exemplo n.º 30
0
void TestTableLayout::initTest(int rows, int columns,
        KoTableStyle *tableStyle,
        const QList<KoTableColumnStyle *> &columnStyles,
        const QList<KoTableRowStyle *> &rowStyles,
        const QMap<QPair<int, int>, KoTableCellStyle *> &cellStyles,
        const QMap<QPair<int, int>, QString> &cellTexts)
{
    // Mock shape of size 200x1000 pt.
    m_shape = new MockTextShape();
    Q_ASSERT(m_shape);
    m_shape->setSize(QSizeF(200, 1000));

    // Document layout.
    m_layout = m_shape->layout;
    Q_ASSERT(m_layout);

    // Document.
    m_doc = m_layout->document();
    Q_ASSERT(m_doc);
    m_doc->setDefaultFont(QFont("Sans Serif", 12, QFont::Normal, false));

    // Layout state (layout helper).
    m_textLayout = new Layout(m_layout);
    Q_ASSERT(m_textLayout);
    m_layout->setLayout(m_textLayout);

    // Style manager.
    m_styleManager = new KoStyleManager();
    Q_ASSERT(m_styleManager);
    KoTextDocument(m_doc).setStyleManager(m_styleManager);

    // Table style.
    m_defaultTableStyle = new KoTableStyle();
    Q_ASSERT(m_defaultTableStyle);
    m_defaultTableStyle->setMargin(0.0);
    m_defaultTableStyle->setWidth(QTextLength(QTextLength::FixedLength, 200));
    QTextTableFormat tableFormat;
    if (tableStyle) {
        tableStyle->applyStyle(tableFormat);
    } else {
        m_defaultTableStyle->applyStyle(tableFormat);
    }

    // Table.
    QTextCursor cursor(m_doc);
    m_table = cursor.insertTable(rows, columns, tableFormat);
    Q_ASSERT(m_table);

    // Column and row style manager.
    m_tableColumnAndRowStyleManager = KoTableColumnAndRowStyleManager::getManager(m_table);

    // Column styles.
    m_defaultColumnStyle.setRelativeColumnWidth(50.0);
    for (int col = 0; col < columns; ++col) {
        if (columnStyles.value(col)) {
            m_tableColumnAndRowStyleManager.setColumnStyle(col, *(columnStyles.at(col)));
        } else {
            m_tableColumnAndRowStyleManager.setColumnStyle(col, m_defaultColumnStyle);
        }
    }

    // Row styles.
    for (int row = 0; row < rows; ++row) {
        if (rowStyles.value(row)) {
            m_tableColumnAndRowStyleManager.setRowStyle(row, *(rowStyles.at(row)));
        } else {
            m_tableColumnAndRowStyleManager.setRowStyle(row, m_defaultRowStyle);
        }
    }

    // Cell styles and texts.
    m_defaultCellStyle = new KoTableCellStyle();
    Q_ASSERT(m_defaultCellStyle);
    for (int row = 0; row < m_table->rows(); ++row) {
        for (int col = 0; col < m_table->columns(); ++col) {
            // Style.
            QTextTableCell cell = m_table->cellAt(row, col);
            QTextTableCellFormat cellFormat = cell.format().toTableCellFormat();
            if (cellStyles.contains(qMakePair(row, col))) {
                cellStyles.value(qMakePair(row, col))->applyStyle(cellFormat);
                cell.setFormat(cellFormat.toCharFormat());
            } else {
                m_defaultCellStyle->applyStyle(cellFormat);
            }
            cell.setFormat(cellFormat.toCharFormat());
            // Text.
            if (cellTexts.contains(qMakePair(row, col))) {
                cell.firstCursorPosition().insertText(cellTexts.value(qMakePair(row, col)));
            }
        }
    }
    KoParagraphStyle style;
    style.setStyleId(101); // needed to do manually since we don't use the stylemanager
    QTextBlock b2 = m_doc->begin();
    while (b2.isValid()) {
        style.applyStyle(b2);
        b2 = b2.next();
    }

}