D10792: Raise annotation window when clicking on annotation
Simone Gaiarin
noreply at phabricator.kde.org
Fri Apr 6 20:47:11 UTC 2018
simgunz added a comment.
Thanks to your suggestions I made some progresses.
My current autotest looks as in the block below.
Problems:
1. If I do not export `AnnotWindow` and call `QVERIFY( part.m_pageView->findChildren<QFrame *>().size() == 1 )` it fails, while calling `QVERIFY( part.m_pageView->findChildren<AnnotWindow *>().size() == 1 )` would succeed.
2. The value returned by ` annot1->boundingRectangle().center(); ` is wrong.
Moreover if I I pass to `mouseMove` a point within the coordinates I specify when I construct the annotation the mouse moves to the wrong position.
In particular the mouse moves to a Y position way below the annotation.
So either I am missing something or there is a bug.
Example where it fails:
annot1->setBoundingRectangle( Okular::NormalizedRect( 0.8, 0.1, 0.85, 0.15 ) );
QTest::mouseMove(part.m_pageView->viewport(), QPoint(width * 0.82, height * 0.13));
For now I am using values find through trial and error.
3. How do I click on the annotation window?
These two commands both fail
QTest::mouseClick(part.m_pageView->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(width * 0.1, height * 0.06)); // The window is under the mouse
QTest::mouseClick(win2, Qt::LeftButton, Qt::NoModifier, QPoint(width * 0.1, height * 0.06)); // win2 is the annotation window widget (under the mouse again)
Isn't it possible to call mouseClick without specifying the target widget, as if I would click manually so that the top widget is the target of the click?
void PartTest::testAnnotWindow()
{
QVariantList dummyArgs;
Okular::Part part(nullptr, nullptr, dummyArgs);
QVERIFY(openDocument(&part, QStringLiteral(KDESRCDIR "data/file2.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);
// wait foqqr pixmap
QTRY_VERIFY(part.m_document->page(0)->hasPixmap(part.m_pageView));
QMetaObject::invokeMethod(part.m_pageView, "slotSetMouseNormal");
QCOMPARE(part.m_document->currentPage(), 0u);
// Create two distinct text annotations
Okular::Annotation * annot1 = new Okular::TextAnnotation();
annot1->setBoundingRectangle( Okular::NormalizedRect( 0.8, 0.1, 0.85, 0.15 ) );
annot1->setContents( QStringLiteral("Annot contents 111111") );
Okular::Annotation *annot2 = new Okular::TextAnnotation();
annot2->setBoundingRectangle( Okular::NormalizedRect( 0.8, 0.3, 0.85, 0.35 ) );
annot2->setContents( QStringLiteral("Annot contents 222222") );
int waitDealy = 1000;
// Add annot1 and annot2 to document
QTest::qWait(waitDealy);
part.m_document->addPageAnnotation( 0, annot1 );
QTest::qWait(waitDealy);
part.m_document->addPageAnnotation( 0, annot2 );
QTest::qWait(waitDealy);
QVERIFY( part.m_document->page( 0 )->annotations().size() == 2 );
// Double click the first annotation to open its window (move mouse for visual feedback)
//NormalizedPoint pt = annot1->boundingRectangle().center();
QTest::mouseMove(part.m_pageView->viewport(), QPoint(width * 0.81, height * 0.06));
//QTest::mouseMove(part.m_pageView->viewport(), QPoint(width * pt.x, height * pt.y));
QTest::qWait(waitDealy);
QTest::mouseDClick(part.m_pageView->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(width * 0.81, height * 0.06));
//QTest::mouseDClick(part.m_pageView->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(width * pt.x, height * pt.y));
QTest::qWait(waitDealy);
QVERIFY( part.m_pageView->findChildren<AnnotWindow *>().size() == 1 );
// Verify that the window is visible
AnnotWindow * win1 = part.m_pageView->findChild<AnnotWindow *>();
QVERIFY( !win1->visibleRegion().isEmpty() );
// Double click the second annotation to open its window (move mouse for visual feedback)
QTest::mouseMove(part.m_pageView->viewport(), QPoint(width * 0.81, height * 0.16));
QTest::qWait(waitDealy);
QTest::mouseDClick(part.m_pageView->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(width * 0.81, height * 0.16));
QTest::qWait(waitDealy);
QVERIFY( part.m_pageView->findChildren<AnnotWindow *>().size() == 2 );
// Verify that the first window is hidden covered by the second, which is visible
QList<AnnotWindow *> lstWin = part.m_pageView->findChildren<AnnotWindow *>();
QFrame * win2;
if (lstWin[0] == win1) {
win2 = lstWin[1];
} else {
win2 = lstWin[0];
}
QVERIFY( win1->visibleRegion().isEmpty() );
QVERIFY( !win2->visibleRegion().isEmpty() );
// Double click the first annotation to raise its window (move mouse for visual feedback)
QTest::mouseMove(part.m_pageView->viewport(), QPoint(width * 0.81, height * 0.06));
QTest::qWait(waitDealy);
QTest::mouseDClick(part.m_pageView->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(width * 0.81, height * 0.06));
QTest::qWait(waitDealy);
// Verify that the second window is hidden covered by the first, which is visible
QVERIFY( !win1->visibleRegion().isEmpty() );
QVERIFY( win2->visibleRegion().isEmpty() );
// Move annotation window 1 to partially show annotation window 2
QTest::qWait(waitDealy);
win1->move(QPoint(width * 0.15, height * 0.1));
QTest::qWait(waitDealy);
// Verify that both windows are partially visible
QVERIFY( !win1->visibleRegion().isEmpty() );
QVERIFY( !win2->visibleRegion().isEmpty() );
// Double click the first annotation to raise its window (move mouse for visual feedback)
QTest::mouseMove(part.m_pageView->viewport(), QPoint(width * 0.1, height * 0.06));
QTest::qWait(1000);
QTest::mouseClick(win2, Qt::LeftButton, Qt::NoModifier, QPoint(width * 0.1, height * 0.06));
QTest::qWait(5000);
}
REPOSITORY
R223 Okular
REVISION DETAIL
https://phabricator.kde.org/D10792
To: simgunz, #okular, aacid
Cc: ngraham, #okular, michaelweghorn, aacid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/okular-devel/attachments/20180406/7aee9d7f/attachment.html>
More information about the Okular-devel
mailing list