From 853d6c70a7a4cf88f8f782a66e31cffc468fb3bb Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Wed, 27 Sep 2006 10:28:03 +0000 Subject: [PATCH] Give a tooltip in the page view for every kind of lnk we support. Also improve a bit the one in the presentation mode, and give a message when the link is a "go to the page x" link. Implements KPDF wish #131361. svn path=/trunk/playground/graphics/okular/; revision=588899 --- core/link.cpp | 2 +- ui/pageview.cpp | 35 +++++++++++++++++++++++++++++++++++ ui/pageview.h | 2 ++ ui/presentationwidget.cpp | 5 +++-- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/core/link.cpp b/core/link.cpp index 1454ce2b4..22ccb655c 100644 --- a/core/link.cpp +++ b/core/link.cpp @@ -27,7 +27,7 @@ QString Link::linkTip() const // Link Tips QString LinkGoto::linkTip() const { - return m_extFileName.isEmpty() ? "" : i18n("Open external file"); + return m_extFileName.isEmpty() ? ( m_vp.pageNumber != -1 ? i18n( "Go to page %1", m_vp.pageNumber ) : "" ) : i18n("Open external file"); } QString LinkExecute::linkTip() const diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 6709e68c0..e3b74d133 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -602,6 +603,40 @@ bool PageView::canUnloadPixmap( int pageNumber ) //END DocumentObserver inherited methods //BEGIN widget events +bool PageView::event( QEvent* e ) +{ + if ( e->type() == QEvent::ToolTip ) + { + QHelpEvent * he = (QHelpEvent*)e; + PageViewItem * pageItem = pickItemOnPoint( he->x() + contentsX(), he->y() + contentsY() ); + const Okular::ObjectRect * rect = 0; + const Okular::Link * link = 0; + if ( pageItem ) + { + double nX = (double)( he->x() + contentsX() - pageItem->geometry().left() ) / (double)pageItem->width(), + nY = (double)( he->y() + contentsY() - pageItem->geometry().top() ) / (double)pageItem->height(); + rect = pageItem->page()->getObjectRect( Okular::ObjectRect::Link, nX, nY, pageItem->width(), pageItem->height() ); + if ( rect ) + link = static_cast< const Okular::Link * >( rect->pointer() ); + } + + if ( link ) + { + // TODO make the rect for the object work + QRect r = rect->boundingRect( pageItem->width(), pageItem->height() ); + r.translate( pageItem->geometry().left(), pageItem->geometry().top() ); + QString tip = link->linkTip(); + if ( !tip.isEmpty() ) + QToolTip::showText( he->globalPos(), tip, this, r ); + } + e->accept(); + return true; + } + else + // do not stop the event + return Q3ScrollView::event( e ); +} + void PageView::viewportPaintEvent( QPaintEvent * pe ) { diff --git a/ui/pageview.h b/ui/pageview.h index a17d39578..d771e8bad 100644 --- a/ui/pageview.h +++ b/ui/pageview.h @@ -93,6 +93,8 @@ class PageView : public Q3ScrollView, public Okular::DocumentObserver void rightClick( const Okular::Page *, const QPoint & ); protected: + bool event( QEvent* ); + // viewport events void viewportPaintEvent( QPaintEvent * pe ); void viewportResizeEvent( QResizeEvent* ); diff --git a/ui/presentationwidget.cpp b/ui/presentationwidget.cpp index bbf4a60cf..4fa6fa66b 100644 --- a/ui/presentationwidget.cpp +++ b/ui/presentationwidget.cpp @@ -191,13 +191,14 @@ bool PresentationWidget::event( QEvent * e ) { QHelpEvent * he = (QHelpEvent*)e; - const Okular::Link * link = getLink( he->x(), he->y(), 0 ); + QRect r; + const Okular::Link * link = getLink( he->x(), he->y(), &r ); if ( link ) { QString tip = link->linkTip(); if ( !tip.isEmpty() ) - QToolTip::showText( he->globalPos(), tip, this ); + QToolTip::showText( he->globalPos(), tip, this, r ); } e->accept(); return true;