diff --git a/autotests/annotationstest.cpp b/autotests/annotationstest.cpp --- a/autotests/annotationstest.cpp +++ b/autotests/annotationstest.cpp @@ -30,6 +30,7 @@ // void testInk(); // void testHighlight(); // void testGeom(); + void testTypewriter(); void cleanupTestCase(); private: @@ -140,6 +141,29 @@ QTest::newRow("Highlight: Outside") << (Okular::Annotation*) highlight << 1.0 << 0.9 << qRound( pow( documentX * 0.1, 2 ) ); } +void AnnotationTest::testTypewriter() +{ + Okular::Annotation * annot = nullptr; + Okular::TextAnnotation * ta = new Okular::TextAnnotation(); + annot = ta; + ta->setFlags( ta->flags() | Okular::Annotation::FixedRotation ); + ta->setTextType( Okular::TextAnnotation::InPlace ); + ta->setInplaceIntent( Okular::TextAnnotation::TypeWriter ); + ta->style().setWidth( 0.0 ); + ta->style().setColor( QColor(255,255,255,0) ); + + annot->setBoundingRectangle( Okular::NormalizedRect( 0.8, 0.1, 0.85, 0.15 ) ); + annot->setContents( QStringLiteral("annot contents") ); + + m_document->addPageAnnotation( 0, annot ); + + QDomNode annotNode = annot->getAnnotationPropertiesDomNode(); + QDomNodeList annotNodeList = annotNode.toElement().elementsByTagName("base"); + QDomElement annotEl = annotNodeList.item(0).toElement(); + QCOMPARE( annotEl.attribute( QStringLiteral("color") ), QStringLiteral("#00ffffff") ); + QCOMPARE( annotEl.attribute( QStringLiteral("flags") ), QStringLiteral("4") ); + QCOMPARE( annotEl.attribute( QStringLiteral("contents") ), QStringLiteral("annot contents") ); +} QTEST_MAIN( AnnotationTest ) #include "annotationstest.moc" diff --git a/autotests/parttest.cpp b/autotests/parttest.cpp --- a/autotests/parttest.cpp +++ b/autotests/parttest.cpp @@ -128,6 +128,7 @@ void testCrashTextEditDestroy(); void testAnnotWindow(); void testAdditionalActionTriggers(); + void testTypewriterAnnotTool(); void testJumpToPage(); void testTabletProximityBehavior(); @@ -1794,6 +1795,46 @@ verifyTargetStates( QStringLiteral( "pb" ), fields, false, false, false, __LINE__ ); } +void PartTest::testTypewriterAnnotTool() +{ + QScopedPointer closeDialogHelper; + Okular::Part part(nullptr, nullptr, QVariantList()); + + part.openUrl(QUrl::fromLocalFile(QStringLiteral(KDESRCDIR "data/file1.pdf"))); + + part.widget()->show(); + QVERIFY(QTest::qWaitForWindowExposed(part.widget())); + + const int width = part.m_pageView->horizontalScrollBar()->maximum() + + part.m_pageView->viewport()->width(); + const int height = part.m_pageView->verticalScrollBar()->maximum() + + part.m_pageView->viewport()->height(); + + part.m_document->setViewportPage(0); + + QMetaObject::invokeMethod(part.m_pageView, "slotToggleAnnotator", Q_ARG( bool, true )); + + QList toolbuttonList = part.m_pageView->findChildren(); + // Check if the tooltip of 10th button is "Typewriter" + QToolButton* typewriterButton = toolbuttonList.at(9); + QCOMPARE( typewriterButton->toolTip(), QStringLiteral("Typewriter") ); + + typewriterButton->click(); + + QTest::mouseMove(part.m_pageView->viewport(), QPoint(width * 0.5, height * 0.2)); + closeDialogHelper.reset(new CloseDialogHelper( QDialogButtonBox::Ok )); // this is the "add new note" dialog + QTest::mouseClick(part.m_pageView->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(width * 0.5, height * 0.2)); + + Annotation* annot = part.m_document->page(0)->annotations().first(); + TextAnnotation* ta = static_cast( annot ); + QVERIFY( annot ); + QVERIFY( ta ); + QCOMPARE( annot->subType(), Okular::Annotation::AText ); + QCOMPARE( annot->style().color(), QColor(255,255,255,0) ); + QCOMPARE( ta->textType(), Okular::TextAnnotation::InPlace ); + QCOMPARE( ta->inplaceIntent(), Okular::TextAnnotation::TypeWriter ); +} + void PartTest::testJumpToPage() { const QString testFile = QStringLiteral( KDESRCDIR "data/simple-multipage.pdf" ); const int targetPage = 25;