Commit 19d98d6a authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Run clang-format

find . \( -name "*.cpp" -or -name "*.h"  -or -name "*.c"  -or -name "*.cc" \) -exec clang-format -i {} \;

If you reached this file doing a git blame, please see README.clang-format (added 2 commits in the future of this one)
parent b85145aa
......@@ -18,20 +18,18 @@
inline KAboutData okularAboutData()
{
KAboutData about(
QStringLiteral("okular"),
i18n("Okular"),
QStringLiteral(OKULAR_VERSION_STRING),
i18n("Okular, a universal document viewer"),
KAboutLicense::GPL,
i18n("(C) 2002 Wilco Greven, Christophe Devriese\n"
"(C) 2004-2005 Enrico Ros\n"
"(C) 2005 Piotr Szymanski\n"
"(C) 2004-2017 Albert Astals Cid\n"
"(C) 2006-2009 Pino Toscano"),
QString(),
QStringLiteral("https://okular.kde.org")
);
KAboutData about(QStringLiteral("okular"),
i18n("Okular"),
QStringLiteral(OKULAR_VERSION_STRING),
i18n("Okular, a universal document viewer"),
KAboutLicense::GPL,
i18n("(C) 2002 Wilco Greven, Christophe Devriese\n"
"(C) 2004-2005 Enrico Ros\n"
"(C) 2005 Piotr Szymanski\n"
"(C) 2004-2017 Albert Astals Cid\n"
"(C) 2006-2009 Pino Toscano"),
QString(),
QStringLiteral("https://okular.kde.org"));
about.addAuthor(QStringLiteral("Pino Toscano"), i18n("Former maintainer"), QStringLiteral("pino@kde.org"));
about.addAuthor(QStringLiteral("Tobias Koenig"), i18n("Lots of framework work, ODT and FictionBook backends"), QStringLiteral("tokoe@kde.org"));
......
......@@ -9,9 +9,9 @@
#include <QtTest>
#include "../core/annotations.h"
#include "../core/document.h"
#include "../core/page.h"
#include "../core/annotations.h"
#include "../settings_core.h"
#include "testingutils.h"
......@@ -33,16 +33,16 @@ private:
void AddRemoveAnnotationTest::initTestCase()
{
Okular::SettingsCore::instance( QStringLiteral("addannotationtest") );
m_document = new Okular::Document( nullptr );
Okular::SettingsCore::instance(QStringLiteral("addannotationtest"));
m_document = new Okular::Document(nullptr);
}
void AddRemoveAnnotationTest::init()
{
const QString testFile = QStringLiteral(KDESRCDIR "data/file1.pdf");
QMimeDatabase db;
const QMimeType mime = db.mimeTypeForFile( testFile );
QCOMPARE( m_document->openDocument(testFile, QUrl(), mime), Okular::Document::OpenSuccess );
const QMimeType mime = db.mimeTypeForFile(testFile);
QCOMPARE(m_document->openDocument(testFile, QUrl(), mime), Okular::Document::OpenSuccess);
}
void AddRemoveAnnotationTest::cleanup()
......@@ -53,139 +53,138 @@ void AddRemoveAnnotationTest::cleanup()
void AddRemoveAnnotationTest::testAddAnnotations()
{
// Undo and Redo should be unavailable when docuemnt is first opened.
QVERIFY( !m_document->canUndo() );
QVERIFY( !m_document->canRedo() );
QVERIFY(!m_document->canUndo());
QVERIFY(!m_document->canRedo());
// Create two distinct text annotations
Okular::Annotation *annot1 = new Okular::TextAnnotation();
annot1->setBoundingRectangle( Okular::NormalizedRect( 0.1, 0.1, 0.15, 0.15 ) );
annot1->setContents( QStringLiteral("annot contents") );
annot1->setBoundingRectangle(Okular::NormalizedRect(0.1, 0.1, 0.15, 0.15));
annot1->setContents(QStringLiteral("annot contents"));
Okular::Annotation *annot2 = new Okular::TextAnnotation();
annot2->setBoundingRectangle( Okular::NormalizedRect( 0.2, 0.2, 0.3, 0.4 ) );
annot2->setContents( QStringLiteral("annot contents") );
annot2->setBoundingRectangle(Okular::NormalizedRect(0.2, 0.2, 0.3, 0.4));
annot2->setContents(QStringLiteral("annot contents"));
// The two annotations shold have different properties XML strings
QVERIFY( TestingUtils::getAnnotationXml( annot1 ) != TestingUtils::getAnnotationXml( annot2 ) );
QVERIFY(TestingUtils::getAnnotationXml(annot1) != TestingUtils::getAnnotationXml(annot2));
// We start with no annotations in the docuemnt
QVERIFY( m_document->page( 0 )->annotations().size() == 0 );
QVERIFY(m_document->page(0)->annotations().size() == 0);
// After adding annot1 we should have one annotation in the page and it should be annot1.
m_document->addPageAnnotation( 0, annot1 );
QVERIFY( m_document->page( 0 )->annotations().size() == 1 );
QCOMPARE( annot1, m_document->page( 0 )->annotations().first() );
m_document->addPageAnnotation(0, annot1);
QVERIFY(m_document->page(0)->annotations().size() == 1);
QCOMPARE(annot1, m_document->page(0)->annotations().first());
// Record the properties and name of annot1 just after insertion for later comparisons
QString origLine1Xml = TestingUtils::getAnnotationXml( annot1 );
QString origLine1Xml = TestingUtils::getAnnotationXml(annot1);
QString annot1Name = annot1->uniqueName();
QVERIFY( !annot1Name.isEmpty() );
QVERIFY(!annot1Name.isEmpty());
// Now undo the addition of annot1 and verify that annot1's properties haven't changed
m_document->undo();
QVERIFY( m_document->page( 0 )->annotations().empty() );
QVERIFY( !m_document->canUndo() );
QVERIFY( m_document->canRedo() );
QCOMPARE( TestingUtils::getAnnotationXml( annot1 ), origLine1Xml );
QVERIFY(m_document->page(0)->annotations().empty());
QVERIFY(!m_document->canUndo());
QVERIFY(m_document->canRedo());
QCOMPARE(TestingUtils::getAnnotationXml(annot1), origLine1Xml);
// redo addition of annot1
m_document->redo();
QVERIFY( m_document->page( 0 )->annotations().size() == 1 );
QVERIFY( annot1 == m_document->page( 0 )->annotations().first() );
QCOMPARE( TestingUtils::getAnnotationXml( annot1 ), origLine1Xml );
QVERIFY(m_document->page(0)->annotations().size() == 1);
QVERIFY(annot1 == m_document->page(0)->annotations().first());
QCOMPARE(TestingUtils::getAnnotationXml(annot1), origLine1Xml);
// undo once more
m_document->undo();
QVERIFY( m_document->page( 0 )->annotations().empty() );
QVERIFY( !m_document->canUndo() );
QVERIFY( m_document->canRedo() );
QCOMPARE( TestingUtils::getAnnotationXml( annot1 ), origLine1Xml );
QVERIFY(m_document->page(0)->annotations().empty());
QVERIFY(!m_document->canUndo());
QVERIFY(m_document->canRedo());
QCOMPARE(TestingUtils::getAnnotationXml(annot1), origLine1Xml);
// Set AnnotationDisposeWatcher dispose function on annot1 so we can detect
// when it is deleted
annot1->setDisposeDataFunction( TestingUtils::AnnotationDisposeWatcher::disposeAnnotation );
annot1->setDisposeDataFunction(TestingUtils::AnnotationDisposeWatcher::disposeAnnotation);
TestingUtils::AnnotationDisposeWatcher::resetDisposedAnnotationName();
QCOMPARE( TestingUtils::AnnotationDisposeWatcher::disposedAnnotationName(), QString() );
QCOMPARE(TestingUtils::AnnotationDisposeWatcher::disposedAnnotationName(), QString());
// now add annot2
m_document->addPageAnnotation( 0, annot2 );
m_document->addPageAnnotation(0, annot2);
QString annot2Name = annot2->uniqueName();
QVERIFY( !annot2Name.isEmpty() );
QVERIFY( annot1Name != annot2Name );
QVERIFY( m_document->page( 0 )->annotations().size() == 1 );
QCOMPARE( annot2, m_document->page( 0 )->annotations().first() );
QVERIFY(!annot2Name.isEmpty());
QVERIFY(annot1Name != annot2Name);
QVERIFY(m_document->page(0)->annotations().size() == 1);
QCOMPARE(annot2, m_document->page(0)->annotations().first());
// Check that adding annot2 while annot1 was in the unadded state triggered the deletion of annot1
QVERIFY( TestingUtils::AnnotationDisposeWatcher::disposedAnnotationName() == annot1Name );
QVERIFY(TestingUtils::AnnotationDisposeWatcher::disposedAnnotationName() == annot1Name);
}
void AddRemoveAnnotationTest::testAddAnnotationUndoWithRotate_Bug318091()
{
Okular::Annotation *annot = new Okular::TextAnnotation();
annot->setBoundingRectangle( Okular::NormalizedRect( 0.1, 0.1, 0.15, 0.15 ) );
annot->setContents( QStringLiteral("annot contents") );
annot->setBoundingRectangle(Okular::NormalizedRect(0.1, 0.1, 0.15, 0.15));
annot->setContents(QStringLiteral("annot contents"));
m_document->addPageAnnotation( 0, annot );
QString origAnnotXml = TestingUtils::getAnnotationXml( annot );
m_document->addPageAnnotation(0, annot);
QString origAnnotXml = TestingUtils::getAnnotationXml(annot);
// Now undo annotation addition, rotate the page, and redo to annotation addition
m_document->undo();
m_document->setRotation( 1 );
m_document->setRotation(1);
m_document->redo();
// Verify that annotation's properties remain unchanged
// In Bug318091 the bounding rectangle was being rotated upon each redo
QString newAnnotXml = TestingUtils::getAnnotationXml( annot );
QCOMPARE( origAnnotXml, newAnnotXml );
QString newAnnotXml = TestingUtils::getAnnotationXml(annot);
QCOMPARE(origAnnotXml, newAnnotXml);
}
void AddRemoveAnnotationTest::testRemoveAnnotations()
{
// Undo and Redo should be unavailable when docuemnt is first opened.
QVERIFY( !m_document->canUndo() );
QVERIFY( !m_document->canRedo() );
QVERIFY(!m_document->canUndo());
QVERIFY(!m_document->canRedo());
// Create two distinct text annotations
Okular::Annotation *annot1 = new Okular::TextAnnotation();
annot1->setBoundingRectangle( Okular::NormalizedRect( 0.1, 0.1, 0.15, 0.15 ) );
annot1->setContents( QStringLiteral("annot contents") );
annot1->setBoundingRectangle(Okular::NormalizedRect(0.1, 0.1, 0.15, 0.15));
annot1->setContents(QStringLiteral("annot contents"));
Okular::Annotation *annot2 = new Okular::TextAnnotation();
annot2->setBoundingRectangle( Okular::NormalizedRect( 0.2, 0.2, 0.3, 0.4 ) );
annot2->setContents( QStringLiteral("annot contents") );
annot2->setBoundingRectangle(Okular::NormalizedRect(0.2, 0.2, 0.3, 0.4));
annot2->setContents(QStringLiteral("annot contents"));
// Add annot1 and annot2 to document
m_document->addPageAnnotation( 0, annot1 );
m_document->addPageAnnotation( 0, annot2 );
QVERIFY( m_document->page( 0 )->annotations().size() == 2 );
QVERIFY( m_document->page( 0 )->annotations().contains(annot1) );
QVERIFY( m_document->page( 0 )->annotations().contains(annot2) );
m_document->addPageAnnotation(0, annot1);
m_document->addPageAnnotation(0, annot2);
QVERIFY(m_document->page(0)->annotations().size() == 2);
QVERIFY(m_document->page(0)->annotations().contains(annot1));
QVERIFY(m_document->page(0)->annotations().contains(annot2));
// Now remove annot1
m_document->removePageAnnotation( 0, annot1 );
QVERIFY( m_document->page( 0 )->annotations().size() == 1 );
QVERIFY( m_document->page( 0 )->annotations().contains(annot2) );
m_document->removePageAnnotation(0, annot1);
QVERIFY(m_document->page(0)->annotations().size() == 1);
QVERIFY(m_document->page(0)->annotations().contains(annot2));
// Undo removal of annot1
m_document->undo();
QVERIFY( m_document->page( 0 )->annotations().size() == 2 );
QVERIFY( m_document->page( 0 )->annotations().contains(annot1) );
QVERIFY( m_document->page( 0 )->annotations().contains(annot2) );
QVERIFY(m_document->page(0)->annotations().size() == 2);
QVERIFY(m_document->page(0)->annotations().contains(annot1));
QVERIFY(m_document->page(0)->annotations().contains(annot2));
// Redo removal
m_document->redo();
QVERIFY( m_document->page( 0 )->annotations().size() == 1 );
QVERIFY( m_document->page( 0 )->annotations().contains(annot2) );
QVERIFY(m_document->page(0)->annotations().size() == 1);
QVERIFY(m_document->page(0)->annotations().contains(annot2));
// Verify that annot1 is disposed of if document is closed with annot1 in removed state
QString annot1Name = annot1->uniqueName();
annot1->setDisposeDataFunction( TestingUtils::AnnotationDisposeWatcher::disposeAnnotation );
annot1->setDisposeDataFunction(TestingUtils::AnnotationDisposeWatcher::disposeAnnotation);
TestingUtils::AnnotationDisposeWatcher::resetDisposedAnnotationName();
QVERIFY( TestingUtils::AnnotationDisposeWatcher::disposedAnnotationName().isEmpty() );
QVERIFY(TestingUtils::AnnotationDisposeWatcher::disposedAnnotationName().isEmpty());
m_document->closeDocument();
QVERIFY( TestingUtils::AnnotationDisposeWatcher::disposedAnnotationName() == annot1Name );
QVERIFY(TestingUtils::AnnotationDisposeWatcher::disposedAnnotationName() == annot1Name);
}
QTEST_MAIN( AddRemoveAnnotationTest )
QTEST_MAIN(AddRemoveAnnotationTest)
#include "addremoveannotationtest.moc"
......@@ -9,13 +9,13 @@
#include <QtTest>
#include "../core/annotations.h"
#include "../core/document.h"
#include "../core/page.h"
#include "../core/annotations.h"
#include "../settings_core.h"
Q_DECLARE_METATYPE(Okular::Annotation*)
Q_DECLARE_METATYPE(Okular::LineAnnotation*)
Q_DECLARE_METATYPE(Okular::Annotation *)
Q_DECLARE_METATYPE(Okular::LineAnnotation *)
class AnnotationTest : public QObject
{
......@@ -25,11 +25,11 @@ private slots:
void initTestCase();
void testDistance();
void testDistance_data();
// void testLine();
// void testPoly();
// void testInk();
// void testHighlight();
// void testGeom();
// void testLine();
// void testPoly();
// void testInk();
// void testHighlight();
// void testGeom();
void testTypewriter();
void cleanupTestCase();
......@@ -39,40 +39,38 @@ private:
void AnnotationTest::initTestCase()
{
Okular::SettingsCore::instance( QStringLiteral("annotationtest") );
m_document = new Okular::Document( nullptr );
Okular::SettingsCore::instance(QStringLiteral("annotationtest"));
m_document = new Okular::Document(nullptr);
const QString testFile = QStringLiteral(KDESRCDIR "data/file1.pdf");
QMimeDatabase db;
const QMimeType mime = db.mimeTypeForFile( testFile );
QCOMPARE( m_document->openDocument(testFile, QUrl(), mime), Okular::Document::OpenSuccess );
const QMimeType mime = db.mimeTypeForFile(testFile);
QCOMPARE(m_document->openDocument(testFile, QUrl(), mime), Okular::Document::OpenSuccess);
}
void AnnotationTest::cleanupTestCase()
{
if ( m_document->isOpened() ) {
const QLinkedList<Okular::Annotation *> annotations = m_document->page( 0 )->annotations();
for ( Okular::Annotation* annotation : annotations ) {
m_document->removePageAnnotation( 0, annotation );
if (m_document->isOpened()) {
const QLinkedList<Okular::Annotation *> annotations = m_document->page(0)->annotations();
for (Okular::Annotation *annotation : annotations) {
m_document->removePageAnnotation(0, annotation);
}
}
}
void AnnotationTest::testDistance()
{
QFETCH(Okular::Annotation*, annotation);
QFETCH(Okular::Annotation *, annotation);
QFETCH(double, x);
QFETCH(double, y);
QFETCH(int, distance);
Okular::AnnotationObjectRect* rect = new Okular::AnnotationObjectRect( annotation );
QCOMPARE( qRound( rect->distanceSqr( x, y, m_document->page(0)->width(), m_document->page(0)->height() ) ), distance );
Okular::AnnotationObjectRect *rect = new Okular::AnnotationObjectRect(annotation);
QCOMPARE(qRound(rect->distanceSqr(x, y, m_document->page(0)->width(), m_document->page(0)->height())), distance);
delete rect;
}
void AnnotationTest::testDistance_data()
{
QTest::addColumn<Okular::Annotation*>("annotation");
QTest::addColumn<Okular::Annotation *>("annotation");
QTest::addColumn<double>("x");
QTest::addColumn<double>("y");
QTest::addColumn<int>("distance");
......@@ -82,91 +80,81 @@ void AnnotationTest::testDistance_data()
// lines
Okular::LineAnnotation *line = new Okular::LineAnnotation;
line->setLinePoints( QLinkedList< Okular::NormalizedPoint >()
<< Okular::NormalizedPoint( 0.1, 0.1 )
<< Okular::NormalizedPoint( 0.9, 0.1 )
);
m_document->addPageAnnotation( 0, line );
QTest::newRow("Line: Base point 1") << (Okular::Annotation*) line << 0.1 << 0.1 << 0;
QTest::newRow("Line: Base point 2") << (Okular::Annotation*) line << 0.5 << 0.1 << 0;
QTest::newRow("Line: Off by a lot") << (Okular::Annotation*) line << 0.5 << 0.5 << qRound( pow( 0.4 * documentY, 2 ) );
QTest::newRow("Line: Off by a little") << (Okular::Annotation*) line << 0.1 << 0.1 + (5.0 /* px */ / documentY) << 25;
line->setLinePoints(QLinkedList<Okular::NormalizedPoint>() << Okular::NormalizedPoint(0.1, 0.1) << Okular::NormalizedPoint(0.9, 0.1));
m_document->addPageAnnotation(0, line);
QTest::newRow("Line: Base point 1") << (Okular::Annotation *)line << 0.1 << 0.1 << 0;
QTest::newRow("Line: Base point 2") << (Okular::Annotation *)line << 0.5 << 0.1 << 0;
QTest::newRow("Line: Off by a lot") << (Okular::Annotation *)line << 0.5 << 0.5 << qRound(pow(0.4 * documentY, 2));
QTest::newRow("Line: Off by a little") << (Okular::Annotation *)line << 0.1 << 0.1 + (5.0 /* px */ / documentY) << 25;
// squares (non-filled squares also act as tests for the ink annotation as they share the path-distance code)
for ( int i = 0; i < 2; ++i )
{
for (int i = 0; i < 2; ++i) {
Okular::GeomAnnotation *square = new Okular::GeomAnnotation;
square->setGeometricalType( Okular::GeomAnnotation::InscribedSquare );
square->setBoundingRectangle( Okular::NormalizedRect( 0.1, 0.1, 0.9, 0.9 ) );
if ( i != 0 )
square->setGeometricalInnerColor( QColor(0, 0, 0) );
m_document->addPageAnnotation( 0, square );
QTest::newRow("Square: Base point 1") << (Okular::Annotation*) square << 0.1 << 0.1 << 0;
QTest::newRow("Square: On edge 1") << (Okular::Annotation*) square << 0.1 << 0.2 << 0;
QTest::newRow("Square: On edge 2") << (Okular::Annotation*) square << 0.2 << 0.1 << 0;
QTest::newRow("Square: Inside") << (Okular::Annotation*) square << 0.2 << 0.2 <<
((i == 0) ? qRound( pow( 0.1 * documentX, 2 ) - 1 /* stroke width */) : 0 );
QTest::newRow("Square: Outside") << (Okular::Annotation*) square << 0.0 << 0.0 <<
qRound( pow( 0.1 * documentX, 2 ) + pow( 0.1 * documentY, 2) ) ;
square->setGeometricalType(Okular::GeomAnnotation::InscribedSquare);
square->setBoundingRectangle(Okular::NormalizedRect(0.1, 0.1, 0.9, 0.9));
if (i != 0)
square->setGeometricalInnerColor(QColor(0, 0, 0));
m_document->addPageAnnotation(0, square);
QTest::newRow("Square: Base point 1") << (Okular::Annotation *)square << 0.1 << 0.1 << 0;
QTest::newRow("Square: On edge 1") << (Okular::Annotation *)square << 0.1 << 0.2 << 0;
QTest::newRow("Square: On edge 2") << (Okular::Annotation *)square << 0.2 << 0.1 << 0;
QTest::newRow("Square: Inside") << (Okular::Annotation *)square << 0.2 << 0.2 << ((i == 0) ? qRound(pow(0.1 * documentX, 2) - 1 /* stroke width */) : 0);
QTest::newRow("Square: Outside") << (Okular::Annotation *)square << 0.0 << 0.0 << qRound(pow(0.1 * documentX, 2) + pow(0.1 * documentY, 2));
}
// ellipsis
for ( int i = 0; i < 2; ++i )
{
for (int i = 0; i < 2; ++i) {
Okular::GeomAnnotation *ellipse = new Okular::GeomAnnotation;
ellipse->setGeometricalType( Okular::GeomAnnotation::InscribedCircle );
ellipse->setBoundingRectangle( Okular::NormalizedRect( 0.1, 0.1, 0.9, 0.5 ) );
if ( i != 0 )
ellipse->setGeometricalInnerColor( QColor(0, 0, 0) );
m_document->addPageAnnotation( 0, ellipse );
QTest::newRow("Ellipse: Base point 1") << (Okular::Annotation*) ellipse << 0.1 << 0.3 << 0;
QTest::newRow("Ellipse: Inside") << (Okular::Annotation*) ellipse << 0.2 << 0.3 <<
qRound( (i == 0) ? pow( documentX * 0.1, 2 ) - 1 /* pen */ : 0 );
QTest::newRow("Ellipse: Outside") << (Okular::Annotation*) ellipse << 0.0 << 0.3 << qRound( pow( documentX * 0.1, 2 ) );
ellipse->setGeometricalType(Okular::GeomAnnotation::InscribedCircle);
ellipse->setBoundingRectangle(Okular::NormalizedRect(0.1, 0.1, 0.9, 0.5));
if (i != 0)
ellipse->setGeometricalInnerColor(QColor(0, 0, 0));
m_document->addPageAnnotation(0, ellipse);
QTest::newRow("Ellipse: Base point 1") << (Okular::Annotation *)ellipse << 0.1 << 0.3 << 0;
QTest::newRow("Ellipse: Inside") << (Okular::Annotation *)ellipse << 0.2 << 0.3 << qRound((i == 0) ? pow(documentX * 0.1, 2) - 1 /* pen */ : 0);
QTest::newRow("Ellipse: Outside") << (Okular::Annotation *)ellipse << 0.0 << 0.3 << qRound(pow(documentX * 0.1, 2));
}
// highlight
Okular::HighlightAnnotation *highlight = new Okular::HighlightAnnotation;
Okular::HighlightAnnotation::Quad q;
q.setPoint( Okular::NormalizedPoint( 0.1, 0.1 ), 0 );
q.setPoint( Okular::NormalizedPoint( 0.2, 0.1 ), 1 );
q.setPoint( Okular::NormalizedPoint( 0.8, 0.9 ), 2 );
q.setPoint( Okular::NormalizedPoint( 0.9, 0.9 ), 3 );
q.setPoint(Okular::NormalizedPoint(0.1, 0.1), 0);
q.setPoint(Okular::NormalizedPoint(0.2, 0.1), 1);
q.setPoint(Okular::NormalizedPoint(0.8, 0.9), 2);
q.setPoint(Okular::NormalizedPoint(0.9, 0.9), 3);
highlight->highlightQuads() << q;
m_document->addPageAnnotation( 0, highlight );
QTest::newRow("Highlight: Point 1") << (Okular::Annotation*) highlight << 0.1 << 0.1 << 0;
QTest::newRow("Highlight: Point 2") << (Okular::Annotation*) highlight << 0.2 << 0.1 << 0;
QTest::newRow("Highlight: Point 3") << (Okular::Annotation*) highlight << 0.8 << 0.9 << 0;
QTest::newRow("Highlight: Point 4") << (Okular::Annotation*) highlight << 0.9 << 0.9 << 0;
QTest::newRow("Highlight: Inside") << (Okular::Annotation*) highlight << 0.5 << 0.5 << 0;
QTest::newRow("Highlight: Outside") << (Okular::Annotation*) highlight << 1.0 << 0.9 << qRound( pow( documentX * 0.1, 2 ) );
m_document->addPageAnnotation(0, highlight);
QTest::newRow("Highlight: Point 1") << (Okular::Annotation *)highlight << 0.1 << 0.1 << 0;
QTest::newRow("Highlight: Point 2") << (Okular::Annotation *)highlight << 0.2 << 0.1 << 0;
QTest::newRow("Highlight: Point 3") << (Okular::Annotation *)highlight << 0.8 << 0.9 << 0;
QTest::newRow("Highlight: Point 4") << (Okular::Annotation *)highlight << 0.9 << 0.9 << 0;
QTest::newRow("Highlight: Inside") << (Okular::Annotation *)highlight << 0.5 << 0.5 << 0;
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(QStringLiteral("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") );
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(QStringLiteral("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 )
QTEST_MAIN(AnnotationTest)
#include "annotationstest.moc"
......@@ -11,28 +11,31 @@
#include <QtTest>
#include <QWidget>
#include <KActionCollection>
#include <QTabBar>
#include <QTabWidget>
#include <QToolBar>
#include <KActionCollection>
#include <QWidget>
#include "../core/page.h"
#include "../part.h"
#include "../settings.h"
#include "../shell/okular_main.h"
#include "../shell/shell.h"
#include "../shell/shellutils.h"
#include "../core/page.h"
#include "../ui/pageview.h"
#include "../part.h"
#include "../settings.h"
namespace Okular {
namespace Okular
{
class PartTest
{
public:
Okular::Document *partDocument(Okular::Part *part) const {
Okular::Document *partDocument(Okular::Part *part) const
{
return part->m_document;
}
PageView *pageView(Okular::Part *part) const {
PageView *pageView(Okular::Part *part) const
{
return part->m_pageView;
}
};
......@@ -44,7 +47,7 @@ class AnnotationToolBarTest : public QObject, public Okular::PartTest