Exemplo n.º 1
0
    TestDocument()
    {
        m_document = new QTextDocument();

        KoTextDocument textDoc(m_document);
        KoTextEditor *editor = new KoTextEditor(m_document);

        textDoc.setInlineTextObjectManager(&m_inlineObjectManager);
        textDoc.setTextRangeManager(&m_rangeManager);
        textDoc.setStyleManager(new KoStyleManager(0));
        textDoc.setTextEditor(editor);

    }
Exemplo n.º 2
0
void RdfTest::testFindMarkers()
{
    QObject parent;

    // the rdf storage. In calligra, it's part of the KoDocument.
    KoDocumentRdf rdfDoc;

    // create a document
    QTextDocument doc;

    KoTextRangeManager rangeManager(&parent);
    KoTextDocument textDoc(&doc);
    textDoc.setTextRangeManager(&rangeManager);

    KoTextEditor editor(&doc);
    textDoc.setTextEditor(&editor);

    // insert some lorem ipsum
    editor.insertText(lorem);

    // insert a table and set a bookmark on it
    QStringList idList;
    QString newId = insertTableWithSemItem(editor, rdfDoc, "test item1");
    idList << newId;

    editor.setPosition(0);

    // now use soprano to find the tables
    QList<hTestSemanticItem> semItems = TestSemanticItem::allObjects(&rdfDoc);
    Q_ASSERT(semItems.length() == 1);

    foreach(hTestSemanticItem semItem, semItems) {
        QStringList xmlidlist = semItem->xmlIdList();

        Q_ASSERT(xmlidlist.length() == 1);
        foreach(const QString xmlid, xmlidlist) {
            Q_ASSERT(idList.contains(xmlid));
            QPair<int, int> position = rdfDoc.findExtent(xmlid);

            QCOMPARE(position.first, lorem.length() + 1);
            QCOMPARE(position.second, lorem.length() + 1 + TABLESIZE - 1);

            editor.setPosition(position.first + 2);
            const QTextTable *table = editor.currentTable();
            QVERIFY(table);
            Q_UNUSED(table);
        }
Exemplo n.º 3
0
void TestKoTextEditor::testRemoveSelectedText()
{
    QObject parent;

    // create a document
    QTextDocument doc;

    KoTextRangeManager rangeManager(&parent);
    KoTextDocument textDoc(&doc);
    textDoc.setTextRangeManager(&rangeManager);

    KoTextEditor editor(&doc);
    textDoc.setTextEditor(&editor);

    // enter some lorem ipsum
    editor.insertText(lorem);

    QTextCursor cur(&doc);
    cur.setPosition(editor.position());
    KoBookmark *bookmark = new KoBookmark(cur);
    bookmark->setName("start!");
    bookmark->setPositionOnlyMode(false); // we want it to be several chars long
    rangeManager.insert(bookmark);

    editor.insertText(lorem);

    bookmark->setRangeEnd(editor.position());

    QCOMPARE(bookmark->rangeStart(), lorem.length());
    QCOMPARE(bookmark->rangeEnd(), lorem.length() * 2);
    Q_ASSERT(rangeManager.textRanges().length() == 1);

    // select all text
    editor.setPosition(0, QTextCursor::MoveAnchor);
    editor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);

    Q_ASSERT(editor.hasSelection());

    // remove the text + the bookmark from the document
    editor.deleteChar();

    // check whether the bookmark has gone.
    Q_ASSERT(rangeManager.textRanges().length() == 0);
}
Exemplo n.º 4
0
HRESULT __stdcall RTFEditor::RTFDocument::get_Selection( IDispatch** d)
{
	if (!d )
		return E_INVALIDARG;

	*d = 0;

	if ( This()->richEditOle )
	{
		mol::punk<ITextDocument> textDoc(This()->richEditOle);
		if ( textDoc )
		{
			mol::punk<ITextSelection> selection;
			HRESULT hr = textDoc->GetSelection(&selection);
			if ( selection)
			{
				return selection.queryInterface(d);
			}		
		}
	}
	return S_OK;
}
Exemplo n.º 5
0
HRESULT __stdcall RTFEditor::RTFDocument::Range( long start, long end,  IDispatch** d)
{
	if (!d )
		return E_INVALIDARG;

	*d = 0;

	if ( This()->richEditOle )
	{
		mol::punk<ITextDocument> textDoc(This()->richEditOle);
		if ( textDoc )
		{
			mol::punk<ITextRange> range;
			HRESULT hr = textDoc->Range( start,end,&range);
			if ( range)
			{
				return range.queryInterface(d);				
			}		
		}
	}
	return S_OK;
}
Exemplo n.º 6
0
void RdfTest::testCreateMarkers()
{
    QObject parent;

    // the rdf storage. In calligra, it's part of the KoDocument.
    KoDocumentRdf rdfDoc;

    // create a document
    QTextDocument doc;

    KoTextRangeManager rangeManager(&parent);
    KoTextDocument textDoc(&doc);
    textDoc.setTextRangeManager(&rangeManager);

    KoTextEditor editor(&doc);
    textDoc.setTextEditor(&editor);

    // insert some lorem ipsum
    editor.insertText(lorem);

    // insert a table and set a bookmark on it with semantics
    QString newId = insertTableWithSemItem(editor, rdfDoc, "test item1");

    // insert some more lorem before the table
    editor.insertText(lorem);

    // verify that the bookmark marks the table and only that
    QPair<int,int> position = rdfDoc.findExtent(newId);
    QCOMPARE(position.first, 2*(lorem.length()+1));
    QCOMPARE(position.second, 2*(lorem.length()+1)+TABLESIZE-1);

    editor.setPosition(position.first + 1);
    QPair<int,int> position2 = rdfDoc.findExtent(&editor);
    qDebug()<<position<<position2;
    QCOMPARE(position, position2);

    // check that the id is like we expext
    QCOMPARE(rdfDoc.findXmlId(&editor), newId);
}
Exemplo n.º 7
0
QSize MsgManageItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    //计算高度
    DataType dataType = (DataType)index.data(Qt::UserRole + DataIndex_Type).toInt();
    Message msg = index.data(Qt::UserRole + DataIndex_Value).value<Message>();
    QString head;
    if (dataType==DataType_MessageBox && msg.box == Message::Box_Dustbin) {
        head = "idle line\nidle line\nidle line\n";
    } else {
        head = "idle line\n";
    }
    int width = option.rect.width();
    int height = 0;
    if (width > 0) {
        QTextDocument textDoc(head + msg.content);
        textDoc.setDefaultFont(option.font);
        textDoc.setTextWidth(width - cons_text_margin);
        height = textDoc.size().height();
    } else {
        height = option.fontMetrics.height();
    }
    return QSize(option.rect.width(), height);
}
Exemplo n.º 8
0
void MainWindow::print()
{
    QString text("<p align='center'>Binary Decision Diagram(BDD)<br>"
            "Version 0.1<br>"
            "By Ali Diouri<br>"
          "[email protected]<br>"
   "Licensed under BSD 3-Clause License</p>");

    QPrinter printer;
    printer.setPaperSize(QPrinter::A4);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName("/home/theshadowx7/Bureau/BDD.pdf");
    QPrintDialog printDialog(&printer, this);
    if (printDialog.exec() == QDialog::Accepted) {
        QTextDocument textDoc(this);
        QPainter painter(&printer);
        painter.setRenderHint(QPainter::Antialiasing);
        //textDoc.setPlainText(text);
        textDoc.setPlainText(this->lineEdit->text());
        this->view->scene->render(&painter);
        textDoc.drawContents(&painter);
    }
}